Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two way infinite scroll react native

I'm making a "todo" view for a calendar application. When you scroll down to the end of the list, it grabs upcoming events from the server and puts them at the bottom of the list. This is simple with react native. However, I would also like to allow the user to scroll up to view earlier dates and events. When they scroll to the top of the list, load earlier items. Unfortunately, there is no equivalent to onEndReached, but for the start. Any ideas/guidance on the best way to handle this?

like image 556
user3413723 Avatar asked Oct 30 '22 08:10

user3413723


1 Answers

Could you not use the ScrollView onScroll callback. The event argument gives you the scroll position. When the value is tending back towards 0, you can load more items and prepend them.

To do this you'd likely need to persist the previous value for comparison to determine the direction of scroll.

Also see this question: React native: get current scroll position of scrollview

like image 86
fubar Avatar answered Dec 01 '22 16:12

fubar