Repository navigation
[General] Press buttons from hardware keys, accessibility services and a TV's Select press - #4614
Conversation
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
Device evidence — before / afterUNFIXED — FIXED — each activation presses its control once: Enter on a
API 34 x86_64 emulator (
Press feedback — Enter held 1.5 s on the Tab-focused |
There was a problem hiding this comment.
🟡 Changes recommended
Stale touch tracking can suppress keyboard activation, and transformed buttons report incorrect absolute coordinates.
3 open issues
What changed in this PR
Enables Android hardware-key activation of focused gesture-handler buttons, extending existing accessibility-click handling.
Changes:
- Tracks held confirm keys and activates native handlers.
- Centers pointerless activations and handles them in both state-machine Pressable engines.
- Adds keyboard flows and regression tests.
| File | Description |
|---|---|
| packages/react-native-gesture-handler/src/v3/components/StatefulPressable.tsx | Handles successful clicks without touches. |
| packages/react-native-gesture-handler/src/components/Pressable/Pressable.tsx | Adds equivalent legacy Pressable handling. |
| packages/react-native-gesture-handler/src/__tests__/pressableClickWithoutTouch.test.tsx | Tests pointerless, touch, and accessibility activation. |
| packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt | Tracks confirm keys and permits keyboard presses. |
| packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt | Centers pointerless native activations. |
| packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt | Adds center-coordinate placement. |
| .argent/flows/keyboard-touchable-test.yaml | Checks nested Touchable activation with Enter and Space. |
| .argent/flows/keyboard-pressable-test.yaml | Checks focused nested Pressable activation with Enter. |
Review effort: Balanced
2c7700e to
cd01505
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
Shared native gesture arbitration and cross-platform press lifecycle changes warrant human review, particularly because tvOS lacks native build and device validation.
No open issues 🎉
3 resolved since last review
Review effort: Balanced
|
Would love to have this, especially with Android 16+ Desktop modes. Accessibility from keyboard nav is crucial. For now I'm wrapping our elements heavily. |
…d a TV's Select press
…nce a button's callbacks run on JS
849bf13 to
3d3a6bf
Compare






Description
On Android, an activation no pointer drives presses no gesture-handler button: a hardware Enter or Space on a focused button, a Switch Access or Voice Access click, and a TalkBack double tap on a default
Pressablethat no finger has touched. Enter and Space activate a focused button (WAI-ARIA APG, Button), and an activation by keyboard or voice fires the click a pointer would (HTML §6.5), as React Native'sPressabledoes, and gesture-handler on web for a key.ButtonViewGroup.setPressedadmits a press only whentouchResponder === this || canBePressedAlongsideOther, so an exclusive button, the default, refuses the pressView.onKeyDownmakes for a confirm key and never clicks — the RectButton doesn't trigger onPress callback when pressed with keyboard Enter/Space key #2204 regression from Fix grabbing delegate insetPressed#3742 — andperformClickactivated the native gesture for a click no touch produced only while touch exploration was on or a key's up had setreceivedKeyEvent. The button now records a click's source whileView's ownonKeyDown,onKeyUporperformAccessibilityActionruns, admits that press without taking the responder where its click would activate a native gesture, and activates the gesture from it, then callsView.performClickfor the click sound andTYPE_VIEW_CLICKEDonce a handler took the press.receivedKeyEvent, the touch-exploration check and the root view's forwardingactivateNativeHandlersare gone.maindoes for a key on a button a finger holds, cancels the finger's touches and leaves the button the touch responder.mainan activation with no pointer reports the last pointer's count, type and position: (0, 0) on a button no pointer has reached, whichPressableWithTouchable'sisTouchWithinInsetrejects.prepareActivationWithoutPointerreports no pointer, as Pointer Events requires of a click a non-pointing device generates (§4.2.12.1), at the view's center mapped to the screen, whereViewtakes a key event to be (View.java); where that section asks for an empty type, it reportsKEYfor a key, as web does, andOTHERfor an accessibility service.handle()now reads a down's pointer before the touch callbacks run, so a handler a UI-threadonTouchesDownactivates, or a second finger begins, reports that touch rather than the last gesture's.makeActiveno longer asks React Native to cancel a touch for an activation no pointer drives, which loggedCan't cancel already finished gesture(JSTouchDispatcher).LegacyPressableandStatefulPressablepress in only onLONG_PRESS_TOUCHES_DOWN, which only a touch sends. A native gesture that begins reporting no pointer now goes around their state machine, pressing in as it begins and out as it ends at the position it reports, asStatefulPressable's TV branch did. Every engine, the defaultPressable's included, presses it before its first layout and under a hit slop that leaves out its center, andisKeyboardDismissingTapno longer takes it, inside a gesture-handlerScrollView, for the tap dismissing the keyboard.NativeViewGestureHandlerPayloaddeclares thex,y,absoluteXandabsoluteYthat Emit coordinates inNativegesture events #4302 emits, and the docs describe such a press.TOUCH, so the defaultPressabledrops it. It now reports the view's center, ashandleSwitch:does, with no pointer andKEY, so the same rule presses it. No CI job builds tvOS and no device here runs it, so that half rests on the iOS build and jest.While a key is down the button shows its native press feedback (recording). Android clicks on the key's up, so
onPressInandonPressarrive together, and a held key presses once, on release, as React Native'sPressabledoes (Pressability.onClick).Test plan
Tested on the following code, as the example app's Empty example:
main, Enter and Space on a Tab-focused button count only on React Native'sPressable; with this PR each key counts once on every button. With TalkBack on, a double tap on gesture-handler'sPressablebefore any touch counts nothing onmainand once with this PR, whileRectButtonand React Native'sPressablecount theirs on both..argent/flows/keyboard-activation-test.yaml, and.argent/flows/keyboard-touchable-test.yaml, which presses aTouchablewith Enter, then Space, fail onmainand pass here (before/after).pressableClickWithoutTouch.test.tsxandapi_v3.test.tsx: every engine presses once for a key, an accessibility click, an Android TV key, a tvOS focus press and an iOS press no touch drives, while a touch keeps the touch path. Withmain's engines every no-pointer case fails but a screen reader's click.ACTION_CLICKwith touch exploration off, as Switch Access and Voice Access click, presses nothing onmainand each control once here.