[Android] Handle hover in Touchable#4282
Open
m-bert wants to merge 4 commits into
Open
Conversation
Contributor
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.
Comment on lines
+445
to
+451
| // Resting (non-pressed) animation targets. While the pointer hovers the | ||
| // button, the press-out animation settles on the hover values instead of | ||
| // the defaults, mirroring the web priority order (pressed > hovered > | ||
| // default). | ||
| private val restingOpacity get() = if (isHovered) hoverOpacity else defaultOpacity | ||
| private val restingScale get() = if (isHovered) hoverScale else defaultScale | ||
| private val restingUnderlayOpacity get() = if (isHovered) hoverUnderlayOpacity else defaultUnderlayOpacity |
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
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: