user3413723
user3413723

Reputation: 12223

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?

Upvotes: 7

Views: 1346

Answers (1)

fubar
fubar

Reputation: 17388

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

Upvotes: 2

Related Questions