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

Conversation

@dotcink
Copy link

@dotcink dotcink commented Mar 16, 2021

Add a common way to initialize Android WebView (make more settings) in Android code.

In most cases, an APP has custom common WebView initialization logic, like WebSettings#setBuiltInZoomControls(boolean), WebSettings#setMixedContentMode(int), WebSettings#setTextZoom(int) etc.
Adding all these settings to Flutter WebView params is tedious, and unnecessary mostly,
or else we can put these initialization on our APP's self native code as below:

FlutterWebView.setCommonIniter(new FlutterWebViewIniter() {
    @Override
    public void initWebView(WebView webView) {
        WebSettings settings = webView.getSettings();
        settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
        settings.setSupportZoom(true);
        settings.setBuiltInZoomControls(true);
        settings.setDisplayZoomControls(false);
    }
});

Fix flutter/flutter#70731, flutter/flutter#48283, flutter/flutter#43595, etc.
Related PRs: #2468, #3325, #3701, #2451

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 Flutter Style Guide and the C++, Objective-C, Java style guides.
  • 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.
  • I updated CHANGELOG.md to add a description of the change.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the 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.

@google-cla google-cla bot added the cla: yes label Mar 16, 2021
@github-actions github-actions bot added p: webview_flutter Edits files for a webview_flutter plugin platform-android labels Mar 16, 2021
@dotcink dotcink force-pushed the android-webview-common-initer branch 2 times, most recently from 6fe7627 to c2bd154 Compare March 16, 2021 17:40
@dotcink dotcink force-pushed the android-webview-common-initer branch from c2bd154 to 26659aa Compare March 16, 2021 17:44
@dotcink
Copy link
Author

dotcink commented Mar 16, 2021

@amirh @mklim @iskakaushik Please Take A Look.
Thank you.

@stuartmorgan-g
Copy link
Contributor

stuartmorgan-g commented Mar 16, 2021

Thanks for the submission! We’re currently working through a large backlog of PRs, and this will require non-trivial review, so it will take some time before we’re able to review it. As explained in CONTRIBUTING.md, votes for the corresponding issue are the primary way we’re prioritizing non-trivial reviews, so we encourage you to file an issue and associate it with this PR.

@stuartmorgan-g
Copy link
Contributor

(As a quick initial note, I'm not sure this is a direct we would want to take; generally Flutter developers expect to be able to control plugin behavior from Dart, in a cross-platform way; this does not allow for either.)

@dotcink
Copy link
Author

dotcink commented Mar 17, 2021

Thanks for the submission! We’re currently working through a large backlog of PRs, and this will require non-trivial review (since we need to evaluate whether there are API changes we need to make at the same time), so it will take some time before we’re able to review it. As explained in CONTRIBUTING.md, votes for the corresponding issue are the primary way we’re prioritizing non-trivial reviews, so we encourage you to file an issue and associate it with this PR.

I've associated this PR to some existing related issues, like flutter/flutter#70731.

@dotcink
Copy link
Author

dotcink commented Mar 17, 2021

(As a quick initial note, I'm not sure this is a direct we would want to take; generally Flutter developers expect to be able to control plugin behavior from Dart, in a cross-platform way; this does not allow for either.)

However, many settings, like mixedContentMode, are Android specific, and adding all WebSettings setters to flutter WebView params is tedious.
For iOS, we might set up WKWebView in plist file, like NSAllowsArbitraryLoadsInWebContent, this PR provides a plist alternative solution.

String userAgent = (String) params.get("userAgent");
updateUserAgent(userAgent);
}
if (commonIniter != null) commonIniter.initWebView(webView);

Choose a reason for hiding this comment

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

At present, websettings lacks many functions, and its behavior is quite different from that of IOS. It is recommended to agree to the change of PR and wait until webview_flutter had all these settings are satisfied, the initWebView method can be deprecated.

@stuartmorgan-g
Copy link
Contributor

Thanks for the submission, but based on recent discussions the team has had about how we want to structure platform-specific plugin logic, this is not an approach we will be going with. A rewrite is underway that will make it much easier to add Android-specific settings where necessary.

(In general, however, we want to make configuration, and defaults, consistent across platforms as much as possible. E.g., the right solution for the zoom controls in your example was to build the defaults into the plugin for consistency, and provide cross-platform options for changing them, not requiring all developers to add native code to their project to do that themselves.)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes p: webview_flutter Edits files for a webview_flutter plugin platform-android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[webview_flutter] Add more access to Webview settings

3 participants