-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[webview_flutter] Expose the allowsLinkPreview property in WKWebView for iOS #5110
Changes from 10 commits
3612a84
d13276f
bb17b4d
e659cd5
6b0ad2e
06ba8dd
4a78973
eec288f
78bec61
ed14ad2
baaf7d5
82be993
09ae8b6
9eadd8e
023d1ff
6f7ef30
87382bc
f21cac9
ebc1dec
9950af8
920a253
b08bab3
7d2f9ef
9bfacc8
a413f89
e34c9c2
a69a34a
77fbc60
a0ae928
8201ae4
bb2d434
1c5d385
b8675f9
8862792
f2ec62b
b642bbe
1aaf428
f86918b
d414528
9548784
12f6da2
0b39035
b0e2496
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 |
|---|---|---|
|
|
@@ -1149,6 +1149,32 @@ Future<void> main() async { | |
| expect(currentUrl, primaryUrl); | ||
| }); | ||
|
|
||
| testWidgets('launches with allowsLinkPreview on iOS', | ||
|
||
| (WidgetTester tester) async { | ||
| final Completer<WebViewController> controllerCompleter = | ||
| Completer<WebViewController>(); | ||
| await tester.pumpWidget( | ||
| Directionality( | ||
| textDirection: TextDirection.ltr, | ||
| child: SizedBox( | ||
| width: 400, | ||
| height: 300, | ||
| child: WebView( | ||
| key: GlobalKey(), | ||
| initialUrl: primaryUrl, | ||
| allowsLinkPreview: false, | ||
| onWebViewCreated: (WebViewController controller) { | ||
| controllerCompleter.complete(controller); | ||
| }, | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
| final WebViewController controller = await controllerCompleter.future; | ||
| final String? currentUrl = await controller.currentUrl(); | ||
| expect(currentUrl, primaryUrl); | ||
| }); | ||
|
|
||
| // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757 | ||
| testWidgets('target _blank opens in same window', | ||
| (WidgetTester tester) async { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,7 @@ class WebView extends StatefulWidget { | |
| this.onWebResourceError, | ||
| this.debuggingEnabled = false, | ||
| this.gestureNavigationEnabled = false, | ||
| this.allowsLinkPreview = true, | ||
| this.userAgent, | ||
| this.zoomEnabled = true, | ||
| this.initialMediaPlaybackPolicy = | ||
|
|
@@ -260,6 +261,13 @@ class WebView extends StatefulWidget { | |
| /// By default `gestureNavigationEnabled` is false. | ||
| final bool gestureNavigationEnabled; | ||
|
|
||
| /// A Boolean value that determines whether pressing a link displays a preview of the destination for the link. | ||
|
||
| /// | ||
| /// This only works on iOS. | ||
| /// | ||
| /// By default `allowsLinkPreview` is true, to match the default on iOS. | ||
|
||
| final bool allowsLinkPreview; | ||
|
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. Should this type be nullable, so on Platforms that doesn't support this feature, the value is null.
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. I'm not a fan of nullable bools in most cases; they are annoying to use, and in practice you generally have to pick a default to treat (We shouldn't say this is
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. Based on the comments, assuming I should keep it as a bool and not a nullable bool. If this is wrong, let me know, and I'll change it. Changed doc comment to 'Not supported on all platforms.' |
||
|
|
||
| /// The value used for the HTTP User-Agent: request header. | ||
| /// | ||
| /// When null the platform's webview default is used for the User-Agent header. | ||
|
|
@@ -380,6 +388,7 @@ WebSettings _webSettingsFromWidget(WebView widget) { | |
| hasProgressTracking: widget.onProgress != null, | ||
| debuggingEnabled: widget.debuggingEnabled, | ||
| gestureNavigationEnabled: widget.gestureNavigationEnabled, | ||
| allowsLinkPreview: widget.allowsLinkPreview, | ||
| allowsInlineMediaPlayback: widget.allowsInlineMediaPlayback, | ||
| userAgent: WebSetting<String?>.of(widget.userAgent), | ||
| zoomEnabled: widget.zoomEnabled, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,9 +19,18 @@ flutter: | |
| dependencies: | ||
| flutter: | ||
| sdk: flutter | ||
| webview_flutter_android: ^2.8.0 | ||
| webview_flutter_platform_interface: ^1.8.0 | ||
| webview_flutter_wkwebview: ^2.7.0 | ||
| # FOR TESTING ONLY. DO NOT MERGE. | ||
|
||
| webview_flutter_android: | ||
| path: | ||
| ../webview_flutter_android | ||
| # FOR TESTING ONLY. DO NOT MERGE. | ||
| webview_flutter_platform_interface: | ||
| path: | ||
| ../webview_flutter_platform_interface | ||
| # FOR TESTING ONLY. DO NOT MERGE. | ||
| webview_flutter_wkwebview: | ||
| path: | ||
| ../webview_flutter_wkwebview | ||
|
|
||
| dev_dependencies: | ||
| build_runner: ^2.1.5 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1139,6 +1139,7 @@ void main() { | |
| const WebView( | ||
| initialUrl: 'https://youtube.com', | ||
| gestureNavigationEnabled: true, | ||
| allowsLinkPreview: false, | ||
|
||
| ), | ||
| ); | ||
|
|
||
|
|
@@ -1155,6 +1156,7 @@ void main() { | |
| debuggingEnabled: false, | ||
| userAgent: const WebSetting<String?>.of(null), | ||
| gestureNavigationEnabled: true, | ||
| allowsLinkPreview: false, | ||
| zoomEnabled: true, | ||
| ), | ||
| ))); | ||
|
|
@@ -1337,6 +1339,7 @@ class MatchesWebSettings extends Matcher { | |
| _webSettings!.debuggingEnabled == webSettings.debuggingEnabled && | ||
| _webSettings!.gestureNavigationEnabled == | ||
| webSettings.gestureNavigationEnabled && | ||
| _webSettings!.allowsLinkPreview == webSettings.allowsLinkPreview && | ||
| _webSettings!.userAgent == webSettings.userAgent && | ||
| _webSettings!.zoomEnabled == webSettings.zoomEnabled; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1241,6 +1241,32 @@ Future<void> main() async { | |
| expect(currentUrl, primaryUrl); | ||
| }); | ||
|
|
||
| testWidgets('launches with allowsLinkPreview on iOS', | ||
|
||
| (WidgetTester tester) async { | ||
| final Completer<WebViewController> controllerCompleter = | ||
| Completer<WebViewController>(); | ||
| await tester.pumpWidget( | ||
| Directionality( | ||
| textDirection: TextDirection.ltr, | ||
| child: SizedBox( | ||
| width: 400, | ||
| height: 300, | ||
| child: WebView( | ||
| key: GlobalKey(), | ||
| initialUrl: primaryUrl, | ||
| allowsLinkPreview: false, | ||
| onWebViewCreated: (WebViewController controller) { | ||
| controllerCompleter.complete(controller); | ||
| }, | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
| final WebViewController controller = await controllerCompleter.future; | ||
| final String? currentUrl = await controller.currentUrl(); | ||
| expect(currentUrl, primaryUrl); | ||
| }); | ||
|
|
||
| testWidgets('target _blank opens in same window', | ||
| (WidgetTester tester) async { | ||
| final Completer<WebViewController> controllerCompleter = | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -267,6 +267,7 @@ class MethodChannelWebViewPlatform implements WebViewPlatformController { | |
| _addIfNonNull('debuggingEnabled', settings.debuggingEnabled); | ||
| _addIfNonNull( | ||
| 'gestureNavigationEnabled', settings.gestureNavigationEnabled); | ||
| _addIfNonNull('allowsLinkPreview', settings.allowsLinkPreview); | ||
|
||
| _addIfNonNull( | ||
| 'allowsInlineMediaPlayback', settings.allowsInlineMediaPlayback); | ||
| _addSettingIfPresent('userAgent', settings.userAgent); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -440,6 +440,7 @@ void main() { | |
| hasProgressTracking: true, | ||
| debuggingEnabled: true, | ||
| gestureNavigationEnabled: true, | ||
| allowsLinkPreview: false, | ||
|
||
| allowsInlineMediaPlayback: true, | ||
| zoomEnabled: false, | ||
| ); | ||
|
|
@@ -457,6 +458,7 @@ void main() { | |
| 'hasProgressTracking': true, | ||
| 'debuggingEnabled': true, | ||
| 'gestureNavigationEnabled': true, | ||
| 'allowsLinkPreview': false, | ||
| 'allowsInlineMediaPlayback': true, | ||
| 'zoomEnabled': false, | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1095,6 +1095,32 @@ Future<void> main() async { | |
| }); | ||
| }); | ||
|
|
||
| testWidgets('launches with allowsLinkPreview on iOS', | ||
|
||
| (WidgetTester tester) async { | ||
| final Completer<WebViewController> controllerCompleter = | ||
| Completer<WebViewController>(); | ||
| await tester.pumpWidget( | ||
| Directionality( | ||
| textDirection: TextDirection.ltr, | ||
| child: SizedBox( | ||
| width: 400, | ||
| height: 300, | ||
| child: WebView( | ||
| key: GlobalKey(), | ||
| initialUrl: primaryUrl, | ||
| allowsLinkPreview: false, | ||
| onWebViewCreated: (WebViewController controller) { | ||
| controllerCompleter.complete(controller); | ||
| }, | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
| final WebViewController controller = await controllerCompleter.future; | ||
| final String? currentUrl = await controller.currentUrl(); | ||
| expect(currentUrl, primaryUrl); | ||
| }); | ||
|
|
||
| testWidgets('launches with gestureNavigationEnabled on iOS', | ||
| (WidgetTester tester) async { | ||
| final Completer<WebViewController> controllerCompleter = | ||
|
|
||
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.
Since this is changing production code it will need to update the version. (This applies for all the packages changed in this PR.)
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.
I have run the
update-release-infocommand with--version=minimal