-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[iOS] Hide keyboard on hot restart #167013
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
engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm
Show resolved
Hide resolved
2f225f8
to
ca25f4c
Compare
41706e9
to
5861980
Compare
5861980
to
01063d3
Compare
// This file is modified during the test and needs to be restored at the end. | ||
final String oldContents = mainFile.readAsStringSync(); | ||
const String forceKeyboardOn = 'const bool forceKeyboard = true;'; | ||
const String forceKeyboardOff = 'const bool forceKeyboard = false;'; |
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.
is it just a raw string to be displayed? why does it look like a piece of code?
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.
I added a comment to clarify:
// When the test starts, the app forces the keyboard to be visible.
// The test turns off this behavior by mutating the app's source code from
// `forceKeyboardOn` to `forceKeyboardOff`.
// See: //dev/integration_tests/keyboard_hot_restart/lib/main.dart
Let me know if you have follow-up questions!
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.
wow changing the source code from the test, i've never seen this before. perhaps we can pass in an argument into the test instead.
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.
A test argument wouldn't work as we need to change the app's behavior at the middle of the test: first it should make the keyboard visible, but after the hot restart it shouldn't. Let me know if you'd like to do a call to talk through this further :)
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.
This seems very brittle. Is this an existing practice?
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.
We have verify few tests that hot reload or hot restart an app. This appears to be an area of significant tech debt, but below are prior art I could find.
Hot mode test verifies that editing the framework's source code invalidates libraries:
flutter/dev/devicelab/lib/tasks/hot_mode_tests.dart
Lines 128 to 131 in b9abb56
flutterFrameworkSource.writeAsStringSync( | |
'${flutterFrameworkSource.readAsStringSync()}\n', | |
); | |
process.stdin.writeln('r'); |
Web dev mode test verifies that web hot reload works as expected:
flutter/dev/devicelab/lib/tasks/web_dev_mode_tests.dart
Lines 90 to 99 in b9abb56
appDartSource.writeAsStringSync( | |
appDartSource.readAsStringSync().replaceFirst( | |
"'Flutter Gallery'", | |
"'Updated Flutter Gallery'", | |
), | |
); | |
sw | |
..reset() | |
..start(); | |
process.stdin.writeln('r'); |
@@ -0,0 +1,5 @@ | |||
# keyboard_hot_restart | |||
|
|||
An app used to verify that the keyboard is not visible after a hot restart. |
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.
bonus: maybe also check system context menu is dismissed?
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.
The presence of the SystemContextMenu widget is probably enough to indicate it's showing or not, if you can check for that. If not, maybe you could print something from the TextField's contextMenuBuilder.
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.
Ahhh I didn't realize I could check for the context menu on the framework side, thanks for the pointers!
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.
Justin and I talked offline. Unfortunately, the presence of the SystemContextMenu
widget and TextField
's contextMenuBuilder
are not enough to detect whether the native context menu is visible. We don't have a good way to verify this native context menu from this "outside" test.
engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm
Outdated
Show resolved
Hide resolved
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.
LGTM but deferring to Huan for iOS expertise. Also I agree you should check for the presence of the system context menu in the test if you can.
Thanks for fixing this! It has annoyed me before. And thanks for writing a devicelab test for this.
@@ -0,0 +1,5 @@ | |||
# keyboard_hot_restart | |||
|
|||
An app used to verify that the keyboard is not visible after a hot restart. |
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.
The presence of the SystemContextMenu widget is probably enough to indicate it's showing or not, if you can check for that. If not, maybe you could print something from the TextField's contextMenuBuilder.
@@ -207,6 +207,7 @@ new PlatformMessageHandlerIos(task_runners.GetPlatformTaskRunner())) {} | |||
} | |||
[owner_controller_.platformViewsController reset]; | |||
[owner_controller_.restorationPlugin reset]; | |||
[owner_controller_.textInputPlugin reset]; |
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.
This is all it took to fix it?
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.
Yup. The fix took 30 seconds, the test took 3 days 😅
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.
Classic haha.
@@ -207,6 +207,7 @@ new PlatformMessageHandlerIos(task_runners.GetPlatformTaskRunner())) {} | |||
} | |||
[owner_controller_.platformViewsController reset]; | |||
[owner_controller_.restorationPlugin reset]; | |||
[owner_controller_.textInputPlugin reset]; |
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.
just curious - the reset
method of text input plugin was defined but never called before?
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.
No reset
is new, but it calls the existing hideTextInput
method which is private and responds to the framework's TextInput.hide
message.
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.
Thank you for chatting offline about modifying the source file reasons.
The keyboard hot restart test does these steps: 1. It launches an app that forces the keyboard to be visible 2. It checks that the keyboard is visible by examining the app's logs 3. It updates the app to no longer force the keyboard to be visible and hot restarts the app 4. It checks that the keyboard is no longer visible by examining the app's logs Previously, the test app printed the keyboard status whenever the app rebuilt. The test would move on as soon as it saw a log that indicates the keyboard was in the expected state. However, since the app could log the keyboard's visibility _before_ the Dart VM was available, hot restart commands could be ignored (or at least, that's my theory from the DeviceLab logs). Now, the test app prints the keyboard status non-stop. The test now waits until the Dart VM is available before checking if the logs indicate the keyboard is open. Also, the test now waits until the hot restart has completed before checking if the keyboard is closed. In theory, this should ensure that hot restart does not happen until after the Dart VM is available. Follow-up to: #167013 Part of: #10713 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This hides the keyboard and text input context menu if you hot restart your iOS app.
Before.MP4
After.MP4
Part of #10713
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.