Detect FlatList onBeginningReached - React Native

Viewed 241

I'm using a <FlatList> component to display a simple list.

This component has events for onEndReached, but I could not find an equivalent for the top, like an onBeginningReached event.

How do you detect that a user has scrolled to the very top of the <FlatList>?

1 Answers

You can use onMomentumScrollEnd prop for that purpose:

onMomentumScrollEnd={e => {
  if (e.nativeEvent.contentOffset.y === 0) {
    // do things
  }
}}

I'm suggesting onMomentumScrollEnd and not onScroll, because it will fire far less often and will put less strain on the performance.

Related