configurable waiting for animation completion

This commit is contained in:
Ivan Pusic 2017-03-03 02:26:25 +01:00
parent d9de140be2
commit f340f358e9
5 changed files with 49 additions and 34 deletions

View File

@ -81,6 +81,7 @@ ImagePicker.clean().then(() => {
| cropperTintColor (android only) | string (default `"#424242"`) | When cropping image, determines the color of Toolbar and other UX elements. Uses UCrop's `setToolbarColor, setActiveWidgetColor, and setStatusBarColor` with color specified. |
| cropperCircleOverlay | bool (default false) | Enable or disable circular cropping mask. |
| maxFiles (ios only) | number (default 5) | Max number of files to select when using `multiple` option |
| waitAnimationEnd (ios only) | bool (default true) | Promise will resolve/reject once ViewController `completion` block is called |
| smartAlbums (ios only) | array (default ['UserLibrary', 'PhotoStream', 'Panoramas', 'Videos', 'Bursts']) | List of smart albums to choose from |
| useFrontCamera (ios only) | bool (default false) | Whether to default to the front/'selfie' camera when opened |
| compressVideoPreset (ios only) | string (default MediumQuality) | Choose which preset will be used for video compression |

View File

@ -128,7 +128,8 @@ export default class App extends Component {
pickMultiple() {
ImagePicker.openPicker({
multiple: true
multiple: true,
waitAnimationEnd: false
}).then(images => {
this.setState({
image: null,

View File

@ -7,7 +7,7 @@
},
"dependencies": {
"react": "^15.4.1",
"react-native": "^0.40.0",
"react-native": "^0.42.0",
"react-native-image-crop-picker": "../",
"react-native-video": "git://github.com/react-native-community/react-native-video.git"
}

View File

@ -54,6 +54,7 @@ RCT_EXPORT_MODULE();
@"compressVideo": @YES,
@"maxFiles": @5,
@"width": @200,
@"waitAnimationEnd": @YES,
@"height": @200,
@"useFrontCamera": @NO,
@"compressImageQuality": @1,
@ -66,6 +67,18 @@ RCT_EXPORT_MODULE();
return self;
}
- (void (^ __nullable)(void))waitAnimationEnd:(void (^ __nullable)(void))completion {
if ([[self.options objectForKey:@"waitAnimationEnd"] boolValue]) {
return completion;
}
if (completion != nil) {
completion();
}
return nil;
}
- (void)checkCameraPermissions:(void(^)(BOOL granted))callback
{
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
@ -141,9 +154,9 @@ RCT_EXPORT_METHOD(openCamera:(NSDictionary *)options
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:^{
[picker dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
self.reject(ERROR_PICKER_CANCEL_KEY, ERROR_PICKER_CANCEL_MSG, nil);
}];
}]];
}
- (NSString*) getTmpDirectory {
@ -399,9 +412,9 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
if (video == nil) {
[indicatorView stopAnimating];
[overlayView removeFromSuperview];
[imagePickerController dismissViewControllerAnimated:YES completion:^{
[imagePickerController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
self.reject(ERROR_CANNOT_PROCESS_VIDEO_KEY, ERROR_CANNOT_PROCESS_VIDEO_MSG, nil);
}];
}]];
return;
}
@ -412,9 +425,9 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
if (processed == [assets count]) {
[indicatorView stopAnimating];
[overlayView removeFromSuperview];
[imagePickerController dismissViewControllerAnimated:YES completion:^{
[imagePickerController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
self.resolve(selections);
}];
}]];
return;
}
});
@ -434,9 +447,9 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
if (filePath == nil) {
[indicatorView stopAnimating];
[overlayView removeFromSuperview];
[imagePickerController dismissViewControllerAnimated:YES completion:^{
[imagePickerController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
self.reject(ERROR_CANNOT_SAVE_IMAGE_KEY, ERROR_CANNOT_SAVE_IMAGE_MSG, nil);
}];
}]];
return;
}
@ -454,9 +467,9 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
[indicatorView stopAnimating];
[overlayView removeFromSuperview];
[imagePickerController dismissViewControllerAnimated:YES completion:^{
[imagePickerController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
self.resolve(selections);
}];
}]];
return;
}
});
@ -473,13 +486,13 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
dispatch_async(dispatch_get_main_queue(), ^{
[indicatorView stopAnimating];
[overlayView removeFromSuperview];
[imagePickerController dismissViewControllerAnimated:YES completion:^{
[imagePickerController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
if (video != nil) {
self.resolve(video);
} else {
self.reject(ERROR_CANNOT_PROCESS_VIDEO_KEY, ERROR_CANNOT_PROCESS_VIDEO_MSG, nil);
}
}];
}]];
});
}];
} else {
@ -501,9 +514,9 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
}
- (void)qb_imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController {
[imagePickerController dismissViewControllerAnimated:YES completion:^{
[imagePickerController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
self.reject(ERROR_PICKER_CANCEL_KEY, ERROR_PICKER_CANCEL_MSG, nil);
}];
}]];
}
// when user selected single image, with camera or from photo gallery,
@ -512,9 +525,9 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
- (void) processSingleImagePick:(UIImage*)image withViewController:(UIViewController*)viewController {
if (image == nil) {
[viewController dismissViewControllerAnimated:YES completion:^{
[viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
self.reject(ERROR_PICKER_NO_DATA_KEY, ERROR_PICKER_NO_DATA_MSG, nil);
}];
}]];
return;
}
@ -524,22 +537,22 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
ImageResult *imageResult = [self.compression compressImage:image withOptions:self.options];
NSString *filePath = [self persistFile:imageResult.data];
if (filePath == nil) {
[viewController dismissViewControllerAnimated:YES completion:^{
[viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
self.reject(ERROR_CANNOT_SAVE_IMAGE_KEY, ERROR_CANNOT_SAVE_IMAGE_MSG, nil);
}];
}]];
return;
}
// Wait for viewController to dismiss before resolving, or we lose the ability to display
// Alert.alert in the .then() handler.
[viewController dismissViewControllerAnimated:YES completion:^{
[viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
self.resolve([self createAttachmentResponse:filePath
withWidth:imageResult.width
withHeight:imageResult.height
withMime:imageResult.mime
withSize:[NSNumber numberWithUnsignedInteger:imageResult.data.length]
withData:[[self.options objectForKey:@"includeBase64"] boolValue] ? [imageResult.data base64EncodedStringWithOptions:0] : [NSNull null]]);
}];
withWidth:imageResult.width
withHeight:imageResult.height
withMime:imageResult.mime
withSize:[NSNumber numberWithUnsignedInteger:imageResult.data.length]
withData:[[self.options objectForKey:@"includeBase64"] boolValue] ? [imageResult.data base64EncodedStringWithOptions:0] : [NSNull null]]);
}]];
}
}
@ -599,9 +612,9 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
// Crop image has been canceled.
- (void)imageCropViewControllerDidCancelCrop:
(RSKImageCropViewController *)controller {
[self dismissCropper:controller completion:^{
[self dismissCropper:controller completion:[self waitAnimationEnd:^{
self.reject(ERROR_PICKER_CANCEL_KEY, ERROR_PICKER_CANCEL_MSG, nil);
}];
}]];
}
- (void) dismissCropper:(RSKImageCropViewController*) controller completion:(void (^)())completion {
@ -628,20 +641,20 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
NSString *filePath = [self persistFile:imageResult.data];
if (filePath == nil) {
[self dismissCropper:controller completion:^{
[self dismissCropper:controller completion:[self waitAnimationEnd:^{
self.reject(ERROR_CANNOT_SAVE_IMAGE_KEY, ERROR_CANNOT_SAVE_IMAGE_MSG, nil);
}];
}]];
return;
}
[self dismissCropper:controller completion:^{
[self dismissCropper:controller completion:[self waitAnimationEnd:^{
self.resolve([self createAttachmentResponse:filePath
withWidth:imageResult.width
withHeight:imageResult.height
withMime:imageResult.mime
withSize:[NSNumber numberWithUnsignedInteger:imageResult.data.length]
withData:[[self.options objectForKey:@"includeBase64"] boolValue] ? [imageResult.data base64EncodedStringWithOptions:0] : [NSNull null]]);
}];
}]];
}
// at the moment it is not possible to upload image by reading PHAsset

View File

@ -1,6 +1,6 @@
{
"name": "react-native-image-crop-picker",
"version": "0.12.5",
"version": "0.12.6",
"description": "Select single or multiple images, with croping option",
"main": "index.js",
"scripts": {