-
Notifications
You must be signed in to change notification settings - Fork 29.8k
[CP][Stable][ios][pv] quick fix to enable and re-enable web view's gesture recognizer #180522
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
[CP][Stable][ios][pv] quick fix to enable and re-enable web view's gesture recognizer #180522
Conversation
…izer (#179908) This is a quick fix to the web view/admob not tappable issue. It performs DFS on a platform view hierarchy to find a web view. If found, it performs another DFS into the web view to "fix" a gesture recognizer. Warning: This is just a "quick fix" that patches the bug. However, a real solution should rely on overriding the "hitTest" behavior. For example, there's still a existing bug that a drawing website's touch is not completely blocked (see #179916). This can only be fixed by "hitTest". However, "hitTest" approach requires plugin updates and would take much longer time, so we decided to [revert it](#179895). But we should revisit after putting out the fire. #175099 #165787 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
|
This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter. Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed. |
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.
Code Review
This pull request introduces a workaround for an issue on iOS where WKWebView becomes unresponsive to taps after scrolling. The fix involves recursively searching for the WKWebView and its private WKTouchEventsGestureRecognizer, then resetting the recognizer by disabling and re-enabling it. The change is accompanied by extensive tests covering various view hierarchy scenarios to validate the fix.
| - (void)searchAndFixWebView:(UIView*)view { | ||
| if ([view isKindOfClass:[WKWebView class]]) { | ||
| return [self searchAndFixWebViewGestureRecognzier:view]; | ||
| } else { | ||
| for (UIView* subview in view.subviews) { | ||
| [self searchAndFixWebView:subview]; | ||
| } | ||
| } | ||
| } |
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.
The structure of this method can be simplified for better readability. The use of return [self searchAndFixWebViewGestureRecognzier:view]; where the method returns void relies on a GNU extension in Clang, which can be confusing. Additionally, the else block is redundant when the if block contains a return.
Refactoring to an if-return-then pattern makes the code clearer and more aligned with standard Objective-C style.
- (void)searchAndFixWebView:(UIView*)view {
if ([view isKindOfClass:[WKWebView class]]) {
[self searchAndFixWebViewGestureRecognzier:view];
return;
}
for (UIView* subview in view.subviews) {
[self searchAndFixWebView:subview];
}
}
References
- The Flutter Style Guide emphasizes optimizing for readability (line 29). The suggested change simplifies the control flow, making the method's logic easier to follow. (link)
| - (void) | ||
| testFlutterPlatformViewBlockGestureUnderEagerPolicyShouldDisableAndReEnableTouchEventsGestureRecognizerForSimpleWebView { | ||
| if (@available(iOS 26.0, *)) { | ||
| flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; | ||
|
|
||
| flutter::TaskRunners runners(/*label=*/self.name.UTF8String, | ||
| /*platform=*/GetDefaultTaskRunner(), | ||
| /*raster=*/GetDefaultTaskRunner(), | ||
| /*ui=*/GetDefaultTaskRunner(), | ||
| /*io=*/GetDefaultTaskRunner()); | ||
| FlutterPlatformViewsController* flutterPlatformViewsController = | ||
| [[FlutterPlatformViewsController alloc] init]; | ||
| flutterPlatformViewsController.taskRunner = GetDefaultTaskRunner(); | ||
| auto platform_view = std::make_unique<flutter::PlatformViewIOS>( | ||
| /*delegate=*/mock_delegate, | ||
| /*rendering_api=*/flutter::IOSRenderingAPI::kMetal, | ||
| /*platform_views_controller=*/flutterPlatformViewsController, | ||
| /*task_runners=*/runners, | ||
| /*worker_task_runner=*/nil, | ||
| /*is_gpu_disabled_jsync_switch=*/std::make_shared<fml::SyncSwitch>()); | ||
|
|
||
| FlutterPlatformViewsTestMockWebViewFactory* factory = | ||
| [[FlutterPlatformViewsTestMockWebViewFactory alloc] init]; | ||
| [flutterPlatformViewsController | ||
| registerViewFactory:factory | ||
| withId:@"MockWebView" | ||
| gestureRecognizersBlockingPolicy:FlutterPlatformViewGestureRecognizersBlockingPolicyEager]; | ||
| FlutterResult result = ^(id result) { | ||
| }; | ||
| [flutterPlatformViewsController | ||
| onMethodCall:[FlutterMethodCall | ||
| methodCallWithMethodName:@"create" | ||
| arguments:@{@"id" : @2, @"viewType" : @"MockWebView"}] | ||
| result:result]; | ||
|
|
||
| XCTAssertNotNil(gMockPlatformView); | ||
|
|
||
| // Find touch inteceptor view | ||
| UIView* touchInteceptorView = gMockPlatformView; | ||
| while (touchInteceptorView != nil && | ||
| ![touchInteceptorView isKindOfClass:[FlutterTouchInterceptingView class]]) { | ||
| touchInteceptorView = touchInteceptorView.superview; | ||
| } | ||
| XCTAssertNotNil(touchInteceptorView); | ||
|
|
||
| /* | ||
| Simple Web View at root, with [*] indicating views containing | ||
| MockTouchEventsGestureRecognizer. | ||
| Root (Web View) [*] | ||
| ├── Child 1 | ||
| └── Child 2 | ||
| ├── Child 2.1 | ||
| └── Child 2.2 [*] | ||
| */ | ||
|
|
||
| UIView* root = gMockPlatformView; | ||
| root.gestureRecognizers = nil; | ||
| for (UIView* subview in root.subviews) { | ||
| [subview removeFromSuperview]; | ||
| } | ||
|
|
||
| MockGestureRecognizer* normalRecognizer0 = [[MockGestureRecognizer alloc] init]; | ||
| [root addGestureRecognizer:normalRecognizer0]; | ||
|
|
||
| UIView* child1 = [[UIView alloc] init]; | ||
| [root addSubview:child1]; | ||
| MockGestureRecognizer* normalRecognizer1 = [[MockGestureRecognizer alloc] init]; | ||
| [child1 addGestureRecognizer:normalRecognizer1]; | ||
|
|
||
| UIView* child2 = [[UIView alloc] init]; | ||
| [root addSubview:child2]; | ||
| MockGestureRecognizer* normalRecognizer2 = [[MockGestureRecognizer alloc] init]; | ||
| [child2 addGestureRecognizer:normalRecognizer2]; | ||
|
|
||
| UIView* child2_1 = [[UIView alloc] init]; | ||
| [child2 addSubview:child2_1]; | ||
| MockGestureRecognizer* normalRecognizer2_1 = [[MockGestureRecognizer alloc] init]; | ||
| [child2_1 addGestureRecognizer:normalRecognizer2_1]; | ||
|
|
||
| UIView* child2_2 = [[UIView alloc] init]; | ||
| [child2 addSubview:child2_2]; | ||
| MockGestureRecognizer* normalRecognizer2_2 = [[MockGestureRecognizer alloc] init]; | ||
| [child2_2 addGestureRecognizer:normalRecognizer2_2]; | ||
|
|
||
| // Add the target recognizer at root & child2_2. | ||
| MockTouchEventsGestureRecognizer* targetRecognizer0 = | ||
| [[MockTouchEventsGestureRecognizer alloc] init]; | ||
| [root addGestureRecognizer:targetRecognizer0]; | ||
|
|
||
| MockTouchEventsGestureRecognizer* targetRecognizer2_2 = | ||
| [[MockTouchEventsGestureRecognizer alloc] init]; | ||
| [child2_2 addGestureRecognizer:targetRecognizer2_2]; | ||
|
|
||
| [(FlutterTouchInterceptingView*)touchInteceptorView blockGesture]; | ||
|
|
||
| NSArray* normalRecognizers = @[ | ||
| normalRecognizer0, normalRecognizer1, normalRecognizer2, normalRecognizer2_1, | ||
| normalRecognizer2_2 | ||
| ]; | ||
|
|
||
| NSArray* targetRecognizers = @[ targetRecognizer0, targetRecognizer2_2 ]; | ||
|
|
||
| NSArray* expectedEmptyHistory = @[]; | ||
| NSArray* expectedToggledHistory = @[ @NO, @YES ]; | ||
|
|
||
| for (MockGestureRecognizer* recognizer in normalRecognizers) { | ||
| XCTAssertEqualObjects(recognizer.toggleHistory, expectedEmptyHistory); | ||
| } | ||
| for (MockGestureRecognizer* recognizer in targetRecognizers) { | ||
| XCTAssertEqualObjects(recognizer.toggleHistory, expectedToggledHistory); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| - (void) | ||
| testFlutterPlatformViewBlockGestureUnderEagerPolicyShouldDisableAndReEnableTouchEventsGestureRecognizerForMultipleWebViewInDifferentBranches { | ||
| if (@available(iOS 26.0, *)) { | ||
| flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; | ||
|
|
||
| flutter::TaskRunners runners(/*label=*/self.name.UTF8String, | ||
| /*platform=*/GetDefaultTaskRunner(), | ||
| /*raster=*/GetDefaultTaskRunner(), | ||
| /*ui=*/GetDefaultTaskRunner(), | ||
| /*io=*/GetDefaultTaskRunner()); | ||
| FlutterPlatformViewsController* flutterPlatformViewsController = | ||
| [[FlutterPlatformViewsController alloc] init]; | ||
| flutterPlatformViewsController.taskRunner = GetDefaultTaskRunner(); | ||
| auto platform_view = std::make_unique<flutter::PlatformViewIOS>( | ||
| /*delegate=*/mock_delegate, | ||
| /*rendering_api=*/flutter::IOSRenderingAPI::kMetal, | ||
| /*platform_views_controller=*/flutterPlatformViewsController, | ||
| /*task_runners=*/runners, | ||
| /*worker_task_runner=*/nil, | ||
| /*is_gpu_disabled_jsync_switch=*/std::make_shared<fml::SyncSwitch>()); | ||
|
|
||
| FlutterPlatformViewsTestMockWrapperWebViewFactory* factory = | ||
| [[FlutterPlatformViewsTestMockWrapperWebViewFactory alloc] init]; | ||
| [flutterPlatformViewsController | ||
| registerViewFactory:factory | ||
| withId:@"MockWrapperWebView" | ||
| gestureRecognizersBlockingPolicy:FlutterPlatformViewGestureRecognizersBlockingPolicyEager]; | ||
| FlutterResult result = ^(id result) { | ||
| }; | ||
| [flutterPlatformViewsController | ||
| onMethodCall:[FlutterMethodCall methodCallWithMethodName:@"create" | ||
| arguments:@{ | ||
| @"id" : @2, | ||
| @"viewType" : @"MockWrapperWebView" | ||
| }] | ||
| result:result]; | ||
|
|
||
| XCTAssertNotNil(gMockPlatformView); | ||
|
|
||
| // Find touch inteceptor view | ||
| UIView* touchInteceptorView = gMockPlatformView; | ||
| while (touchInteceptorView != nil && | ||
| ![touchInteceptorView isKindOfClass:[FlutterTouchInterceptingView class]]) { | ||
| touchInteceptorView = touchInteceptorView.superview; | ||
| } | ||
| XCTAssertNotNil(touchInteceptorView); | ||
|
|
||
| /* | ||
| Platform View with Multiple Web Views in different branches, with [*] indicating views | ||
| containing MockTouchEventsGestureRecognizer. | ||
| Root (Platform View) | ||
| ├── Child 1 | ||
| ├── Child 2 (Web View) | ||
| | ├── Child 2.1 | ||
| | └── Child 2.2 [*] | ||
| └── Child 3 | ||
| └── Child 3.1 (Web View) | ||
| ├── Child 3.1.1 | ||
| └── Child 3.1.2 [*] | ||
| */ | ||
|
|
||
| UIView* root = gMockPlatformView; | ||
| for (UIView* subview in root.subviews) { | ||
| [subview removeFromSuperview]; | ||
| } | ||
|
|
||
| MockGestureRecognizer* normalRecognizer0 = [[MockGestureRecognizer alloc] init]; | ||
| [root addGestureRecognizer:normalRecognizer0]; | ||
|
|
||
| UIView* child1 = [[UIView alloc] init]; | ||
| [root addSubview:child1]; | ||
| MockGestureRecognizer* normalRecognizer1 = [[MockGestureRecognizer alloc] init]; | ||
| [child1 addGestureRecognizer:normalRecognizer1]; | ||
|
|
||
| UIView* child2 = [[WKWebView alloc] init]; | ||
| child2.gestureRecognizers = nil; | ||
| for (UIView* subview in child2.subviews) { | ||
| [subview removeFromSuperview]; | ||
| } | ||
| [root addSubview:child2]; | ||
| MockGestureRecognizer* normalRecognizer2 = [[MockGestureRecognizer alloc] init]; | ||
| [child2 addGestureRecognizer:normalRecognizer2]; | ||
|
|
||
| UIView* child2_1 = [[UIView alloc] init]; | ||
| [child2 addSubview:child2_1]; | ||
| MockGestureRecognizer* normalRecognizer2_1 = [[MockGestureRecognizer alloc] init]; | ||
| [child2_1 addGestureRecognizer:normalRecognizer2_1]; | ||
|
|
||
| UIView* child2_2 = [[UIView alloc] init]; | ||
| [child2 addSubview:child2_2]; | ||
| MockGestureRecognizer* normalRecognizer2_2 = [[MockGestureRecognizer alloc] init]; | ||
| [child2_2 addGestureRecognizer:normalRecognizer2_2]; | ||
|
|
||
| UIView* child3 = [[UIView alloc] init]; | ||
| [root addSubview:child3]; | ||
| MockGestureRecognizer* normalRecognizer3 = [[MockGestureRecognizer alloc] init]; | ||
| [child3 addGestureRecognizer:normalRecognizer3]; | ||
|
|
||
| UIView* child3_1 = [[WKWebView alloc] init]; | ||
| child3_1.gestureRecognizers = nil; | ||
| for (UIView* subview in child3_1.subviews) { | ||
| [subview removeFromSuperview]; | ||
| } | ||
| [child3 addSubview:child3_1]; | ||
| MockGestureRecognizer* normalRecognizer3_1 = [[MockGestureRecognizer alloc] init]; | ||
| [child3_1 addGestureRecognizer:normalRecognizer3_1]; | ||
|
|
||
| UIView* child3_1_1 = [[UIView alloc] init]; | ||
| [child3_1 addSubview:child3_1_1]; | ||
| MockGestureRecognizer* normalRecognizer3_1_1 = [[MockGestureRecognizer alloc] init]; | ||
| [child3_1_1 addGestureRecognizer:normalRecognizer3_1_1]; | ||
|
|
||
| UIView* child3_1_2 = [[UIView alloc] init]; | ||
| [child3_1 addSubview:child3_1_2]; | ||
| MockGestureRecognizer* normalRecognizer3_1_2 = [[MockGestureRecognizer alloc] init]; | ||
| [child3_1_2 addGestureRecognizer:normalRecognizer3_1_2]; | ||
|
|
||
| // Add the target recognizer at child2_2 & child3_1_2 | ||
|
|
||
| MockTouchEventsGestureRecognizer* targetRecognizer2_2 = | ||
| [[MockTouchEventsGestureRecognizer alloc] init]; | ||
| [child2_2 addGestureRecognizer:targetRecognizer2_2]; | ||
|
|
||
| MockTouchEventsGestureRecognizer* targetRecognizer3_1_2 = | ||
| [[MockTouchEventsGestureRecognizer alloc] init]; | ||
| [child3_1_2 addGestureRecognizer:targetRecognizer3_1_2]; | ||
|
|
||
| [(FlutterTouchInterceptingView*)touchInteceptorView blockGesture]; | ||
|
|
||
| NSArray* normalRecognizers = @[ | ||
| normalRecognizer0, normalRecognizer1, normalRecognizer2, normalRecognizer2_1, | ||
| normalRecognizer2_2, normalRecognizer3, normalRecognizer3_1, normalRecognizer3_1_1, | ||
| normalRecognizer3_1_2 | ||
| ]; | ||
| NSArray* targetRecognizers = @[ targetRecognizer2_2, targetRecognizer3_1_2 ]; | ||
|
|
||
| NSArray* expectedEmptyHistory = @[]; | ||
| NSArray* expectedToggledHistory = @[ @NO, @YES ]; | ||
|
|
||
| for (MockGestureRecognizer* recognizer in normalRecognizers) { | ||
| XCTAssertEqualObjects(recognizer.toggleHistory, expectedEmptyHistory); | ||
| } | ||
|
|
||
| for (MockGestureRecognizer* recognizer in targetRecognizers) { | ||
| XCTAssertEqualObjects(recognizer.toggleHistory, expectedToggledHistory); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| - (void) | ||
| testFlutterPlatformViewBlockGestureUnderEagerPolicyShouldDisableAndReEnableTouchEventsGestureRecognizerForNestedMultipleWebView { | ||
| if (@available(iOS 26.0, *)) { | ||
| flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; | ||
|
|
||
| flutter::TaskRunners runners(/*label=*/self.name.UTF8String, | ||
| /*platform=*/GetDefaultTaskRunner(), | ||
| /*raster=*/GetDefaultTaskRunner(), | ||
| /*ui=*/GetDefaultTaskRunner(), | ||
| /*io=*/GetDefaultTaskRunner()); | ||
| FlutterPlatformViewsController* flutterPlatformViewsController = | ||
| [[FlutterPlatformViewsController alloc] init]; | ||
| flutterPlatformViewsController.taskRunner = GetDefaultTaskRunner(); | ||
| auto platform_view = std::make_unique<flutter::PlatformViewIOS>( | ||
| /*delegate=*/mock_delegate, | ||
| /*rendering_api=*/flutter::IOSRenderingAPI::kMetal, | ||
| /*platform_views_controller=*/flutterPlatformViewsController, | ||
| /*task_runners=*/runners, | ||
| /*worker_task_runner=*/nil, | ||
| /*is_gpu_disabled_jsync_switch=*/std::make_shared<fml::SyncSwitch>()); | ||
|
|
||
| FlutterPlatformViewsTestMockWebViewFactory* factory = | ||
| [[FlutterPlatformViewsTestMockWebViewFactory alloc] init]; | ||
| [flutterPlatformViewsController | ||
| registerViewFactory:factory | ||
| withId:@"MockWebView" | ||
| gestureRecognizersBlockingPolicy:FlutterPlatformViewGestureRecognizersBlockingPolicyEager]; | ||
| FlutterResult result = ^(id result) { | ||
| }; | ||
| [flutterPlatformViewsController | ||
| onMethodCall:[FlutterMethodCall | ||
| methodCallWithMethodName:@"create" | ||
| arguments:@{@"id" : @2, @"viewType" : @"MockWebView"}] | ||
| result:result]; | ||
|
|
||
| XCTAssertNotNil(gMockPlatformView); | ||
|
|
||
| // Find touch inteceptor view | ||
| UIView* touchInteceptorView = gMockPlatformView; | ||
| while (touchInteceptorView != nil && | ||
| ![touchInteceptorView isKindOfClass:[FlutterTouchInterceptingView class]]) { | ||
| touchInteceptorView = touchInteceptorView.superview; | ||
| } | ||
| XCTAssertNotNil(touchInteceptorView); | ||
|
|
||
| /* | ||
| Platform View with nested web views, with [*] indicating views containing | ||
| MockTouchEventsGestureRecognizer. | ||
| Root (Web View) | ||
| ├── Child 1 | ||
| ├── Child 2 | ||
| | ├── Child 2.1 | ||
| | └── Child 2.2 [*] | ||
| └── Child 3 | ||
| └── Child 3.1 (Another Web View) | ||
| └── Child 3.1.1 | ||
| └── Child 3.1.2 | ||
| ├── Child 3.1.2.1 | ||
| └── Child 3.1.2.2 [*] | ||
| */ | ||
|
|
||
| UIView* root = gMockPlatformView; | ||
| root.gestureRecognizers = nil; | ||
| for (UIView* subview in root.subviews) { | ||
| [subview removeFromSuperview]; | ||
| } | ||
|
|
||
| MockGestureRecognizer* normalRecognizer0 = [[MockGestureRecognizer alloc] init]; | ||
| [root addGestureRecognizer:normalRecognizer0]; | ||
|
|
||
| UIView* child1 = [[UIView alloc] init]; | ||
| [root addSubview:child1]; | ||
| MockGestureRecognizer* normalRecognizer1 = [[MockGestureRecognizer alloc] init]; | ||
| [child1 addGestureRecognizer:normalRecognizer1]; | ||
|
|
||
| UIView* child2 = [[UIView alloc] init]; | ||
| [root addSubview:child2]; | ||
| MockGestureRecognizer* normalRecognizer2 = [[MockGestureRecognizer alloc] init]; | ||
| [child2 addGestureRecognizer:normalRecognizer2]; | ||
|
|
||
| UIView* child2_1 = [[UIView alloc] init]; | ||
| [child2 addSubview:child2_1]; | ||
| MockGestureRecognizer* normalRecognizer2_1 = [[MockGestureRecognizer alloc] init]; | ||
| [child2_1 addGestureRecognizer:normalRecognizer2_1]; | ||
|
|
||
| UIView* child2_2 = [[UIView alloc] init]; | ||
| [child2 addSubview:child2_2]; | ||
| MockGestureRecognizer* normalRecognizer2_2 = [[MockGestureRecognizer alloc] init]; | ||
| [child2_2 addGestureRecognizer:normalRecognizer2_2]; | ||
|
|
||
| UIView* child3 = [[UIView alloc] init]; | ||
| [root addSubview:child3]; | ||
| MockGestureRecognizer* normalRecognizer3 = [[MockGestureRecognizer alloc] init]; | ||
| [child3 addGestureRecognizer:normalRecognizer3]; | ||
|
|
||
| UIView* child3_1 = [[WKWebView alloc] init]; | ||
| child3_1.gestureRecognizers = nil; | ||
| for (UIView* subview in child3_1.subviews) { | ||
| [subview removeFromSuperview]; | ||
| } | ||
| [child3 addSubview:child3_1]; | ||
| MockGestureRecognizer* normalRecognizer3_1 = [[MockGestureRecognizer alloc] init]; | ||
| [child3_1 addGestureRecognizer:normalRecognizer3_1]; | ||
|
|
||
| UIView* child3_1_1 = [[UIView alloc] init]; | ||
| [child3_1 addSubview:child3_1_1]; | ||
| MockGestureRecognizer* normalRecognizer3_1_1 = [[MockGestureRecognizer alloc] init]; | ||
| [child3_1_1 addGestureRecognizer:normalRecognizer3_1_1]; | ||
|
|
||
| UIView* child3_1_2 = [[UIView alloc] init]; | ||
| [child3_1 addSubview:child3_1_2]; | ||
| MockGestureRecognizer* normalRecognizer3_1_2 = [[MockGestureRecognizer alloc] init]; | ||
| [child3_1_2 addGestureRecognizer:normalRecognizer3_1_2]; | ||
|
|
||
| UIView* child3_1_2_1 = [[UIView alloc] init]; | ||
| [child3_1_2 addSubview:child3_1_2_1]; | ||
| MockGestureRecognizer* normalRecognizer3_1_2_1 = [[MockGestureRecognizer alloc] init]; | ||
| [child3_1_2_1 addGestureRecognizer:normalRecognizer3_1_2_1]; | ||
|
|
||
| UIView* child3_1_2_2 = [[UIView alloc] init]; | ||
| [child3_1_2 addSubview:child3_1_2_2]; | ||
| MockGestureRecognizer* normalRecognizer3_1_2_2 = [[MockGestureRecognizer alloc] init]; | ||
| [child3_1_2_2 addGestureRecognizer:normalRecognizer3_1_2_2]; | ||
|
|
||
| // Add the target recognizer at child2_2 & child3_1_2_2 | ||
|
|
||
| MockTouchEventsGestureRecognizer* targetRecognizer2_2 = | ||
| [[MockTouchEventsGestureRecognizer alloc] init]; | ||
| [child2_2 addGestureRecognizer:targetRecognizer2_2]; | ||
|
|
||
| MockTouchEventsGestureRecognizer* targetRecognizer3_1_2_2 = | ||
| [[MockTouchEventsGestureRecognizer alloc] init]; | ||
| [child3_1_2_2 addGestureRecognizer:targetRecognizer3_1_2_2]; | ||
|
|
||
| [(FlutterTouchInterceptingView*)touchInteceptorView blockGesture]; | ||
|
|
||
| NSArray* normalRecognizers = @[ | ||
| normalRecognizer0, normalRecognizer1, normalRecognizer2, normalRecognizer2_1, | ||
| normalRecognizer2_2, normalRecognizer3, normalRecognizer3_1, normalRecognizer3_1_1, | ||
| normalRecognizer3_1_2, normalRecognizer3_1_2_1, normalRecognizer3_1_2_2 | ||
| ]; | ||
|
|
||
| NSArray* targetRecognizers = @[ targetRecognizer2_2, targetRecognizer3_1_2_2 ]; | ||
|
|
||
| NSArray* expectedEmptyHistory = @[]; | ||
| NSArray* expectedToggledHistory = @[ @NO, @YES ]; | ||
|
|
||
| for (MockGestureRecognizer* recognizer in normalRecognizers) { | ||
| XCTAssertEqualObjects(recognizer.toggleHistory, expectedEmptyHistory); | ||
| } | ||
|
|
||
| for (MockGestureRecognizer* recognizer in targetRecognizers) { | ||
| XCTAssertEqualObjects(recognizer.toggleHistory, expectedToggledHistory); | ||
| } | ||
| } | ||
| } |
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.
These three new test methods share a significant amount of boilerplate setup code for the FlutterPlatformViewsController, runners, platform_view, and platform view creation. This duplication makes the tests harder to read and maintain.
To improve this, consider extracting the common setup logic into a helper method. This helper could take the view factory and view type as arguments and return the touchInteceptorView. This would make each test focus only on its specific view hierarchy and assertions, improving clarity and reducing code duplication.
For example, a helper method could look like this:
- (FlutterTouchInterceptingView*)setupEagerPolicyTestWithFactory:(id<FlutterPlatformViewFactory>)factory
viewType:(NSString*)viewType {
// ... common setup code ...
return (FlutterTouchInterceptingView*)touchInteceptorView;
}References
- The Flutter Style Guide suggests avoiding duplication (line 30, 'Avoid duplicating state', which can be extended to code). Refactoring the duplicated test setup into a helper method improves maintainability and readability. (link)
camsim99
left a comment
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.
LGTM thanks!
…iew's gesture recognizer (flutter/flutter#180522)
Stable CP PR: #180522
Beta CP PR: #179974
Original PR: #179908
The "cherry-pick template" linked in https://github.com/flutter/flutter/wiki/Flutter-Cherrypick-Process/e7b042dd481d4ac66477fb281b6e626e8dba8a4e seems to be broken, so I copied the template from previous CP.
Issue Link:
What is the link to the issue this cherry-pick is addressing?
#175099
#165787
Impact Description:
What is the impact (ex. visual jank on Samsung phones, app crash, cannot ship an iOS app)?
Does it impact development (ex. flutter doctor crashes when Android Studio is installed),
or the shipping of production apps (the app crashes on launch).
This information is for domain experts and release engineers to understand the consequences of saying yes or no to the cherry pick.
WebViews (including ads) on iOS 26 are unclickable after being scrolled or after a Flutter menu is open and then closed. This is a serious regression that impacts revenue. This impacts all Flutter apps running on iOS 26 that use WebViews.
Changelog Description:
Explain this cherry pick:
See best practices for examples.
< Replace with changelog description here >
[flutter/165787, flutter/175099] When WebViews are scrolled on iOS 26, they become unclickable.
Workaround:
Is there a workaround for this issue?
None
Risk:
What is the risk level of this cherry-pick?
Test Coverage:
Are you confident that your fix is well-tested by automated tests?
Validation Steps:
What are the steps to validate that this fix works?
Use sample project from #165787 (comment). Touch and scroll on an ad, then try to click the ad. The ad will be unclickable.
If you need help, consider asking for advice on the #hackers-new channel on Discord.
#175099
#165787
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.