react-native-reanimated-carousel icon indicating copy to clipboard operation
react-native-reanimated-carousel copied to clipboard

fix: typeof "function" onProgressChange - fixes app crash

Open nmassey opened this issue 7 months ago • 7 comments

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

  1. expo: 50.0.19
  2. react-native-reanimated: 3.6.2
  3. 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!! 🥳🙌

nmassey avatar Jul 22 '24 02:07 nmassey