Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 13:06:47 +03:00
|
|
|
/**
|
2018-09-12 01:27:47 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 13:06:47 +03:00
|
|
|
*
|
2018-02-17 05:24:55 +03:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 13:06:47 +03:00
|
|
|
*
|
2018-05-11 05:06:46 +03:00
|
|
|
* @format
|
2019-12-06 02:58:55 +03:00
|
|
|
* @flow strict-local
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 13:06:47 +03:00
|
|
|
*/
|
2018-05-11 05:06:46 +03:00
|
|
|
|
2019-07-19 22:02:19 +03:00
|
|
|
import NativeImagePickerIOS from './NativeImagePickerIOS';
|
|
|
|
import invariant from 'invariant';
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 13:06:47 +03:00
|
|
|
|
2018-05-11 01:44:52 +03:00
|
|
|
const ImagePickerIOS = {
|
2021-11-03 08:10:46 +03:00
|
|
|
canRecordVideos: function (callback: (result: boolean) => void): void {
|
2019-07-19 22:02:19 +03:00
|
|
|
invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
|
|
|
|
return NativeImagePickerIOS.canRecordVideos(callback);
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 13:06:47 +03:00
|
|
|
},
|
2021-11-03 08:10:46 +03:00
|
|
|
canUseCamera: function (callback: (result: boolean) => void): void {
|
2019-07-19 22:02:19 +03:00
|
|
|
invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
|
|
|
|
return NativeImagePickerIOS.canUseCamera(callback);
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 13:06:47 +03:00
|
|
|
},
|
2021-11-03 08:10:46 +03:00
|
|
|
openCameraDialog: function (
|
2019-07-19 22:02:19 +03:00
|
|
|
config: $ReadOnly<{|
|
|
|
|
unmirrorFrontFacingCamera?: boolean,
|
|
|
|
videoMode?: boolean,
|
|
|
|
|}>,
|
|
|
|
successCallback: (imageURL: string, height: number, width: number) => void,
|
|
|
|
cancelCallback: () => void,
|
2019-08-09 20:06:53 +03:00
|
|
|
): void {
|
2019-07-19 22:02:19 +03:00
|
|
|
invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
|
|
|
|
|
|
|
|
var newConfig = {
|
|
|
|
videoMode: true,
|
|
|
|
unmirrorFrontFacingCamera: false,
|
2015-12-01 03:20:41 +03:00
|
|
|
};
|
2019-07-19 22:02:19 +03:00
|
|
|
|
|
|
|
if (config.videoMode != null) {
|
|
|
|
newConfig.videoMode = config.videoMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config.unmirrorFrontFacingCamera != null) {
|
|
|
|
newConfig.unmirrorFrontFacingCamera = config.unmirrorFrontFacingCamera;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NativeImagePickerIOS.openCameraDialog(
|
|
|
|
newConfig,
|
2018-05-11 05:06:46 +03:00
|
|
|
successCallback,
|
|
|
|
cancelCallback,
|
|
|
|
);
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 13:06:47 +03:00
|
|
|
},
|
2021-11-03 08:10:46 +03:00
|
|
|
openSelectDialog: function (
|
2019-07-19 22:02:19 +03:00
|
|
|
config: $ReadOnly<{|
|
|
|
|
showImages?: boolean,
|
|
|
|
showVideos?: boolean,
|
|
|
|
|}>,
|
|
|
|
successCallback: (imageURL: string, height: number, width: number) => void,
|
|
|
|
cancelCallback: () => void,
|
2019-08-09 20:06:53 +03:00
|
|
|
): void {
|
2019-07-19 22:02:19 +03:00
|
|
|
invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
|
|
|
|
|
|
|
|
var newConfig = {
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 13:06:47 +03:00
|
|
|
showImages: true,
|
|
|
|
showVideos: false,
|
2015-12-01 03:20:41 +03:00
|
|
|
};
|
2019-07-19 22:02:19 +03:00
|
|
|
|
|
|
|
if (config.showImages != null) {
|
|
|
|
newConfig.showImages = config.showImages;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config.showVideos != null) {
|
|
|
|
newConfig.showVideos = config.showVideos;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NativeImagePickerIOS.openSelectDialog(
|
|
|
|
newConfig,
|
2018-05-11 05:06:46 +03:00
|
|
|
successCallback,
|
|
|
|
cancelCallback,
|
|
|
|
);
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 13:06:47 +03:00
|
|
|
},
|
2019-10-12 02:31:17 +03:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2021-11-03 08:10:46 +03:00
|
|
|
removePendingVideo: function (url: string): void {
|
2019-10-12 02:31:17 +03:00
|
|
|
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.
|
|
|
|
*/
|
2021-11-03 08:10:46 +03:00
|
|
|
clearAllPendingVideos: function (): void {
|
2019-10-12 02:31:17 +03:00
|
|
|
invariant(NativeImagePickerIOS, 'ImagePickerIOS is not available');
|
|
|
|
NativeImagePickerIOS.clearAllPendingVideos();
|
|
|
|
},
|
Add support for selecting media from library
Summary:
This PR adds support for UIImagePickerController to allow selecting a photo / video from the users camera roll.
![ios simulator screen shot jun 14 2015 4 50 03 pm](https://cloud.githubusercontent.com/assets/688326/8147758/ae6dc8d4-12b6-11e5-80f0-2bcaa964a5d8.png)
Example:
Selecting something from camera roll
```
ImagePickerIOS.openSelectDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
showImages: true, // defaults to true
showVideos: false // defaults to false
}, function (data) {
console.info("Got a callback!");
console.info(data); // file URL as in assets-library://asset/asset.JPG?id=E2741A73-D185-44B6-A2E6-2D55F69CD088&ext=JPG
}, function() {
console.info("Cancelled");
});
```
Using camera
```
ImagePickerIOS.openCameraDialog(<config>, <successCallback>, <cancelCallback>);
ImagePickerIOS.openSelectDialog({
videoMode: false, // defaults to true, whether to record videos instead
}, function (data) {
console.info("Got
Closes https://github.com/facebook/react-native/pull/1620
Github Author: David Mohl <me@dave.cx>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-06-22 13:06:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ImagePickerIOS;
|