onEndReached of FlatList only called once
See original GitHub issueIs this a bug report?
Yes
Environment
react-native -v
: react-native-cli: 1.0.0 react-native: 0.46.1node -v
: v6.3.1npm -v
: 3.10.3yarn --version
:
Then, specify:
- Target Platform: iOS & Android
- Development Operating System: Mac OS
- Build tools: both Xcode and Android Studio
Steps to Reproduce
(Write your steps here:) code related to onEndReached here:
onEndReached={this.handleEndReached.bind(this)}
onEndReachedThreshold={0.3}
and the list has 100 items.
- pull down the list to index of 85 , onEndReached called as expect
- pull up to index of 50,
- pull down the list to index of 85 again
Expected Behavior
onEndReached should be called again after step 3.
Actual Behavior
onEndReached not called.
i wonder if i need to re-render the component to reset some status related to onEndReached, so i did something in my handleEndReached
handleEndReached() {
console.log("mytest onEndReached");
// setTimeout(
// ()=>{this.setState({
// data: this.state.data.concat(this.getOldData()),
// })},
// 2000);
setTimeout(
()=>{this.setState({
data: this.state.data,
})},
2000);
}
but noting changed. It sounds like that the onEndReached would be called again only if the length of list had been changed. if I uncomment the above code and onEndReached would be called.
My use case is that FlatList would try to fetch some more data when user scroll to the bottom of the list. But you cannot count on that the fetch succeeds or more data fetched for every try. If it failed one time, onEndReached never triggered again. This is the point blocking me.
(Write what happened. Add screenshots!)
Reproducible Demo
(Paste the link to an example project and exact instructions to reproduce the issue.)
Here is the link to Expo
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:6
Top GitHub Comments
I suppose if there is no props or state change after calling onEndReachd, it won’t be fired again.
This should not be closed yet. It is a must to mention in the docs that onEndReached does not trigger again until/unless there is a prop or state change. It was a huge confusing factor to and without @codingrhythm I would have never got it.
So all we need here is an update to the docs, which I don’t know how to do. For the sake of others, it would be nice if someone with the time and possibly Facebook’s excellent pay can do it. Seems like a one liner.