Skip to content

[General] Press buttons from hardware keys, accessibility services and a TV's Select press - #4614

Open
YevheniiKotyrlo wants to merge 2 commits into
software-mansion:mainfrom
YevheniiKotyrlo:fix/pressable-android-click-without-touch
Open

YevheniiKotyrlo wants to merge 2 commits into
software-mansion:mainfrom
YevheniiKotyrlo:fix/pressable-android-click-without-touch

Conversation

@YevheniiKotyrlo

@YevheniiKotyrlo YevheniiKotyrlo commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

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 Pressable that 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's Pressable does, and gesture-handler on web for a key.

  • ButtonViewGroup.setPressed admits a press only when touchResponder === this || canBePressedAlongsideOther, so an exclusive button, the default, refuses the press View.onKeyDown makes 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 in setPressed #3742 — and performClick activated the native gesture for a click no touch produced only while touch exploration was on or a key's up had set receivedKeyEvent. The button now records a click's source while View's own onKeyDown, onKeyUp or performAccessibilityAction runs, admits that press without taking the responder where its click would activate a native gesture, and activates the gesture from it, then calls View.performClick for the click sound and TYPE_VIEW_CLICKED once a handler took the press. receivedKeyEvent, the touch-exploration check and the root view's forwarding activateNativeHandlers are gone.
  • The activation leaves a gesture a pointer already drives, or one waiting on another's failure, to that gesture: ending it from the click, as main does for a key on a button a finger holds, cancels the finger's touches and leaves the button the touch responder.
  • On main an activation with no pointer reports the last pointer's count, type and position: (0, 0) on a button no pointer has reached, which PressableWithTouchable's isTouchWithinInset rejects. prepareActivationWithoutPointer reports 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, where View takes a key event to be (View.java); where that section asks for an empty type, it reports KEY for a key, as web does, and OTHER for an accessibility service. handle() now reads a down's pointer before the touch callbacks run, so a handler a UI-thread onTouchesDown activates, or a second finger begins, reports that touch rather than the last gesture's. makeActive no longer asks React Native to cancel a touch for an activation no pointer drives, which logged Can't cancel already finished gesture (JSTouchDispatcher).
  • Without a screen reader, LegacyPressable and StatefulPressable press in only on LONG_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, as StatefulPressable's TV branch did. Every engine, the default Pressable's included, presses it before its first layout and under a hit slop that leaves out its center, and isKeyboardDismissingTap no longer takes it, inside a gesture-handler ScrollView, for the tap dismissing the keyboard. NativeViewGestureHandlerPayload declares the x, y, absoluteX and absoluteY that Emit coordinates in Native gesture events #4302 emits, and the docs describe such a press.
  • Apple's native view handler reports a press no touch drives, a tvOS focus Select among them, at (0, 0) as TOUCH, so the default Pressable drops it. It now reports the view's center, as handleSwitch: does, with no pointer and KEY, 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 onPressIn and onPress arrive together, and a held key presses once, on release, as React Native's Pressable does (Pressability.onClick).

Test plan

Tested on the following code, as the example app's Empty example:
import { useState } from 'react';
import {
  Pressable as ReactNativePressable,
  StyleSheet,
  Text,
  View,
} from 'react-native';
import { Pressable, RectButton } from 'react-native-gesture-handler';

export default function EmptyExample() {
  const [presses, setPresses] = useState({
    pressable: 0,
    rectButton: 0,
    reactNativePressable: 0,
  });
  const count = (button: keyof typeof presses) => () =>
    setPresses((current) => ({ ...current, [button]: current[button] + 1 }));

  return (
    <View style={styles.container}>
      <Pressable style={styles.button} onPress={count('pressable')}>
        <Text>{`Pressable: ${presses.pressable}`}</Text>
      </Pressable>
      <RectButton style={styles.button} onPress={count('rectButton')}>
        <Text>{`RectButton: ${presses.rectButton}`}</Text>
      </RectButton>
      <ReactNativePressable
        style={styles.button}
        onPress={count('reactNativePressable')}>
        <Text>{`React Native Pressable: ${presses.reactNativePressable}`}</Text>
      </ReactNativePressable>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    gap: 16,
  },
  button: {
    width: 240,
    padding: 16,
    alignItems: 'center',
    backgroundColor: '#e0e0e0',
  },
});
  • The code above, on an API 34 emulator: on main, Enter and Space on a Tab-focused button count only on React Native's Pressable; with this PR each key counts once on every button. With TalkBack on, a double tap on gesture-handler's Pressable before any touch counts nothing on main and once with this PR, while RectButton and React Native's Pressable count theirs on both.
  • The new Keyboard activation example's flow, .argent/flows/keyboard-activation-test.yaml, and .argent/flows/keyboard-touchable-test.yaml, which presses a Touchable with Enter, then Space, fail on main and pass here (before/after).
  • pressableClickWithoutTouch.test.tsx and api_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. With main's engines every no-pointer case fails but a screen reader's click.
  • On the same emulator, an accessibility client's ACTION_CLICK with touch exploration off, as Switch Access and Voice Access click, presses nothing on main and each control once here.
  • Every Android and JavaScript job passes on Linux, emulator flows included; on a Mac with Xcode 27.1, for a device, so do the iOS build, every flow on an iPhone 12 Pro Max and the SPM build, with and without react-native-worklets.

