Closed
Description
<FlatList
ref={(flatList)=>this._flatList = flatList}
ListHeaderComponent={this._header}
ListFooterComponent={this._footer}
ItemSeparatorComponent={this._separator}
renderItem={this._renderItem}
getItemLayout={(data,index)=>({length: ITEM_HEIGHT, offset: (ITEM_HEIGHT+2) * index, index})}
onEndReachedThreshold={0.5}
onEndReached={(info)=>{
console.log(JSON.stringify(info));
}}
data={data}
/>
When the scroll speed is fast enough,onEndReached triggered 2 times or more times
Is there any solution?
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
parkerproject commentedon May 17, 2017
mine doesn't even trigger.
fengshanjian commentedon May 18, 2017
@parkerproject
My paltform is ios 10.3,mac osx 10.12.5
benderlidze commentedon May 18, 2017
@fengshanjian
Yep, got the same - fires 2 times. But if you are using redux or even state - you can use something like this
JonoH commentedon May 31, 2017
Same issue my side. Seems to be a bug in the ScrollView bouncing feature on iOS (when you over scroll on iOS the ScrollView scrolls past the content and bounces back to the end of the content by default).
Setting
bounces={false}
solved onEndReached being called twice for me. Still not an ideal solution though as you lose that nice smooth/fluid feel in the UX.[-]FlatList onEndReached triggered 2 times[/-][+][FlatList] onEndReached triggered 2 times[/+]hramos commentedon Jun 2, 2017
Hey, thanks for reporting this issue!
It looks like your description is missing some necessary information. Can you please add all the details specified in the template? This is necessary for people to be able to understand and reproduce the issue being reported.
grin commentedon Jun 23, 2017
I'm definitely seeing the second
onEndReached
call triggered by the bouncing effect on iOS. Addingbounces={false}
to the FlatList fixed it for me. I think ideally, RN should not callonEndReached
while the list is in the "bouncing" state. Not sure how doable is this though.grin commentedon Jun 23, 2017
OK, here is my solution for how to avoid the second
onEndReached
call with the bouncing effect enabled on iOS:onMomentumScrollBegin
prop to yourFlatList
declaration.onEndReached
callback to trigger data fetching only once per momentum.Tested with RN 0.44.0.
gonglong commentedon Jul 22, 2017
hi @grin can you pls refer me some document about the function onMomentumScrollBegin? i cannot find any on http://facebook.github.io/react-native/releases/0.46/docs/flatlist.html
vomchik commentedon Jul 31, 2017
@gonglong you can find information about props here https://github.com/facebook/react-native/blob/master/Libraries/Components/ScrollView/ScrollView.js#L246
vomchik commentedon Jul 31, 2017
FlatList is just wrapper of the ScrollView
hramos commentedon Jul 31, 2017
Hey, thanks for reporting this issue!
It looks like your description is missing some necessary information, or the list of reproduction steps is not complete. Can you please add all the details specified in the template? This is necessary for people to be able to understand and reproduce the issue being reported.
I am going to close this, but feel free to open a new issue with the additional information provided. Thanks!
8 remaining items
harish-aka-shivi commentedon Dec 21, 2017
Was also happening with me, try keeping a flag to stop making request.
Then I set the state to loading false after completing of request
AyubaMakoa commentedon Jan 30, 2018
`constructor(props){
super(props);
this.state = {
flatListReady:false
}
}
_scrolled(){
this.setState({flatListReady:true})
}
loadMore = () => {
if(!this.state.flatListReady){ return null}
//you can now load more data here from your backend
<FlatList
onScroll={this._scrolled.bind(this)}
style={{width:'100%',flexGrow:1}}
ListHeaderComponent={this.headerComponent}
data={this.props.data}
renderItem={this.renderItem}
keyExtractor={(item,index) => index }
onEndReached={(x) => {this.loadMore()}}
onEndReachedThreshold={0.5}
`
anil1712 commentedon Feb 2, 2018
onEndReached
is not working as expected. It's not triggering continuously when we reached the end.FYI: I am using the
native-base
components.gougoushan commentedon Feb 11, 2018
using
setTimeout
forsetState
, eg.setTimeout(() => this.setState({ arr: [ ...newArr ] }), 3000);
anil1712 commentedon Feb 12, 2018
@gougoushan Not working for me
nsyujian commentedon Mar 16, 2018
don't use onEndReached
react-native-refresh-list-view
mtx62 commentedon Apr 9, 2018
@GaoYuJian You are a hero!!
chunghalu commentedon May 16, 2018
This is my solution:
rizwanahmed19 commentedon Jul 4, 2018
For some reasons my
onMomentumScrollBegin
is not being fired. Is this happening to anybody else?pisacode commentedon Jul 5, 2018
I have solved it with using debounce from lodash
first
import debounce from 'lodash.debounce'
and then just add this to your
constructor
this._onEndReached = debounce(this._onEndReached, 500);
bnbon commentedon Jul 23, 2018
Is this going to be fixed in the next release or is the hack necessary?