react-native: FlatList onEndReached can not be called!
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!
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 5
- Comments: 36 (2 by maintainers)
@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:
And if this not scroll envolved into ScrollView: ScrollView -> View (height) -> FlatList
just add onEndReachedThreshold={0.3} or number between [0,1] worked for me. usage for message list
Guys please make sure FaltList is not inside a scrollview or maybe has auto a width parent!
0.61.3 still happening …
onLoadMoreData(){
}; I worked on React Native 0.61 and onEndReached function works good.
This worked for me…!! 💯
With decimal values for
onEndReachedThreshold
the callback,onEndReached
doesn’t get called until the end of the list. For example,0.5
calls the callback at the end not halfway. But when I use whole numbers,5
, let’s say, the callback gets run halfway. Where the larger the number, the earlier the call and the smaller the number the later it gets called. I’m usingSectionList
so maybe there’s a difference? I really would not think there’d be a difference. Hope this helps.OR onEndReachedThreshold={0.5}
true
https://github.com/ifsnow/react-native-infinite-flatlist-patch/tree/master/patches does not support rn versions > 0.68. Do you still experience this issue? Should I work on this? Thanks
https://github.com/ifsnow/react-native-infinite-flatlist-patch/issues/11
<ScrollView style={{ flex: 1 }} onScrollBeginDrag={() => { //用户触摸过屏幕后 if (!isEndReached) { isEndReached = true; setIsEndReached(isEndReached); onEndReached(); } }} refreshControl={ <RefreshControl refreshing={refreshing} enabled={true} title={'松手刷新'} onRefresh={refresPage} /> } > <View></View> <FlatList data={listState} style={{ flex: 1 }} renderItem={({ item, index }) => {}} ListFooterComponent={ListFooterComponent()} ListEmptyComponent={ListEmptyComponent()} keyExtractor={({ index }) => {
key_${index}}} onEndReached={onEndReached} onEndReachedThreshold={0.01} /> </ScrollView>
same problem. RN 0.62.2.
https://github.com/ifsnow/react-native-infinite-flatlist-patch
I made a patch library to help with this issue. I hope this helps.