Copilot AI balanced review requested due to automatic review settings October 19, 2026 12:50
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features

    • Added support for activating pressable and gesture-handled controls without touch input, including keyboard and accessibility activation.
    • Added a keyboard activation example demonstrating pressables, buttons, touchables, gestures, and event details.
    • Improved coordinate and pointer information reported for activations without touch input.
  • Bug Fixes

    • Press callbacks now work for activations without touch input, without incorrectly dismissing the soft keyboard.
    • Improved native button activation and gesture coordination.
  • Documentation

    • Clarified pointerless activation behavior, coordinates, pointer counts, and responder cancellation.
  • Tests

    • Added Android flows and regression coverage for keyboard, accessibility, touch, and focus-based activation.

The change adds pointerless activation support across native gesture handling and Pressable components. It updates keyboard-dismiss detection and event coordinates, documents pointer metadata, and adds Android tests and an example screen.

Changes: Pointerless Press Activation

Layer / File(s) Summary
Native activation and event data
packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/*, packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/*, packages/react-native-gesture-handler/apple/Handlers/RNNativeViewHandler.mm, packages/react-native-gesture-handler/src/handlers/GestureHandlerEventPayload.ts, packages/docs-gesture-handler/docs/gestures/*
Android gesture handlers and buttons now prepare and dispatch pointerless activations with pointer type and center coordinates. iOS native view events report key pointer types and center coordinates for touchless TV presses. Documentation describes pointerless event data and Android responder behavior.
Pressable handling and keyboard dismissal
packages/react-native-gesture-handler/src/components/Pressable/*, packages/react-native-gesture-handler/src/v3/components/*, packages/react-native-gesture-handler/src/v3/scrollViewInterop.ts, packages/react-native-gesture-handler/src/__tests__/*, packages/react-native-gesture-handler/src/jestUtils/jestUtils.ts
Pressable implementations now handle activations without pointers. Keyboard-dismiss detection receives pointer-count data and excludes pointerless activations. Tests cover press handling across platforms and keyboard interactions.
Example screen and end-to-end flows
apps/common-app/src/new_api/index.tsx, apps/common-app/src/new_api/tests/keyboardActivation/index.tsx, .argent/flows/keyboard-activation-test.yaml, .argent/flows/keyboard-touchable-test.yaml
The common app now includes a keyboard activation example that logs press events and coordinates. Android flows test keyboard activation and nested touchable behavior.

Sequence Diagram(s)

sequenceDiagram
  participant ButtonViewGroup
  participant GestureHandlerOrchestrator
  participant GestureHandler
  ButtonViewGroup->>GestureHandlerOrchestrator: Request native activation with pointer type
  GestureHandlerOrchestrator->>GestureHandler: Prepare and run activation lifecycle
  GestureHandlerOrchestrator-->>ButtonViewGroup: Return activation result
  ButtonViewGroup->>ButtonViewGroup: Perform click
Loading

Suggested reviewers: m-bert

Merge Risk: Minimal · up to 3d3a6

This change lets gesture-handler buttons activate from hardware keys, accessibility services and a TV's Select press, and keeps touch behavior on its existing path. No actionable merge-blocking defect remains. One minor edge case, where a keyboard dismissal can be skipped under a custom requireToFail setup, is not worth blocking on. The tvOS path rests on the iOS build and Jest, since no tvOS build or device was available.

Pre-merge checks: Passed 3

Check name Status Explanation
Title check Passed The title names the main change: gesture-handler buttons now activate from hardware keys, accessibility services, and a TV's Select press without a pointer. The raw summary shows the Android key and a…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: gesture-handler buttons now activate from hardware keys, accessibility services, and a TV's Select press without a pointer. The raw summary shows the Android key and accessibility click paths, the iOS/tvOS no-pointer handling, and the Pressable and StatefulPressable routing that match this. The title is specific and does not describe anything absent from the changeset. The '[General]' prefix is a conventional tag and does not make the title vague. The title is long at 90 characters, but it is still a single, readable sentence.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d818dd41-b4bd-45ae-bb16-c2b6d3a6b6c6
Commits

Reviewing files that changed from the base of the PR and between 849bf13 and 3d3a6bf.

Files selected for processing: 10

  • .argent/flows/keyboard-activation-test.yaml
  • apps/common-app/src/new_api/index.tsx
  • apps/common-app/src/new_api/tests/keyboardActivation/index.tsx
  • packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt
  • packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt
  • packages/react-native-gesture-handler/src/__tests__/api_v3.test.tsx
  • packages/react-native-gesture-handler/src/components/Pressable/utils.ts
  • packages/react-native-gesture-handler/src/v3/components/PressableWithTouchable.tsx
  • packages/react-native-gesture-handler/src/v3/components/StatefulPressable.tsx
  • packages/react-native-gesture-handler/src/v3/components/Touchable/Touchable.tsx
Files with no reviewable changes: 1

  • packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@YevheniiKotyrlo

YevheniiKotyrlo commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Device evidence — before / after

UNFIXED — main presses nothing for Enter or Space on a Tab-focused gesture-handler control, nor for an accessibility service's click.

FIXED — each activation presses its control once: Enter on a Pressable no pointer has touched, on the outer state-machine and legacy Pressables after a tap on their inner one, and on the Pressable beside an input holding the soft keyboard; a RectButton's gesture begins with KEY and 0 pointers; a key on a Touchable under a scale: 0.5 parent lands where a tap on it did; Enter and Space each press a Touchable once.

before — main after — with this PR
Keyboard activation
Nested touchables

API 34 x86_64 emulator (google_apis, 320×640 at 160 dpi), release builds of apps/expo-example from main at the base commit, with this PR's Keyboard activation screen added, and from this branch. Each image is the console after the screen's key presses; on Keyboard activation, lines 1–9 are the taps that come first, the same on both builds.

On Keyboard activation main this PR
ACTION_CLICK from an accessibility client with touch exploration off — the path Switch Access and Voice Access take — on four controls nothing, while each action reports performed each control pressed once; the RectButton reports OTHER with 0 pointers
the same on a disabled Pressable nothing nothing
TalkBack 14.2 double tap on the default Pressable no finger has touched nothing pressed once
Enter on the Pressable beside the input, the soft keyboard up nothing pressed once, the keyboard still up
Enter held 9 s on the RectButton nothing pressed once
uiautomator events across Enter on the RectButton no TYPE_VIEW_CLICKED one TYPE_VIEW_CLICKED
the screen's first tap on a RawButton its UI-thread onTouchesDown activates onActivate OTHER with 0 pointers onActivate TOUCH with 1 pointers at its touch

Press feedback — Enter held 1.5 s on the Tab-focused RectButton, on the same builds and emulator at full animation speed: main shows nothing and logs nothing; with this PR the button shows its ripple while the key is down, then logs onBegin KEY with 0 pointers and onPress. A screen recording holds a frame only when the screen changes: main's holds 5 frames over 6.5 s and the button's region never changes, while this PR's holds 91 frames through the hold, about 60 a second (before, after).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

@YevheniiKotyrlo YevheniiKotyrlo changed the title [Android] Press a focused button on a hardware Enter or Space [Android] Press buttons from hardware keys and accessibility services Oct 19, 2026
@YevheniiKotyrlo
YevheniiKotyrlo force-pushed the fix/pressable-android-click-without-touch branch from 2c7700e to cd01505 Compare October 20, 2026 13:26
@YevheniiKotyrlo YevheniiKotyrlo changed the title [Android] Press buttons from hardware keys and accessibility services [General] Press buttons from hardware keys, accessibility services and a TV's Select press Oct 21, 2026
@YevheniiKotyrlo
YevheniiKotyrlo marked this pull request as ready for review October 21, 2026 23:20
@YevheniiKotyrlo
YevheniiKotyrlo requested a balanced review from Copilot October 23, 2026 19:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Shared native gesture-lifecycle changes and the acknowledged lack of tvOS build and device validation warrant final platform-owner review.

No open issues 🎉

Review effort: Balanced

@jrlucier

Copy link
Copy Markdown

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.

@YevheniiKotyrlo
YevheniiKotyrlo force-pushed the fix/pressable-android-click-without-touch branch from 849bf13 to 3d3a6bf Compare December 1, 2026 20:37

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants