Skip to content

Commit aa38b23

Browse files
committed
[webview_flutter_wkwebview] Address gesture policy review feedback
1 parent 0df39ee commit aa38b23

5 files changed

Lines changed: 43 additions & 20 deletions

File tree

‎packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## 3.27.0
22

3-
* Adds `WebKitWebViewWidgetCreationParams.gestureBlockingPolicy` for choosing the gesture
3+
* Adds `WebKitWebViewWidgetCreationParams.uiKitGestureBlockingPolicy` for choosing the gesture
44
blocking policy of the iOS platform view. Setting it to `doNotBlockGesture` works around web
55
views becoming unresponsive to touches. See
66
https://github.com/flutter/flutter/issues/175099.

‎packages/webview_flutter/webview_flutter_wkwebview/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ should add it to your `pubspec.yaml` as usual.
1313

1414
### Gesture blocking policy on iOS
1515

16-
If a web view stops responding to touches after the first interaction on iOS, letting the web view
17-
handle those touches itself, rather than disambiguating them through Flutter's gesture arena, can
16+
If a web view stops responding to touches after the first interaction on iOS, using hit-test results
17+
instead of Flutter's gesture arena to decide when to block the web view's gesture recognizers can
1818
work around it:
1919

2020
<?code-excerpt "example/lib/readme_excerpts.dart (gesture_blocking_policy_example)"?>
2121
```dart
2222
final params = WebKitWebViewWidgetCreationParams(
2323
controller: controller,
24-
gestureBlockingPolicy: .doNotBlockGesture,
24+
uiKitGestureBlockingPolicy: .doNotBlockGesture,
2525
);
2626
```
2727

‎packages/webview_flutter/webview_flutter_wkwebview/example/lib/readme_excerpts.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ PlatformWebViewWidgetCreationParams createParamsWithoutGestureBlocking(
1212
// #docregion gesture_blocking_policy_example
1313
final params = WebKitWebViewWidgetCreationParams(
1414
controller: controller,
15-
gestureBlockingPolicy: .doNotBlockGesture,
15+
uiKitGestureBlockingPolicy: .doNotBlockGesture,
1616
);
1717
// #enddocregion gesture_blocking_policy_example
1818
return params;

‎packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_controller.dart‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ class WebKitWebViewWidgetCreationParams extends PlatformWebViewWidgetCreationPar
953953
required super.controller,
954954
super.layoutDirection,
955955
super.gestureRecognizers,
956-
this.gestureBlockingPolicy = .fallbackToPluginDefault,
956+
this.uiKitGestureBlockingPolicy = .fallbackToPluginDefault,
957957
});
958958

959959
/// Constructs a [WebKitWebViewWidgetCreationParams] using a
@@ -978,22 +978,22 @@ class WebKitWebViewWidgetCreationParams extends PlatformWebViewWidgetCreationPar
978978
/// Defaults to [UiKitViewGestureBlockingPolicy.fallbackToPluginDefault],
979979
/// which uses the policy the plugin registers the platform view with.
980980
///
981-
/// With [UiKitViewGestureBlockingPolicy.doNotBlockGesture], Flutter never
982-
/// blocks touches that land on the web view: they are handled by the web view
983-
/// and are not disambiguated through Flutter's gesture arena. That can work
984-
/// around a web view that stops responding to touches, at the cost of the web
985-
/// view recognizing gestures that should have been blocked.
986-
final UiKitViewGestureBlockingPolicy gestureBlockingPolicy;
981+
/// With [UiKitViewGestureBlockingPolicy.doNotBlockGesture], Flutter blocks
982+
/// these gesture recognizers based on hit-test results instead of relying on
983+
/// Flutter's gesture arena. This can work around a web view that stops
984+
/// responding to touches, but may cause the web view to recognize a gesture
985+
/// that should have been blocked.
986+
final UiKitViewGestureBlockingPolicy uiKitGestureBlockingPolicy;
987987

