Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedded Android views can't bring up the keyboard #19718

Open
amirh opened this issue Jul 24, 2018 · 99 comments

Comments

@amirh
Copy link
Contributor

commented Jul 24, 2018

To make sure that Flutter can always bring up the keyboard I made the window of virtual display's presentation non focusable.
As a result the embedded Android views cannot bring up the keyboard.

We should figure out if there's some window trickery we can do to let the unfocused window bring up the keyboard. Alternatively see if it's possible to dynamically select the focused window when delivering input events.

@fujinjun

This comment has been minimized.

Copy link

commented Dec 5, 2018

anyone solved this problem?

@bvedam

This comment has been minimized.

Copy link

commented Jan 16, 2019

Still seeing the issue on the following versions. Surprised to see this issue is still not resolved after 6 months.

compileSdkVersion = targetSdkVersion = 26 & 27

Tried both stable and beta channels.

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v1.0.0, on Microsoft Windows [Version 10.0.16299.847], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK 28.0.3)
[√] Android Studio (version 3.2)
[√] VS Code, 64-bit edition (version 1.30.2)
[√] Connected device (1 available)

• No issues found!

Can someone respond with the status please. Thanks.

@amirh

This comment has been minimized.

Copy link
Contributor Author

commented Jan 16, 2019

Since as far as I can tell there isn't a way for an Android app to dynamically change the focused window, and as only the focused window can bring up and use a keyboard, the only approach I see right now is to setup up some proxying mechanism for input connections which isn't trivial on it's own as non trivial trickery is required to figure out when a webview is asking for keyboard. Last I dug into this I had a somewhat complex plan which I haven't tested yet (if someone have a suggestion for a clean solution I'd be very happy to hear about it).

An alternative approach would be to use an iOS style platform view embedding mechanism when keyboard is needed (splitting the Flutter surface instead of rendering to a texture), this will have the drawback of not supporting all transforms (e.g if you'll opt in for keyboard support you will trade things like color filters, backdrop filter, perspective transforms and more).

All this to say that this is a non trivial effort, I do think it is important and will try to get it, but right now I'm focusing on finalizing and quality of the current set of platform views features.

@bvedam

This comment has been minimized.

Copy link

commented Jan 17, 2019

Thank you very much for detailing the problem in hand, and its complexity. Currently using flutter_inappbrowser plugin based that is based on AndroidView, which is why I have this problem. I initially used the flutter community plugin "flutter_webview_plugin" but that doesn't support setting cookies (inappbrowser does). Is there a web view plugin you could recommend that supports setting webview cookies and not have this keyboard issue. Appreciate your response.

@amirh

This comment has been minimized.

Copy link
Contributor Author

commented Jan 18, 2019

I have no experience with webview plugins other than webview_flutter, you might have a better luck asking in one of the community channels: https://flutter.io/community

@Steve-sy

This comment has been minimized.

Copy link

commented Feb 7, 2019

Hello Guys, anyone solved this issue?

@alexelisenko

This comment has been minimized.

Copy link

commented Feb 11, 2019

Having the same issue with webview_flutter: ^0.3.0+2 on Android. Does anyone have any workarounds?

@Steve-sy

This comment has been minimized.

Copy link

commented Feb 11, 2019

Having the same issue with webview_flutter: ^0.3.0+2 on Android. Does anyone have any workarounds?

its really shame on flutter man! look at the issue its from Jul 24, 2018! @amirh any news can help us bro?

@Hixie

This comment has been minimized.

Copy link
Contributor

commented Feb 13, 2019

@Steve-sy Please consider reading through https://github.com/flutter/flutter/blob/master/CODE_OF_CONDUCT.md at some point soon. Thanks! :-)

@nhojjava

This comment has been minimized.

Copy link

commented Feb 15, 2019

In my app, when the WebView is showing, that is the only place there will ever be a need for a keyboard. In this scenario, the WebView is shown in full screen with a floating button to access settings and exit WebView.

This plugin is great compared to the others I've tried but I really need that keyboard on Android. My app also has components written in Flutter, with many more to be added soon, but because we have a web login, we can't get very far (literally nowhere) in our app without a keyboard!

Could we do something like a FullScreenWebView that DOES allow the window of virtual display's presentation to be focusable?

Thanks

@dazza5000

This comment has been minimized.

Copy link

commented May 25, 2019

The keyboard works on this plugin: https://pub.dev/packages/flutter_webview_plugin#-installing-tab-

@DreamBuddy

This comment has been minimized.

Copy link

commented May 25, 2019

@dazza5000 This plugin is not inline webview

@jockebq

This comment has been minimized.

Copy link

commented May 26, 2019

So this has been an issue since July 2018, and is basic functionality for webview, but still not solved? When can we expect it working, without using flutter_webview_plugin ?

@pravinarr

This comment has been minimized.

Copy link

commented May 30, 2019

Is there any ETA on the fix to be available in dev/stable ?

@mohammadmdp

This comment has been minimized.

Copy link

commented Jun 1, 2019

Does this warning help?:
chromium: [WARNING:autofill_agent.cc(767)] Autofill suggestions are disabled because the document isn't a secure context.

Whenever I tap on the text field, it shows this warning in the Logcat and doesn't show the keyboard.

And also there is another warning in the console whenever I tap on a text field:
W/cr_AwAutofillManager(16131): WebView autofill is disabled because WebView isn't created with activity context.

@mohSalah66

This comment has been minimized.

Copy link

commented Jun 1, 2019

Any updates on this issue?

@humazed

This comment has been minimized.

Copy link

commented Jun 3, 2019

I switched to master and #32773 doesn't seem to fix the problem.

thanks, @marcosgallardo your solution works nicely until we have a complete fix.

@pravinarr

This comment has been minimized.

Copy link

commented Jun 3, 2019

@marcosgallardo Thanks for your workaround code. Your code will not work for webpages developed with ReactJS. I had to update the javascript code on onChanged event.

_controller.evaluateJavascript('''
                  window.lastValue = window.input.value;
                  window.input.value = '$input';
                  // to trigger onchange event on react text input component
                  window.newevent = new Event('input', { bubbles: true });
                  window.newtracker = window.input._valueTracker;
                  if (window.newtracker) {
                    window.newtracker.setValue(window.lastValue);
                  }
                  window.input.dispatchEvent(window.newevent);
                 ''');
        },
@ashish173

This comment has been minimized.

Copy link

commented Jun 4, 2019

Let's stop asking for updates since the Google team has already added this to October 2019 milestone. Please don't expect this before that.

Having said that I just wish someone from the Flutter team could understand the severity of this issue. Developers have started porting their apps to different platforms. I think issues like these can be picked up earlier even if other things are in pipeline.

If a fix for this issue depends on the work which is already in progress then even Google can't do anything about the timeline for this fix. But a comment above from a team member suggests this as a small fix. Also, since this is a flutter engine fix we are not confident either about fixing it even if we try it.

I am an admirer of Google and its way of working but it's a bit sad to see no one from the flutter top management actually understanding this kind of critical feedback from their users.

Now we will have to port our app from flutter to something else since we make heavy use of Web views. We have more than 100k installs on the app store. Management at my company won't wait till October for this issue to get resolved.

Apologies for complaining like this but it is actually hurting us.

PS: I have read the code of conduct. One is free to say I have not understood it though.

@amirh amirh referenced this issue Jun 5, 2019

Merged

Respond to AndroidView focus events. #33901

8 of 9 tasks complete
@phanirithvij

This comment has been minimized.

Copy link

commented Jun 5, 2019

#33901
Please merge this as soon as possible.
I've been waiting for this to get fixed as we're planning on using Webviews for login and signup in our application.
And this is what's stopping us from using flutter.
I don't think we can wait until October.

And it says "flutter-build is currently broken. Do not merge request unless it is a fix for the broken build."

thisisbull

@nicktran29

This comment has been minimized.

Copy link

commented Jun 6, 2019

We used Webview Flutter and hacked our way through with hidden text fields and jschannels but soon realised it’s just impossible to cover all scenarios so we made a switch to Flutter Webview Plugin as an alternative. Been working like a charm for us. Just make sure to remove the io.flutter.embedded_views_preview in Info.plist if you had it added as per Webview Flutter instruction.

@ashish173

This comment has been minimized.

Copy link

commented Jun 7, 2019

A big thanks to @amirh for prioritising this. 💯 The PR is merged in master. We are going to test things on master channel now.

amirh added a commit to flutter/engine that referenced this issue Jun 7, 2019

Keyboard support for embedded Android views. (#9203)
Generally what this PR is doing is setting up a delegation mechanism
for Android's onCreateInputConnection.

It works by letting the framework know when an embedded view gets loses
focus(within the virtual display), the framework maintains a focus node
for each Android view that is kept in sync with the focus state of the
embedded view.

The TextInputPlugin is extended to allow for 2 type of text clients a
"framework client"(what we had before) and a "platform view client".
When the AndroidView's focus node in the framework is focused the
framework sets a "platform view text client" for the TextInputPlugin,
which will result in the TextInputPlugin delegating
createInputConnection to the platform view.

When a platform view is resized, we are detaching it from a virtual
display and attaching it to a new one, as a side affect a platform view
might lose an active input connection, to workaround that we "lock" the
connection when resizing(by caching it and forcing the cached copy until
the resize is done).

Additional things worth calling out in this PR:

To properly answer which views are allowed for input connection
proxying we compare a candidate view's root view to the set of root
views of all virtual displays.
We also preserve a view's focus state across resizes.
Note that this PR only wires text for the io.flutter.view.FlutterView
For the new Android embedding some additional plumbing is necessary.

Corresponding framework PR: flutter/flutter#33901

flutter/flutter#19718
@amirh

This comment has been minimized.

Copy link
Contributor Author

commented Jun 7, 2019

With #32773 , #33901, and flutter/engine#9203 (not yet rolled as of writing this) Android platform views can use the keyboard.

Note that WebViews running on Android versions before N still can't use the keyboard. This is because the threaded input connection mechanism WebView is using prevents us from proxying the connection directly to the webview. My current plan to workaround this issue is to setup our own equivalent mechanism for a non main thread input connection, and proxy the connection from there. I believe that it should work, but I haven't prototyped yet to confirm, and devil is in the details for these kind of things. I do understand that this is important for many use cases and I am treating this as a high priority.

@alocher

This comment has been minimized.

Copy link

commented Jun 8, 2019

Just tried with v1.7.4-pre.23 and doesn't look like anything has changed?
(Android 9, emulated)

[√] Flutter (Channel master, v1.7.4-pre.23, on Microsoft Windows [Version 10.0.17763.504], locale en-GB)
• Flutter version 1.7.4-pre.23 at x
• Framework revision 1a56015 (49 minutes ago), 2019-06-08 07:04:10 -0700
• Engine revision e8ee6acf8d
• Dart version 2.3.2 (build 2.3.2-dev.0.1 7f146e431e)

@sakina1403

This comment has been minimized.

Copy link

commented Jun 10, 2019

I have tried with master too.

[✓] Flutter (Channel master, v1.7.4-pre.30, on Linux, locale en_GB.UTF-8)

Getting the same error."WebView autofill is disabled because WebView isn't created with activity context."

Has anyone got a successful test????? This is really disappointing. I am testing on device with Android version 9.

@amirh

This comment has been minimized.

Copy link
Contributor Author

commented Jun 10, 2019

The engine change was rolled back as it broke one of the integration tests(#34085).

I just landed it again with a fix in flutter/engine#9257. You will only see this working on master after the engine change is rolled into the framework(if you really don't want to wait you can build a local engine).

@amirh

This comment has been minimized.

Copy link
Contributor Author

commented Jun 11, 2019

This was rolled to the framework and is available on master starting 7a877f6.

I'm reminding that for WebViews the keyboard currently only works starting Android N(see #19718 (comment)).

Feel free to experiment with it, if you hit any bugs please report them in separate issues.

@DreamBuddy

This comment has been minimized.

Copy link

commented Jun 12, 2019

Flutter 1.7.4-pre.70 • channel master • https://github.com/flutter/flutter.git
I tested ,keyboard is ok after Android N.
But my app's release version can't run in Android 8.x,but Android 9.0 work well.

@madmat

This comment has been minimized.

Copy link

commented Jun 12, 2019

Thanks @amirh to work on this issue. But it doesn't work in my app.
I'm running Android Pie 9.0.
I've tested on Huawei P30 pro and also various emulators.
The keyboard is shown only in some rare and erratics case, and once opened there is no way to close it.

I'm using webview_flutter-0.3.6 to display WebViews.

[✓] Flutter (Channel master, v1.7.4-pre.71, on Mac OS X 10.14 18A391, locale fr-FR)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[!] Xcode - develop for iOS and macOS (Xcode 10.1)
! CocoaPods out of date (1.6.0 is recommended).
CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your
plugin usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To upgrade:
brew upgrade cocoapods
pod setup
[✓] iOS tools - develop for iOS devices
[✓] Android Studio (version 3.3)
[✓] VS Code (version 1.35.0)
[✓] Connected device (3 available)

huqiuser pushed a commit to huqiuser/engine that referenced this issue Jun 12, 2019

Keyboard support for embedded Android views. (flutter#9203)
Generally what this PR is doing is setting up a delegation mechanism
for Android's onCreateInputConnection.

It works by letting the framework know when an embedded view gets loses
focus(within the virtual display), the framework maintains a focus node
for each Android view that is kept in sync with the focus state of the
embedded view.

The TextInputPlugin is extended to allow for 2 type of text clients a
"framework client"(what we had before) and a "platform view client".
When the AndroidView's focus node in the framework is focused the
framework sets a "platform view text client" for the TextInputPlugin,
which will result in the TextInputPlugin delegating
createInputConnection to the platform view.

When a platform view is resized, we are detaching it from a virtual
display and attaching it to a new one, as a side affect a platform view
might lose an active input connection, to workaround that we "lock" the
connection when resizing(by caching it and forcing the cached copy until
the resize is done).

Additional things worth calling out in this PR:

To properly answer which views are allowed for input connection
proxying we compare a candidate view's root view to the set of root
views of all virtual displays.
We also preserve a view's focus state across resizes.
Note that this PR only wires text for the io.flutter.view.FlutterView
For the new Android embedding some additional plumbing is necessary.

Corresponding framework PR: flutter/flutter#33901

flutter/flutter#19718
@amirh

This comment has been minimized.

Copy link
Contributor Author

commented Jun 13, 2019

@madmat can you try the webview example app on the same device?

@madmat

This comment has been minimized.

Copy link

commented Jun 13, 2019

@madmat can you try the webview example app on the same device?

@amirh Of course I've also tried with the WebViews example and I get the same results than our app.
Did you push something new since v1.7.4-pre.71, and if so do you want me to try again ?

@amirh

This comment has been minimized.

Copy link
Contributor Author

commented Jun 13, 2019

Last update was 7a877f6 (flutter doctor -v should tell you which commit you're on), I'll try it on an Android P emulator hopefully I could reproduce the same issue you're seeing.

@stoconnor

This comment has been minimized.

Copy link

commented Jun 13, 2019

Tried with the latest didn't work for me on API 28 (Pie) using Nexus 5X and the following Flutter version:

[✓] Flutter (Channel master, v1.7.4-pre.87, on Mac OS X 10.14.4 18E226, locale en-IE)
    • Flutter version 1.7.4-pre.87 at
    • Framework revision f31fc1bd0f (9 hours ago), 2019-06-12 23:12:35 -0700
    • Engine revision 209250da1b
    • Dart version 2.3.3 (build 2.3.3-dev.0.0 3166bbf24b)
@alocher

This comment has been minimized.

Copy link

commented Jun 16, 2019

@amirh in my testing I noticed that when I use the keyboard at least once in my Flutter app, before opening a webview where I expect to use the keyboard, it seems to work. Whenever I don't use the keboard in the app, and directly go to the webview, it won't display. Maybe that helps tracking things down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.