From ea6159177ff20f847c221bcb47f9e2d34b372b4f Mon Sep 17 00:00:00 2001 From: Michael Klimushyn Date: Fri, 9 Aug 2019 14:46:08 -0700 Subject: [PATCH] [webview_flutter] Fix double tap on resize issue WebView is incorrectly dropping some input events as unhandled. Previously we were restarting the input connection to try and work around this, but that causes a long tail of bugs in various SDK and WebView versions. Stop the events from bubbling instead since they still appear to be correctly handled despite being marked wrong. Long term we should figure out why this is happening in WebView and figure out a deeper fix for this issue, but this workaround solves the linked bugs in the immediate short term. --- packages/webview_flutter/CHANGELOG.md | 5 +++++ packages/webview_flutter/README.md | 6 ++---- .../webviewflutter/FlutterWebViewClient.java | 15 +++++++++++++++ .../plugins/webviewflutter/InputAwareWebView.java | 9 +++------ .../webviewflutter/WebViewFlutterPlugin.java | 1 - packages/webview_flutter/pubspec.yaml | 2 +- 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/packages/webview_flutter/CHANGELOG.md b/packages/webview_flutter/CHANGELOG.md index 6e7f498968f0..0bcb47f4cab3 100644 --- a/packages/webview_flutter/CHANGELOG.md +++ b/packages/webview_flutter/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.3.11+2 + +* Add fix for input connection being dropped after a screen resize on certain + Android devices. + ## 0.3.11+1 * Work around a bug in old Android WebView versions that was causing a crash diff --git a/packages/webview_flutter/README.md b/packages/webview_flutter/README.md index 8e8d3979d8f8..47e5c008edf6 100644 --- a/packages/webview_flutter/README.md +++ b/packages/webview_flutter/README.md @@ -22,12 +22,10 @@ Keyboard support within webviews is also experimental. The above tags also surface known issues with keyboard input. Some currently known keyboard issues, as of `webview_flutter` version `0.3.10+4`: -* [Input needs to be tapped twice to be registered on Samsung - devices](https://github.com/flutter/flutter/issues/35867) -* [Keyboard behavior is buggy after a - resize](https://github.com/flutter/flutter/issues/36978) * [Keyboard persists after tapping outside text field](https://github.com/flutter/flutter/issues/36478) +* [WebView's text selection dialog is not responding to touch + events](https://github.com/flutter/flutter/issues/24585) ## Setup diff --git a/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebViewClient.java b/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebViewClient.java index e7b10ce2257b..bdd6abb66282 100644 --- a/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebViewClient.java +++ b/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebViewClient.java @@ -7,6 +7,7 @@ import android.annotation.TargetApi; import android.os.Build; import android.util.Log; +import android.view.KeyEvent; import android.webkit.WebResourceRequest; import android.webkit.WebView; import android.webkit.WebViewClient; @@ -110,6 +111,13 @@ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request public void onPageFinished(WebView view, String url) { FlutterWebViewClient.this.onPageFinished(view, url); } + + @Override + public void onUnhandledKeyEvent(WebView view, KeyEvent event) { + // Deliberately empty. Occasionally the webview will mark events as having failed to be + // handled even though they were handled. We don't want to propagate those as they're not + // truly lost. + } }; } @@ -130,6 +138,13 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) { public void onPageFinished(WebView view, String url) { FlutterWebViewClient.this.onPageFinished(view, url); } + + @Override + public void onUnhandledKeyEvent(WebView view, KeyEvent event) { + // Deliberately empty. Occasionally the webview will mark events as having failed to be + // handled even though they were handled. We don't want to propagate those as they're not + // truly lost. + } }; } diff --git a/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/InputAwareWebView.java b/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/InputAwareWebView.java index 93b5c57926fd..b4783c1746f9 100644 --- a/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/InputAwareWebView.java +++ b/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/InputAwareWebView.java @@ -43,14 +43,11 @@ void lockInputConnection() { /** Sets the proxy adapter view back to its default behavior. */ void unlockInputConnection() { - if (proxyAdapterView != null) { - proxyAdapterView.setLocked(false); + if (proxyAdapterView == null) { + return; } - // Restart the input connection to avoid ViewRootImpl assuming an incorrect window state. - InputMethodManager imm = - (InputMethodManager) containerView.getContext().getSystemService(INPUT_METHOD_SERVICE); - imm.restartInput(containerView); + proxyAdapterView.setLocked(false); } /** Restore the original InputConnection, if needed. */ diff --git a/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.java b/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.java index abc4f09f8034..17177541222c 100644 --- a/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.java +++ b/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.java @@ -8,7 +8,6 @@ /** WebViewFlutterPlugin */ public class WebViewFlutterPlugin { - /** Plugin registration. */ public static void registerWith(Registrar registrar) { registrar diff --git a/packages/webview_flutter/pubspec.yaml b/packages/webview_flutter/pubspec.yaml index 9999ca9519b3..5af01a9b0a1c 100644 --- a/packages/webview_flutter/pubspec.yaml +++ b/packages/webview_flutter/pubspec.yaml @@ -1,6 +1,6 @@ name: webview_flutter description: A Flutter plugin that provides a WebView widget on Android and iOS. -version: 0.3.11+1 +version: 0.3.11+2 author: Flutter Team homepage: https://github.com/flutter/plugins/tree/master/packages/webview_flutter