-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[webview_flutter] Expose the allowsLinkPreview property in WKWebView for iOS #5110
Changes from all 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 |
---|---|---|
|
@@ -1114,6 +1114,58 @@ void main() { | |
}); | ||
}); | ||
|
||
group('allowsLinkPreview', () { | ||
testWidgets('defaults to true', (WidgetTester tester) async { | ||
await tester.pumpWidget(const WebView()); | ||
|
||
final CreationParams params = captureBuildArgs( | ||
mockWebViewPlatform, | ||
creationParams: true, | ||
).single as CreationParams; | ||
|
||
expect(params.webSettings!.allowsLinkPreview, true); | ||
}); | ||
|
||
testWidgets('can be disabled', (WidgetTester tester) async { | ||
await tester.pumpWidget(const WebView( | ||
allowsLinkPreview: false, | ||
)); | ||
|
||
final CreationParams params = captureBuildArgs( | ||
mockWebViewPlatform, | ||
creationParams: true, | ||
).single as CreationParams; | ||
|
||
expect(params.webSettings!.allowsLinkPreview, false); | ||
}); | ||
|
||
testWidgets('can be changed', (WidgetTester tester) async { | ||
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 test is failing because the 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 have removed 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. No, you still want WebSettings _clearUnchangedWebSettings(
WebSettings currentValue, WebSettings newValue) {
assert(currentValue.javascriptMode != null);
/* other values */
assert(newValue.allowsLinkPreview != null);
JavascriptMode? javascriptMode;
/* other values */
bool? allowsLinkPreview;
if (currentValue.javascriptMode != newValue.javascriptMode) {
javascriptMode = newValue.javascriptMode;
}
/* other values */
if (currentValue.allowsLinkPreview != newValue.allowsLinkPreview) {
allowsLinkPreview = newValue.allowsLinkPreview;
}
return WebSettings(
javascriptMode: javascriptMode,
/* other values */
allowsLinkPreview: allowsLinkPreview,
);
} 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. Sorry for the misunderstanding; that's my bad. I have added it back in and made the changes |
||
final GlobalKey key = GlobalKey(); | ||
await tester.pumpWidget(WebView(key: key)); | ||
|
||
await tester.pumpWidget(WebView( | ||
key: key, | ||
allowsLinkPreview: false, | ||
)); | ||
|
||
final WebSettings enabledSettings = | ||
verify(mockWebViewPlatformController.updateSettings(captureAny)) | ||
.captured | ||
.last as WebSettings; | ||
expect(enabledSettings.allowsLinkPreview, false); | ||
|
||
await tester.pumpWidget(WebView( | ||
key: key, | ||
)); | ||
|
||
final WebSettings disabledSettings = | ||
verify(mockWebViewPlatformController.updateSettings(captureAny)) | ||
.captured | ||
.last as WebSettings; | ||
expect(disabledSettings.allowsLinkPreview, true); | ||
}); | ||
}); | ||
|
||
group('Custom platform implementation', () { | ||
setUp(() { | ||
WebView.platform = MyWebViewPlatform(); | ||
|
@@ -1143,6 +1195,7 @@ void main() { | |
debuggingEnabled: false, | ||
userAgent: const WebSetting<String?>.of(null), | ||
gestureNavigationEnabled: true, | ||
allowsLinkPreview: true, | ||
zoomEnabled: true, | ||
), | ||
))); | ||
|
@@ -1325,6 +1378,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; | ||
} | ||
|
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.
Should this type be nullable, so on Platforms that doesn't support this feature, the value is null.
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'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
null
as eventually anyway.(We shouldn't say this is
iOS
only by the way; we should instead say it's not supported on all platforms.)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.
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.'