Skip to content

[Android] Activate buttons when setPressed(true) is called by the OS#4116

Open
j-piasecki wants to merge 1 commit intomainfrom
@jpiasecki/touchable-press-in-on-active
Open

[Android] Activate buttons when setPressed(true) is called by the OS#4116
j-piasecki wants to merge 1 commit intomainfrom
@jpiasecki/touchable-press-in-on-active

Conversation

@j-piasecki
Copy link
Copy Markdown
Member

Description

Updates the NativeViewGestureHandler hooks to allow direct access to the used handler.
Updates the button implementation on Android to use the new hook methods and move to ACTIVE state when the OS decides the button is pressed instead of waiting for move or up events.

This aligns native Android button behavior with other platforms.

With that change, it's possible to simplify the Touchable implementation not to rely on begin and finalize callbacks at all, since we can now assume that when a button is pressed, it's in the ACTIVE state.

Test plan

Verify existing Touchable examples.

Copilot AI review requested due to automatic review settings April 24, 2026 10:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates Android NativeViewGestureHandler/button integration so that when the OS marks a view as pressed (setPressed(true)), the associated gesture handler transitions to ACTIVE immediately. This brings Android button/touchable behavior closer to other platforms and allows Touchable to rely on activation/deactivation rather than begin/finalize timing.

Changes:

  • Refactors Touchable to start press-in/long-press logic on onActivate and complete press handling in onDeactivate.
  • Adds handler retention hooks to NativeViewGestureHandlerHook and invokes them from NativeViewGestureHandler prepare/reset.
  • Updates Android button (RNGestureHandlerButtonViewManager) to activate the attached NativeViewGestureHandler when the view becomes pressed.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/react-native-gesture-handler/src/v3/components/Touchable/Touchable.tsx Moves press lifecycle handling to onActivate/onDeactivate to match Android’s earlier activation.
packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt Captures the attached native handler and activates it when setPressed(true) occurs.
packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/NativeViewGestureHandler.kt Introduces hook attach/detach callbacks and calls them during handler prepare/reset.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants