react-native-reanimated-carousel
react-native-reanimated-carousel copied to clipboard
fix: typeof "function" onProgressChange - fixes app crash
What: the bug
On iOS, when running in "Release" configuration (i.e. not "development" configuration), if onProgressChange
is a function, the app crashes. 😖
On Android, similar crash. Thanks to @yannick-softwerft for providing a traceback in a comment below.
This bug was accidentally introduced in 0d2b930f394f65fd70a03593ea8c7b16fb552e62 (in code here)
Why
Since the callback functions in useAnimatedReaction
are automatically workletized, when running in Xcode "Release" configuration (i.e. not "development" configuration), if the variable onProgressChange
is set to a function (from within the JS thread), then typeof onProgressChange
will be equal to "object"
from within the workletized function (in the UI thread).
So, the code assumes that the value is a SharedValue and attempts to set onProgressChange.value = absoluteProgress
. However, this seems to immediately cause the app to crash.
My configuration
- expo: 50.0.19
- react-native-reanimated: 3.6.2
- react-native-reanimated-carousel: 4.0.0-alpha.12
What: the fix
Remember the value for typeof onProgressChange
in the JS thread (instead trying to check it from within the UI thread).
App no longer crashes! And onProgressChange
as function works correctly again!! 🥳🙌