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

Commit e1e9bd1

Browse files
author
Emmanuel Garcia
committed
Bring HTML inputs into view automatically
1 parent 088bdee commit e1e9bd1

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
public class FlutterWebView implements PlatformView, MethodCallHandler {
3131
private static final String JS_CHANNEL_NAMES_FIELD = "javascriptChannelNames";
32-
private final InputAwareWebView webView;
32+
private final WebView webView;
3333
private final MethodChannel methodChannel;
3434
private final FlutterWebViewClient flutterWebViewClient;
3535
private final Handler platformThreadHandler;
@@ -92,7 +92,13 @@ public void onProgressChanged(WebView view, int progress) {
9292
DisplayManager displayManager =
9393
(DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
9494
displayListenerProxy.onPreWebViewInitialization(displayManager);
95-
webView = new InputAwareWebView(context, containerView);
95+
96+
Boolean usesHybridComposition = (Boolean) params.get("usesHybridComposition");
97+
webView =
98+
(usesHybridComposition)
99+
? new WebView(context)
100+
: new InputAwareWebView(context, containerView);
101+
96102
displayListenerProxy.onPostWebViewInitialization(displayManager);
97103

98104
platformThreadHandler = new Handler(context.getMainLooper());
@@ -140,7 +146,9 @@ public View getView() {
140146
// of Flutter but used as an override anyway wherever it's actually defined.
141147
// TODO(mklim): Add the @Override annotation once flutter/engine#9727 rolls to stable.
142148
public void onInputConnectionUnlocked() {
143-
webView.unlockInputConnection();
149+
if (webView instanceof InputAwareWebView) {
150+
((InputAwareWebView) webView).unlockInputConnection();
151+
}
144152
}
145153

146154
// @Override
@@ -150,7 +158,9 @@ public void onInputConnectionUnlocked() {
150158
// of Flutter but used as an override anyway wherever it's actually defined.
151159
// TODO(mklim): Add the @Override annotation once flutter/engine#9727 rolls to stable.
152160
public void onInputConnectionLocked() {
153-
webView.lockInputConnection();
161+
if (webView instanceof InputAwareWebView) {
162+
((InputAwareWebView) webView).lockInputConnection();
163+
}
154164
}
155165

156166
// @Override
@@ -160,7 +170,9 @@ public void onInputConnectionLocked() {
160170
// of Flutter but used as an override anyway wherever it's actually defined.
161171
// TODO(mklim): Add the @Override annotation once stable passes v1.10.9.
162172
public void onFlutterViewAttached(View flutterView) {
163-
webView.setContainerView(flutterView);
173+
if (webView instanceof InputAwareWebView) {
174+
((InputAwareWebView) webView).setContainerView(flutterView);
175+
}
164176
}
165177

166178
// @Override
@@ -170,7 +182,9 @@ public void onFlutterViewAttached(View flutterView) {
170182
// of Flutter but used as an override anyway wherever it's actually defined.
171183
// TODO(mklim): Add the @Override annotation once stable passes v1.10.9.
172184
public void onFlutterViewDetached() {
173-
webView.setContainerView(null);
185+
if (webView instanceof InputAwareWebView) {
186+
((InputAwareWebView) webView).setContainerView(null);
187+
}
174188
}
175189

176190
@Override
@@ -425,7 +439,9 @@ private void updateUserAgent(String userAgent) {
425439
@Override
426440
public void dispose() {
427441
methodChannel.setMethodCallHandler(null);
428-
webView.dispose();
442+
if (webView instanceof InputAwareWebView) {
443+
((InputAwareWebView) webView).dispose();
444+
}
429445
webView.destroy();
430446
}
431447
}

packages/webview_flutter/lib/src/webview_method_channel.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,16 @@ class MethodChannelWebViewPlatform implements WebViewPlatformController {
201201
/// This is used for the `creationParams` argument of the platform views created by
202202
/// [AndroidWebViewBuilder] and [CupertinoWebViewBuilder].
203203
static Map<String, dynamic> creationParamsToMap(
204-
CreationParams creationParams) {
204+
CreationParams creationParams, {
205+
bool usesHybridComposition = false,
206+
}) {
205207
return <String, dynamic>{
206208
'initialUrl': creationParams.initialUrl,
207209
'settings': _webSettingsToMap(creationParams.webSettings),
208210
'javascriptChannelNames': creationParams.javascriptChannelNames.toList(),
209211
'userAgent': creationParams.userAgent,
210212
'autoMediaPlaybackPolicy': creationParams.autoMediaPlaybackPolicy.index,
213+
'usesHybridComposition': usesHybridComposition,
211214
};
212215
}
213216
}

packages/webview_flutter/lib/webview_flutter.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class SurfaceAndroidWebView extends AndroidWebView {
109109
layoutDirection: TextDirection.rtl,
110110
creationParams: MethodChannelWebViewPlatform.creationParamsToMap(
111111
creationParams,
112+
usesHybridComposition: true,
112113
),
113114
creationParamsCodec: const StandardMessageCodec(),
114115
)

0 commit comments

Comments
 (0)