Просмотр исходного кода

Merge pull request #143 from peter9teufel/stop_loading

stopLoading() MethodCall
Hadrien Lejard 7 лет назад
Родитель
Сommit
fc12f02990

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

@@ -67,6 +67,9 @@ public class FlutterWebviewPlugin implements MethodCallHandler, PluginRegistry.A
                 break;
                 break;
             case "reloadUrl":
             case "reloadUrl":
                 reloadUrl(call, result);
                 reloadUrl(call, result);
+                break;
+            case "stopLoading":
+                stopLoading(call, result);
                 break;				
                 break;				
             default:
             default:
                 result.notImplemented();
                 result.notImplemented();
@@ -128,6 +131,12 @@ public class FlutterWebviewPlugin implements MethodCallHandler, PluginRegistry.A
         return params;
         return params;
     }
     }
 
 
+    private void stopLoading(MethodCall call, MethodChannel.Result result) {
+        if (webViewManager != null){
+            webViewManager.stopLoading(call, result);
+        }
+    }
+
     private void close(MethodCall call, MethodChannel.Result result) {
     private void close(MethodCall call, MethodChannel.Result result) {
         if (webViewManager != null) {
         if (webViewManager != null) {
             webViewManager.close(call, result);
             webViewManager.close(call, result);

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

@@ -301,4 +301,10 @@ class WebviewManager {
             webView.setVisibility(View.VISIBLE);
             webView.setVisibility(View.VISIBLE);
         }
         }
     }
     }
+
+    void stopLoading(MethodCall call, MethodChannel.Result result){
+        if (webView != null){
+            webView.stopLoading();
+        }
+    }
 }
 }

+ 8 - 0
ios/Classes/FlutterWebviewPlugin.m

@@ -55,6 +55,9 @@ static NSString *const CHANNEL_NAME = @"flutter_webview_plugin";
     } else if ([@"hide" isEqualToString:call.method]) {
     } else if ([@"hide" isEqualToString:call.method]) {
         [self hide];
         [self hide];
         result(nil);
         result(nil);
+    } else if ([@"stopLoading" isEqualToString:call.method]) {
+        [self stopLoading];
+        result(nil);
     } else {
     } else {
         result(FlutterMethodNotImplemented);
         result(FlutterMethodNotImplemented);
     }
     }
@@ -196,6 +199,11 @@ static NSString *const CHANNEL_NAME = @"flutter_webview_plugin";
         self.webview.hidden = true;
         self.webview.hidden = true;
     }
     }
 }
 }
+- (void)stopLoading {
+    if (self.webview != nil) {
+        [self.webview stopLoading];
+    }
+}
 
 
 #pragma mark -- WkWebView Delegate
 #pragma mark -- WkWebView Delegate
 - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction
 - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction

+ 3 - 0
lib/src/base.dart

@@ -172,6 +172,9 @@ class FlutterWebviewPlugin {
     await _channel.invokeMethod('reloadUrl', args);
     await _channel.invokeMethod('reloadUrl', args);
   }
   }
 
 
+  // Stops current loading process
+  Future stopLoading() => _channel.invokeMethod("stopLoading");
+
   /// adds the plugin as ActivityResultListener
   /// adds the plugin as ActivityResultListener
   /// Only needed and used on Android
   /// Only needed and used on Android
   Future registerAcitivityResultListener() =>
   Future registerAcitivityResultListener() =>