Visitar URL original
[ios][pv]fix admob banner scrollable on ios 18.2 by hellohuanlin · Pull Request #183274 · flutter/flutter · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -563,15 +563,12 @@ - (void)releaseGesture {
self.delayingRecognizer.state = UIGestureRecognizerStateFailed;
}

- (BOOL)containsWebView:(UIView*)view remainingSubviewDepth:(int)remainingSubviewDepth {
if (remainingSubviewDepth < 0) {
return NO;
}
- (BOOL)containsWebView:(UIView*)view {
if ([view isKindOfClass:[WKWebView class]]) {
return YES;
}
for (UIView* subview in view.subviews) {
if ([self containsWebView:subview remainingSubviewDepth:remainingSubviewDepth - 1]) {
if ([self containsWebView:subview]) {
return YES;
}
}
Expand Down Expand Up @@ -636,13 +633,10 @@ - (void)blockGesture {
[self searchAndFixWebView:self.embeddedView];
}
} else if (@available(iOS 18.2, *)) {
// This workaround is designed for WKWebView only. The 1P web view plugin provides a
// WKWebView itself as the platform view. However, some 3P plugins provide wrappers of
// WKWebView instead. So we perform DFS to search the view hierarchy (with a depth limit).
// Passing a limit of 0 means only searching for platform view itself; Pass 1 to include its
// children as well, and so on. We should be conservative and start with a small number. The
// AdMob banner has a WKWebView at depth 7.
if ([self containsWebView:self.embeddedView remainingSubviewDepth:1]) {
// The 1P web view plugin provides a WKWebView itself as the platform view. However, some 3P
// plugins provide wrappers of WKWebView instead, and AdMob banner has a WKWebView at
// depth 7. So we perform DFS to search the view hierarchy.
if ([self containsWebView:self.embeddedView]) {
[self removeGestureRecognizer:self.delayingRecognizer];
[self addGestureRecognizer:self.delayingRecognizer];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3389,8 +3389,9 @@ - (void)testFlutterPlatformViewTouchesEndedOrTouchesCancelledEventDoesNotFailThe

BOOL shouldReAddDelayingRecognizer = NO;
if (@available(iOS 26.0, *)) {
// TODO(hellohuanlin): find a solution for iOS 26,
// https://github.com/flutter/flutter/issues/175099.
// We use a different workaround for iOS 26 and it is tested separately.
// See:
// testFlutterPlatformViewBlockGestureUnderEagerPolicyShouldDisableAndReEnableTouchEventsGestureRecognizerForSimpleWebView.
} else if (@available(iOS 18.2, *)) {
shouldReAddDelayingRecognizer = YES;
}
Expand All @@ -3405,7 +3406,7 @@ - (void)testFlutterPlatformViewTouchesEndedOrTouchesCancelledEventDoesNotFailThe
}

- (void)
testFlutterPlatformViewBlockGestureUnderEagerPolicyShouldNotRemoveAndAddBackDelayingRecognizerForNestedWrapperWebView {
testFlutterPlatformViewBlockGestureUnderEagerPolicyShouldRemoveAndAddBackDelayingRecognizerForNestedWrapperWebView {
flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;

flutter::TaskRunners runners(/*label=*/self.name.UTF8String,
Expand Down Expand Up @@ -3459,8 +3460,22 @@ - (void)testFlutterPlatformViewTouchesEndedOrTouchesCancelledEventDoesNotFailThe

[(FlutterTouchInterceptingView*)touchInteceptorView blockGesture];

XCTAssertEqual(touchInteceptorView.gestureRecognizers[0], delayingRecognizer);
XCTAssertEqual(touchInteceptorView.gestureRecognizers[1], forwardingRecognizer);
BOOL shouldReAddDelayingRecognizer = NO;
if (@available(iOS 26.0, *)) {
// We use a different workaround for iOS 26 and it is tested separately.
// See:
// testFlutterPlatformViewBlockGestureUnderEagerPolicyShouldDisableAndReEnableTouchEventsGestureRecognizerForSimpleWebView.
} else if (@available(iOS 18.2, *)) {
shouldReAddDelayingRecognizer = YES;
}
Comment on lines +3561 to +3568

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This logic to determine shouldReAddDelayingRecognizer is duplicated in a few places in this file (e.g., in testFlutterPlatformViewBlockGestureUnderEagerPolicyShouldRemoveAndAddBackDelayingRecognizerForWrapperWebView). To improve maintainability and reduce redundancy, consider extracting it into a helper function.

For example:

+ (BOOL)shouldReAddDelayingRecognizerForWebViewWorkaround {
  if (@available(iOS 26.0, *)) {
    return NO;
  }
  if (@available(iOS 18.2, *)) {
    return YES;
  }
  return NO;
}

You could then call this helper in the tests where this logic is needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no gemini, this extra function call makes the unit test less readable

if (shouldReAddDelayingRecognizer) {
// Since we remove and add back delayingRecognizer, it would be reordered to the last.
XCTAssertEqual(touchInteceptorView.gestureRecognizers[0], forwardingRecognizer);
XCTAssertEqual(touchInteceptorView.gestureRecognizers[1], delayingRecognizer);
} else {
XCTAssertEqual(touchInteceptorView.gestureRecognizers[0], delayingRecognizer);
XCTAssertEqual(touchInteceptorView.gestureRecognizers[1], forwardingRecognizer);
}
}

- (void)
Expand Down