question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FlatList onEndReached can not be called!

See original GitHub issue

React Native version: 0.59.9

Steps To Reproduce

I console log in VirtualizedLIst. The function _maybeCallOnEndReached() called.

_maybeCallOnEndReached() {
 const {
   data,
   getItemCount,
   onEndReached,
   onEndReachedThreshold,
 } = this.props;
 const {contentLength, visibleLength, offset} = this._scrollMetrics;
 const distanceFromEnd = contentLength - visibleLength - offset;
 if (
   onEndReached &&
   this.state.last === getItemCount(data) - 1 &&
   /* $FlowFixMe(>=0.63.0 site=react_native_fb) This comment suppresses an
    * error found when Flow v0.63 was deployed. To see the error delete this
    * comment and run Flow. */
   distanceFromEnd < onEndReachedThreshold * visibleLength &&
   (this._hasDataChangedSinceEndReached ||
     this._scrollMetrics.contentLength !== this._sentEndForContentLength)
 ) {
   // Only call onEndReached once for a given dataset + content length.
   this._hasDataChangedSinceEndReached = false;
   this._sentEndForContentLength = this._scrollMetrics.contentLength;
   onEndReached({distanceFromEnd});
 }
}

console result: this.state.last = 0; getItemCount(data) = 2; this.state.last !== getItemCount(data) -1 , so can not trigger onEndReached!

But for FlatList, it has reach end!

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:31 (1 by maintainers)

github_iconTop GitHub Comments

30reactions
ssancheza227commented, Jul 19, 2019

@JerakRus @luoyushouchai @e1016 Hi guys 😃 good news, well the solution was envolved flatList into View and set height (const {height} = Dimensions.get(‘window’);) to view, percent not work:

<View style={{flex: 1, height: height}}>
   <FlatList
       data={data}
       keyExtractor={(item, index) => index.toString()}
       onEndReached={this.handleLoadMore} 
       onEndReachedThreshold={0.01}
       ListFooterComponent={() => this.state.loading ? <ActivityIndicator/> : null}
       renderItem={({item, index}) => this.renderTransaction(item, index)}
   />
</View>

And if this not scroll envolved into ScrollView: ScrollView -> View (height) -> FlatList

6reactions
ggdegreatcommented, Dec 7, 2019

0.61.3 still happening …

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReactNative Flatlist onEndReached not working
I'm calling the this.state.pageNo at the end and it's not updating. I want to use this logic later in infinite scroll but not...
Read more >
Unable to render data to ReactNative FlatList on Scroll down ...
I am using FlatList's onEndReached prop to get new items on scroll ... Warning: Can't perform a React state update on an unmounted...
Read more >
onEndReached not working : r/reactnative - Reddit
Hello guys, I successfully implemented the API with pagination in app using FlatList. It successfully calls the next page on reaching the ...
Read more >
FlatList onEndReached Called On Load [iOS] - Expo Snack
FlatList onEndReached Called On Load [iOS]. No description. Open with Expo Go. Open in editor. Need Expo? Don't have the Expo Go?
Read more >
FlatList onEndReached being called multiple times-React Native
Coding example for the question FlatList onEndReached being called multiple times-React Native. ... onEndReached trigger is not being called in FlatList ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found