Skip to content

Commit 7b025bd

Browse files
authored
Merge pull request #648 from nmassey/fix-remoteFunction-onProgressChange
fix: typeof "function" onProgressChange - fixes app crash
2 parents 0cd751f + 0abdb2d commit 7b025bd

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

.changeset/nine-moose-whisper.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-native-reanimated-carousel": patch
3+
---
4+
5+
fix app crash when using "onProgressChange" prop as function

src/hooks/useOnProgressChange.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ export function useOnProgressChange(
1919
const { autoFillData, loop, offsetX, size, rawDataLength, onProgressChange }
2020
= opts;
2121

22+
// remember `isFunc` here because we can't accurately check typeof
23+
// from within useAnimatedReaction because its code has been workletized;
24+
// the `onProgressChange` value will be typeof "object" from within
25+
// the worklet code even if it's a function.
26+
const isFunc = typeof onProgressChange === "function";
27+
2228
useAnimatedReaction(
2329
() => offsetX.value,
2430
(_value) => {
@@ -43,7 +49,7 @@ export function useOnProgressChange(
4349
absoluteProgress = rawDataLength - absoluteProgress;
4450

4551
if (onProgressChange) {
46-
if (typeof onProgressChange === "function")
52+
if (isFunc)
4753
runOnJS(onProgressChange)(value, absoluteProgress);
4854

4955
else

0 commit comments

Comments
 (0)