Browse Source

Exposes displayZoomControls, withOverviewMode and useWideViewPort settings for Android WebView

John Zhong 6 years ago
parent
commit
5905fb4015

+ 3 - 0
README.md

@@ -156,6 +156,9 @@ Future<Null> launch(String url, {
    bool supportMultipleWindows: false,
    bool appCacheEnabled: false,
    bool allowFileURLs: false,
+   bool displayZoomControls: false,
+   bool useWideViewPort: false,
+   bool withOverviewMode: false,
 });
 ```
 

+ 4 - 0
android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java

@@ -93,7 +93,9 @@ public class FlutterWebviewPlugin implements MethodCallHandler, PluginRegistry.A
         boolean clearCache = call.argument("clearCache");
         boolean clearCookies = call.argument("clearCookies");
         boolean withZoom = call.argument("withZoom");
+        boolean displayZoomControls = call.argument("displayZoomControls");
         boolean withLocalStorage = call.argument("withLocalStorage");
+        boolean withOverviewMode = call.argument("withOverviewMode");
         boolean supportMultipleWindows = call.argument("supportMultipleWindows");
         boolean appCacheEnabled = call.argument("appCacheEnabled");
         Map<String, String> headers = call.argument("headers");
@@ -119,7 +121,9 @@ public class FlutterWebviewPlugin implements MethodCallHandler, PluginRegistry.A
                 url,
                 headers,
                 withZoom,
+                displayZoomControls,
                 withLocalStorage,
+                withOverviewMode,
                 scrollBar,
                 supportMultipleWindows,
                 appCacheEnabled,

+ 4 - 0
android/src/main/java/com/flutter_webview_plugin/WebviewManager.java

@@ -339,7 +339,9 @@ class WebviewManager {
             String url,
             Map<String, String> headers,
             boolean withZoom,
+            boolean displayZoomControls,
             boolean withLocalStorage,
+            boolean withOverviewMode,
             boolean scrollBar,
             boolean supportMultipleWindows,
             boolean appCacheEnabled,
@@ -351,7 +353,9 @@ class WebviewManager {
         webView.getSettings().setJavaScriptEnabled(withJavascript);
         webView.getSettings().setBuiltInZoomControls(withZoom);
         webView.getSettings().setSupportZoom(withZoom);
+        webView.getSettings().setDisplayZoomControls(displayZoomControls);
         webView.getSettings().setDomStorageEnabled(withLocalStorage);
+        webView.getSettings().setLoadWithOverviewMode(withOverviewMode);
         webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(supportMultipleWindows);
 
         webView.getSettings().setSupportMultipleWindows(supportMultipleWindows);

+ 8 - 0
lib/src/base.dart

@@ -104,6 +104,10 @@ class FlutterWebviewPlugin {
   /// - [invalidUrlRegex] is the regular expression of URLs that web view shouldn't load.
   /// For example, when webview is redirected to a specific URL, you want to intercept
   /// this process by stopping loading this URL and replacing webview by another screen.
+  ///   Android only settings:
+  /// - [displayZoomControls]: display zoom controls on webview
+  /// - [withOverviewMode]: enable overview mode for Android webview ( setLoadWithOverviewMode )
+  /// - [useWideViewPort]: use wide viewport for Android webview ( setUseWideViewPort )
   Future<Null> launch(String url, {
     Map<String, String> headers,
     bool withJavascript,
@@ -114,8 +118,10 @@ class FlutterWebviewPlugin {
     Rect rect,
     String userAgent,
     bool withZoom,
+    bool displayZoomControls,
     bool withLocalStorage,
     bool withLocalUrl,
+    bool withOverviewMode,
     bool scrollBar,
     bool supportMultipleWindows,
     bool appCacheEnabled,
@@ -133,6 +139,7 @@ class FlutterWebviewPlugin {
       'enableAppScheme': enableAppScheme ?? true,
       'userAgent': userAgent,
       'withZoom': withZoom ?? false,
+      'displayZoomControls': displayZoomControls ?? false,
       'withLocalStorage': withLocalStorage ?? true,
       'withLocalUrl': withLocalUrl ?? false,
       'scrollBar': scrollBar ?? true,
@@ -142,6 +149,7 @@ class FlutterWebviewPlugin {
       'useWideViewPort': useWideViewPort ?? false,
       'invalidUrlRegex': invalidUrlRegex,
       'geolocationEnabled': geolocationEnabled ?? false,
+      'withOverviewMode': withOverviewMode ?? false,
     };
 
     if (headers != null) {

+ 9 - 0
lib/src/webview_scaffold.dart

@@ -22,8 +22,11 @@ class WebviewScaffold extends StatefulWidget {
     this.persistentFooterButtons,
     this.bottomNavigationBar,
     this.withZoom,
+    this.displayZoomControls,
     this.withLocalStorage,
     this.withLocalUrl,
+    this.withOverviewMode,
+    this.useWideViewPort,
     this.scrollBar,
     this.supportMultipleWindows,
     this.appCacheEnabled,
@@ -47,6 +50,7 @@ class WebviewScaffold extends StatefulWidget {
   final List<Widget> persistentFooterButtons;
   final Widget bottomNavigationBar;
   final bool withZoom;
+  final bool displayZoomControls;
   final bool withLocalStorage;
   final bool withLocalUrl;
   final bool scrollBar;
@@ -58,6 +62,8 @@ class WebviewScaffold extends StatefulWidget {
   final bool resizeToAvoidBottomInset;
   final String invalidUrlRegex;
   final bool geolocationEnabled;
+  final bool withOverviewMode;
+  final bool useWideViewPort;
 
   @override
   _WebviewScaffoldState createState() => _WebviewScaffoldState();
@@ -125,8 +131,11 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
               userAgent: widget.userAgent,
               rect: _rect,
               withZoom: widget.withZoom,
+              displayZoomControls: widget.displayZoomControls,
               withLocalStorage: widget.withLocalStorage,
               withLocalUrl: widget.withLocalUrl,
+              withOverviewMode: widget.withOverviewMode,
+              useWideViewPort: widget.useWideViewPort,
               scrollBar: widget.scrollBar,
               supportMultipleWindows: widget.supportMultipleWindows,
               appCacheEnabled: widget.appCacheEnabled,