Forráskód Böngészése

Merge pull request #117 from lakexyde/master

Scrollbar functionality to Web view
Hadrien Lejard 7 éve
szülő
commit
361d3d6f9a

+ 2 - 1
README.md

@@ -92,7 +92,8 @@ Future<Null> launch(String url,
          Rect rect: null,
          String userAgent: null,
          bool withZoom: false,
-         bool withLocalStorage: true});
+         bool withLocalStorage: true,
+         bool scrollBar: true});
 ```
 ```dart
 Future<String> evalJavascript(String code);

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

@@ -83,6 +83,7 @@ public class FlutterWebviewPlugin implements MethodCallHandler, PluginRegistry.A
         boolean clearCookies = call.argument("clearCookies");
         boolean withZoom = call.argument("withZoom");
         boolean withLocalStorage = call.argument("withLocalStorage");
+        boolean scrollBar = call.argument("scrollBar");
 
         if (webViewManager == null || webViewManager.closed == true) {
             webViewManager = new WebviewManager(activity);
@@ -99,7 +100,8 @@ public class FlutterWebviewPlugin implements MethodCallHandler, PluginRegistry.A
                 userAgent,
                 url,
                 withZoom,
-                withLocalStorage
+                withLocalStorage,
+                scrollBar
         );
         result.success(null);
     }

+ 5 - 1
android/src/main/java/com/flutter_webview_plugin/WebviewManager.java

@@ -175,7 +175,7 @@ class WebviewManager {
         webView.clearFormData();
     }
 
-    void openUrl(boolean withJavascript, boolean clearCache, boolean hidden, boolean clearCookies, String userAgent, String url, boolean withZoom, boolean withLocalStorage) {
+    void openUrl(boolean withJavascript, boolean clearCache, boolean hidden, boolean clearCookies, String userAgent, String url, boolean withZoom, boolean withLocalStorage, boolean scrollBar) {
         webView.getSettings().setJavaScriptEnabled(withJavascript);
         webView.getSettings().setBuiltInZoomControls(withZoom);
         webView.getSettings().setSupportZoom(withZoom);
@@ -197,6 +197,10 @@ class WebviewManager {
             webView.getSettings().setUserAgentString(userAgent);
         }
 
+        if(!scrollBar){
+            webView.setVerticalScrollBarEnabled(false);
+        }
+
         webView.loadUrl(url);
     }
 

+ 3 - 0
ios/Classes/FlutterWebviewPlugin.m

@@ -68,6 +68,7 @@ static NSString *const CHANNEL_NAME = @"flutter_webview_plugin";
     _enableAppScheme = call.arguments[@"enableAppScheme"];
     NSString *userAgent = call.arguments[@"userAgent"];
     NSNumber *withZoom = call.arguments[@"withZoom"];
+    NSNumber *scrollBar = call.arguments[@"scrollBar"];
     
     if (clearCache != (id)[NSNull null] && [clearCache boolValue]) {
         [[NSURLCache sharedURLCache] removeAllCachedResponses];
@@ -93,6 +94,8 @@ static NSString *const CHANNEL_NAME = @"flutter_webview_plugin";
     self.webview.navigationDelegate = self;
     self.webview.scrollView.delegate = self;
     self.webview.hidden = [hidden boolValue];
+    self.webview.showsHorizontalScrollIndicator = [scrollBar boolValue];
+    self.webView.showsVerticalScrollIndicator = [scrollBar boolValue];
 
     _enableZoom = [withZoom boolValue];
 

+ 5 - 2
lib/src/base.dart

@@ -76,6 +76,7 @@ class FlutterWebviewPlugin {
   ///     It is always enabled in UIWebView of iOS and  can not be disabled.
   /// - [withLocalUrl]: allow url as a local path
   ///     Allow local files on iOs > 9.0
+  /// - [scrollBar]: enable or disable scrollbar
   Future<Null> launch(String url,
       {bool withJavascript,
       bool clearCache,
@@ -86,7 +87,8 @@ class FlutterWebviewPlugin {
       String userAgent,
       bool withZoom,
       bool withLocalStorage,
-      bool withLocalUrl}) async {
+      bool withLocalUrl,
+      bool scrollBar}) async {
     Map<String, dynamic> args = {
       "url": url,
       "withJavascript": withJavascript ?? true,
@@ -97,7 +99,8 @@ class FlutterWebviewPlugin {
       "userAgent": userAgent,
       "withZoom": withZoom ?? false,
       "withLocalStorage": withLocalStorage ?? true,
-      "withLocalUrl": withLocalUrl ?? false
+      "withLocalUrl": withLocalUrl ?? false,
+      "scrollBar": scrollBar ?? true
     };
     if (rect != null) {
       args["rect"] = {

+ 5 - 2
lib/src/webview_scaffold.dart

@@ -19,6 +19,7 @@ class WebviewScaffold extends StatefulWidget {
   final bool withZoom;
   final bool withLocalStorage;
   final bool withLocalUrl;
+  final bool scrollBar;
 
   WebviewScaffold(
       {Key key,
@@ -34,7 +35,8 @@ class WebviewScaffold extends StatefulWidget {
       this.bottomNavigationBar,
       this.withZoom,
       this.withLocalStorage,
-      this.withLocalUrl})
+      this.withLocalUrl,
+      this.scrollBar})
       : super(key: key);
 
   @override
@@ -70,7 +72,8 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
           rect: _rect,
           withZoom: widget.withZoom,
           withLocalStorage: widget.withLocalStorage,
-          withLocalUrl: widget.withLocalUrl);
+          withLocalUrl: widget.withLocalUrl,
+          scrollBar: widget.scrollBar);
     } else {
       Rect rect = _buildRect(context);
       if (_rect != rect) {