Repository navigation
Add onLongPress to TextInput - #59148
Draft
YevheniiKotyrlo wants to merge 2 commits into
Draft
YevheniiKotyrlo wants to merge 2 commits into
YevheniiKotyrlo wants to merge 2 commits into
Conversation
TextInput already handles its presses through Pressability and exposes onPress, onPressIn and onPressOut, but not onLongPress, so a held press on a TextInput cannot be told apart from a tap. TextInput now hands onLongPress to Pressability. Once a touch is held past the long press delay, onLongPress is called, and the release that follows does not call onPress, as on Pressable. Without onLongPress a held press is still a press.
|
Warning JavaScript API change detected This PR commits an update to
This change was flagged as: |
The release of a press is where TextInput focuses itself, and a long press removes that release, so a held field was focused only by the platform: on Android, a field with contextMenuHidden ended focused with no keyboard. TextInput now focuses the input when onLongPress fires, as it does on a press. Without onLongPress nothing changes. The first onLongPress case now lifts its finger: the touch it left down kept the responder, so the next case's touches never reached its field.
This branch has not been deployed
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.
Summary:
TextInputalready handles its touches throughPressabilityand exposesonPress,onPressInandonPressOut, but notonLongPress, so a component cannot tell a held press on a field from a tap. #39701 addedonPresson the same grounds.This passes
onLongPressto thePressabilityconfigTextInputalready builds. A touch held past the long press delay calls it, and the release that follows calls noonPress, as onPressable. That release is whereTextInputfocuses itself, so the input is focused whenonLongPressfires instead; without that, a held field withcontextMenuHiddenon Android ends focused by the platform with no keyboard. WithoutonLongPress, a held press is still a press.I need it for a one-time-code field that sets
contextMenuHiddenon Android and offers its own Paste on a long press.Changelog:
[GENERAL] [ADDED] - Add
onLongPresstoTextInputTest Plan:
Four Fantom cases in
TextInput-itest.jsunderonLongPress: a touch held past the delay calls it once; it focuses the input when it fires, and the release that follows calls noonPress; a press released before the delay still callsonPressand focuses; and withoutonLongPressa held press still callsonPressand focuses. Onmainthe first two fail (onLongPressis called 0 times; no focus command is sent when the delay passes); with this change the file passes, 38 of 38.yarn flow-check,yarn lint,yarn test-typescript-legacy,yarn build-types(theReactNativeApi.d.tssnapshot gainsonLongPressonTextInputBaseProps),yarn test-generated-typescriptandyarn test-cipass.In RNTester's Playground:
Holding each field for 1.5 s and lifting, in RNTester debug builds on an Android 16 (API 36) emulator: on
mainnothing is logged while the finger is down andonPressis logged on release; with this changeonLongPressis logged while it is down and nothing on release. Both fields end focused with the keyboard up on both builds, and a tap logsonPresson both. Holding acontextMenuHiddenfield on its text leaves the keyboard down on both builds, because Android's own long press focuses the field first; #59130 stops that long press.