-
Notifications
You must be signed in to change notification settings - Fork 24.2k
/
ImagePickerIOS.js
103 lines (92 loc) · 3.1 KB
/
ImagePickerIOS.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow strict-local
*/
import NativeImagePickerIOS from './NativeImagePickerIOS';
import invariant from 'invariant';
const ImagePickerIOS = {
canRecordVideos: function (callback: (result: boolean) => void): void {
invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
return NativeImagePickerIOS.canRecordVideos(callback);
},
canUseCamera: function (callback: (result: boolean) => void): void {
invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
return NativeImagePickerIOS.canUseCamera(callback);
},
openCameraDialog: function (
config: $ReadOnly<{|
unmirrorFrontFacingCamera?: boolean,
videoMode?: boolean,
|}>,
successCallback: (imageURL: string, height: number, width: number) => void,
cancelCallback: () => void,
): void {
invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
var newConfig = {
videoMode: true,
unmirrorFrontFacingCamera: false,
};
if (config.videoMode != null) {
newConfig.videoMode = config.videoMode;
}
if (config.unmirrorFrontFacingCamera != null) {
newConfig.unmirrorFrontFacingCamera = config.unmirrorFrontFacingCamera;
}
return NativeImagePickerIOS.openCameraDialog(
newConfig,
successCallback,
cancelCallback,
);
},
openSelectDialog: function (
config: $ReadOnly<{|
showImages?: boolean,
showVideos?: boolean,
|}>,
successCallback: (imageURL: string, height: number, width: number) => void,
cancelCallback: () => void,
): void {
invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
var newConfig = {
showImages: true,
showVideos: false,
};
if (config.showImages != null) {
newConfig.showImages = config.showImages;
}
if (config.showVideos != null) {
newConfig.showVideos = config.showVideos;
}
return NativeImagePickerIOS.openSelectDialog(
newConfig,
successCallback,
cancelCallback,
);
},
/**
* In iOS 13, the video URLs returned by the Image Picker are invalidated when
* the picker is dismissed, unless reference to it is held. This API allows
* the application to signal when it's finished with the video so that the
* reference can be cleaned up.
* It is safe to call this method for urlsthat aren't video URLs;
* it will be a no-op.
*/
removePendingVideo: function (url: string): void {
invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
NativeImagePickerIOS.removePendingVideo(url);
},
/**
* WARNING: In most cases, removePendingVideo should be used instead because
* clearAllPendingVideos could clear out pending videos made by other callers.
*/
clearAllPendingVideos: function (): void {
invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
NativeImagePickerIOS.clearAllPendingVideos();
},
};
module.exports = ImagePickerIOS;