1 |
|
2 |
|
3 | import { NativeModules } from 'react-native';
|
4 |
|
5 | const { ExponentImagePicker } = NativeModules;
|
6 |
|
7 | const MEDIA_TYPE_OPTIONS = {
|
8 | All: 'All',
|
9 | Videos: 'Videos',
|
10 | Images: 'Images',
|
11 | };
|
12 |
|
13 | type ImageInfo = {|
|
14 | uri: string,
|
15 | width: number,
|
16 | height: number,
|
17 | |};
|
18 |
|
19 | type ImageResult = {| cancelled: true |} | ({| cancelled: false |} & ImageInfo);
|
20 |
|
21 | type ImageLibraryOptions = {
|
22 | allowsEditing?: boolean,
|
23 | aspect?: [number, number],
|
24 | quality?: number,
|
25 | mediaTypes?: $Keys<typeof MEDIA_TYPE_OPTIONS>,
|
26 | };
|
27 |
|
28 | export async function launchImageLibraryAsync(
|
29 | options?: ImageLibraryOptions = {}
|
30 | ): Promise<ImageResult> {
|
31 | return ExponentImagePicker.launchImageLibraryAsync(options);
|
32 | }
|
33 |
|
34 | type CameraOptions = {
|
35 | allowsEditing?: boolean,
|
36 | aspect?: [number, number],
|
37 | quality?: number,
|
38 | };
|
39 |
|
40 | export async function launchCameraAsync(options?: CameraOptions = {}): Promise<ImageResult> {
|
41 | return ExponentImagePicker.launchCameraAsync(options);
|
42 | }
|
43 |
|
44 | export const MediaTypeOptions: Object = MEDIA_TYPE_OPTIONS;
|