mirror of
https://github.com/status-im/react-native-image-crop-picker.git
synced 2025-02-23 19:08:12 +00:00
Merge pull request #248 from calvium/fix_alert_after_openCamera_then
iOS: Wait for viewController to dismiss before resolving or rejecting
This commit is contained in:
commit
df954b07fd
@ -141,8 +141,9 @@ RCT_EXPORT_METHOD(openCamera:(NSDictionary *)options
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
|
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
|
||||||
|
[picker dismissViewControllerAnimated:YES completion:^{
|
||||||
self.reject(ERROR_PICKER_CANCEL_KEY, ERROR_PICKER_CANCEL_MSG, nil);
|
self.reject(ERROR_PICKER_CANCEL_KEY, ERROR_PICKER_CANCEL_MSG, nil);
|
||||||
[picker dismissViewControllerAnimated:YES completion:NULL];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString*) getTmpDirectory {
|
- (NSString*) getTmpDirectory {
|
||||||
@ -396,10 +397,11 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
[lock lock];
|
[lock lock];
|
||||||
|
|
||||||
if (video == nil) {
|
if (video == nil) {
|
||||||
self.reject(ERROR_CANNOT_PROCESS_VIDEO_KEY, ERROR_CANNOT_PROCESS_VIDEO_MSG, nil);
|
|
||||||
[indicatorView stopAnimating];
|
[indicatorView stopAnimating];
|
||||||
[overlayView removeFromSuperview];
|
[overlayView removeFromSuperview];
|
||||||
[imagePickerController dismissViewControllerAnimated:YES completion:nil];
|
[imagePickerController dismissViewControllerAnimated:YES completion:^{
|
||||||
|
self.reject(ERROR_CANNOT_PROCESS_VIDEO_KEY, ERROR_CANNOT_PROCESS_VIDEO_MSG, nil);
|
||||||
|
}];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,10 +410,11 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
[lock unlock];
|
[lock unlock];
|
||||||
|
|
||||||
if (processed == [assets count]) {
|
if (processed == [assets count]) {
|
||||||
self.resolve(selections);
|
|
||||||
[indicatorView stopAnimating];
|
[indicatorView stopAnimating];
|
||||||
[overlayView removeFromSuperview];
|
[overlayView removeFromSuperview];
|
||||||
[imagePickerController dismissViewControllerAnimated:YES completion:nil];
|
[imagePickerController dismissViewControllerAnimated:YES completion:^{
|
||||||
|
self.resolve(selections);
|
||||||
|
}];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -429,10 +432,11 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
NSString *filePath = [self persistFile:imageResult.data];
|
NSString *filePath = [self persistFile:imageResult.data];
|
||||||
|
|
||||||
if (filePath == nil) {
|
if (filePath == nil) {
|
||||||
self.reject(ERROR_CANNOT_SAVE_IMAGE_KEY, ERROR_CANNOT_SAVE_IMAGE_MSG, nil);
|
|
||||||
[indicatorView stopAnimating];
|
[indicatorView stopAnimating];
|
||||||
[overlayView removeFromSuperview];
|
[overlayView removeFromSuperview];
|
||||||
[imagePickerController dismissViewControllerAnimated:YES completion:nil];
|
[imagePickerController dismissViewControllerAnimated:YES completion:^{
|
||||||
|
self.reject(ERROR_CANNOT_SAVE_IMAGE_KEY, ERROR_CANNOT_SAVE_IMAGE_MSG, nil);
|
||||||
|
}];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -447,10 +451,12 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
[lock unlock];
|
[lock unlock];
|
||||||
|
|
||||||
if (processed == [assets count]) {
|
if (processed == [assets count]) {
|
||||||
self.resolve(selections);
|
|
||||||
[indicatorView stopAnimating];
|
[indicatorView stopAnimating];
|
||||||
[overlayView removeFromSuperview];
|
[overlayView removeFromSuperview];
|
||||||
[imagePickerController dismissViewControllerAnimated:YES completion:nil];
|
[imagePickerController dismissViewControllerAnimated:YES completion:^{
|
||||||
|
self.resolve(selections);
|
||||||
|
}];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -465,16 +471,15 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
if (phAsset.mediaType == PHAssetMediaTypeVideo) {
|
if (phAsset.mediaType == PHAssetMediaTypeVideo) {
|
||||||
[self getVideoAsset:phAsset completion:^(NSDictionary* video) {
|
[self getVideoAsset:phAsset completion:^(NSDictionary* video) {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[indicatorView stopAnimating];
|
||||||
|
[overlayView removeFromSuperview];
|
||||||
|
[imagePickerController dismissViewControllerAnimated:YES completion:^{
|
||||||
if (video != nil) {
|
if (video != nil) {
|
||||||
self.resolve(video);
|
self.resolve(video);
|
||||||
} else {
|
} else {
|
||||||
self.reject(ERROR_CANNOT_PROCESS_VIDEO_KEY, ERROR_CANNOT_PROCESS_VIDEO_MSG, nil);
|
self.reject(ERROR_CANNOT_PROCESS_VIDEO_KEY, ERROR_CANNOT_PROCESS_VIDEO_MSG, nil);
|
||||||
}
|
}
|
||||||
|
}];
|
||||||
|
|
||||||
[indicatorView stopAnimating];
|
|
||||||
[overlayView removeFromSuperview];
|
|
||||||
[imagePickerController dismissViewControllerAnimated:YES completion:nil];
|
|
||||||
});
|
});
|
||||||
}];
|
}];
|
||||||
} else {
|
} else {
|
||||||
@ -496,8 +501,9 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)qb_imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController {
|
- (void)qb_imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController {
|
||||||
|
[imagePickerController dismissViewControllerAnimated:YES completion:^{
|
||||||
self.reject(ERROR_PICKER_CANCEL_KEY, ERROR_PICKER_CANCEL_MSG, nil);
|
self.reject(ERROR_PICKER_CANCEL_KEY, ERROR_PICKER_CANCEL_MSG, nil);
|
||||||
[imagePickerController dismissViewControllerAnimated:YES completion:nil];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
// when user selected single image, with camera or from photo gallery,
|
// when user selected single image, with camera or from photo gallery,
|
||||||
@ -506,8 +512,9 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
- (void) processSingleImagePick:(UIImage*)image withViewController:(UIViewController*)viewController {
|
- (void) processSingleImagePick:(UIImage*)image withViewController:(UIViewController*)viewController {
|
||||||
|
|
||||||
if (image == nil) {
|
if (image == nil) {
|
||||||
|
[viewController dismissViewControllerAnimated:YES completion:^{
|
||||||
self.reject(ERROR_PICKER_NO_DATA_KEY, ERROR_PICKER_NO_DATA_MSG, nil);
|
self.reject(ERROR_PICKER_NO_DATA_KEY, ERROR_PICKER_NO_DATA_MSG, nil);
|
||||||
[viewController dismissViewControllerAnimated:YES completion:nil];
|
}];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -517,19 +524,22 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
ImageResult *imageResult = [self.compression compressImage:image withOptions:self.options];
|
ImageResult *imageResult = [self.compression compressImage:image withOptions:self.options];
|
||||||
NSString *filePath = [self persistFile:imageResult.data];
|
NSString *filePath = [self persistFile:imageResult.data];
|
||||||
if (filePath == nil) {
|
if (filePath == nil) {
|
||||||
|
[viewController dismissViewControllerAnimated:YES completion:^{
|
||||||
self.reject(ERROR_CANNOT_SAVE_IMAGE_KEY, ERROR_CANNOT_SAVE_IMAGE_MSG, nil);
|
self.reject(ERROR_CANNOT_SAVE_IMAGE_KEY, ERROR_CANNOT_SAVE_IMAGE_MSG, nil);
|
||||||
[viewController dismissViewControllerAnimated:YES completion:nil];
|
}];
|
||||||
return;
|
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:^{
|
||||||
self.resolve([self createAttachmentResponse:filePath
|
self.resolve([self createAttachmentResponse:filePath
|
||||||
withWidth:imageResult.width
|
withWidth:imageResult.width
|
||||||
withHeight:imageResult.height
|
withHeight:imageResult.height
|
||||||
withMime:imageResult.mime
|
withMime:imageResult.mime
|
||||||
withSize:[NSNumber numberWithUnsignedInteger:imageResult.data.length]
|
withSize:[NSNumber numberWithUnsignedInteger:imageResult.data.length]
|
||||||
withData:[[self.options objectForKey:@"includeBase64"] boolValue] ? [imageResult.data base64EncodedStringWithOptions:0] : [NSNull null]]);
|
withData:[[self.options objectForKey:@"includeBase64"] boolValue] ? [imageResult.data base64EncodedStringWithOptions:0] : [NSNull null]]);
|
||||||
|
}];
|
||||||
[viewController dismissViewControllerAnimated:YES completion:nil];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -589,18 +599,19 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
// Crop image has been canceled.
|
// Crop image has been canceled.
|
||||||
- (void)imageCropViewControllerDidCancelCrop:
|
- (void)imageCropViewControllerDidCancelCrop:
|
||||||
(RSKImageCropViewController *)controller {
|
(RSKImageCropViewController *)controller {
|
||||||
|
[self dismissCropper:controller completion:^{
|
||||||
self.reject(ERROR_PICKER_CANCEL_KEY, ERROR_PICKER_CANCEL_MSG, nil);
|
self.reject(ERROR_PICKER_CANCEL_KEY, ERROR_PICKER_CANCEL_MSG, nil);
|
||||||
[self dismissCropper:controller];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) dismissCropper:(RSKImageCropViewController*) controller {
|
- (void) dismissCropper:(RSKImageCropViewController*) controller completion:(void (^)())completion {
|
||||||
//We've presented the cropper on top of the image picker as to not have a double modal animation.
|
//We've presented the cropper on top of the image picker as to not have a double modal animation.
|
||||||
//Thus, we need to dismiss the image picker view controller to dismiss the whole stack.
|
//Thus, we need to dismiss the image picker view controller to dismiss the whole stack.
|
||||||
if (!self.cropOnly) {
|
if (!self.cropOnly) {
|
||||||
UIViewController *topViewController = controller.presentingViewController.presentingViewController;
|
UIViewController *topViewController = controller.presentingViewController.presentingViewController;
|
||||||
[topViewController dismissViewControllerAnimated:YES completion:nil];
|
[topViewController dismissViewControllerAnimated:YES completion:completion];
|
||||||
} else {
|
} else {
|
||||||
[controller dismissViewControllerAnimated:YES completion:nil];
|
[controller dismissViewControllerAnimated:YES completion:completion];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,19 +628,20 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
|
|
||||||
NSString *filePath = [self persistFile:imageResult.data];
|
NSString *filePath = [self persistFile:imageResult.data];
|
||||||
if (filePath == nil) {
|
if (filePath == nil) {
|
||||||
|
[self dismissCropper:controller completion:^{
|
||||||
self.reject(ERROR_CANNOT_SAVE_IMAGE_KEY, ERROR_CANNOT_SAVE_IMAGE_MSG, nil);
|
self.reject(ERROR_CANNOT_SAVE_IMAGE_KEY, ERROR_CANNOT_SAVE_IMAGE_MSG, nil);
|
||||||
[self dismissCropper:controller];
|
}];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[self dismissCropper:controller completion:^{
|
||||||
self.resolve([self createAttachmentResponse:filePath
|
self.resolve([self createAttachmentResponse:filePath
|
||||||
withWidth:imageResult.width
|
withWidth:imageResult.width
|
||||||
withHeight:imageResult.height
|
withHeight:imageResult.height
|
||||||
withMime:imageResult.mime
|
withMime:imageResult.mime
|
||||||
withSize:[NSNumber numberWithUnsignedInteger:imageResult.data.length]
|
withSize:[NSNumber numberWithUnsignedInteger:imageResult.data.length]
|
||||||
withData:[[self.options objectForKey:@"includeBase64"] boolValue] ? [imageResult.data base64EncodedStringWithOptions:0] : [NSNull null]]);
|
withData:[[self.options objectForKey:@"includeBase64"] boolValue] ? [imageResult.data base64EncodedStringWithOptions:0] : [NSNull null]]);
|
||||||
|
}];
|
||||||
[self dismissCropper:controller];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// at the moment it is not possible to upload image by reading PHAsset
|
// at the moment it is not possible to upload image by reading PHAsset
|
||||||
|
Loading…
x
Reference in New Issue
Block a user