988988
@override
989-
int get hashCode => Object.hash(controller, layoutDirection, gestureBlockingPolicy);
989+
int get hashCode => Object.hash(controller, layoutDirection, uiKitGestureBlockingPolicy);
990990

991991
@override
992992
bool operator ==(Object other) {
993993
return other is WebKitWebViewWidgetCreationParams &&
994994
controller == other.controller &&
995995
layoutDirection == other.layoutDirection &&
996-
gestureBlockingPolicy == other.gestureBlockingPolicy;
996+
uiKitGestureBlockingPolicy == other.uiKitGestureBlockingPolicy;
997997
}
998998
}
999999

@@ -1033,7 +1033,7 @@ class WebKitWebViewWidget extends PlatformWebViewWidget {
10331033
return UiKitView(
10341034
key: key,
10351035
viewType: 'plugins.flutter.io/webview',
1036-
gestureBlockingPolicy: _webKitParams.gestureBlockingPolicy,
1036+
gestureBlockingPolicy: _webKitParams.uiKitGestureBlockingPolicy,
10371037
onPlatformViewCreated: (_) {},
10381038
layoutDirection: params.layoutDirection,
10391039
gestureRecognizers: params.gestureRecognizers,

‎packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_widget_test.dart‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void main() {
4242
debugDefaultTargetPlatformOverride = null;
4343
});
4444

45-
testWidgets('gestureBlockingPolicy defaults to falling back to the plugin default', (
45+
testWidgets('uiKitGestureBlockingPolicy defaults to falling back to the plugin default', (
4646
WidgetTester tester,
4747
) async {
4848
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
@@ -61,15 +61,17 @@ void main() {
6161
debugDefaultTargetPlatformOverride = null;
6262
});
6363

64-
testWidgets('gestureBlockingPolicy is passed to the UiKitView', (WidgetTester tester) async {
64+
testWidgets('uiKitGestureBlockingPolicy is passed to the UiKitView', (
65+
WidgetTester tester,
66+
) async {
6567
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
6668

6769
final WebKitWebViewController controller = createTestWebViewController();
6870

6971
final widget = WebKitWebViewWidget(
7072
WebKitWebViewWidgetCreationParams(
7173
controller: controller,
72-
gestureBlockingPolicy: .doNotBlockGesture,
74+
uiKitGestureBlockingPolicy: .doNotBlockGesture,
7375
),
7476
);
7577

@@ -83,7 +85,28 @@ void main() {
8385
debugDefaultTargetPlatformOverride = null;
8486
});
8587

86-
testWidgets('Key of the PlatformView changes when the gestureBlockingPolicy changes', (
88+
testWidgets('uiKitGestureBlockingPolicy does not change the macOS platform view type', (
89+
WidgetTester tester,
90+
) async {
91+
debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
92+
93+
final WebKitWebViewController controller = createTestWebViewController();
94+
final widget = WebKitWebViewWidget(
95+
WebKitWebViewWidgetCreationParams(
96+
controller: controller,
97+
uiKitGestureBlockingPolicy: .doNotBlockGesture,
98+
),
99+
);
100+
101+
await tester.pumpWidget(Builder(builder: (BuildContext context) => widget.build(context)));
102+
103+
expect(find.byType(AppKitView), findsOneWidget);
104+
expect(find.byType(UiKitView), findsNothing);
105+
106+
debugDefaultTargetPlatformOverride = null;
107+
});
108+
109+
testWidgets('Key of the PlatformView changes when the uiKitGestureBlockingPolicy changes', (
87110
WidgetTester tester,
88111
) async {
89112
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
@@ -102,7 +125,7 @@ void main() {
102125
final webViewWidget2 = WebKitWebViewWidget(
103126
WebKitWebViewWidgetCreationParams(
104127
controller: controller,
105-
gestureBlockingPolicy: .doNotBlockGesture,
128+
uiKitGestureBlockingPolicy: .doNotBlockGesture,
106129
),
107130
);
108131

0 commit comments

Comments
 (0)