Support synchronous onScroll events on the UI thread by using Reanimated
See original GitHub issueDescribe the feature
Currently the onPageScroll
, onPageSelected
and onPageScrollStateChanged
events are dispatched as bubbling events using the batched bridge. This is really slow and doesn’t allow for any smooth (60 FPS) interpolations based on scroll state, such as smooth title changes etc.
I’m suggesting to support synchronous callbacks by using the Reanimated APIs (worklets on the UI thread), which shouldn’t be too hard to implement and allow for perfectly smooth 60 FPS animations all without crossing threads and spamming the bridge (see react-native-gesture-handler, they do the same thing with the onGesture
event.)
Motivation
- Way better Performance
- No Bridge-spam
- Allow reanimated worklet interpolations with 60 FPS
Implementation
I wanted to do the same thing for a gyroscope library but haven’t come around to actually implement it. I believe reanimated already does a lot of work for you, but I don’t exactly know how this is going to work. I’ll have to take a look myself, but it looks like they also just have an RCTEventDispatcher
set up, which then simply sends those events… 🤔 So I think there are no native code changes required here, but we somehow need a hook similar to the useAnimatedGestureHandler
hook.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:7
Top GitHub Comments
This PR has been merged, allowing the low-level
useHandler
hooks to be used.I don’t have an app anymore that uses this Pager View library, but I will start working on this feature once reanimated ships a release anyway just because I think the challenge is interesting 😅
I was able to do the following to get it working with reanimated. This is a modified version of
react-native-tab-view
: