[Android] Activate buttons when setPressed(true) is called by the OS#4116
Open
j-piasecki wants to merge 1 commit intomainfrom
Open
[Android] Activate buttons when setPressed(true) is called by the OS#4116j-piasecki wants to merge 1 commit intomainfrom
setPressed(true) is called by the OS#4116j-piasecki wants to merge 1 commit intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
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
Touchableto start press-in/long-press logic ononActivateand complete press handling inonDeactivate. - Adds handler retention hooks to
NativeViewGestureHandlerHookand invokes them fromNativeViewGestureHandlerprepare/reset. - Updates Android button (
RNGestureHandlerButtonViewManager) to activate the attachedNativeViewGestureHandlerwhen 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.
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
Updates the
NativeViewGestureHandlerhooks to allow direct access to the used handler.Updates the button implementation on Android to use the new hook methods and move to
ACTIVEstate 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
Touchableimplementation not to rely onbeginandfinalizecallbacks at all, since we can now assume that when a button is pressed, it's in theACTIVEstate.Test plan
Verify existing Touchable examples.