mirror of
https://github.com/apache/cordova-plugin-camera.git
synced 2025-01-19 03:42:52 +08:00
CB-8780 - Display popover using main thread. Fixes popover slowness (closes #81)
This commit is contained in:
parent
629dbcb712
commit
af36e74d05
@ -130,8 +130,8 @@ static NSString* toBase64(NSData* data) {
|
|||||||
[self.commandDelegate runInBackground:^{
|
[self.commandDelegate runInBackground:^{
|
||||||
|
|
||||||
CDVPictureOptions* pictureOptions = [CDVPictureOptions createFromTakePictureArguments:command];
|
CDVPictureOptions* pictureOptions = [CDVPictureOptions createFromTakePictureArguments:command];
|
||||||
pictureOptions.popoverSupported = [self popoverSupported];
|
pictureOptions.popoverSupported = [weakSelf popoverSupported];
|
||||||
pictureOptions.usesGeolocation = [self usesGeolocation];
|
pictureOptions.usesGeolocation = [weakSelf usesGeolocation];
|
||||||
pictureOptions.cropToSize = NO;
|
pictureOptions.cropToSize = NO;
|
||||||
|
|
||||||
BOOL hasCamera = [UIImagePickerController isSourceTypeAvailable:pictureOptions.sourceType];
|
BOOL hasCamera = [UIImagePickerController isSourceTypeAvailable:pictureOptions.sourceType];
|
||||||
@ -142,13 +142,6 @@ static NSString* toBase64(NSData* data) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a popover is already open, close it; we only want one at a time.
|
|
||||||
if (([[weakSelf pickerController] pickerPopoverController] != nil) && [[[weakSelf pickerController] pickerPopoverController] isPopoverVisible]) {
|
|
||||||
[[[weakSelf pickerController] pickerPopoverController] dismissPopoverAnimated:YES];
|
|
||||||
[[[weakSelf pickerController] pickerPopoverController] setDelegate:nil];
|
|
||||||
[[weakSelf pickerController] setPickerPopoverController:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
CDVCameraPicker* cameraPicker = [CDVCameraPicker createFromPictureOptions:pictureOptions];
|
CDVCameraPicker* cameraPicker = [CDVCameraPicker createFromPictureOptions:pictureOptions];
|
||||||
weakSelf.pickerController = cameraPicker;
|
weakSelf.pickerController = cameraPicker;
|
||||||
|
|
||||||
@ -157,20 +150,27 @@ static NSString* toBase64(NSData* data) {
|
|||||||
// we need to capture this state for memory warnings that dealloc this object
|
// we need to capture this state for memory warnings that dealloc this object
|
||||||
cameraPicker.webView = weakSelf.webView;
|
cameraPicker.webView = weakSelf.webView;
|
||||||
|
|
||||||
if ([weakSelf popoverSupported] && (pictureOptions.sourceType != UIImagePickerControllerSourceTypeCamera)) {
|
// Perform UI operations on the main thread
|
||||||
if (cameraPicker.pickerPopoverController == nil) {
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
cameraPicker.pickerPopoverController = [[NSClassFromString(@"UIPopoverController") alloc] initWithContentViewController:cameraPicker];
|
// If a popover is already open, close it; we only want one at a time.
|
||||||
|
if (([[weakSelf pickerController] pickerPopoverController] != nil) && [[[weakSelf pickerController] pickerPopoverController] isPopoverVisible]) {
|
||||||
|
[[[weakSelf pickerController] pickerPopoverController] dismissPopoverAnimated:YES];
|
||||||
|
[[[weakSelf pickerController] pickerPopoverController] setDelegate:nil];
|
||||||
|
[[weakSelf pickerController] setPickerPopoverController:nil];
|
||||||
}
|
}
|
||||||
[weakSelf displayPopover:pictureOptions.popoverOptions];
|
|
||||||
weakSelf.hasPendingOperation = NO;
|
|
||||||
|
|
||||||
} else {
|
if ([weakSelf popoverSupported] && (pictureOptions.sourceType != UIImagePickerControllerSourceTypeCamera)) {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
if (cameraPicker.pickerPopoverController == nil) {
|
||||||
|
cameraPicker.pickerPopoverController = [[NSClassFromString(@"UIPopoverController") alloc] initWithContentViewController:cameraPicker];
|
||||||
|
}
|
||||||
|
[weakSelf displayPopover:pictureOptions.popoverOptions];
|
||||||
|
weakSelf.hasPendingOperation = NO;
|
||||||
|
} else {
|
||||||
[weakSelf.viewController presentViewController:cameraPicker animated:YES completion:^{
|
[weakSelf.viewController presentViewController:cameraPicker animated:YES completion:^{
|
||||||
weakSelf.hasPendingOperation = NO;
|
weakSelf.hasPendingOperation = NO;
|
||||||
}];
|
}];
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user