Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what onEndReachedThreshold really means in react-native

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.

like image 458
Manjeet Singh Avatar asked Sep 07 '16 09:09

Manjeet Singh


People also ask

What is onEndReachedThreshold in react native?

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.

What is onEndReachedThreshold in FlatList react native?

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.

How do you use onRefresh 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.


2 Answers

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

like image 158
jhm Avatar answered Sep 20 '22 15:09

jhm


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

like image 40
dv3 Avatar answered Sep 16 '22 15:09

dv3