-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
native.ts
61 lines (55 loc) · 1.46 KB
/
native.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import {NativeModules} from 'react-native';
import {
CameraOptions,
ImageLibraryOptions,
Callback,
ImagePickerResponse,
} from '../types';
const DEFAULT_OPTIONS: ImageLibraryOptions & CameraOptions = {
mediaType: 'photo',
videoQuality: 'high',
quality: 1,
maxWidth: 0,
maxHeight: 0,
includeBase64: false,
cameraType: 'back',
selectionLimit: 1,
saveToPhotos: false,
durationLimit: 0,
includeExtra: false,
presentationStyle: 'pageSheet',
assetRepresentationMode: 'auto',
};
// @ts-ignore We want to check whether __turboModuleProxy exitst, it may not
const isTurboModuleEnabled = global.__turboModuleProxy != null;
const nativeImagePicker = isTurboModuleEnabled ?
require("./NativeImagePicker").default :
NativeModules.ImagePicker;
export function camera(
options: CameraOptions,
callback?: Callback,
): Promise<ImagePickerResponse> {
return new Promise((resolve) => {
nativeImagePicker.launchCamera(
{...DEFAULT_OPTIONS, ...options},
(result: ImagePickerResponse) => {
if (callback) callback(result);
resolve(result);
},
);
});
}
export function imageLibrary(
options: ImageLibraryOptions,
callback?: Callback,
): Promise<ImagePickerResponse> {
return new Promise((resolve) => {
nativeImagePicker.launchImageLibrary(
{...DEFAULT_OPTIONS, ...options},
(result: ImagePickerResponse) => {
if (callback) callback(result);
resolve(result);
},
);
});
}