oblador / react-native-animatable

Standard set of easy to use animations and declarative transitions for React Native
MIT License
9.82k stars 701 forks source link

Ref assign problem #294

Open erdemildiz opened 4 years ago

erdemildiz commented 4 years ago

I am using blow code block, but I am getting
dataListRef.scrollToOffset is not a function. (In 'dataListRef.scrollToOffset({ animated: true, offset: 0 })', 'dataListRef.scrollToOffset' is undefined) error when I try this

this.dataListRef.scrollToOffset({ animated: true, offset: 0 });

<AnimatableFlatList                 
useNativeDriver
ref={ref => {
this.dataListRef = ref;
}} 
/>
Shumuu commented 4 years ago

Does it work when you do this.dataListRef.current.scrollToOffset({animated: true, offset: 0)} ?

erdemildiz commented 4 years ago

I am sorry, It didn't worked. @shauns

matt-pawley commented 4 years ago

May be a better solution, but managed to get it working by doing the following:

this.dataListRef.current.ref.getNode().scrollToOffset(...);

The getNode() should return the actual element (FlatList in this example) so you can use the methods on it.