Expose animatable refs for v3 touchables#4230
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds an “animatable ref” surface to v3 Pressable and Touchable by attaching getAnimatableRef() to the underlying native button ref, and exercises it in the API v3 test suite.
Changes:
- Introduces a shared
setAndForwardAnimatableRefhelper to set a local ref, attachgetAnimatableRef, and forward refs. - Updates
TouchableandPressableto use a callback ref that installsgetAnimatableRef. - Adds tests asserting
Pressable/TouchableexposegetAnimatableRef().
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/react-native-gesture-handler/src/v3/components/animatableRef.ts | New helper for setting+forwarding refs and attaching getAnimatableRef(). |
| packages/react-native-gesture-handler/src/v3/components/Touchable/Touchable.tsx | Uses helper to install getAnimatableRef() on the native button ref. |
| packages/react-native-gesture-handler/src/v3/components/Pressable.tsx | Uses helper to install getAnimatableRef() on the native button ref. |
| packages/react-native-gesture-handler/src/tests/api_v3.test.tsx | Adds coverage asserting getAnimatableRef() exists for Pressable/Touchable. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| localRef.current = ref; | ||
|
|
||
| if (ref) { | ||
| (ref as AnimatableRef<T>).getAnimatableRef = () => localRef.current; | ||
| } |
| test('Pressable exposes the native button as an animatable ref', () => { | ||
| const ref = createRef<AnimatableViewRef>(); | ||
|
|
||
| render( | ||
| <GestureHandlerRootView> | ||
| <Pressable ref={ref} /> | ||
| </GestureHandlerRootView> | ||
| ); | ||
|
|
||
| expect(ref.current?.getAnimatableRef?.()).toBe(ref.current); | ||
| }); |
|
I think this may be on Reanimated's side. I opened software-mansion/react-native-reanimated#9587 yesterday, and I'd like to wait for a response from the Reanimated team before proceeding. |
38e4d00 to
ed5cd84
Compare
|
Hey guys, issue #9587 is now resolved on |
Description
Fixes #4225.
When v3
Pressable/Touchableare wrapped with Reanimated'screateAnimatedComponent, Reanimated can resolve the composite to the outer gesture detector instead of the inner native button. That means style writes likewidthandopacitycan land on the detector wrapper while only subtree-affecting transforms visibly survive.This change forwards refs through v3
PressableandTouchableto their inner native button and attachesgetAnimatableRefto that native ref. Reanimated already understands that method and will use it as the host target for animated styles.Test plan
Notes:
lint-jspasses with the repository's existing warnings.apps/common-apptype-checking becausereact-native-pager-viewtypes are missing.