Skip to content

Commit 6a8681e

Browse files
authored
[image_picker] Fix pickImage not returning on iOS when dismissing the PHPicker view by swiping down. (flutter#4228)
1 parent b1fe191 commit 6a8681e

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

packages/image_picker/image_picker/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 0.8.3+3
22

3+
* Fix pickImage not returning a value on iOS when dismissing PHPicker sheet by swiping.
34
* Updated Android lint settings.
45

56
## 0.8.3+2

packages/image_picker/image_picker/ios/Classes/FLTImagePickerPlugin.m

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
@interface FLTImagePickerPlugin () <UINavigationControllerDelegate,
2020
UIImagePickerControllerDelegate,
21-
PHPickerViewControllerDelegate>
21+
PHPickerViewControllerDelegate,
22+
UIAdaptivePresentationControllerDelegate>
2223

2324
@property(copy, nonatomic) FlutterResult result;
2425

@@ -92,6 +93,7 @@ - (void)pickImageWithPHPicker:(int)maxImagesAllowed API_AVAILABLE(ios(14)) {
9293

9394
_pickerViewController = [[PHPickerViewController alloc] initWithConfiguration:config];
9495
_pickerViewController.delegate = self;
96+
_pickerViewController.presentationController.delegate = self;
9597

9698
self.maxImagesAllowed = maxImagesAllowed;
9799

@@ -373,18 +375,28 @@ - (NSNumber *)getDesiredImageQuality:(NSNumber *)imageQuality {
373375
return imageQuality;
374376
}
375377

378+
- (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController {
379+
if (self.result != nil) {
380+
self.result(nil);
381+
self.result = nil;
382+
self->_arguments = nil;
383+
}
384+
}
385+
376386
- (void)picker:(PHPickerViewController *)picker
377387
didFinishPicking:(NSArray<PHPickerResult *> *)results API_AVAILABLE(ios(14)) {
378388
[picker dismissViewControllerAnimated:YES completion:nil];
379-
dispatch_queue_t backgroundQueue =
380-
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0);
381-
dispatch_async(backgroundQueue, ^{
382-
if (results.count == 0) {
389+
if (results.count == 0) {
390+
if (self.result != nil) {
383391
self.result(nil);
384392
self.result = nil;
385393
self->_arguments = nil;
386-
return;
387394
}
395+
return;
396+
}
397+
dispatch_queue_t backgroundQueue =
398+
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0);
399+
dispatch_async(backgroundQueue, ^{
388400
NSNumber *maxWidth = [self->_arguments objectForKey:@"maxWidth"];
389401
NSNumber *maxHeight = [self->_arguments objectForKey:@"maxHeight"];
390402
NSNumber *imageQuality = [self->_arguments objectForKey:@"imageQuality"];

packages/image_picker/image_picker/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for selecting images from the Android and iOS image
33
library, and taking new pictures with the camera.
44
repository: https://github.com/flutter/plugins/tree/master/packages/image_picker/image_picker
55
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
6-
version: 0.8.3+2
6+
version: 0.8.3+3
77

88
environment:
99
sdk: ">=2.12.0 <3.0.0"

0 commit comments

Comments
 (0)