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

Commit

Permalink
Bring HTML inputs into view automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Garcia committed Mar 2, 2021
1 parent 088bdee commit e1e9bd1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

public class FlutterWebView implements PlatformView, MethodCallHandler {
private static final String JS_CHANNEL_NAMES_FIELD = "javascriptChannelNames";
private final InputAwareWebView webView;
private final WebView webView;
private final MethodChannel methodChannel;
private final FlutterWebViewClient flutterWebViewClient;
private final Handler platformThreadHandler;
Expand Down Expand Up @@ -92,7 +92,13 @@ public void onProgressChanged(WebView view, int progress) {
DisplayManager displayManager =
(DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
displayListenerProxy.onPreWebViewInitialization(displayManager);
webView = new InputAwareWebView(context, containerView);

Boolean usesHybridComposition = (Boolean) params.get("usesHybridComposition");
webView =
(usesHybridComposition)
? new WebView(context)
: new InputAwareWebView(context, containerView);

displayListenerProxy.onPostWebViewInitialization(displayManager);

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

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

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

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

@Override
Expand Down Expand Up @@ -425,7 +439,9 @@ private void updateUserAgent(String userAgent) {
@Override
public void dispose() {
methodChannel.setMethodCallHandler(null);
webView.dispose();
if (webView instanceof InputAwareWebView) {
((InputAwareWebView) webView).dispose();
}
webView.destroy();
}
}
5 changes: 4 additions & 1 deletion packages/webview_flutter/lib/src/webview_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,16 @@ class MethodChannelWebViewPlatform implements WebViewPlatformController {
/// This is used for the `creationParams` argument of the platform views created by
/// [AndroidWebViewBuilder] and [CupertinoWebViewBuilder].
static Map<String, dynamic> creationParamsToMap(
CreationParams creationParams) {
CreationParams creationParams, {
bool usesHybridComposition = false,
}) {
return <String, dynamic>{
'initialUrl': creationParams.initialUrl,
'settings': _webSettingsToMap(creationParams.webSettings),
'javascriptChannelNames': creationParams.javascriptChannelNames.toList(),
'userAgent': creationParams.userAgent,
'autoMediaPlaybackPolicy': creationParams.autoMediaPlaybackPolicy.index,
'usesHybridComposition': usesHybridComposition,
};
}
}
1 change: 1 addition & 0 deletions packages/webview_flutter/lib/webview_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class SurfaceAndroidWebView extends AndroidWebView {
layoutDirection: TextDirection.rtl,
creationParams: MethodChannelWebViewPlatform.creationParamsToMap(
creationParams,
usesHybridComposition: true,
),
creationParamsCodec: const StandardMessageCodec(),
)
Expand Down

0 comments on commit e1e9bd1

Please sign in to comment.