Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[webview_flutter] Expose the allowsLinkPreview property in WKWebView for iOS #5110

Closed

Conversation

b099l3
Copy link

@b099l3 b099l3 commented Mar 26, 2022

This PR fixes this issue:

Exposes the allowsLinkPreview boolean property on WKWebview. To enable or disable link previews.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@bparrishMines
Copy link
Contributor

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.

@stuartmorgan
Copy link
Contributor

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.

@b099l3
Copy link
Author

b099l3 commented Jul 29, 2022

nice I'll take a look this weekend

@b099l3 b099l3 requested a review from cyanglaz as a code owner July 31, 2022 21:32
@@ -1139,6 +1139,7 @@ void main() {
const WebView(
initialUrl: 'https://youtube.com',
gestureNavigationEnabled: true,
allowsLinkPreview: false,
Copy link
Contributor

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?

Copy link
Author

@b099l3 b099l3 Sep 2, 2022

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;
Copy link
Contributor

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.

Copy link
Contributor

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.)

Copy link
Author

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.'

@bparrishMines
Copy link
Contributor

@b099l3 Was this ready for another review? Are you still working on it?

@b099l3
Copy link
Author

b099l3 commented Sep 2, 2022

Hi sorry still working on it, had to get my head back in the code, looking at it today

@b099l3 b099l3 requested review from cyanglaz and removed request for ditman and bparrishMines September 2, 2022 16:24
@b099l3
Copy link
Author

b099l3 commented Sep 7, 2022

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);
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

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

changed to allowsLinkPreview

Comment on lines 250 to 252
if (allowsInlineMediaPlayback != null) {
configuration.setAllowsInlineMediaPlayback(allowsInlineMediaPlayback);
}
Copy link
Contributor

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.

Copy link
Author

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.
Copy link
Contributor

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.

Copy link
Author

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

@b099l3
Copy link
Author

b099l3 commented Sep 10, 2022

@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

@b099l3 b099l3 requested review from bparrishMines and stuartmorgan and removed request for bparrishMines September 10, 2022 12:17
@@ -435,6 +435,7 @@ void main() {
hasProgressTracking: true,
debuggingEnabled: true,
gestureNavigationEnabled: true,
allowsLinkPreview: false,
Copy link
Contributor

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.

Copy link
Author

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 {
Copy link
Contributor

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.

Copy link
Author

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?

Copy link
Contributor

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,
  );
}

Copy link
Author

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

@bparrishMines
Copy link
Contributor

The ios-build_all_plugins CHANNEL:stable is failing due to an infra error. It should pass on a rerun.
ios-platform_tests CHANNEL:master is failing due to a flake. It should pass on a rerun as well.

@b099l3 b099l3 requested review from bparrishMines and removed request for stuartmorgan September 17, 2022 12:19
Copy link
Contributor

@bparrishMines bparrishMines left a 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

@stuartmorgan
Copy link
Contributor

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.

@stuartmorgan
Copy link
Contributor

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!

@stuartmorgan stuartmorgan marked this pull request as draft February 9, 2023 20:48
@stuartmorgan
Copy link
Contributor

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!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p: webview_flutter Edits files for a webview_flutter plugin platform-ios
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants