[Android] Handle hover in Touchable#4282
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds Android hover animations to Touchable by extending the native RNGestureHandlerButton implementation to react to hover enter/exit, aligning behavior with the existing web hover support and avoiding hover→press flicker via a post-frame hover-out.
Changes:
- Extend the codegen native component spec to include hover-related props (opacity/scale/underlay + hover in/out durations).
- Update Android
RNGestureHandlerButtonViewManagerto animate hover in/out and to let press-out settle on hover values when appropriate. - Update JS/TS docs for
GestureHandlerButtonhover props to indicate Android support.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/react-native-gesture-handler/src/specs/RNGestureHandlerButtonNativeComponent.ts | Adds hover props to the native component spec (including sentinel defaults for hover values). |
| packages/react-native-gesture-handler/src/components/GestureHandlerButton.tsx | Updates prop docs to reflect hover support on Android. |
| packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt | Implements Android hover handling, delayed hover-out to avoid flicker, and press-out targeting logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| MotionEvent.ACTION_POINTER_UP, | ||
| -> | ||
| if (isHoveringPointer(event)) { | ||
| isHovered = isWithinBounds(event) |
There was a problem hiding this comment.
What about styluses without hover support?
| val callback = Choreographer.FrameCallback { | ||
| pendingHoverOut = null | ||
| isHovered = false | ||
| applyHoverState() | ||
| } |
There was a problem hiding this comment.
Same as on iOS - do we need to schedule this to the next frame? Aren't hover-out and press-down happening at the same time?
There was a problem hiding this comment.
do we need to schedule this to the next frame?
Unfortunately yes 😞 While those events have the same timestamp, Android dispatches hover event first. That results in first running hover out animation and then going to pressed state - flickers are visible (presented offline).
Description
This PR brings hover effects for the
Touchablecomponent on Android. Previously, animations based on hover were possible only on web.Hovering out is handled in post-frame callback. This is due to the fact that on Android
ACTION_HOVER_EXITis dispatched right beforeACTION_DOWN, so without delaying hover out effect we would be left with flickers.Test plan
Tested on existing Touchable example and on the code below: