computerjazz / react-native-infinite-pager

An infinitely-swipeable pager component.
MIT License
174 stars 16 forks source link

render outside the pager is slow after onPageChange #5

Closed CptMaumau closed 2 years ago

CptMaumau commented 2 years ago

Hi, I'm trying to update a value in onPageChange so it matches the current page but the new value renders really late. From my tests I think it's due to my update being queued behind all the pages rendering, any idea how I could improve this? The value has to be outside the pager.

CptMaumau commented 2 years ago

@computerjazz would it be possible to add something like onPageWillChange? So that I can update my value before the pager starts a new render.

computerjazz commented 2 years ago

At the individual page level you can listen to animated values passed to your PageComponent: https://github.com/computerjazz/react-native-infinite-pager/blob/main/src/index.tsx#L308-L310

You could use pageAnim or focusAnim in a useAnimatedReaction to trigger some side effect when the values pass some threshold (maybe using Math,round()).

Or pass in a pageCallbackNode and do the same thing at the parent level: https://github.com/computerjazz/react-native-infinite-pager/blob/main/src/index.tsx#L47

CptMaumau commented 2 years ago

It works!! Thank you for the feedback!