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