|
1 | 1 | --- |
2 | 2 | id: apis/ImagePickerIOS |
3 | 3 | title: ImagePickerIOS |
4 | | -wip: true |
| 4 | +officialDoc: https://facebook.github.io/react-native/docs/imagepickerios |
5 | 5 | --- |
6 | 6 |
|
| 7 | +## Note |
| 8 | + |
| 9 | +This API will be removed from React Native as part of the |
| 10 | +[_Lean Core_](https://github.com/facebook/react-native/issues/23313) effort. |
| 11 | +While it has already been moved to a community |
| 12 | +[repo](https://github.com/react-native-community/react-native-image-picker-ios), |
| 13 | +more current packages such as |
| 14 | +[`react-native-image-picker`](https://github.com/react-native-community/react-native-image-picker) |
| 15 | +and [`expo-image-picker`](https://docs.expo.io/versions/latest/sdk/imagepicker/) |
| 16 | +are recommended instead. |
| 17 | + |
| 18 | +--- |
| 19 | + |
| 20 | +Before you may use this API, you need to link the `RCTCameraRoll` library to |
| 21 | +your app and provide a description for your use of the Photo Library. |
| 22 | + |
| 23 | +- you need to add `RCTCameraRoll.xcodeproj` (located in the |
| 24 | + `node_modules/react-native/Libraries/CameraRoll` subdirectory of your app) to |
| 25 | + your project's Libraries tree in XCode, then |
| 26 | +- you need to specify `libRCTCameraRoll.a` under _Link Binary with Libraries_ in |
| 27 | + your app's _Build Phases_ tab. |
| 28 | +- you also need to set the _Privacy - Photo Library Usage Description_ (or |
| 29 | + _NSPhotoLibraryUsageDescription_) key under _Custom iOS Target Properties_ in |
| 30 | + your apps' _Info_ tab. |
| 31 | + |
| 32 | +## Types |
| 33 | + |
| 34 | +### `imageUri` |
| 35 | + |
| 36 | +An alias for the `string` type |
| 37 | + |
7 | 38 | ```reason |
8 | | -type imageUri = string; |
| 39 | +type imageUri = string |
| 40 | +``` |
| 41 | + |
| 42 | +### `cameraDialogConfig` |
| 43 | + |
| 44 | +An abstract type which can be created using the constructor of the same name. |
| 45 | +You may call the constructor as `cameraDialogConfig()` to use the default |
| 46 | +values. |
9 | 47 |
|
10 | | -[@bs.module "react-native"] [@bs.scope "ImagePickerIOS"] |
11 | | -external canUseCamera: (bool => unit) => unit = ""; |
| 48 | +```reason |
| 49 | +cameraDialogConfig: (~videoMode: bool=?, unit) => cameraDialogConfig |
| 50 | +``` |
12 | 51 |
|
13 | | -[@bs.module "react-native"] [@bs.scope "ImagePickerIOS"] |
14 | | -external canRecordVideos: (bool => unit) => unit = ""; |
| 52 | +### `selectDialogConfig` |
| 53 | + |
| 54 | +An abstract type which can be created using the constructor of the same name. |
| 55 | +You may call the constructor as `selectDialogConfig()` to use the default |
| 56 | +values. |
| 57 | + |
| 58 | +```reason |
| 59 | +selectDialogConfig: |
| 60 | + (~showImages: bool=?, ~showVideos: bool=?, unit) => selectDialogConfig |
| 61 | +``` |
15 | 62 |
|
16 | | -type cameraDialogConfig; |
17 | | -[@bs.obj] |
18 | | -external cameraDialogConfig: (~videoMode: bool=?, unit) => cameraDialogConfig = |
19 | | - ""; |
| 63 | +## Methods |
20 | 64 |
|
21 | | -type selectDialogConfig; |
22 | | -[@bs.obj] |
23 | | -external selectDialogConfig: |
24 | | - (~showImages: bool=?, ~showVideos: bool=?, unit) => selectDialogConfig = |
25 | | - ""; |
| 65 | +### `canUseCamera` |
26 | 66 |
|
27 | | -[@bs.module "react-native"] [@bs.scope "ImagePickerIOS"] |
28 | | -external openCameraDialog: |
| 67 | +Method to check whether the app has permissions to use the camera, takes a |
| 68 | +callback of type `bool => unit`. |
| 69 | + |
| 70 | +```reason |
| 71 | +canUseCamera: (bool => unit) => unit |
| 72 | +``` |
| 73 | + |
| 74 | +### `canRecordVideos` |
| 75 | + |
| 76 | +Method to check whether the app has permissions to record videos, takes a |
| 77 | +callback of type `bool => unit`. |
| 78 | + |
| 79 | +```reason |
| 80 | +canRecordVideos: (bool => unit) => unit |
| 81 | +``` |
| 82 | + |
| 83 | +### `openCameraDialog` |
| 84 | + |
| 85 | +Method to request the Camera dialog given a config (of type |
| 86 | +[`cameraDialogConfig`](#cameraDialogConfig)) to specify whether the camera is |
| 87 | +launched in video mode. When an image or video is captured, `onSuccess` callback |
| 88 | +is passed the returned `imageUri`, `height` and `width`; `onError` callback is |
| 89 | +applied otherwise. As`'error` is an abstract type |
| 90 | + |
| 91 | +```reason |
| 92 | +openCameraDialog: |
29 | 93 | ( |
30 | 94 | ~config: cameraDialogConfig, |
31 | | - ~onSuccess: imageUri => unit, |
| 95 | + ~onSuccess: (imageUri, ~height: float, ~width: float, unit) => unit, |
32 | 96 | ~onError: 'error => unit |
33 | 97 | ) => |
34 | | - unit = |
35 | | - ""; |
| 98 | + unit |
| 99 | +``` |
36 | 100 |
|
37 | | -[@bs.module "react-native"] [@bs.scope "ImagePickerIOS"] |
38 | | -external openSelectDialog: |
| 101 | +### `openSelectDialog` |
| 102 | + |
| 103 | +Method to request the Image Gallery given a config (of type |
| 104 | +[`openSelectDialog`](#openSelectDialog)) to specify whether images and/or videos |
| 105 | +should be listed. When an image or video is selected, `onSuccess` callback is |
| 106 | +passed the returned `imageUri`, `height` and `width`; `onError` callback is |
| 107 | +executed otherwise. As`'error` is an abstract type |
| 108 | + |
| 109 | +```reason |
| 110 | +openSelectDialog: |
39 | 111 | ( |
40 | 112 | ~config: selectDialogConfig, |
41 | | - ~onSuccess: imageUri => unit, |
| 113 | + ~onSuccess: (imageUri, ~height: float, ~width: float, unit) => unit, |
42 | 114 | ~onError: 'error => unit |
43 | 115 | ) => |
44 | | - unit = |
45 | | - ""; |
46 | | -
|
| 116 | + unit |
47 | 117 | ``` |
0 commit comments