Get current scroll position of FlatList

Viewed 6157

I have this code:

<FlatList
    ref={(x) => (this.flatList = x)}
    data={players}
    style={this.props.style}
/>

What I need is to save the current scroll position of the FlatList when the user e.g. navigates away.

So something like this.flatList.getCurrentScrollPosition().

Is there such a thing?

1 Answers

FlatList inherits all of ScrollView props. Therefore you can use onScroll.

onScroll = (event) => {
  const scrollOffset = event.nativeEvent.contentOffset.y
}
Related