/* * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. */ import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport'; import { TurboModuleRegistry } from 'react-native'; export interface ImagePickerResponse { customButton: string; didCancel: boolean; error: string; data: string; uri: string; origURL?: string; isVertical: boolean; width: number; height: number; fileSize: number; type?: string; fileName?: string; path?: string; latitude?: number; longitude?: number; timestamp?: string; originalRotation?: number; } export interface ImagePickerCustomButtonOptions { name?: string; title?: string; } export interface ImagePickerOptions { title?: string; cancelButtonTitle?: string; takePhotoButtonTitle?: string; chooseFromLibraryButtonTitle?: string; chooseWhichLibraryTitle?: string; customButtons?: ImagePickerCustomButtonOptions[]; cameraType?: 'front' | 'back'; mediaType?: 'photo' | 'video' | 'mixed'; maxWidth?: number; maxHeight?: number; quality?: number; videoQuality?: 'low' | 'medium' | 'high'; durationLimit?: number; rotation?: number; allowsEditing?: boolean; noData?: boolean; storageOptions?: ImagePickerStorageOptions; permissionDenied?: ImagePickerPermissionDeniedOptions; tintColor?: number | string; } export interface ImagePickerStorageOptions { skipBackup?: boolean; path?: string; cameraRoll?: boolean; waitUntilSaved?: boolean; } export interface ImagePickerPermissionDeniedOptions { title: string; text: string; reTryTitle: string; okTitle: string; } export interface Spec extends TurboModule { launchCamera( options: ImagePickerOptions, callback: (response: ImagePickerResponse) => void ): void; launchImageLibrary( options: ImagePickerOptions, callback: (response: ImagePickerResponse) => void ): void; showImagePicker: ( options: ImagePickerOptions, callback: (response: ImagePickerResponse) => void ) => void; } const ImagePickerManager = TurboModuleRegistry.get( 'ImagePicker' ); if (!ImagePickerManager) { throw new Error(`react-native-image-picker: NativeModule.ImagePickerManager is null. To fix this issue try these steps: • Run \`react-native link react-native-image-picker\` in the project root. • Rebuild and re-run the app. • If you are using CocoaPods on iOS, run \`pod install\` in the \`ios\` directory and then rebuild and re-run the app. You may also need to re-open Xcode to get the new pods. • Check that the library was linked correctly when you used the link command by running through the manual installation instructions in the README. * If you are getting this error while unit testing you need to mock the native module. Follow the guide in the README. If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-community/react-native-image-picker`); } export default ImagePickerManager;