From 23f6ebc0b323752eb402432b891953721f76cc21 Mon Sep 17 00:00:00 2001 From: Jussi Lahdenniemi Date: Thu, 10 Jun 2021 08:53:57 +0300 Subject: [PATCH] Add a flag for forcing software rendering on Android --- README.md | 1 + .../com/flutter_webview_plugin/FlutterWebviewPlugin.java | 4 +++- .../java/com/flutter_webview_plugin/WebviewManager.java | 7 ++++++- lib/src/base.dart | 3 +++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3d03835b..fe391276 100644 --- a/README.md +++ b/README.md @@ -239,6 +239,7 @@ Future launch(String url, { bool geolocationEnabled: false, bool debuggingEnabled: false, bool ignoreSSLErrors: false, + bool softwareRender: false, }); ``` diff --git a/android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java b/android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java index 71e90444..764f1075 100644 --- a/android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java +++ b/android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java @@ -128,6 +128,7 @@ void openUrl(MethodCall call, MethodChannel.Result result) { boolean geolocationEnabled = call.argument("geolocationEnabled"); boolean debuggingEnabled = call.argument("debuggingEnabled"); boolean ignoreSSLErrors = call.argument("ignoreSSLErrors"); + boolean softwareRender = call.argument("softwareRender"); if (webViewManager == null || webViewManager.closed == true) { Map arguments = (Map) call.arguments; @@ -162,7 +163,8 @@ void openUrl(MethodCall call, MethodChannel.Result result) { invalidUrlRegex, geolocationEnabled, debuggingEnabled, - ignoreSSLErrors + ignoreSSLErrors, + softwareRender ); result.success(null); } diff --git a/android/src/main/java/com/flutter_webview_plugin/WebviewManager.java b/android/src/main/java/com/flutter_webview_plugin/WebviewManager.java index e19b2a08..2da02f76 100644 --- a/android/src/main/java/com/flutter_webview_plugin/WebviewManager.java +++ b/android/src/main/java/com/flutter_webview_plugin/WebviewManager.java @@ -380,7 +380,8 @@ void openUrl( String invalidUrlRegex, boolean geolocationEnabled, boolean debuggingEnabled, - boolean ignoreSSLErrors + boolean ignoreSSLErrors, + boolean softwareRender ) { webView.getSettings().setJavaScriptEnabled(withJavascript); webView.getSettings().setBuiltInZoomControls(withZoom); @@ -440,6 +441,10 @@ void openUrl( webView.setVerticalScrollBarEnabled(false); } + if (softwareRender) { + webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); + } + if (headers != null) { webView.loadUrl(url, headers); } else { diff --git a/lib/src/base.dart b/lib/src/base.dart index 2fdc0384..cf8be744 100644 --- a/lib/src/base.dart +++ b/lib/src/base.dart @@ -139,6 +139,7 @@ class FlutterWebviewPlugin { /// - [withOverviewMode]: enable overview mode for Android webview ( setLoadWithOverviewMode ) /// - [useWideViewPort]: use wide viewport for Android webview ( setUseWideViewPort ) /// - [ignoreSSLErrors]: use to bypass Android/iOS SSL checks e.g. for self-signed certificates + /// - [softwareRender]: use to force software rendering on Android Future launch( String url, { Map? headers, @@ -166,6 +167,7 @@ class FlutterWebviewPlugin { bool geolocationEnabled = false, bool debuggingEnabled = false, bool ignoreSSLErrors = false, + bool softwareRender = false, }) async { final args = { 'url': url, @@ -191,6 +193,7 @@ class FlutterWebviewPlugin { 'withOverviewMode': withOverviewMode, 'debuggingEnabled': debuggingEnabled, 'ignoreSSLErrors': ignoreSSLErrors, + 'softwareRender' : softwareRender, }; if (headers != null) {