-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[image_picker] Transparent pressing on iOS 26 (#173453) #10533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,8 @@ @interface FLTImagePickerPlugin () | |
| /// the array. | ||
| @property(strong, nonatomic) | ||
| NSMutableArray<UIImagePickerController *> *imagePickerControllerOverrides; | ||
| @property(strong, nonatomic) UIWindow *interactionBlockerWindow; | ||
| @property(weak, nonatomic) UIWindow *previousKeyWindow; | ||
|
|
||
| @end | ||
|
|
||
|
|
@@ -323,6 +325,7 @@ - (void)showCamera:(UIImagePickerControllerCameraDevice)device | |
| [UIImagePickerController isCameraDeviceAvailable:device]) { | ||
| imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; | ||
| imagePickerController.cameraDevice = device; | ||
| [self addInteractionBlocker]; | ||
| [[self viewControllerWithWindow:nil] presentViewController:imagePickerController | ||
| animated:YES | ||
| completion:nil]; | ||
|
|
@@ -532,7 +535,11 @@ - (void)picker:(PHPickerViewController *)picker | |
| - (void)imagePickerController:(UIImagePickerController *)picker | ||
| didFinishPickingMediaWithInfo:(NSDictionary<NSString *, id> *)info { | ||
| NSURL *videoURL = info[UIImagePickerControllerMediaURL]; | ||
| [picker dismissViewControllerAnimated:YES completion:nil]; | ||
| __weak typeof(self) weakSelf = self; | ||
| [picker dismissViewControllerAnimated:YES | ||
| completion:^{ | ||
| [weakSelf removeInteractionBlocker]; | ||
| }]; | ||
| // The method dismissViewControllerAnimated does not immediately prevent | ||
| // further didFinishPickingMediaWithInfo invocations. A nil check is necessary | ||
| // to prevent below code to be unwantly executed multiple times and cause a | ||
|
|
@@ -618,7 +625,11 @@ - (void)imagePickerController:(UIImagePickerController *)picker | |
| } | ||
|
|
||
| - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { | ||
| [picker dismissViewControllerAnimated:YES completion:nil]; | ||
| __weak typeof(self) weakSelf = self; | ||
| [picker dismissViewControllerAnimated:YES | ||
| completion:^{ | ||
| [weakSelf removeInteractionBlocker]; | ||
| }]; | ||
| [self sendCallResultWithSavedPathList:nil]; | ||
| } | ||
|
|
||
|
|
@@ -674,4 +685,44 @@ - (void)sendCallResultWithError:(FlutterError *)error { | |
| self.callContext = nil; | ||
| } | ||
|
|
||
| - (void)addInteractionBlocker { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this needs some documentation on why we need it. |
||
| if (self.interactionBlockerWindow != nil) { | ||
| return; | ||
| } | ||
| UIViewController *topController = [self viewControllerWithWindow:nil]; | ||
| UIWindow *presentingWindow = topController.view.window; | ||
| if (!presentingWindow) { | ||
| return; | ||
| } | ||
| self.previousKeyWindow = presentingWindow; | ||
| UIWindow *blockerWindow; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need a
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, @hellohuanlin We’re using a separate UIWindow instead of dropping a view in the Flutter hierarchy to make the touch blocker reliable:
The following 2 screenshots are using view and image picker will replace the flutter view controller. The first one shows we are in flutter view controller, the second one shows when we trigger the camera page from flutter, the flutter view become invisible and image picker takes place all the view.
The following is using a window for camera In the first 2 hierarchy snapshots, the picker is full screen, so the Flutter view is temporarily out of the visible view tree. In the third snapshot, both the picker stack and FlutterViewController appear under the same key UIWindow, showing they share one window for event delivery. That’s why a blocker tied to the host view can shift or disappear during the modal transition, while a separate window stays put and reliably swallows taps. |
||
| if (@available(iOS 13.0, *) && presentingWindow.windowScene) { | ||
| blockerWindow = [[UIWindow alloc] initWithWindowScene:presentingWindow.windowScene]; | ||
| } else { | ||
| blockerWindow = [[UIWindow alloc] initWithFrame:presentingWindow.bounds]; | ||
| } | ||
| blockerWindow.frame = presentingWindow.bounds; | ||
| blockerWindow.autoresizingMask = | ||
| UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | ||
| blockerWindow.windowLevel = presentingWindow.windowLevel + 1; | ||
| UIViewController *vc = [[UIViewController alloc] init]; | ||
| vc.view.backgroundColor = [UIColor clearColor]; | ||
| vc.view.userInteractionEnabled = YES; | ||
| blockerWindow.rootViewController = vc; | ||
| [blockerWindow makeKeyAndVisible]; | ||
| self.interactionBlockerWindow = blockerWindow; | ||
| } | ||
|
|
||
| - (void)removeInteractionBlocker { | ||
| if (!self.interactionBlockerWindow) { | ||
| return; | ||
| } | ||
| self.interactionBlockerWindow.hidden = YES; | ||
| if (self.previousKeyWindow) { | ||
| [self.previousKeyWindow makeKeyWindow]; | ||
| } | ||
| self.interactionBlockerWindow = nil; | ||
| self.previousKeyWindow = nil; | ||
| } | ||
|
|
||
| @end | ||



There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To reproduce the issue, have to comment this line. Not sure we are going to remove it, so I comment it.