-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[webview_flutter] Expose the allowsLinkPreview property in WKWebView for iOS #5110
[webview_flutter] Expose the allowsLinkPreview property in WKWebView for iOS #5110
Conversation
…oid with allowsLinkPreview
Hi @b099l3, thanks for the contribution! We're currently working on reworking the plugin interface and converting the platform implementation to mirror the native apis. We have a current halt on new features until these two issues are complete. We'll revisit this PR/issue thereafter. |
The Dart conversion is complete, and this doesn't change anything problematic in the platform interface, so this is unblocked now. You'll just need to update the implementation for the new Dart version. |
nice I'll take a look this weekend |
@@ -1139,6 +1139,7 @@ void main() { | |||
const WebView( | |||
initialUrl: 'https://youtube.com', | |||
gestureNavigationEnabled: true, | |||
allowsLinkPreview: false, |
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.
can we also test the default value is true
?
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.
Removed the bool from this test 'creation' and created a new group for allowsLinkPreview
with default, disable, and can change tests.
/// This only works on iOS. | ||
/// | ||
/// By default `allowsLinkPreview` is true, to match the default on iOS. | ||
final bool allowsLinkPreview; |
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.'
@b099l3 Was this ready for another review? Are you still working on it? |
Hi sorry still working on it, had to get my head back in the code, looking at it today |
Cool think this is good for a review @bparrishMines when you have time |
verify(mockWebViewPlatformController.updateSettings(captureAny)) | ||
.captured | ||
.last as WebSettings; | ||
expect(disabledSettings.debuggingEnabled, true); |
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.
Shouldn't this be testing allowsLinkPreview
not debuggingEnabled
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.
changed to allowsLinkPreview
if (allowsInlineMediaPlayback != null) { | ||
configuration.setAllowsInlineMediaPlayback(allowsInlineMediaPlayback); | ||
} |
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 are a copy of the lines above.
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.
deleted these lines
@@ -243,6 +243,12 @@ abstract class PlatformWebViewController extends PlatformInterface { | |||
'enableGestureNavigation is not implemented on the current platform'); | |||
} | |||
|
|||
/// Whether to allow link previews on supported 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.
So it looks like you're adding the ability to set the value in the PlatformWebViewController.enableLinkPreview
and through WebView.allowsLinkPreview
. It should be one or the other because they can contradict. I don't have a preference on which one, so you can decide.
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.
removed PlatformWebViewController.enableLinkPreview
in favour of WebView.allowsLinkPreview
@bparrishMines I'm getting some funky test failures but I don't think I have changed that code. I have made the changes from the review |
@@ -435,6 +435,7 @@ void main() { | |||
hasProgressTracking: true, | |||
debuggingEnabled: true, | |||
gestureNavigationEnabled: true, | |||
allowsLinkPreview: false, |
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 believe a unit test is failing because you removed this value from the Method Channel implementation in #5110 (comment). So you can remove the changes to this test.
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.
Removed from the method channel test
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 comment
The reason will be displayed to describe this comment to others. Learn more.
This test is failing because the allowsLinkPreview
values needs to be updated at https://github.com/flutter/plugins/blob/main/packages/webview_flutter/webview_flutter/lib/src/webview.dart#L390.
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 removed allowsLinkPreview
from WebSettings
, I think that is correct?
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.
No, you still want allowsLinkPreview
in WebSettings
so that updates can be made to it. I would also re-add the test that were removed for it. You just need to add the updates to allowsLinkPreview
in the method mentioned above. e.g.
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 comment
The 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
The |
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!
If this looks good to @stuartmorgan and @cyanglaz, you should be able to make a separate PR with just the interface changes and we can land that first (#3): https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins
This will need to be updated for the restructuring in webview_flutter v4; once that's done we can re-review. Apologies that this fell through the cracks on secondary review while the v4 changes were happening, but we can make sure to review faster once it's updated. |
I'm going to go ahead and mark this as a draft since it needs to be reworked for v4, just to get it off of our review queue. Please mark it as ready for review once that's been done. Thanks! |
We've just completed the migration of the plugin code to the flutter/packages repository, as described in https://flutter.dev/go/flutter-plugins-repo-migration, and this repository is now being archived. Unfortunately that means that all in-progress PRs here must be moved to flutter/packages. Please see our instructions for an explanation of how to move your PR, and if you have any issues moving your PR please don't hesitate to reach out in the #hackers-ecosystem channel in Discord. Our apologies that your PR was caught in this one-time transition. We're aware that it's disruptive in the short term, and appreciate your help in getting us to a better long-term state! |
This PR fixes this issue:
Exposes the allowsLinkPreview boolean property on WKWebview. To enable or disable link previews.
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.