Ver Fonte

Merge branch 'master' into add_resizeToAvoidBottomPadding

Matthew Jaoudi há 6 anos atrás
pai
commit
d6dd0a20a4

+ 10 - 1
android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java

@@ -97,6 +97,7 @@ public class FlutterWebviewPlugin implements MethodCallHandler, PluginRegistry.A
         Map<String, String> headers = call.argument("headers");
         boolean scrollBar = call.argument("scrollBar");
         boolean allowFileURLs = call.argument("allowFileURLs");
+        boolean geolocationEnabled = call.argument("geolocationEnabled");
 
         if (webViewManager == null || webViewManager.closed == true) {
             webViewManager = new WebviewManager(activity);
@@ -118,7 +119,8 @@ public class FlutterWebviewPlugin implements MethodCallHandler, PluginRegistry.A
                 scrollBar,
                 supportMultipleWindows,
                 appCacheEnabled,
-                allowFileURLs
+                allowFileURLs,
+                geolocationEnabled
         );
         result.success(null);
     }
@@ -147,6 +149,7 @@ public class FlutterWebviewPlugin implements MethodCallHandler, PluginRegistry.A
         if (webViewManager != null) {
             webViewManager.stopLoading(call, result);
         }
+        result.success(null);
     }
 
     private void close(MethodCall call, MethodChannel.Result result) {
@@ -163,6 +166,7 @@ public class FlutterWebviewPlugin implements MethodCallHandler, PluginRegistry.A
         if (webViewManager != null) {
             webViewManager.back(call, result);
         }
+        result.success(null);
     }
 
     /**
@@ -172,6 +176,7 @@ public class FlutterWebviewPlugin implements MethodCallHandler, PluginRegistry.A
         if (webViewManager != null) {
             webViewManager.forward(call, result);
         }
+        result.success(null);
     }
 
     /**
@@ -181,6 +186,7 @@ public class FlutterWebviewPlugin implements MethodCallHandler, PluginRegistry.A
         if (webViewManager != null) {
             webViewManager.reload(call, result);
         }
+        result.success(null);
     }
 
     private void reloadUrl(MethodCall call, MethodChannel.Result result) {
@@ -188,6 +194,7 @@ public class FlutterWebviewPlugin implements MethodCallHandler, PluginRegistry.A
             String url = call.argument("url");
             webViewManager.reloadUrl(url);
         }
+        result.success(null);
     }
 
     private void eval(MethodCall call, final MethodChannel.Result result) {
@@ -208,12 +215,14 @@ public class FlutterWebviewPlugin implements MethodCallHandler, PluginRegistry.A
         if (webViewManager != null) {
             webViewManager.hide(call, result);
         }
+        result.success(null);
     }
 
     private void show(MethodCall call, final MethodChannel.Result result) {
         if (webViewManager != null) {
             webViewManager.show(call, result);
         }
+        result.success(null);
     }
 
     private void cleanCookies(MethodCall call, final MethodChannel.Result result) {

+ 15 - 3
android/src/main/java/com/flutter_webview_plugin/WebviewManager.java

@@ -10,6 +10,7 @@ import android.view.KeyEvent;
 import android.view.View;
 import android.view.ViewGroup;
 import android.webkit.CookieManager;
+import android.webkit.GeolocationPermissions;
 import android.webkit.ValueCallback;
 import android.webkit.WebChromeClient;
 import android.webkit.WebSettings;
@@ -204,7 +205,8 @@ class WebviewManager {
             boolean scrollBar,
             boolean supportMultipleWindows,
             boolean appCacheEnabled,
-            boolean allowFileURLs
+            boolean allowFileURLs,
+            boolean geolocationEnabled
     ) {
         webView.getSettings().setJavaScriptEnabled(withJavascript);
         webView.getSettings().setBuiltInZoomControls(withZoom);
@@ -219,6 +221,16 @@ class WebviewManager {
         webView.getSettings().setAllowFileAccessFromFileURLs(allowFileURLs);
         webView.getSettings().setAllowUniversalAccessFromFileURLs(allowFileURLs);
 
+        if (geolocationEnabled) {
+            webView.getSettings().setGeolocationEnabled(true);
+            webView.setWebChromeClient(new WebChromeClient() {
+                @Override
+                public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
+                    callback.invoke(origin, true, false);
+                }
+            });
+        }
+
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
             webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
         }
@@ -228,7 +240,7 @@ class WebviewManager {
         }
 
         if (hidden) {
-            webView.setVisibility(View.INVISIBLE);
+            webView.setVisibility(View.GONE);
         }
 
         if (clearCookies) {
@@ -325,7 +337,7 @@ class WebviewManager {
     }
     void hide(MethodCall call, MethodChannel.Result result) {
         if (webView != null) {
-            webView.setVisibility(View.INVISIBLE);
+            webView.setVisibility(View.GONE);
         }
     }
     void show(MethodCall call, MethodChannel.Result result) {

+ 11 - 1
ios/Classes/FlutterWebviewPlugin.m

@@ -3,7 +3,7 @@
 static NSString *const CHANNEL_NAME = @"flutter_webview_plugin";
 
 // UIWebViewDelegate
-@interface FlutterWebviewPlugin() <WKNavigationDelegate, UIScrollViewDelegate> {
+@interface FlutterWebviewPlugin() <WKNavigationDelegate, UIScrollViewDelegate, WKUIDelegate> {
     BOOL _enableAppScheme;
     BOOL _enableZoom;
 }
@@ -105,6 +105,7 @@ static NSString *const CHANNEL_NAME = @"flutter_webview_plugin";
     }
 
     self.webview = [[WKWebView alloc] initWithFrame:rc];
+    self.webview.UIDelegate = self;
     self.webview.navigationDelegate = self;
     self.webview.scrollView.delegate = self;
     self.webview.hidden = [hidden boolValue];
@@ -260,6 +261,15 @@ static NSString *const CHANNEL_NAME = @"flutter_webview_plugin";
     }
 }
 
+- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration
+    forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures {
+
+    if (!navigationAction.targetFrame.isMainFrame) {
+        [webView loadRequest:navigationAction.request];
+    }
+
+    return nil;
+}
 
 - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
     [channel invokeMethod:@"onState" arguments:@{@"type": @"startLoad", @"url": webView.URL.absoluteString}];

+ 2 - 0
lib/src/base.dart

@@ -110,6 +110,7 @@ class FlutterWebviewPlugin {
     bool supportMultipleWindows,
     bool appCacheEnabled,
     bool allowFileURLs,
+    bool geolocationEnabled,
   }) async {
     final args = <String, dynamic>{
       'url': url,
@@ -126,6 +127,7 @@ class FlutterWebviewPlugin {
       'supportMultipleWindows': supportMultipleWindows ?? false,
       'appCacheEnabled': appCacheEnabled ?? false,
       'allowFileURLs': allowFileURLs ?? false,
+      'geolocationEnabled': geolocationEnabled ?? false,
     };
 
     if (headers != null) {

+ 13 - 0
lib/src/webview_scaffold.dart

@@ -31,6 +31,7 @@ class WebviewScaffold extends StatefulWidget {
     this.initialChild,
     this.allowFileURLs,
     this.resizeToAvoidBottomPadding = true,
+    this.geolocationEnabled
   }) : super(key: key);
 
   final PreferredSizeWidget appBar;
@@ -54,6 +55,7 @@ class WebviewScaffold extends StatefulWidget {
   final Widget initialChild;
   final bool allowFileURLs;
   final bool resizeToAvoidBottomPadding;
+  final bool geolocationEnabled;
 
   @override
   _WebviewScaffoldState createState() => _WebviewScaffoldState();
@@ -65,11 +67,19 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
   Timer _resizeTimer;
   StreamSubscription<WebViewStateChanged> _onStateChanged;
 
+  var _onDestroy;
+
   @override
   void initState() {
     super.initState();
     webviewReference.close();
 
+    _onDestroy = webviewReference.onDestroy.listen((_) {
+      if (mounted) {
+        Navigator.of(context).pop();
+      }
+    });
+
     if (widget.hidden) {
       _onStateChanged = webviewReference.onStateChanged.listen((WebViewStateChanged state) {
         if (state.type == WebViewState.finishLoad) {
@@ -82,6 +92,7 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
   @override
   void dispose() {
     super.dispose();
+    _onDestroy?.cancel();
     _resizeTimer?.cancel();
     webviewReference.close();
     if (widget.hidden) {
@@ -95,6 +106,7 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
     return Scaffold(
       appBar: widget.appBar,
       resizeToAvoidBottomPadding: widget.resizeToAvoidBottomPadding,
+      resizeToAvoidBottomInset: false,
       persistentFooterButtons: widget.persistentFooterButtons,
       bottomNavigationBar: widget.bottomNavigationBar,
       body: _WebviewPlaceholder(
@@ -118,6 +130,7 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
               supportMultipleWindows: widget.supportMultipleWindows,
               appCacheEnabled: widget.appCacheEnabled,
               allowFileURLs: widget.allowFileURLs,
+              geolocationEnabled: widget.geolocationEnabled
             );
           } else {
             if (_rect != value) {

+ 1 - 1
pubspec.yaml

@@ -7,7 +7,7 @@ authors:
 - Simon Lightfoot <simon@devangels.london>
 - Rafal Wachol <gorudonu@gmail.com>
 homepage: https://github.com/dart-flitter/flutter_webview_plugin
-version: 0.3.0+2
+version: 0.3.1
 maintainer: Simon Lightfoot (@slightfoot)
 
 environment: