Search code examples
react-nativereact-native-reanimated-v2

Share animation values with child components - React reanimated 2


I have a snack here where I want to take the scroll Y value and pass it to an animated view inside a sibling component and have that view animate as I scroll, for this example I just want to animate the height. Smaller when scrolling down, larger when scrolling up (doesn't matter). The snack currently passes it as state which I know is incorrect but I'm not sure how else I would achieve this.

How I can animate the component the correct way?


Solution

  • Turns out I'm overthinking it. Just use the useSharedValue hook and pass the scroll value in there then use it as a prop on the sibling component...

    Here is the updated snack if anyone was wondering