0

Using react-native-reanimated v1.

I have created a snack reproducing this issue - https://snack.expo.io/@noitidart/reanimated-scroll-view-ref

I have created a reanimatable component out of ScrollView like this:

import { ScrollView } from 'react-native-gesture-handler';
import Reanimated from 'react-native-reanimated';

const ReanimatedScrollView = Reanimated.createAnimatedComponent(ScrollView);

When I render it I want to get a ref to it so I can do ref.current.scrollTo(). However the ref is coming back without scrollTo on it. Here is my code:

const ref = useRef();

const scrollToFoo = () => {
   if (ref.current) {
       ref.current.scrollTo({ y: 100 });
   }
}

return (
<ReanimatedScrollView ref={ref} />
)

If I do this with a regular ScrollView, ref.current properly has scrollTo on it.

Noitidart
  • 35,443
  • 37
  • 154
  • 323

1 Answers1

0

You can use getNode() to get access to the component:

ref.current.getNode().scrollTo({ y: 100 });