This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[webview_flutter] add COMMON support for Android WebView initializing #3721
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebViewIniter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Copyright 2019 The Chromium Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| package io.flutter.plugins.webviewflutter; | ||
|
|
||
| import android.webkit.WebView; | ||
|
|
||
| /** | ||
| * Interface to initialize Flutter WebView in native Android code. | ||
| * | ||
| * <p>Why? In most cases, an APP has custom COMMON WebView initialization logic, like {@link | ||
| * android.webkit.WebSettings#setBuiltInZoomControls(boolean)}, {@link | ||
| * android.webkit.WebSettings#setMixedContentMode(int)}, {@link | ||
| * android.webkit.WebSettings#setTextZoom(int)} etc. | ||
| * | ||
| * <p>Adding all these settings to Flutter WebView params is tedious, and unnecessary mostly, so we | ||
| * can put these initialization on our APP's self native code as you like. | ||
| */ | ||
| public interface FlutterWebViewIniter { | ||
| /** How to initialize WebView */ | ||
| void initWebView(WebView webView); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...utter/example/android/app/src/main/java/io/flutter/plugins/webviewflutterexample/App.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package io.flutter.plugins.webviewflutterexample; | ||
|
|
||
| import android.os.Build; | ||
| import android.webkit.WebSettings; | ||
| import android.webkit.WebView; | ||
| import io.flutter.app.FlutterApplication; | ||
| import io.flutter.plugins.webviewflutter.FlutterWebView; | ||
| import io.flutter.plugins.webviewflutter.FlutterWebViewIniter; | ||
|
|
||
| public class App extends FlutterApplication implements FlutterWebViewIniter { | ||
| @Override | ||
| public void onCreate() { | ||
| super.onCreate(); | ||
|
|
||
| FlutterWebView.setCommonIniter(this); | ||
| } | ||
|
|
||
| @Override | ||
| public void initWebView(WebView webView) { | ||
| WebSettings settings = webView.getSettings(); | ||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
| settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE); | ||
| } | ||
| settings.setSupportZoom(true); | ||
| settings.setBuiltInZoomControls(true); | ||
| settings.setDisplayZoomControls(false); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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
initWebViewmethod can be deprecated.