-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Respond to AndroidView focus events. #33901
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
Conversation
When an AndroidView gains focus we invoke the(newly introduced) 'TextInput.setPlatformViewClient' text_input system channel method which sets the platform view as the text input target. When the AndroidView loses focus we send a `clearFocus` message to platform views system channel(so the engine can clear the focus from the platform view). This PR is going to land before the engine implementation is rolled to the framework, we swallow MissingPluginException for the newly introduced methdo channel methods so this is a no-op before the engine is ready(after the engine is rolled with the corresponding change I'll remove the logic to swallow the exceptions).
|
cc @jason-simmons (for context when reviewing the corresponding engine PR) |
|
Please merge this as soon as possible. |
gspencergoog
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-Authored-By: Greg Spencer <[email protected]>
|
Waiting for flutter/engine#9203 to be approved before landing this one. |
Is there an ETA??? Waiting desperately for this since March. Tired of using workarounds. We really love Flutter but this has been holding me back since a long time. Our App has heavy use of WebView and a lot of JS communication as well and this is the only plugin perfect for postMessage Communication. We have 100K+ downloads but usability is affecting largely because of this issue. Thank you for all your efforts @amirh . Unless and until it's reaally necessary to wait please please merge this ASAP. |
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
* master: (25 commits) Increase daemon protocol version for getSupportedPlatforms (flutter#33980) skip web test on crazy import (flutter#34017) Compatibility pass on flutter/foundation tests for JavaScript compilation. (1) (flutter#33349) 0602dbb Roll src/third_party/dart 9dcb026b26..6e0d978505 (72 commits) (flutter#34027) Add chrome stable to dockerfile and web shard (flutter#33787) Codegen an entrypoint for flutter web applications (flutter#33956) Revert "Reland "Text inline widgets, TextSpan rework" (flutter#33946)" (flutter#34002) Revert "Re-add deprecated method for plugin migration compatibility. (flutter#34006)" (flutter#34022) Remove print (flutter#34004) Manual roll the engine to land the timing API (flutter#33989) Make plugins Swift-first on macOS (flutter#33997) Re-add deprecated method for plugin migration compatibility. (flutter#34006) make sure version check includes hotfixes (flutter#33459) Respond to AndroidView focus events. (flutter#33901) Add 'doctor' support for Windows (flutter#33872) Add use_frameworks to macOS Podfile template (flutter#33987) [Material] Create a themable Range Slider (continuous and discrete) (flutter#31681) Updating names to correct versioning convention (flutter#33865) Whitelist adb.exe heap corruption exit code. (flutter#33951) [flutter_tool] Fix 'q' for Fuchsia profile/debug mode (flutter#33846) ...
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

Description
When an AndroidView gains focus we invoke the(newly introduced)
'TextInput.setPlatformViewClient' text_input system channel method
which sets the platform view as the text input target.
When the AndroidView loses focus we send a
clearFocusmessage toplatform views system channel(so the engine can clear the focus from
the platform view).
This PR is going to land before the engine implementation is rolled to
the framework, we swallow MissingPluginException for the newly
introduced method channel methods so this is a no-op before the engine
is ready(after the engine is rolled with the corresponding change I'll
remove the logic to swallow the exceptions).
The engine counterpart is in: flutter/engine#9203
Related Issues
#19718
Tests
I added the following tests:
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?