Repository navigation
android: Hide the keyboard on a tap in a scroll view when the field is outside it - #717
Merged
Merged
Conversation
…s outside it keyboardShouldPersistTaps "never" swallows the tap to hide the keyboard, but looked for the focused field only inside the scroll view. A chat's composer sits below its list, so the tap did nothing at all: the keyboard stayed up and the row under the finger never got the press.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On Android, a tap in a scroll view does nothing while the keyboard is up, when the focused field sits outside the scroll view. That is the layout of every chat screen: the messages scroll, the composer sits below them. With the default
keyboardShouldPersistTaps="never"the tap is taken to dismiss the keyboard (""never": the tap only dismisses it",website/modules/nsh-list.md), yet the keyboard stays up and the row under the finger does not hear the press either.The cause is
ScrollBox.hideKeyboard(): it looks for the focused view withfindFocus(), which searches only the scroll view's own subtree. The composer is not in it, so nothing is hidden.The fix looks up focus from the root view, and falls back to
Mounter.focusedInput(). The change is 3 lines inScrollBox.java, plus a regression test (examples/gallery/tests/keyboard-taps.test.tsxand its fixture). No API change, no new dependency.How to Test
The fixture has a scroll view with one row, a button that counts its presses, and below it, outside the scroll view, an
Input; a line showskeyboardFrame(). The test types into the field, presses the row and waits for "keyboard: down":--target android(Android 15 arm64 emulator)`text:keyboard: down` showing never happened in 5000 ms; on screen: ["keyboard: up", "Row 1, pressed 0"]With the fix the GIF also shows the row's
onPressrunning ("pressed 1"). The docs above say a "never" tap only dismisses the keyboard; this PR does not change which view hears the tap, and the test does not check it. Tell me if you want that tap kept from the row as well.CI runs no
--target androidjob, so the Android row is a command for the reviewer to run. The runtime was built withcargo xtask android --release --dev --abi arm64-v8a.Not tested: iOS, which takes a separate path; a physical device; armeabi-v7a and x86_64.
Checklist
cargo test --workspace,cargo +nightly fmt --alland clippy (including the Catalyst and Android runs for platform code). (cargo test --workspaceon dde7f77 with this commit and the four other Android fixes of this series: 3260 passed, 0 failed, 43 ignored.cargo xtask clippy-androidpasses on main at 201d780, and this PR changes no Rust. The Java is compiled bycargo xtask android, and there is no Rust forfmtto check)tests/compat/(cargo xtask compat). (No API change.)examples/gallerydemos on iOS and Android (if the change is visible or platform-specific). (The test above, on Android.)