-
-
Notifications
You must be signed in to change notification settings - Fork 349
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
- when
autoplayis enabled, rather than using timers, the code inplay()runs as quickly as it can on every animation frame. This uses a LOT of processor (see video screengrab below) and ultimately battery life - autoplay now has different timings: subsequent scrolls do not wait for the
scrollAnimationDurationtime
How to fix
I recommend reverting:
Unfortunately, this PR seems to have a few issues:
- primarily, running this check code in
requestAnimationFrame()over and over again is really awful for processor usage / performance / battery usage. UsingsetTimeout(or perhaps some other method for a timer?) would be better - since
lastTimestampRef.current = currentTimestampis called immediately inplay()after when callingnext()andprev(), it restarts the countdown too soon (rather than waiting for the scroll to complete)
I'm not fully sure what #536 is intended to fix, but unfortunately it seems to add a few issues.
To Reproduce
<Carousel
autoPlay={true}
autoPlayInterval={1000}
scrollAnimationDuration={1000}Screengrab videos
4.0.0-alpha.12 (old code, better performance)
Notice that the CPU time stays low. It increases a little bit during scroll, but otherwise it stays low.
Also, see that it's almost exactly 2 seconds between transitions (1 second for the scrollAnimationDuration plus 1 second for autoPlayInterval)
Screen.Recording.2024-09-11.at.12.26.58.mov
4.0.0-canary.13 (includes #536, worse performance)
Notice that the CPU time stays high. 😮
Also, notice that the time between transitions is not the same as in previous versions.
Screen.Recording.2024-09-11.at.12.23.33.mov
Versions:
- expo: v50.0.20
- react: v18.2.0
- react-native: v0.73.6
- react-native-reanimated: v3.6.2
- react-native-reanimated-carousel: v4.0.0-canary.13
- react-native-gesture-handler: v2.14.1
Smartphone:
- Device: iPhone 15 Pro Simulator
- OS: 17.5
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working