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 triggered before reach onEndReachedThreshold

See original GitHub issue

Description

FlatList onEndReached triggered before reach end of list. If legacyImplementation is set to true or render with ListView, onEndReached will trigger correctly when it reached end of list

Reproduction

Based from FlatListExample on UIExplorer in React Native v0.43.0-rc.1, add onEndReached to FlatList

state = {
  data: genItemData(30),
  debug: false,
  horizontal: false,
  filterText: '',
  fixedHeight: true,
  logViewable: false,
  virtualized: true,
};

<FlatList
  HeaderComponent={HeaderComponent}
  FooterComponent={FooterComponent}
  SeparatorComponent={SeparatorComponent}
  data={filteredData}
  debug={this.state.debug}
  disableVirtualization={!this.state.virtualized}
  getItemLayout={this.state.fixedHeight ?
    this._getItemLayout :
    undefined
  }
  horizontal={this.state.horizontal}
  key={(this.state.horizontal ? 'h' : 'v') +
    (this.state.fixedHeight ? 'f' : 'd')
  }
  legacyImplementation={false}
  numColumns={1}
  onRefresh={this._onRefresh}
  onViewableItemsChanged={this._onViewableItemsChanged}
  ref={this._captureRef}
  refreshing={false}
  renderItem={this._renderItemComponent}
  shouldItemUpdate={this._shouldItemUpdate}
  viewabilityConfig={VIEWABILITY_CONFIG}
  onEndReachedThreshold={1}
  onEndReached={({ distanceFromEnd }) => {
    console.log('on end reached ', distanceFromEnd)
  }}
/>  

Additional Information

  • React Native version: v0.43.0-rc.1
  • Platform: Both
  • Operating System: MacOS

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:16
  • Comments:40 (5 by maintainers)

github_iconTop GitHub Comments

63reactions
idibidiartcommented, Aug 6, 2017

I believe Content is from NativeBase and I believe that implements a ScrollView. FlatList cannot work right inside a ScrollView.

25reactions
rqzheng2015commented, Mar 27, 2017

I know how to solve this, you just need to set onEndReachedThreshold as a rate of visibleLength. So you just need to set it as a number smaller than 1, then it worked!!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

react native - FlatList calls `onEndReached` when it's rendered
But my problem is onEndReached is called when render() is called In other words, FlatList's onEndReached is triggered before it reach the bottom....
Read more >
FlatList - React Native
Thus a value of 0.5 will trigger onEndReached when the end of the content is within half the visible length of the list....
Read more >
How it works | React Native Bidirectional Infinite Scroll
You can add a prop onEndReached on FlatList . This function gets called when your scroll is near the end of the list,...
Read more >
flatlist onendreached not working
onEndReached is called one or two times before the first load ends and data array is filled. ... onendreachedthreshold flatlist not working.
Read more >
React Native — Infinite Scroll Pagination with FlatList
onEndReachedThreshold is used to determine how far the distance from the bottom in order to trigger onEndReached . The smaller the threshold, ...
Read more >

github_iconTop Related Medium Post

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