From 6237e8a089c608e464214f55c02024e4c529c46c Mon Sep 17 00:00:00 2001 From: Aleksandra Cynk Date: Tue, 2 Apr 2024 19:58:35 +0200 Subject: [PATCH 1/2] Include factory --- src/reanimated2/animation/util.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/reanimated2/animation/util.ts b/src/reanimated2/animation/util.ts index dcd425d6906..09730c3b0ca 100644 --- a/src/reanimated2/animation/util.ts +++ b/src/reanimated2/animation/util.ts @@ -58,10 +58,15 @@ export function assertEasingIsWorklet( // It is possible to run reanimated on web without plugin, so let's skip this check on web return; } - if (!isWorkletFunction(easing)) { - throw new Error( - '[Reanimated] The easing function is not a worklet. Please make sure you import `Easing` from react-native-reanimated.' - ); + + if ('factory' in easing) { + assertEasingIsWorklet(easing.factory()); + } else { + if (!isWorkletFunction(easing)) { + throw new Error( + '[Reanimated] The easing function is not a worklet. Please make sure you import `Easing` from react-native-reanimated.' + ); + } } } From 30f1da9e4f6d985762cad26caf4a8d1e29a52532 Mon Sep 17 00:00:00 2001 From: Aleksandra Cynk Date: Wed, 3 Apr 2024 12:01:26 +0200 Subject: [PATCH 2/2] Code review --- src/reanimated2/animation/util.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/reanimated2/animation/util.ts b/src/reanimated2/animation/util.ts index 09730c3b0ca..cf969412745 100644 --- a/src/reanimated2/animation/util.ts +++ b/src/reanimated2/animation/util.ts @@ -58,15 +58,15 @@ export function assertEasingIsWorklet( // It is possible to run reanimated on web without plugin, so let's skip this check on web return; } + // @ts-ignore typescript wants us to use `in` instead, which doesn't work with host objects + if (easing?.factory) { + return; + } - if ('factory' in easing) { - assertEasingIsWorklet(easing.factory()); - } else { - if (!isWorkletFunction(easing)) { - throw new Error( - '[Reanimated] The easing function is not a worklet. Please make sure you import `Easing` from react-native-reanimated.' - ); - } + if (!isWorkletFunction(easing)) { + throw new Error( + '[Reanimated] The easing function is not a worklet. Please make sure you import `Easing` from react-native-reanimated.' + ); } }