ReactNative Flatlist onEndReached not working

瘦欲@ 提交于 2019-12-01 11:44:27

The property you are looking for in FlatList is onEndReachedThreshold instead of onEndThreshold.

In my case the problem was with nativebase <Content>. It was creating problems when <FlatList> was used inside it. Solution :

<Content
  style={{flex: 1}}
  contentContainerStyle={{flex: 1}} // important!
>

Source : https://github.com/GeekyAnts/NativeBase/issues/1736

There is an issue for that here: https://github.com/facebook/react-native/issues/14312. Looks like a lot of people are experiencing the same. There is a suggestion to change the onEndReachedThreshold to value bigger that 0, for example: 0.3.

First of all, you should make sure that your onEndReached listens to your onMomentumScrollBegin and onMomentumScrollEnd props of FlatList. Another important thing is distanceFromEnd param of onEndReached prop of FaltList. So you can use it as follows:

          onMomentumScrollBegin={() => this.setState({ scrollBegin: true })}
          onMomentumScrollEnd={() => this.setState({ scrollBegin: false })}
          onEndReached={({ distanceFromEnd }) =>
            distanceFromEnd<=0.5&&
            this.state.scrollBegin &&
            this.onEndReached()
          }

And then you can define your onEndReached function, which will work as needed.

Hope this will help someone to save time on this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!