react-native-animatable icon indicating copy to clipboard operation
react-native-animatable copied to clipboard

Ref assign problem

Open erdemildiz opened this issue 6 years ago • 3 comments

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;
        }} 
/>

erdemildiz avatar Oct 28 '19 07:10 erdemildiz

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

Shumuu avatar Nov 06 '19 14:11 Shumuu

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

erdemildiz avatar Nov 11 '19 17:11 erdemildiz

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.

matt-pawley avatar Jan 03 '20 10:01 matt-pawley