Reputation: 909
what i'm trying to do is that when i run onPress, i want to scroll down as much as value of y (which is 499)
but if i use my code it doesn't work anything
this is my code
const TodoList = ({}) => {
const height = Dimensions.get('window').height;
const flatListRef = useRef()
return (
<FlatList
ref={flatListRef}
style={{height}}
keyExtractor={(item) => String(item.id)}
renderItem={({item}) => (
<TodoItem
onPress={() => {
const node = flatListRef.current;
if (node) {
node.scrollToIndex({x: 0, y: 499, animated: true, index:0});
}
}}
/>
)}
/>
what code should i fix?...
Upvotes: 2
Views: 414
Reputation: 3045
I think you are using the wrong method. You should be using scrollToOffset
if (node) {
node.scrollToOffset({ offset: 499, animated: true });
}
Upvotes: 1