Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 560694c

Browse files
author
Michael Klimushyn
authored
[webview_flutter] Fix double tap on resize issue (#1965)
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.
1 parent 40ef139 commit 560694c

File tree

6 files changed

+26
-12
lines changed

6 files changed

+26
-12
lines changed

packages/webview_flutter/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.3.11+2
2+
3+
* Add fix for input connection being dropped after a screen resize on certain
4+
Android devices.
5+
16
## 0.3.11+1
27

38
* Work around a bug in old Android WebView versions that was causing a crash

packages/webview_flutter/README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ Keyboard support within webviews is also experimental. The above tags also
2222
surface known issues with keyboard input. Some currently known keyboard issues,
2323
as of `webview_flutter` version `0.3.10+4`:
2424

25-
* [Input needs to be tapped twice to be registered on Samsung
26-
devices](https://github.com/flutter/flutter/issues/35867)
27-
* [Keyboard behavior is buggy after a
28-
resize](https://github.com/flutter/flutter/issues/36978)
2925
* [Keyboard persists after tapping outside text
3026
field](https://github.com/flutter/flutter/issues/36478)
27+
* [WebView's text selection dialog is not responding to touch
28+
events](https://github.com/flutter/flutter/issues/24585)
3129

3230
## Setup
3331

packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebViewClient.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.annotation.TargetApi;
88
import android.os.Build;
99
import android.util.Log;
10+
import android.view.KeyEvent;
1011
import android.webkit.WebResourceRequest;
1112
import android.webkit.WebView;
1213
import android.webkit.WebViewClient;
@@ -110,6 +111,13 @@ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request
110111
public void onPageFinished(WebView view, String url) {
111112
FlutterWebViewClient.this.onPageFinished(view, url);
112113
}
114+
115+
@Override
116+
public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
117+
// Deliberately empty. Occasionally the webview will mark events as having failed to be
118+
// handled even though they were handled. We don't want to propagate those as they're not
119+
// truly lost.
120+
}
113121
};
114122
}
115123

@@ -130,6 +138,13 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
130138
public void onPageFinished(WebView view, String url) {
131139
FlutterWebViewClient.this.onPageFinished(view, url);
132140
}
141+
142+
@Override
143+
public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
144+
// Deliberately empty. Occasionally the webview will mark events as having failed to be
145+
// handled even though they were handled. We don't want to propagate those as they're not
146+
// truly lost.
147+
}
133148
};
134149
}
135150

packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/InputAwareWebView.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,11 @@ void lockInputConnection() {
4343

4444
/** Sets the proxy adapter view back to its default behavior. */
4545
void unlockInputConnection() {
46-
if (proxyAdapterView != null) {
47-
proxyAdapterView.setLocked(false);
46+
if (proxyAdapterView == null) {
47+
return;
4848
}
4949

50-
// Restart the input connection to avoid ViewRootImpl assuming an incorrect window state.
51-
InputMethodManager imm =
52-
(InputMethodManager) containerView.getContext().getSystemService(INPUT_METHOD_SERVICE);
53-
imm.restartInput(containerView);
50+
proxyAdapterView.setLocked(false);
5451
}
5552

5653
/** Restore the original InputConnection, if needed. */

packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
/** WebViewFlutterPlugin */
1010
public class WebViewFlutterPlugin {
11-
1211
/** Plugin registration. */
1312
public static void registerWith(Registrar registrar) {
1413
registrar

packages/webview_flutter/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: webview_flutter
22
description: A Flutter plugin that provides a WebView widget on Android and iOS.
3-
version: 0.3.11+1
3+
version: 0.3.11+2
44
author: Flutter Team <flutter-dev@googlegroups.com>
55
homepage: https://github.com/flutter/plugins/tree/master/packages/webview_flutter
66

0 commit comments

Comments
 (0)