from documentation:
onEndReachedThreshold number
Threshold in pixels (virtual, not physical) for calling onEndReached. so I just wanted to know what it means, is it threshold from the top, or is it threshold from the bottom.
From the top? - if I set a value of onEndReachedThreshold ={10}, is my onEndReached called as soon as I scrolled to 10 pixel, or something else.
From the bottom? - if I set value of onEndReachedThreshold ={listview height -10}, will my onEndReached called as soon as I scrolled to 10 pixel, or something else.
onEndReachedThreshold Thus a value of 0.5 will trigger onEndReached when the end of the content is within half the visible length of the list.
The onEndReachedThreshold support float value thus If we pass 0.5 then it will represent 0.5 as Half of device screen. So if we pass onEndReachedThreshold={0.5} then it will call the onEndReached when user is half way from reaching end of FlatList.
To implement pull to refresh FlatList with React Native, we can set the refreshing and onRefresh props. to set the refreshing prop to isFetching , which is true when we're getting data for the FlatList . And we set onRefresh to the onRefresh which sets refreshing to true and then set it back to false after 2 seconds.
For anyone using FlatList
INSTEAD of ListView
, note that the parameter units have changed.
For ListView
it was in pixels from the bottom, but according to docs for FlatList, it is instead units of length from the bottom in list items.
How far from the end (in units of visible length of the list) the bottom edge of the list must be from the end of the content to trigger the onEndReached callback. Thus a value of 0.5 will trigger onEndReached when the end of the content is within half the visible length of the list.
Thus, if you want the list to update when the user is halfway down the current dataset, set the value to 0.5
The documentation is always the best way to go:
onEndReached function
Called when all rows have been rendered and the list has been scrolled to within onEndReachedThreshold of the bottom. The native scroll event is provided.onEndReachedThreshold number
Threshold in pixels (virtual, not physical) for calling onEndReached.
So as I see it: if you do onEndReachedThreshold ={10}
it calls onEndReached
if you scrolled to 10 pixels from the bottom
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With