2

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>?

Azametzin
  • 5,223
  • 12
  • 28
  • 46
0xD1x0n
  • 686
  • 4
  • 12
  • 31

1 Answers1

2

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.

giotskhada
  • 2,326
  • 1
  • 11
  • 18
  • Thank you sir ! Exactly the solution I was looking for. works exactly as expected. – 0xD1x0n Mar 09 '20 at 14:50
  • I guess there's an issue with `onMomentumScrollEnd` in android? check this [example](https://snack.expo.io/@anastely/gallery-ex) you will see – Oliver D Oct 06 '20 at 15:49