diff --git a/apps/common-app/src/examples/RuntimeTests/RuntimeTestsExample.tsx b/apps/common-app/src/examples/RuntimeTests/RuntimeTestsExample.tsx index 59da4a81f0d..6a460dbf4ef 100644 --- a/apps/common-app/src/examples/RuntimeTests/RuntimeTestsExample.tsx +++ b/apps/common-app/src/examples/RuntimeTests/RuntimeTestsExample.tsx @@ -49,6 +49,8 @@ export default function RuntimeTestsExample() { require('./tests/core/useAnimatedStyle/reuseAnimatedStyle.test'); require('./tests/core/useDerivedValue/basic.test'); require('./tests/core/useDerivedValue/chain.test'); + + require('./tests/core/useSharedValue/animationsCompilerApi.test'); }, }, { diff --git a/apps/common-app/src/examples/RuntimeTests/tests/animations/withTiming/basic.test.tsx b/apps/common-app/src/examples/RuntimeTests/tests/animations/withTiming/basic.test.tsx index d1192fdc43c..f7cd63ceb50 100644 --- a/apps/common-app/src/examples/RuntimeTests/tests/animations/withTiming/basic.test.tsx +++ b/apps/common-app/src/examples/RuntimeTests/tests/animations/withTiming/basic.test.tsx @@ -27,7 +27,15 @@ const WIDTH_COMPONENT_PASSIVE_REF = 'WidthComponentPassive'; type Width = number | `${number}%` | 'auto'; describe('withTiming animation of WIDTH', () => { - const WidthComponent = ({ startWidth, finalWidth }: { startWidth: Width; finalWidth: Width }) => { + const WidthComponent = ({ + startWidth, + finalWidth, + compilerApi, + }: { + startWidth: Width; + finalWidth: Width; + compilerApi: boolean; + }) => { const widthActiveSV = useSharedValue(startWidth); const widthPassiveSV = useSharedValue(startWidth); @@ -36,22 +44,30 @@ describe('withTiming animation of WIDTH', () => { const styleActive = useAnimatedStyle(() => { return { - width: withTiming(widthActiveSV.value, { duration: 500 }), + width: withTiming(compilerApi ? widthActiveSV.get() : widthActiveSV.value, { duration: 500 }), }; }); const stylePassive = useAnimatedStyle(() => { return { - width: widthPassiveSV.value, + width: compilerApi ? widthPassiveSV.get() : widthPassiveSV.value, }; }); useEffect(() => { - widthActiveSV.value = finalWidth; - }, [widthActiveSV, finalWidth]); + if (compilerApi) { + widthActiveSV.set(finalWidth); + } else { + widthActiveSV.value = finalWidth; + } + }, [widthActiveSV, finalWidth, compilerApi]); useEffect(() => { - widthPassiveSV.value = withTiming(finalWidth, { duration: 500 }); - }, [widthPassiveSV, finalWidth]); + if (compilerApi) { + widthPassiveSV.set(withTiming(finalWidth, { duration: 500 })); + } else { + widthPassiveSV.value = withTiming(finalWidth, { duration: 500 }); + } + }, [widthPassiveSV, finalWidth, compilerApi]); return ( @@ -69,31 +85,41 @@ describe('withTiming animation of WIDTH', () => { finalWidth: Width; finalWidthInPixels: number; description: string; + compilerApi: boolean; } - test.each([ - { startWidth: 0, finalWidth: 100, finalWidthInPixels: 100, description: 'width in pixels' }, - { - startWidth: '0%', - finalWidth: '100%', - finalWidthInPixels: Dimensions.get('window').width, - description: 'width in percents', - }, - { - startWidth: '0%', - finalWidth: '75%', - finalWidthInPixels: Dimensions.get('window').width * 0.75, - description: 'width in percents', - }, - { - startWidth: 20, - finalWidth: '40%', - finalWidthInPixels: Dimensions.get('window').width * 0.4, - description: 'width from pixels to percents (not supported)', - }, - ] as Array)( + test.each( + [ + { startWidth: 0, finalWidth: 100, finalWidthInPixels: 100, description: 'width in pixels' }, + { + startWidth: '0%', + finalWidth: '100%', + finalWidthInPixels: Dimensions.get('window').width, + description: 'width in percents', + }, + { + startWidth: '0%', + finalWidth: '75%', + finalWidthInPixels: Dimensions.get('window').width * 0.75, + description: 'width in percents', + }, + { + startWidth: 20, + finalWidth: '40%', + finalWidthInPixels: Dimensions.get('window').width * 0.4, + description: 'width from pixels to percents (not supported)', + }, + ].reduce( + (acc, element) => [ + ...acc, + { ...element, compilerApi: false }, + { ...element, compilerApi: true, description: `${element.description} (compiler API)` }, + ], + [] as Record[], + ) as unknown as Array, + )( '${description}, from ${startWidth} to ${finalWidth}', - async ({ startWidth, finalWidth, finalWidthInPixels }: TestCase) => { - await render(); + async ({ startWidth, finalWidth, finalWidthInPixels, compilerApi }: TestCase) => { + await render(); const componentActive = getTestComponent(WIDTH_COMPONENT_ACTIVE_REF); const WidthComponentPassive = getTestComponent(WIDTH_COMPONENT_PASSIVE_REF); await wait(1000); @@ -103,7 +129,7 @@ describe('withTiming animation of WIDTH', () => { ); test('Width from percent to pixels is NOT handled correctly', async () => { - await render(); + await render(); const componentActive = getTestComponent(WIDTH_COMPONENT_ACTIVE_REF); const WidthComponentPassive = getTestComponent(WIDTH_COMPONENT_PASSIVE_REF); await wait(1000); diff --git a/apps/common-app/src/examples/RuntimeTests/tests/core/useDerivedValue/basic.test.tsx b/apps/common-app/src/examples/RuntimeTests/tests/core/useDerivedValue/basic.test.tsx index 71e7a247cab..fb4cbdce871 100644 --- a/apps/common-app/src/examples/RuntimeTests/tests/core/useDerivedValue/basic.test.tsx +++ b/apps/common-app/src/examples/RuntimeTests/tests/core/useDerivedValue/basic.test.tsx @@ -43,12 +43,14 @@ describe('Test useDerivedValue changing width', () => { animate, animationType, deriveFunction, + compilerApi, }: { startWidth: number; finalWidth: number; animate: AnimationLocation; animationType: AnimationType; deriveFunction: (a: number) => number; + compilerApi: boolean; }) => { const basicValue = useSharedValue(startWidth); const componentRef = useTestRef(WIDTH_COMPONENT); @@ -60,20 +62,30 @@ describe('Test useDerivedValue changing width', () => { if (animate === AnimationLocation.ANIMATED_STYLE) { return { width: - animationType === AnimationType.TIMING ? withTiming(derivedValue.value) : withSpring(derivedValue.value), + animationType === AnimationType.TIMING + ? withTiming(compilerApi ? derivedValue.get() : derivedValue.value) + : withSpring(compilerApi ? derivedValue.get() : derivedValue.value), }; } else { - return { width: derivedValue.value }; + return { width: compilerApi ? derivedValue.get() : derivedValue.value }; } }); useEffect(() => { if (animate === AnimationLocation.USE_EFFECT) { - basicValue.value = animationType === AnimationType.TIMING ? withTiming(finalWidth) : withSpring(finalWidth); + if (compilerApi) { + basicValue.set(animationType === AnimationType.TIMING ? withTiming(finalWidth) : withSpring(finalWidth)); + } else { + basicValue.value = animationType === AnimationType.TIMING ? withTiming(finalWidth) : withSpring(finalWidth); + } } else { - basicValue.value = finalWidth; + if (compilerApi) { + basicValue.set(finalWidth); + } else { + basicValue.value = finalWidth; + } } - }, [basicValue, finalWidth, animate, animationType]); + }, [basicValue, finalWidth, animate, animationType, compilerApi]); return ( @@ -108,6 +120,7 @@ describe('Test useDerivedValue changing width', () => { finalWidth: number, animate: AnimationLocation, animationType: AnimationType, + compilerApi: boolean, ) { await mockAnimationTimer(); const updatesContainerActive = await recordAnimationUpdates(); @@ -118,6 +131,7 @@ describe('Test useDerivedValue changing width', () => { animate={animate} animationType={animationType} deriveFunction={derivedFun} + compilerApi={compilerApi} />, ); const testComponent = getTestComponent(WIDTH_COMPONENT); @@ -129,68 +143,81 @@ describe('Test useDerivedValue changing width', () => { return [updates, naiveUpdates]; } - test.each([ - { - startWidth: 0, - finalWidth: 100, - animate: AnimationLocation.USE_EFFECT, - animationType: AnimationType.TIMING, - }, - { - startWidth: 0, - finalWidth: 100, - animate: AnimationLocation.ANIMATED_STYLE, - animationType: AnimationType.TIMING, - }, - { - startWidth: 0, - finalWidth: 100, - animate: AnimationLocation.ANIMATED_STYLE, - animationType: AnimationType.SPRING, - }, - { - startWidth: 0, - finalWidth: 100, - animate: AnimationLocation.USE_EFFECT, - animationType: AnimationType.SPRING, - }, - { - startWidth: 0, - finalWidth: 100, - animate: AnimationLocation.NONE, - animationType: AnimationType.NONE, - }, - { - startWidth: 100, - finalWidth: 20, - animate: AnimationLocation.USE_EFFECT, - animationType: AnimationType.TIMING, - }, - { - startWidth: 400, - finalWidth: 300, - animate: AnimationLocation.ANIMATED_STYLE, - animationType: AnimationType.TIMING, - }, - { - startWidth: 20, - finalWidth: 100, - animate: AnimationLocation.ANIMATED_STYLE, - animationType: AnimationType.SPRING, - }, - { - startWidth: 55.5, - finalWidth: 155.5, - animate: AnimationLocation.USE_EFFECT, - animationType: AnimationType.SPRING, - }, - { - startWidth: 300, - finalWidth: 33, - animate: AnimationLocation.NONE, - animationType: AnimationType.NONE, - }, - ])( + test.each( + [ + { + startWidth: 0, + finalWidth: 100, + animate: AnimationLocation.USE_EFFECT, + animationType: AnimationType.TIMING, + }, + { + startWidth: 0, + finalWidth: 100, + animate: AnimationLocation.ANIMATED_STYLE, + animationType: AnimationType.TIMING, + }, + { + startWidth: 0, + finalWidth: 100, + animate: AnimationLocation.ANIMATED_STYLE, + animationType: AnimationType.SPRING, + }, + { + startWidth: 0, + finalWidth: 100, + animate: AnimationLocation.USE_EFFECT, + animationType: AnimationType.SPRING, + }, + { + startWidth: 0, + finalWidth: 100, + animate: AnimationLocation.NONE, + animationType: AnimationType.NONE, + }, + { + startWidth: 100, + finalWidth: 20, + animate: AnimationLocation.USE_EFFECT, + animationType: AnimationType.TIMING, + }, + { + startWidth: 400, + finalWidth: 300, + animate: AnimationLocation.ANIMATED_STYLE, + animationType: AnimationType.TIMING, + }, + { + startWidth: 20, + finalWidth: 100, + animate: AnimationLocation.ANIMATED_STYLE, + animationType: AnimationType.SPRING, + }, + { + startWidth: 55.5, + finalWidth: 155.5, + animate: AnimationLocation.USE_EFFECT, + animationType: AnimationType.SPRING, + }, + { + startWidth: 300, + finalWidth: 33, + animate: AnimationLocation.NONE, + animationType: AnimationType.NONE, + }, + ].reduce( + (acc, element) => { + return [...acc, { ...element, compilerApi: false }, { ...element, compilerApi: true }]; + }, + [] as { + startWidth: number; + finalWidth: number; + animate: AnimationLocation; + animationType: AnimationType; + compilerApi: boolean; + }[], + ), + )( 'Animate from ${startWidth} to ${finalWidth}, ${animationType} ${animate}', async ({ startWidth, finalWidth, animate, animationType }) => { const snapshotIdPerType = { @@ -212,6 +239,7 @@ describe('Test useDerivedValue changing width', () => { finalWidth, animate, animationType, + false, ); expect(updates).toMatchSnapshots(snapshot[snapshotName]); diff --git a/apps/common-app/src/examples/RuntimeTests/tests/core/useSharedValue/animationsCompilerApi.test.tsx b/apps/common-app/src/examples/RuntimeTests/tests/core/useSharedValue/animationsCompilerApi.test.tsx new file mode 100644 index 00000000000..59ed30b4673 --- /dev/null +++ b/apps/common-app/src/examples/RuntimeTests/tests/core/useSharedValue/animationsCompilerApi.test.tsx @@ -0,0 +1,153 @@ +import React, { useEffect } from 'react'; +import type { SharedValue } from 'react-native-reanimated'; +import { + useSharedValue, + withClamp, + withDecay, + withDelay, + withRepeat, + withSequence, + withSpring, + withTiming, +} from 'react-native-reanimated'; +import { + describe, + test, + expect, + render, + registerValue, + getRegisteredValue, + wait, +} from '../../../ReJest/RuntimeTestsApi'; +import { ComparisonMode } from '../../../ReJest/types'; +import { ProgressBar } from './components'; + +const SHARED_VALUE_REF = 'SHARED_VALUE_REF'; + +describe(`Test animation assignments on Shared Value using compiler API`, () => { + const WithTiming = ({ progress }: { progress: number }) => { + const sharedValue = useSharedValue(0); + registerValue(SHARED_VALUE_REF, sharedValue as SharedValue); + + useEffect(() => { + sharedValue.set(withTiming(100)); + }); + return ; + }; + + const WithClamp = ({ progress }: { progress: number }) => { + const sharedValue = useSharedValue(0); + registerValue(SHARED_VALUE_REF, sharedValue as SharedValue); + + useEffect(() => { + sharedValue.set(withClamp({ min: 0, max: 100 }, withTiming(200))); + }); + return ; + }; + + const WithDecay = ({ progress }: { progress: number }) => { + const sharedValue = useSharedValue(0); + registerValue(SHARED_VALUE_REF, sharedValue as SharedValue); + + useEffect(() => { + sharedValue.set(withDecay({})); + }); + return ; + }; + + const WithDelay = ({ progress }: { progress: number }) => { + const sharedValue = useSharedValue(0); + registerValue(SHARED_VALUE_REF, sharedValue as SharedValue); + + useEffect(() => { + sharedValue.set(withDelay(100, withTiming(100))); + }); + return ; + }; + + const WithSpring = ({ progress }: { progress: number }) => { + const sharedValue = useSharedValue(0); + registerValue(SHARED_VALUE_REF, sharedValue as SharedValue); + + useEffect(() => { + sharedValue.set(withSpring(100, { duration: 250 })); + }); + return ; + }; + + const WithRepeat = ({ progress }: { progress: number }) => { + const sharedValue = useSharedValue(0); + registerValue(SHARED_VALUE_REF, sharedValue as SharedValue); + + useEffect(() => { + sharedValue.set(withRepeat(withTiming(100), 2, true)); + }); + return ; + }; + + const WithSequence = ({ progress }: { progress: number }) => { + const sharedValue = useSharedValue(0); + registerValue(SHARED_VALUE_REF, sharedValue as SharedValue); + + useEffect(() => { + sharedValue.set(withSequence(withTiming(100), withTiming(200))); + }); + return ; + }; + + test('WithTiming', async () => { + await render(); + await wait(300); + const sharedValue = await getRegisteredValue(SHARED_VALUE_REF); + expect(sharedValue.onJS).toBe(100, ComparisonMode.NUMBER); + expect(sharedValue.onUI).toBe(100, ComparisonMode.NUMBER); + }); + + test('WithClamp', async () => { + await render(); + await wait(300); + const sharedValue = await getRegisteredValue(SHARED_VALUE_REF); + expect(sharedValue.onJS).toBe(100, ComparisonMode.NUMBER); + expect(sharedValue.onUI).toBe(100, ComparisonMode.NUMBER); + }); + + test('WithDecay', async () => { + await render(); + await wait(300); + const sharedValue = await getRegisteredValue(SHARED_VALUE_REF); + expect(sharedValue.onJS).toBe(0, ComparisonMode.NUMBER); + expect(sharedValue.onUI).toBe(0, ComparisonMode.NUMBER); + }); + + test('WithDelay', async () => { + await render(); + await wait(400); + const sharedValue = await getRegisteredValue(SHARED_VALUE_REF); + expect(sharedValue.onJS).toBe(100, ComparisonMode.NUMBER); + expect(sharedValue.onUI).toBe(100, ComparisonMode.NUMBER); + }); + + test('WithSpring', async () => { + await render(); + await wait(300); + const sharedValue = await getRegisteredValue(SHARED_VALUE_REF); + expect(sharedValue.onJS).toBe(100, ComparisonMode.NUMBER); + expect(sharedValue.onUI).toBe(100, ComparisonMode.NUMBER); + }); + + test('WithRepeat', async () => { + await render(); + await wait(600); + const sharedValue = await getRegisteredValue(SHARED_VALUE_REF); + expect(sharedValue.onJS).toBe(0, ComparisonMode.NUMBER); + expect(sharedValue.onUI).toBe(0, ComparisonMode.NUMBER); + }); + + test('WithSequence', async () => { + await render(); + await wait(600); + const sharedValue = await getRegisteredValue(SHARED_VALUE_REF); + expect(sharedValue.onJS).toBe(200, ComparisonMode.NUMBER); + expect(sharedValue.onUI).toBe(200, ComparisonMode.NUMBER); + }); +}); diff --git a/apps/common-app/src/examples/RuntimeTests/tests/plugin/fileWorkletization.ts b/apps/common-app/src/examples/RuntimeTests/tests/plugin/fileWorkletization.ts index a65545a8f98..03c3f00ce0a 100644 --- a/apps/common-app/src/examples/RuntimeTests/tests/plugin/fileWorkletization.ts +++ b/apps/common-app/src/examples/RuntimeTests/tests/plugin/fileWorkletization.ts @@ -23,12 +23,17 @@ export const implicitContextObject = { }, }; -export class ImplicitWorkletClass { - getSix() { +interface IWorkletClass { + getSix(): number; + getSeven(): number; +} + +export class ImplicitWorkletClass implements IWorkletClass { + getSix(): number { return 6; } - getSeven() { + getSeven(): number { return this.getSix() + 1; } } diff --git a/apps/common-app/src/examples/RuntimeTests/tests/plugin/recursion.test.tsx b/apps/common-app/src/examples/RuntimeTests/tests/plugin/recursion.test.tsx index d9ec95bbc8f..9ab0a39408d 100644 --- a/apps/common-app/src/examples/RuntimeTests/tests/plugin/recursion.test.tsx +++ b/apps/common-app/src/examples/RuntimeTests/tests/plugin/recursion.test.tsx @@ -1,6 +1,6 @@ import React, { useEffect } from 'react'; import { View } from 'react-native'; -import { useSharedValue, runOnUI, runOnJS } from 'react-native-reanimated'; +import { useSharedValue, runOnUI } from 'react-native-reanimated'; import { render, wait, describe, getRegisteredValue, registerValue, test, expect } from '../../ReJest/RuntimeTestsApi'; const SHARED_VALUE_REF = 'SHARED_VALUE_REF'; @@ -85,15 +85,13 @@ describe('Test recursion in worklets', () => { const output = useSharedValue(null); registerValue(SHARED_VALUE_REF, output); function recursiveWorklet(a: number) { - if (a === 2) { + if (a === 1) { output.value = a; - } else if (a === 1) { - try { - // TODO: Such case isn't supported at the moment - - // a function can't be a Worklet and a Remote function at the same time. - // Consider supporting it in the future. - runOnJS(recursiveWorklet)(a + 1); - } catch {} + } else if (a === 2) { + // TODO: Such case isn't supported at the moment - + // a function can't be a Worklet and a Remote function at the same time. + // Consider supporting it in the future. + // runOnJS(recursiveWorklet)(a + 1); } else { recursiveWorklet(a + 1); } @@ -108,6 +106,6 @@ describe('Test recursion in worklets', () => { await render(); await wait(100); const sharedValue = await getRegisteredValue(SHARED_VALUE_REF); - expect(sharedValue.onJS).toBe(null); + expect(sharedValue.onJS).toBe(1); }); }); diff --git a/apps/common-app/src/examples/RuntimeTests/tests/plugin/workletClasses.test.tsx b/apps/common-app/src/examples/RuntimeTests/tests/plugin/workletClasses.test.tsx index bd4d0244ecb..838e8e1f9db 100644 --- a/apps/common-app/src/examples/RuntimeTests/tests/plugin/workletClasses.test.tsx +++ b/apps/common-app/src/examples/RuntimeTests/tests/plugin/workletClasses.test.tsx @@ -21,6 +21,28 @@ class WorkletClass { } } +interface ITypeScriptClass { + getOne(): number; + getTwo(): number; + getIncremented(): number; +} + +class TypeScriptClass implements ITypeScriptClass { + __workletClass: boolean = true; + value: number = 0; + getOne(): number { + return 1; + } + + getTwo(): number { + return this.getOne() + 1; + } + + getIncremented(): number { + return ++this.value; + } +} + describe('Test worklet classes', () => { test('class works on React runtime', async () => { const ExampleComponent = () => { @@ -134,5 +156,26 @@ describe('Test worklet classes', () => { expect(sharedValue.onUI).toBe(true); }); + test('TypeScript classes work on Worklet runtime', async () => { + const ExampleComponent = () => { + const output = useSharedValue(null); + registerValue(SHARED_VALUE_REF, output); + + useEffect(() => { + runOnUI(() => { + const clazz = new TypeScriptClass(); + output.value = clazz.getOne(); + })(); + }); + + return ; + }; + await render(); + await wait(100); + const sharedValue = await getRegisteredValue(SHARED_VALUE_REF); + expect(sharedValue.onUI).toBe(1); + }); + // TODO: Add a test that throws when class is sent from React to Worklet runtime. + // TODO: Add a test that throws when trying to use Worklet Class with inheritance. }); diff --git a/apps/fabric-example/ios/Podfile.lock b/apps/fabric-example/ios/Podfile.lock index b0f218a85c5..166dcff5405 100644 --- a/apps/fabric-example/ios/Podfile.lock +++ b/apps/fabric-example/ios/Podfile.lock @@ -1747,7 +1747,7 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga - - RNReanimated (3.16.1): + - RNReanimated (3.16.2): - DoubleConversion - glog - hermes-engine @@ -1767,10 +1767,10 @@ PODS: - ReactCodegen - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - - RNReanimated/reanimated (= 3.16.1) - - RNReanimated/worklets (= 3.16.1) + - RNReanimated/reanimated (= 3.16.2) + - RNReanimated/worklets (= 3.16.2) - Yoga - - RNReanimated/reanimated (3.16.1): + - RNReanimated/reanimated (3.16.2): - DoubleConversion - glog - hermes-engine @@ -1790,9 +1790,9 @@ PODS: - ReactCodegen - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - - RNReanimated/reanimated/apple (= 3.16.1) + - RNReanimated/reanimated/apple (= 3.16.2) - Yoga - - RNReanimated/reanimated/apple (3.16.1): + - RNReanimated/reanimated/apple (3.16.2): - DoubleConversion - glog - hermes-engine @@ -1813,7 +1813,7 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga - - RNReanimated/worklets (3.16.1): + - RNReanimated/worklets (3.16.2): - DoubleConversion - glog - hermes-engine @@ -2229,11 +2229,11 @@ SPEC CHECKSUMS: RNCPicker: d051e0647af8b2ad01a3d39a6b5dd9b7c0ccc166 RNFlashList: 6f169ad83e52579b7754cbbcec1b004c27d82c93 RNGestureHandler: c374c750a0a9bacd95f5c740d146ab9428549d6b - RNReanimated: 587f378599bc92a40a0959ecd7b44d66ca01b3f1 + RNReanimated: 897b43389156dfb9a547882d5452df5f8b208fc2 RNScreens: de6e57426ba0e6cbc3fb5b4f496e7f08cb2773c2 RNSVG: 08750404f92a36162a92522cc77dee437be1d257 SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748 - Yoga: 8833bd4378ffd79f1dea711d6dc7231c09e63590 + Yoga: 2a74e67570a7902969ff44f35dd41f47a9693be8 PODFILE CHECKSUM: 3eb88d49c8fe32af0ac2c85501e29d29171f1070 diff --git a/apps/macos-example/macos/Podfile.lock b/apps/macos-example/macos/Podfile.lock index 2ed744a678e..10961d2b521 100644 --- a/apps/macos-example/macos/Podfile.lock +++ b/apps/macos-example/macos/Podfile.lock @@ -1023,25 +1023,25 @@ PODS: - glog - RCT-Folly (= 2022.05.16.00) - React-Core - - RNReanimated (3.16.1): + - RNReanimated (3.16.2): - glog - RCT-Folly (= 2022.05.16.00) - React-Core - ReactCommon/turbomodule/core - - RNReanimated/reanimated (= 3.16.1) - - RNReanimated/worklets (= 3.16.1) - - RNReanimated/reanimated (3.16.1): + - RNReanimated/reanimated (= 3.16.2) + - RNReanimated/worklets (= 3.16.2) + - RNReanimated/reanimated (3.16.2): - glog - RCT-Folly (= 2022.05.16.00) - React-Core - ReactCommon/turbomodule/core - - RNReanimated/reanimated/apple (= 3.16.1) - - RNReanimated/reanimated/apple (3.16.1): + - RNReanimated/reanimated/apple (= 3.16.2) + - RNReanimated/reanimated/apple (3.16.2): - glog - RCT-Folly (= 2022.05.16.00) - React-Core - ReactCommon/turbomodule/core - - RNReanimated/worklets (3.16.1): + - RNReanimated/worklets (3.16.2): - glog - RCT-Folly (= 2022.05.16.00) - React-Core @@ -1270,10 +1270,10 @@ SPEC CHECKSUMS: RNCAsyncStorage: ec53e44dc3e75b44aa2a9f37618a49c3bc080a7a RNCPicker: 0173dedc74776227ec6dcc61bb85cd9f07bbb2ac RNGestureHandler: bb81850add626ddd265294323310fec6e861c96b - RNReanimated: 93361622ed1106b6edbe14e960c3e9767ba869ce + RNReanimated: c2481afa76442a90614d08e544c3902b4bddd22d RNSVG: 01eb8d8a0e2289ec3ecc9626ce920e00d2174992 SocketRocket: f6c6249082c011e6de2de60ed641ef8bbe0cfac9 - Yoga: 329461de6a23b9e0c108d197fd0f6e87c8c8ecf2 + Yoga: 0639c9c8a20ae8043b0b64e2ef6d7a2cd5806aac PODFILE CHECKSUM: ddae34ca2842288eb8f70e6df3c2d638c2f56027 diff --git a/apps/paper-example/ios/Podfile.lock b/apps/paper-example/ios/Podfile.lock index 730333b6ac9..5ce9cd44736 100644 --- a/apps/paper-example/ios/Podfile.lock +++ b/apps/paper-example/ios/Podfile.lock @@ -1601,7 +1601,7 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga - - RNReanimated (3.16.1): + - RNReanimated (3.16.2): - DoubleConversion - glog - hermes-engine @@ -1621,10 +1621,10 @@ PODS: - ReactCodegen - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - - RNReanimated/reanimated (= 3.16.1) - - RNReanimated/worklets (= 3.16.1) + - RNReanimated/reanimated (= 3.16.2) + - RNReanimated/worklets (= 3.16.2) - Yoga - - RNReanimated/reanimated (3.16.1): + - RNReanimated/reanimated (3.16.2): - DoubleConversion - glog - hermes-engine @@ -1644,9 +1644,9 @@ PODS: - ReactCodegen - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - - RNReanimated/reanimated/apple (= 3.16.1) + - RNReanimated/reanimated/apple (= 3.16.2) - Yoga - - RNReanimated/reanimated/apple (3.16.1): + - RNReanimated/reanimated/apple (3.16.2): - DoubleConversion - glog - hermes-engine @@ -1667,7 +1667,7 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga - - RNReanimated/worklets (3.16.1): + - RNReanimated/worklets (3.16.2): - DoubleConversion - glog - hermes-engine @@ -2019,11 +2019,11 @@ SPEC CHECKSUMS: RNCPicker: 0173dedc74776227ec6dcc61bb85cd9f07bbb2ac RNFlashList: 115dd44377580761bff386a0caebf165424cf16f RNGestureHandler: 6dfe7692a191ee224748964127114edf057a1475 - RNReanimated: e04a7c74b5c79fbc23cee1b81bd9941e9ea3c216 + RNReanimated: 607d45b7bfad5e594fc5c389fbae028952fc28d8 RNScreens: 19719a9c326e925498ac3b2d35c4e50fe87afc06 RNSVG: 01eb8d8a0e2289ec3ecc9626ce920e00d2174992 SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748 - Yoga: 8833bd4378ffd79f1dea711d6dc7231c09e63590 + Yoga: 2a74e67570a7902969ff44f35dd41f47a9693be8 PODFILE CHECKSUM: 44956aee8c836a85949aa1fa8dde2c10e661633e diff --git a/apps/tvos-example/ios/Podfile.lock b/apps/tvos-example/ios/Podfile.lock index 9b796913197..ee9c5f6073e 100644 --- a/apps/tvos-example/ios/Podfile.lock +++ b/apps/tvos-example/ios/Podfile.lock @@ -1031,25 +1031,25 @@ PODS: - React-jsi (= 0.73.4-0) - React-logger (= 0.73.4-0) - React-perflogger (= 0.73.4-0) - - RNReanimated (3.16.1): + - RNReanimated (3.16.2): - glog - RCT-Folly (= 2022.05.16.00) - React-Core - ReactCommon/turbomodule/core - - RNReanimated/reanimated (= 3.16.1) - - RNReanimated/worklets (= 3.16.1) - - RNReanimated/reanimated (3.16.1): + - RNReanimated/reanimated (= 3.16.2) + - RNReanimated/worklets (= 3.16.2) + - RNReanimated/reanimated (3.16.2): - glog - RCT-Folly (= 2022.05.16.00) - React-Core - ReactCommon/turbomodule/core - - RNReanimated/reanimated/apple (= 3.16.1) - - RNReanimated/reanimated/apple (3.16.1): + - RNReanimated/reanimated/apple (= 3.16.2) + - RNReanimated/reanimated/apple (3.16.2): - glog - RCT-Folly (= 2022.05.16.00) - React-Core - ReactCommon/turbomodule/core - - RNReanimated/worklets (3.16.1): + - RNReanimated/worklets (3.16.2): - glog - RCT-Folly (= 2022.05.16.00) - React-Core @@ -1267,9 +1267,9 @@ SPEC CHECKSUMS: React-runtimescheduler: 20b2202e3396589a71069d12ae9f328949c7c7b8 React-utils: 0307d396f233e47a167b5aaf045b0e4e1dc19d74 ReactCommon: 17891ca337bfa5a7263649b09f27a8c664537bf2 - RNReanimated: b2793c6d7fe45e86b4439e89a34d909a6b5abbfd + RNReanimated: be3cf829e5d326cc85c4f5fcbab7c7ce85cbf775 SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 - Yoga: e7f2a2256464d4ef7b3825d216bd22aac3b449c1 + Yoga: ab50eb8f7fcf1b36aad1801b5687b66b2c0aa000 PODFILE CHECKSUM: c2efe42da2b9ce73832f8f03df86727f3f712fff diff --git a/packages/docs-reanimated/docs/reanimated-babel-plugin/about.md b/packages/docs-reanimated/docs/reanimated-babel-plugin/about.md index cb1b9a5b1f0..7fbc63e36b6 100644 --- a/packages/docs-reanimated/docs/reanimated-babel-plugin/about.md +++ b/packages/docs-reanimated/docs/reanimated-babel-plugin/about.md @@ -146,6 +146,7 @@ runOnUI(() => new Clazz().foo())(); // Logs 'Hello from WorkletClass' **Pitfalls:** +- Worklet Classes don't support inheritance. - Worklet Classes don't support static methods and properties. - Class instances cannot be shared between JS and UI threads. diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.cpp b/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.cpp index 475ec7a7788..832fb06df14 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.cpp +++ b/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.cpp @@ -32,6 +32,8 @@ #ifdef RCT_NEW_ARCH_ENABLED #include +#include +#include #endif // RCT_NEW_ARCH_ENABLED // Standard `__cplusplus` macro reference: diff --git a/packages/react-native-reanimated/package.json b/packages/react-native-reanimated/package.json index 6ad1db3c417..5e13e847c7e 100644 --- a/packages/react-native-reanimated/package.json +++ b/packages/react-native-reanimated/package.json @@ -1,6 +1,6 @@ { "name": "react-native-reanimated", - "version": "3.16.1", + "version": "3.16.2", "description": "More powerful alternative to Animated library for React Native.", "scripts": { "test": "jest", diff --git a/packages/react-native-reanimated/plugin/index.js b/packages/react-native-reanimated/plugin/index.js index c9f66b09455..7603e29c3b6 100644 --- a/packages/react-native-reanimated/plugin/index.js +++ b/packages/react-native-reanimated/plugin/index.js @@ -1,3 +1,3 @@ -"use strict";var Ye=Object.create;var be=Object.defineProperty;var Ke=Object.getOwnPropertyDescriptor;var Qe=Object.getOwnPropertyNames;var et=Object.getPrototypeOf,tt=Object.prototype.hasOwnProperty;var p=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var rt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Qe(t))!tt.call(e,i)&&i!==r&&be(e,i,{get:()=>t[i],enumerable:!(n=Ke(t,i))||n.enumerable});return e};var M=(e,t,r)=>(r=e!=null?Ye(et(e)):{},rt(t||!e||!e.__esModule?be(r,"default",{value:e,enumerable:!0}):r,e));var E=p(m=>{"use strict";Object.defineProperty(m,"__esModule",{value:!0});m.workletClassFactorySuffix=m.isWorkletizableObjectNode=m.isWorkletizableObjectPath=m.isWorkletizableFunctionNode=m.isWorkletizableFunctionPath=m.WorkletizableObject=m.WorkletizableFunction=void 0;var U=require("@babel/types");m.WorkletizableFunction="FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ObjectMethod";m.WorkletizableObject="ObjectExpression";function nt(e){return e.isFunctionDeclaration()||e.isFunctionExpression()||e.isArrowFunctionExpression()||e.isObjectMethod()}m.isWorkletizableFunctionPath=nt;function it(e){return(0,U.isFunctionDeclaration)(e)||(0,U.isFunctionExpression)(e)||(0,U.isArrowFunctionExpression)(e)||(0,U.isObjectMethod)(e)}m.isWorkletizableFunctionNode=it;function ot(e){return e.isObjectExpression()}m.isWorkletizableObjectPath=ot;function st(e){return(0,U.isObjectExpression)(e)}m.isWorkletizableObjectNode=st;m.workletClassFactorySuffix="__classFactory"});var Z=p(x=>{"use strict";Object.defineProperty(x,"__esModule",{value:!0});x.initializeGlobals=x.globals=x.defaultGlobals=void 0;var at=["globalThis","Infinity","NaN","undefined","eval","isFinite","isNaN","parseFloat","parseInt","decodeURI","decodeURIComponent","encodeURI","encodeURIComponent","escape","unescape","Object","Function","Boolean","Symbol","Error","AggregateError","EvalError","RangeError","ReferenceError","SyntaxError","TypeError","URIError","InternalError","Number","BigInt","Math","Date","String","RegExp","Array","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","BigInt64Array","BigUint64Array","Float32Array","Float64Array","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Atomics","JSON","WeakRef","FinalizationRegistry","Iterator","AsyncIterator","Promise","GeneratorFunction","AsyncGeneratorFunction","Generator","AsyncGenerator","AsyncFunction","Reflect","Proxy","Intl","null","this","global","window","globalThis","console","performance","queueMicrotask","requestAnimationFrame","setImmediate","arguments","HermesInternal","_WORKLET","ReanimatedError","__reanimatedLoggerConfig"],lt=["_IS_FABRIC","_log","_toString","_scheduleHostFunctionOnJS","_scheduleRemoteFunctionOnJS","_scheduleOnRuntime","_makeShareableClone","_updatePropsPaper","_updatePropsFabric","_removeFromPropsRegistry","_measurePaper","_measureFabric","_scrollToPaper","_dispatchCommandPaper","_dispatchCommandFabric","_setGestureState","_notifyAboutProgress","_notifyAboutEnd","_runOnUIQueue","_getAnimationTimestamp"];x.defaultGlobals=new Set(at.concat(lt));function ct(){x.globals=new Set(x.defaultGlobals)}x.initializeGlobals=ct});var D=p(F=>{"use strict";Object.defineProperty(F,"__esModule",{value:!0});F.replaceWithFactoryCall=F.addCustomGlobals=F.isRelease=void 0;var B=require("@babel/types"),ut=Z();function dt(){var e,t;let r=/(prod|release|stag[ei])/i;return!!(!((e=process.env.BABEL_ENV)===null||e===void 0)&&e.match(r)||!((t=process.env.NODE_ENV)===null||t===void 0)&&t.match(r))}F.isRelease=dt;function ft(){this.opts&&Array.isArray(this.opts.globals)&&this.opts.globals.forEach(e=>{ut.globals.add(e)})}F.addCustomGlobals=ft;function pt(e,t,r){if(!t||!bt(e))e.replaceWith(r);else{let n=(0,B.variableDeclaration)("const",[(0,B.variableDeclarator)((0,B.identifier)(t),r)]);e.replaceWith(n)}}F.replaceWithFactoryCall=pt;function bt(e){return(0,B.isScopable)(e.parent)||(0,B.isExportNamedDeclaration)(e.parent)}});var ye=p(O=>{"use strict";var mt=O&&O.__createBinding||(Object.create?function(e,t,r,n){n===void 0&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){n===void 0&&(n=r),e[n]=t[r]}),yt=O&&O.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),me=O&&O.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)r!=="default"&&Object.prototype.hasOwnProperty.call(e,r)&&mt(t,e,r);return yt(t,e),t},kt=O&&O.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(O,"__esModule",{value:!0});O.buildWorkletString=void 0;var se=require("@babel/core"),gt=kt(require("@babel/generator")),c=require("@babel/types"),G=require("assert"),_t=me(require("convert-source-map")),Ot=me(require("fs")),vt=E(),ht=D(),Et="mock source map";function It(e,t,r,n,i){St(e,n);let s=e.program.body.find(g=>(0,c.isFunctionDeclaration)(g))||e.program.body.find(g=>(0,c.isExpressionStatement)(g))||void 0;(0,G.strict)(s,"[Reanimated] `draftExpression` is undefined.");let l=(0,c.isFunctionDeclaration)(s)?s:s.expression;(0,G.strict)("params"in l,"'params' property is undefined in 'expression'"),(0,G.strict)((0,c.isBlockStatement)(l.body),"[Reanimated] `expression.body` is not a `BlockStatement`");let u=new Set;(0,se.traverse)(e,{NewExpression(g){if(!(0,c.isIdentifier)(g.node.callee))return;let W=g.node.callee.name;if(!r.some(H=>H.name===W)||u.has(W))return;let A=r.findIndex(H=>H.name===W);r.splice(A,1);let ne=W+vt.workletClassFactorySuffix;r.push((0,c.identifier)(ne)),(0,c.assertBlockStatement)(l.body),l.body.body.unshift((0,c.variableDeclaration)("const",[(0,c.variableDeclarator)((0,c.identifier)(W),(0,c.callExpression)((0,c.identifier)(ne),[]))])),u.add(W)}});let f=(0,c.functionExpression)((0,c.identifier)(n),l.params,l.body,l.generator,l.async),k=(0,gt.default)(f).code;(0,G.strict)(i,"[Reanimated] `inputMap` is undefined.");let _=!((0,ht.isRelease)()||t.opts.disableSourceMaps);if(_){i.sourcesContent=[];for(let g of i.sources)i.sourcesContent.push(Ot.readFileSync(g).toString("utf-8"))}let R=(0,se.transformSync)(k,{plugins:[Ct(r)],compact:!0,sourceMaps:_,inputSourceMap:i,ast:!1,babelrc:!1,configFile:!1,comments:!1});(0,G.strict)(R,"[Reanimated] `transformed` is null.");let j;return _&&(Wt()?j=Et:(j=_t.fromObject(R.map).toObject(),delete j.sourcesContent)),[R.code,JSON.stringify(j)]}O.buildWorkletString=It;function St(e,t){(0,se.traverse)(e,{FunctionExpression(r){if(!r.node.id){r.stop();return}let n=r.node.id.name;r.scope.rename(n,t)}})}function Wt(){return process.env.REANIMATED_JEST_SHOULD_MOCK_SOURCE_MAP==="1"}function xt(e,t,r){t.length===0||!(0,c.isProgram)(e.parent)||(0,c.isExpression)(e.node.body)||e.node.body.body.unshift(r)}function Ft(e){var t;(0,c.isProgram)(e.parent)&&!(0,c.isArrowFunctionExpression)(e.node)&&!(0,c.isObjectMethod)(e.node)&&e.node.id&&e.scope.parent&&((t=e.scope.parent.bindings[e.node.id.name])===null||t===void 0?void 0:t.references)>0&&e.node.body.body.unshift((0,c.variableDeclaration)("const",[(0,c.variableDeclarator)((0,c.identifier)(e.node.id.name),(0,c.memberExpression)((0,c.thisExpression)(),(0,c.identifier)("_recur")))]))}function Ct(e){let t=(0,c.variableDeclaration)("const",[(0,c.variableDeclarator)((0,c.objectPattern)(e.map(r=>(0,c.objectProperty)((0,c.identifier)(r.name),(0,c.identifier)(r.name),!1,!0))),(0,c.memberExpression)((0,c.thisExpression)(),(0,c.identifier)("__closure")))]);return{visitor:{"FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ObjectMethod":r=>{xt(r,e,t),Ft(r)}}}}});var Oe=p(P=>{"use strict";var wt=P&&P.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(P,"__esModule",{value:!0});P.makeWorkletFactory=void 0;var ge=require("@babel/core"),jt=wt(require("@babel/generator")),o=require("@babel/types"),C=require("assert"),_e=require("path"),Dt=Z(),ke=E(),ae=D(),Rt=ye(),At=require("../package.json").version,Mt="x.y.z",Pt=[require.resolve("@babel/preset-typescript")],qt=[require.resolve("@babel/plugin-transform-shorthand-properties"),require.resolve("@babel/plugin-transform-arrow-functions"),require.resolve("@babel/plugin-transform-optional-chaining"),require.resolve("@babel/plugin-transform-nullish-coalescing-operator"),[require.resolve("@babel/plugin-transform-template-literals"),{loose:!0}]];function Lt(e,t){zt(e),(0,C.strict)(t.file.opts.filename,"[Reanimated] `state.file.opts.filename` is undefined.");let r=(0,jt.default)(e.node,{sourceMaps:!0,sourceFileName:t.file.opts.filename});r.code="("+(e.isObjectMethod()?"function ":"")+r.code+` -)`;let n=(0,ge.transformSync)(r.code,{filename:t.file.opts.filename,presets:Pt,plugins:qt,ast:!0,babelrc:!1,configFile:!1,inputSourceMap:r.map});(0,C.strict)(n,"[Reanimated] `transformed` is undefined."),(0,C.strict)(n.ast,"[Reanimated] `transformed.ast` is undefined.");let i=Bt(n.ast,e),s=(0,o.cloneNode)(e.node),l=(0,o.isBlockStatement)(s.body)?(0,o.functionExpression)(null,s.params,s.body,s.generator,s.async):s,{workletName:u,reactName:f}=Ut(e,t),[k,_]=(0,Rt.buildWorkletString)(n.ast,t,i,u,n.map);(0,C.strict)(k,"[Reanimated] `funString` is undefined.");let R=Tt(k),j=1;i.length>0&&(j-=i.length+2);let g=e.parentPath.isProgram()?e:e.findParent(y=>{var ie,oe;return(oe=(ie=y.parentPath)===null||ie===void 0?void 0:ie.isProgram())!==null&&oe!==void 0?oe:!1});(0,C.strict)(g,"[Reanimated] `pathForStringDefinitions` is null."),(0,C.strict)(g.parentPath,"[Reanimated] `pathForStringDefinitions.parentPath` is null.");let W=g.parentPath.scope.generateUidIdentifier(`worklet_${R}_init_data`),A=(0,o.objectExpression)([(0,o.objectProperty)((0,o.identifier)("code"),(0,o.stringLiteral)(k))]);if(!(0,ae.isRelease)()){let y=t.file.opts.filename;t.opts.relativeSourceLocation&&(y=(0,_e.relative)(t.cwd,y),_=_==null?void 0:_.replace(t.file.opts.filename,y)),A.properties.push((0,o.objectProperty)((0,o.identifier)("location"),(0,o.stringLiteral)(y)))}_&&A.properties.push((0,o.objectProperty)((0,o.identifier)("sourceMap"),(0,o.stringLiteral)(_))),!(0,ae.isRelease)()&&A.properties.push((0,o.objectProperty)((0,o.identifier)("version"),(0,o.stringLiteral)(Nt()?Mt:At)));let pe=!t.opts.omitNativeOnlyData;pe&&g.insertBefore((0,o.variableDeclaration)("const",[(0,o.variableDeclarator)(W,A)])),(0,C.strict)(!(0,o.isFunctionDeclaration)(l),"[Reanimated] `funExpression` is a `FunctionDeclaration`."),(0,C.strict)(!(0,o.isObjectMethod)(l),"[Reanimated] `funExpression` is an `ObjectMethod`.");let T=[(0,o.variableDeclaration)("const",[(0,o.variableDeclarator)((0,o.identifier)(f),l)]),(0,o.expressionStatement)((0,o.assignmentExpression)("=",(0,o.memberExpression)((0,o.identifier)(f),(0,o.identifier)("__closure"),!1),(0,o.objectExpression)(i.map(y=>y.name.endsWith(ke.workletClassFactorySuffix)?(0,o.objectProperty)((0,o.identifier)(y.name),(0,o.memberExpression)((0,o.identifier)(y.name.slice(0,y.name.length-ke.workletClassFactorySuffix.length)),(0,o.identifier)(y.name))):(0,o.objectProperty)((0,o.identifier)(y.name),y,!1,!0))))),(0,o.expressionStatement)((0,o.assignmentExpression)("=",(0,o.memberExpression)((0,o.identifier)(f),(0,o.identifier)("__workletHash"),!1),(0,o.numericLiteral)(R)))];return pe&&T.push((0,o.expressionStatement)((0,o.assignmentExpression)("=",(0,o.memberExpression)((0,o.identifier)(f),(0,o.identifier)("__initData"),!1),W))),(0,ae.isRelease)()||(T.unshift((0,o.variableDeclaration)("const",[(0,o.variableDeclarator)((0,o.identifier)("_e"),(0,o.arrayExpression)([(0,o.newExpression)((0,o.memberExpression)((0,o.identifier)("global"),(0,o.identifier)("Error")),[]),(0,o.numericLiteral)(j),(0,o.numericLiteral)(-27)]))])),T.push((0,o.expressionStatement)((0,o.assignmentExpression)("=",(0,o.memberExpression)((0,o.identifier)(f),(0,o.identifier)("__stackDetails"),!1),(0,o.identifier)("_e"))))),T.push((0,o.returnStatement)((0,o.identifier)(f))),(0,o.functionExpression)(void 0,[],(0,o.blockStatement)(T))}P.makeWorkletFactory=Lt;function zt(e){e.traverse({DirectiveLiteral(t){t.node.value==="worklet"&&t.getFunctionParent()===e&&t.parentPath.remove()}})}function Nt(){return process.env.REANIMATED_JEST_SHOULD_MOCK_VERSION==="1"}function Tt(e){let t=e.length,r=5381,n=52711;for(;t--;){let i=e.charCodeAt(t);r=r*33^i,n=n*33^i}return(r>>>0)*4096+(n>>>0)}function Ut(e,t){let r="unknownFile";if(t.file.opts.filename){let l=t.file.opts.filename;r=(0,_e.basename)(l);let u=l.split("/"),f=u.indexOf("node_modules");f!==-1&&(r=`${u[f+1]}_${r}`)}let n=`${r}${t.workletNumber++}`,i="";(0,o.isObjectMethod)(e.node)&&(0,o.isIdentifier)(e.node.key)?i=e.node.key.name:((0,o.isFunctionDeclaration)(e.node)||(0,o.isFunctionExpression)(e.node))&&(0,o.isIdentifier)(e.node.id)&&(i=e.node.id.name);let s=i?(0,o.toIdentifier)(`${i}_${n}`):(0,o.toIdentifier)(n);return i=i||(0,o.toIdentifier)(n),{workletName:s,reactName:i}}function Bt(e,t){let r=new Map,n=new Map;return(0,ge.traverse)(e,{Identifier(i){if(!i.isReferencedIdentifier())return;let s=i.node.name;if(Dt.globals.has(s)||"id"in t.node&&t.node.id&&t.node.id.name===s)return;let l=i.parent;if((0,o.isMemberExpression)(l)&&l.property===i.node&&!l.computed||(0,o.isObjectProperty)(l)&&(0,o.isObjectExpression)(i.parentPath.parent)&&i.node!==l.value)return;let u=i.scope;for(;u!=null;){if(u.bindings[s]!=null)return;u=u.parent}r.set(s,i.node),n.set(s,!1)}}),t.traverse({Identifier(i){if(!i.isReferencedIdentifier())return;let s=r.get(i.node.name);!s||n.get(i.node.name)||(s.loc=i.node.loc,n.set(i.node.name,!0))}}),Array.from(r.values())}});var ve=p(V=>{"use strict";Object.defineProperty(V,"__esModule",{value:!0});V.makeWorkletFactoryCall=void 0;var Gt=require("@babel/types"),Ht=Oe();function Zt(e,t){let r=(0,Ht.makeWorkletFactory)(e,t),n=(0,Gt.callExpression)(r,[]);return Vt(e,n),n}V.makeWorkletFactoryCall=Zt;function Vt(e,t){let r=e.node.loc;r&&(t.callee.loc={filename:r.filename,identifierName:r.identifierName,start:r.start,end:r.start})}});var J=p(w=>{"use strict";Object.defineProperty(w,"__esModule",{value:!0});w.substituteObjectMethodWithObjectProperty=w.processWorklet=w.processIfWithWorkletDirective=void 0;var le=require("@babel/types"),Jt=E(),Xt=D(),$t=ve();function he(e,t){return!(0,le.isBlockStatement)(e.node.body)||!Yt(e.node.body.directives)?!1:(Ee(e,t),!0)}w.processIfWithWorkletDirective=he;function Ee(e,t){t.opts.processNestedWorklets&&e.traverse({[Jt.WorkletizableFunction](n,i){he(n,i)}},t);let r=(0,$t.makeWorkletFactoryCall)(e,t);Kt(e,r)}w.processWorklet=Ee;function Yt(e){return e.some(t=>(0,le.isDirectiveLiteral)(t.value)&&t.value.value==="worklet")}function Kt(e,t){var r;if(e.isObjectMethod())Ie(e,t);else{let n="id"in e.node?(r=e.node.id)===null||r===void 0?void 0:r.name:void 0;(0,Xt.replaceWithFactoryCall)(e,n,t)}}function Ie(e,t){let r=(0,le.objectProperty)(e.node.key,t);e.replaceWith(r)}w.substituteObjectMethodWithObjectProperty=Ie});var We=p(X=>{"use strict";Object.defineProperty(X,"__esModule",{value:!0});X.isGestureHandlerEventCallback=void 0;var I=require("@babel/types"),Qt=new Set(["Tap","Pan","Pinch","Rotation","Fling","LongPress","ForceTouch","Native","Manual","Race","Simultaneous","Exclusive","Hover"]),er=new Set(["onBegin","onStart","onEnd","onFinalize","onUpdate","onChange","onTouchesDown","onTouchesMove","onTouchesUp","onTouchesCancelled"]);function tr(e){return(0,I.isCallExpression)(e.parent)&&(0,I.isExpression)(e.parent.callee)&&rr(e.parent.callee)}X.isGestureHandlerEventCallback=tr;function rr(e){return(0,I.isMemberExpression)(e)&&(0,I.isIdentifier)(e.property)&&er.has(e.property.name)&&Se(e.object)}function Se(e){return!!(nr(e)||(0,I.isCallExpression)(e)&&(0,I.isMemberExpression)(e.callee)&&Se(e.callee.object))}function nr(e){return(0,I.isCallExpression)(e)&&(0,I.isMemberExpression)(e.callee)&&(0,I.isIdentifier)(e.callee.object)&&e.callee.object.name==="Gesture"&&(0,I.isIdentifier)(e.callee.property)&&Qt.has(e.callee.property.name)}});var Ce=p($=>{"use strict";Object.defineProperty($,"__esModule",{value:!0});$.isLayoutAnimationCallback=void 0;var S=require("@babel/types"),ir=new Set(["BounceIn","BounceInDown","BounceInLeft","BounceInRight","BounceInUp","BounceOut","BounceOutDown","BounceOutLeft","BounceOutRight","BounceOutUp","FadeIn","FadeInDown","FadeInLeft","FadeInRight","FadeInUp","FadeOut","FadeOutDown","FadeOutLeft","FadeOutRight","FadeOutUp","FlipInEasyX","FlipInEasyY","FlipInXDown","FlipInXUp","FlipInYLeft","FlipInYRight","FlipOutEasyX","FlipOutEasyY","FlipOutXDown","FlipOutXUp","FlipOutYLeft","FlipOutYRight","LightSpeedInLeft","LightSpeedInRight","LightSpeedOutLeft","LightSpeedOutRight","PinwheelIn","PinwheelOut","RollInLeft","RollInRight","RollOutLeft","RollOutRight","RotateInDownLeft","RotateInDownRight","RotateInUpLeft","RotateInUpRight","RotateOutDownLeft","RotateOutDownRight","RotateOutUpLeft","RotateOutUpRight","SlideInDown","SlideInLeft","SlideInRight","SlideInUp","SlideOutDown","SlideOutLeft","SlideOutRight","SlideOutUp","StretchInX","StretchInY","StretchOutX","StretchOutY","ZoomIn","ZoomInDown","ZoomInEasyDown","ZoomInEasyUp","ZoomInLeft","ZoomInRight","ZoomInRotate","ZoomInUp","ZoomOut","ZoomOutDown","ZoomOutEasyDown","ZoomOutEasyUp","ZoomOutLeft","ZoomOutRight","ZoomOutRotate","ZoomOutUp"]),or=new Set(["Layout","LinearTransition","SequencedTransition","FadingTransition","JumpingTransition","CurvedTransition","EntryExitTransition"]),xe=new Set([...ir,...or]),sr=new Set(["build","duration","delay","getDuration","randomDelay","getDelay","getDelayFunction"]),ar=new Set(["easing","rotate","springify","damping","mass","stiffness","overshootClamping","restDisplacementThreshold","restSpeedThreshold","withInitialValues","getAnimationAndConfig"]),lr=new Set(["easingX","easingY","easingWidth","easingHeight","entering","exiting","reverse"]),cr=new Set([...sr,...ar,...lr]),ur=new Set(["withCallback"]);function dr(e){return(0,S.isCallExpression)(e.parent)&&(0,S.isExpression)(e.parent.callee)&&fr(e.parent.callee)}$.isLayoutAnimationCallback=dr;function fr(e){return(0,S.isMemberExpression)(e)&&(0,S.isIdentifier)(e.property)&&ur.has(e.property.name)&&Fe(e.object)}function Fe(e){return(0,S.isIdentifier)(e)&&xe.has(e.name)?!0:!!((0,S.isNewExpression)(e)&&(0,S.isIdentifier)(e.callee)&&xe.has(e.callee.name)||(0,S.isCallExpression)(e)&&(0,S.isMemberExpression)(e.callee)&&(0,S.isIdentifier)(e.callee.property)&&cr.has(e.callee.property.name)&&Fe(e.callee.object))}});var we=p(Y=>{"use strict";Object.defineProperty(Y,"__esModule",{value:!0});Y.findReferencedWorklet=void 0;var q=E();function pr(e,t,r){let n=e.node.name,s=e.scope.getBinding(n);return s?t&&s.path.isFunctionDeclaration()?s.path:s.constant?br(s,t,r):mr(s,t,r):void 0}Y.findReferencedWorklet=pr;function br(e,t,r){let n=e.path;if(!n.isVariableDeclarator())return;let i=n.get("init");if(t&&(0,q.isWorkletizableFunctionPath)(i)||r&&(0,q.isWorkletizableObjectPath)(i))return i}function mr(e,t,r){let n=e.constantViolations.reverse().find(s=>s.isAssignmentExpression()&&(t&&(0,q.isWorkletizableFunctionPath)(s.get("right"))||r&&(0,q.isWorkletizableObjectPath)(s.get("right"))));if(!n||!n.isAssignmentExpression())return;let i=n.get("right");if(t&&(0,q.isWorkletizableFunctionPath)(i)||r&&(0,q.isWorkletizableObjectPath)(i))return i}});var De=p(K=>{"use strict";Object.defineProperty(K,"__esModule",{value:!0});K.processWorkletizableObject=void 0;var yr=E(),je=J();function kr(e,t){let r=e.get("properties");for(let n of r)if(n.isObjectMethod())(0,je.processWorklet)(n,t);else if(n.isObjectProperty()){let i=n.get("value");(0,yr.isWorkletizableFunctionPath)(i)&&(0,je.processWorklet)(i,t)}else throw new Error(`[Reanimated] '${n.type}' as to-be workletized argument is not supported for object hooks.`)}K.processWorkletizableObject=kr});var Pe=p(L=>{"use strict";Object.defineProperty(L,"__esModule",{value:!0});L.processCalleesAutoworkletizableCallbacks=L.processIfAutoworkletizableCallback=void 0;var gr=require("@babel/types"),Q=E(),Me=J(),_r=We(),Or=Ce(),vr=we(),hr=De(),Re=new Set(["useAnimatedGestureHandler","useAnimatedScrollHandler"]),Ae=new Set(["useFrameCallback","useAnimatedStyle","useAnimatedProps","createAnimatedPropAdapter","useDerivedValue","useAnimatedScrollHandler","useAnimatedReaction","useWorkletCallback","withTiming","withSpring","withDecay","withRepeat","runOnUI","executeOnUIRuntimeSync"]),Er=new Map([["useAnimatedGestureHandler",[0]],["useFrameCallback",[0]],["useAnimatedStyle",[0]],["useAnimatedProps",[0]],["createAnimatedPropAdapter",[0]],["useDerivedValue",[0]],["useAnimatedScrollHandler",[0]],["useAnimatedReaction",[0,1]],["useWorkletCallback",[0]],["withTiming",[2]],["withSpring",[2]],["withDecay",[1]],["withRepeat",[3]],["runOnUI",[0]],["executeOnUIRuntimeSync",[0]]]);function Ir(e,t){return(0,_r.isGestureHandlerEventCallback)(e)||(0,Or.isLayoutAnimationCallback)(e)?((0,Me.processWorklet)(e,t),!0):!1}L.processIfAutoworkletizableCallback=Ir;function Sr(e,t){let r=(0,gr.isSequenceExpression)(e.node.callee)?e.node.callee.expressions[e.node.callee.expressions.length-1]:e.node.callee,n="name"in r?r.name:"property"in r&&"name"in r.property?r.property.name:void 0;if(n!==void 0&&(Ae.has(n)||Re.has(n))){let i=Ae.has(n),s=Re.has(n),l=Er.get(n),u=e.get("arguments").filter((f,k)=>l.includes(k));Wr(u,t,i,s)}}L.processCalleesAutoworkletizableCallbacks=Sr;function Wr(e,t,r,n){e.forEach(i=>{let s=xr(i,r,n);s&&((0,Q.isWorkletizableFunctionPath)(s)?(0,Me.processWorklet)(s,t):(0,Q.isWorkletizableObjectPath)(s)&&(0,hr.processWorkletizableObject)(s,t))})}function xr(e,t,r){if(t&&(0,Q.isWorkletizableFunctionPath)(e)||r&&(0,Q.isWorkletizableObjectPath)(e))return e;if(e.isReferencedIdentifier()&&e.isIdentifier())return(0,vr.findReferencedWorklet)(e,t,r)}});var ce=p(h=>{"use strict";Object.defineProperty(h,"__esModule",{value:!0});h.isContextObject=h.processIfWorkletContextObject=h.contextObjectMarker=void 0;var v=require("@babel/types");h.contextObjectMarker="__workletContextObject";function Fr(e,t){return qe(e.node)?(wr(e.node),Cr(e.node),!0):!1}h.processIfWorkletContextObject=Fr;function qe(e){return e.properties.some(t=>(0,v.isObjectProperty)(t)&&(0,v.isIdentifier)(t.key)&&t.key.name===h.contextObjectMarker)}h.isContextObject=qe;function Cr(e){let t=(0,v.functionExpression)(null,[],(0,v.blockStatement)([(0,v.returnStatement)((0,v.cloneNode)(e))],[(0,v.directive)((0,v.directiveLiteral)("worklet"))]));e.properties.push((0,v.objectProperty)((0,v.identifier)(`${h.contextObjectMarker}Factory`),t))}function wr(e){e.properties=e.properties.filter(t=>!((0,v.isObjectProperty)(t)&&(0,v.isIdentifier)(t.key)&&t.key.name===h.contextObjectMarker))}});var Ue=p(z=>{"use strict";Object.defineProperty(z,"__esModule",{value:!0});z.isImplicitContextObject=z.processIfWorkletFile=void 0;var b=require("@babel/types"),Le=E(),ze=ce();function jr(e,t){return e.node.directives.some(r=>r.value.value==="worklet")?(e.node.directives=e.node.directives.filter(r=>r.value.value!=="worklet"),Dr(e),!0):!1}z.processIfWorkletFile=jr;function Dr(e){let t=e.get("body");Nr(e.node),t.forEach(r=>{let n=Rr(r);ue(n)})}function Rr(e){return e.isExportNamedDeclaration()||e.isExportDefaultDeclaration()?e.get("declaration"):e}function ue(e){(0,Le.isWorkletizableFunctionPath)(e)?(e.isArrowFunctionExpression()&&Pr(e.node),Ne(e.node.body)):(0,Le.isWorkletizableObjectPath)(e)?Te(e)?qr(e.node):Mr(e):e.isVariableDeclaration()?Ar(e):e.isClassDeclaration()&&zr(e.node.body)}function Ar(e){e.get("declarations").forEach(r=>{let n=r.get("init");n.isExpression()&&ue(n)})}function Mr(e){e.get("properties").forEach(r=>{if(r.isObjectMethod())Ne(r.node.body);else if(r.isObjectProperty()){let n=r.get("value");ue(n)}})}function Pr(e){(0,b.isBlockStatement)(e.body)||(e.body=(0,b.blockStatement)([(0,b.returnStatement)(e.body)]))}function Ne(e){e.directives.some(t=>t.value.value==="worklet")||e.directives.push((0,b.directive)((0,b.directiveLiteral)("worklet")))}function qr(e){e.properties.some(t=>(0,b.isObjectProperty)(t)&&(0,b.isIdentifier)(t.key)&&t.key.name===ze.contextObjectMarker)||e.properties.push((0,b.objectProperty)((0,b.identifier)(`${ze.contextObjectMarker}`),(0,b.booleanLiteral)(!0)))}function Te(e){return e.get("properties").some(r=>r.isObjectMethod()?Lr(r):!1)}z.isImplicitContextObject=Te;function Lr(e){let t=!1;return e.traverse({ThisExpression(r){t=!0,r.stop()}}),t}function zr(e){e.body.push((0,b.classProperty)((0,b.identifier)("__workletClass"),(0,b.booleanLiteral)(!0)))}function Nr(e){let t=e.body,r=t.length,n=0;for(;n{"use strict";Object.defineProperty(ee,"__esModule",{value:!0});ee.processInlineStylesWarning=void 0;var d=require("@babel/types"),Ur=D(),de=require("assert");function Br(e){return(0,d.callExpression)((0,d.arrowFunctionExpression)([],(0,d.blockStatement)([(0,d.expressionStatement)((0,d.callExpression)((0,d.memberExpression)((0,d.identifier)("console"),(0,d.identifier)("warn")),[(0,d.callExpression)((0,d.memberExpression)((0,d.callExpression)((0,d.identifier)("require"),[(0,d.stringLiteral)("react-native-reanimated")]),(0,d.identifier)("getUseOfValueInStyleWarning")),[])])),(0,d.returnStatement)(e.node)])),[])}function Gr(e){e.isMemberExpression()&&(0,d.isIdentifier)(e.node.property)&&e.node.property.name==="value"&&e.replaceWith(Br(e))}function Hr(e){if((0,d.isArrayExpression)(e.node)){let t=e.get("elements");(0,de.strict)(Array.isArray(t),"[Reanimated] `elements` should be an array.");for(let r of t)r.isObjectExpression()&&fe(r)}}function fe(e){let t=e.get("properties");for(let r of t)if(r.isObjectProperty()){let n=r.get("value");(0,d.isIdentifier)(r.node.key)&&r.node.key.name==="transform"?Hr(n):Gr(n)}}function Zr(e,t){if((0,Ur.isRelease)()||t.opts.disableInlineStylesWarning||e.node.name.name!=="style"||!(0,d.isJSXExpressionContainer)(e.node.value))return;let r=e.get("value").get("expression");if((0,de.strict)(!Array.isArray(r),"[Reanimated] `expression` should not be an array."),r.isArrayExpression()){let n=r.get("elements");(0,de.strict)(Array.isArray(n),"[Reanimated] `elements` should be an array.");for(let i of n)i.isObjectExpression()&&fe(i)}else r.isObjectExpression()&&fe(r)}ee.processInlineStylesWarning=Zr});var He=p(te=>{"use strict";Object.defineProperty(te,"__esModule",{value:!0});te.substituteWebCallExpression=void 0;var Ge=require("@babel/types");function Vr(e){let t=e.node.callee;if((0,Ge.isIdentifier)(t)){let r=t.name;(r==="isWeb"||r==="shouldBeUseWeb")&&e.replaceWith((0,Ge.booleanLiteral)(!0))}}te.substituteWebCallExpression=Vr});var Xe=p(N=>{"use strict";var Ze=N&&N.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(N,"__esModule",{value:!0});N.processIfWorkletClass=void 0;var Jr=require("@babel/core"),Xr=Ze(require("@babel/generator")),$r=Ze(require("@babel/traverse")),a=require("@babel/types"),re=require("assert"),Yr=E(),Kr=D(),Ve="__workletClass";function Qr(e,t){return!e.node.id||!sn(e.node.body)?!1:(an(e.node.body),en(e,t),!0)}N.processIfWorkletClass=Qr;function en(e,t){(0,re.strict)(e.node.id);let r=e.node.id.name,n=tn(e.node,t);ln(n),rn(n.program.body),nn(n.program.body,r),n.program.body.push((0,a.returnStatement)((0,a.identifier)(r)));let i=(0,a.functionExpression)(null,[],(0,a.blockStatement)([...n.program.body])),s=(0,a.callExpression)(i,[]);(0,Kr.replaceWithFactoryCall)(e,r,s)}function tn(e,t){let r=(0,Xr.default)(e).code,n=(0,Jr.transformSync)(r,{plugins:["@babel/plugin-transform-class-properties","@babel/plugin-transform-classes","@babel/plugin-transform-unicode-regex"],filename:t.file.opts.filename,ast:!0,babelrc:!1,configFile:!1});return(0,re.strict)(n&&n.ast),n.ast}function rn(e){e.forEach(t=>{if((0,a.isFunctionDeclaration)(t)){let r=(0,a.directive)((0,a.directiveLiteral)("worklet"));t.body.directives.push(r)}})}function nn(e,t){let r=t+Yr.workletClassFactorySuffix,n=on(e,t),s=e[n].declarations[0].init,l=(0,a.functionDeclaration)((0,a.identifier)(r),[],(0,a.blockStatement)([(0,a.variableDeclaration)("const",[(0,a.variableDeclarator)((0,a.identifier)(t),s)]),(0,a.expressionStatement)((0,a.assignmentExpression)("=",(0,a.memberExpression)((0,a.identifier)(t),(0,a.identifier)(r)),(0,a.identifier)(r))),(0,a.returnStatement)((0,a.identifier)(t))],[(0,a.directive)((0,a.directiveLiteral)("worklet"))])),u=(0,a.variableDeclaration)("const",[(0,a.variableDeclarator)((0,a.identifier)(t),(0,a.callExpression)((0,a.identifier)(r),[]))]);e.splice(n,1,l,u)}function on(e,t){let r=e.findIndex(n=>(0,a.isVariableDeclaration)(n)&&n.declarations.some(i=>(0,a.isIdentifier)(i.id)&&i.id.name===t));return(0,re.strict)(r>=0),r}function sn(e){return e.body.some(t=>(0,a.isClassProperty)(t)&&(0,a.isIdentifier)(t.key)&&t.key.name===Ve)}function an(e){e.body=e.body.filter(t=>!(0,a.isClassProperty)(t)||!(0,a.isIdentifier)(t.key)||t.key.name!==Ve)}function ln(e){let t=cn(e),r=un(t),n=t.map(u=>u.index),i=r.map(u=>u.index),s=e.program.body,l=[...s];for(let u=0;u{r.get("body").forEach((i,s)=>{var l;let u=i.getBindingIdentifiers();if(!i.isFunctionDeclaration()||!(!((l=i.node.id)===null||l===void 0)&&l.name))return;let f={name:i.node.id.name,index:s,dependencies:new Set};t.push(f),i.traverse({Identifier(k){dn(k,u,i)&&f.dependencies.add(k.node.name)}})})}}}),t}function un(e){let t=[],r=new Set;for(let n of e)Je(n,e,t,r);return t}function Je(e,t,r,n){if(n.has(e.name))throw new Error("Cycle detected. This should never happen.");if(!r.find(i=>i.name===e.name)){n.add(e.name);for(let i of e.dependencies)if(!r.find(s=>s.name===i)){let s=t.find(l=>l.name===i);(0,re.strict)(s),Je(s,t,r,n)}r.push(e),n.delete(e.name)}}function dn(e,t,r){return e.isReferencedIdentifier()&&!(e.node.name in t)&&!r.scope.hasOwnBinding(e.node.name)&&r.scope.hasReference(e.node.name)}});Object.defineProperty(exports,"__esModule",{value:!0});var $e=Pe(),fn=ce(),pn=Ue(),bn=Z(),mn=Be(),yn=E(),kn=D(),gn=He(),_n=J(),On=Xe();module.exports=function(){function e(t){try{t()}catch(r){throw new Error(`[Reanimated] Babel plugin exception: ${r}`)}}return{pre(t){e(()=>{t.workletNumber=1,(0,bn.initializeGlobals)(),kn.addCustomGlobals.call(this)})},visitor:{CallExpression:{enter(t,r){e(()=>{(0,$e.processCalleesAutoworkletizableCallbacks)(t,r),r.opts.substituteWebPlatformChecks&&(0,gn.substituteWebCallExpression)(t)})}},[yn.WorkletizableFunction]:{enter(t,r){e(()=>{(0,_n.processIfWithWorkletDirective)(t,r)||(0,$e.processIfAutoworkletizableCallback)(t,r)})}},ObjectExpression:{enter(t,r){e(()=>{(0,fn.processIfWorkletContextObject)(t,r)})}},ClassDeclaration:{enter(t,r){e(()=>{(0,On.processIfWorkletClass)(t,r)})}},Program:{enter(t,r){e(()=>{r.workletNumber=1,(0,pn.processIfWorkletFile)(t,r)})}},JSXAttribute:{enter(t,r){e(()=>(0,mn.processInlineStylesWarning)(t,r))}}}}}; +"use strict";var et=Object.create;var me=Object.defineProperty;var tt=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var rt=Object.getPrototypeOf,it=Object.prototype.hasOwnProperty;var b=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var ot=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of nt(t))!it.call(e,i)&&i!==n&&me(e,i,{get:()=>t[i],enumerable:!(r=tt(t,i))||r.enumerable});return e};var R=(e,t,n)=>(n=e!=null?et(rt(e)):{},ot(t||!e||!e.__esModule?me(n,"default",{value:e,enumerable:!0}):n,e));var S=b(y=>{"use strict";Object.defineProperty(y,"__esModule",{value:!0});y.workletClassFactorySuffix=y.isWorkletizableObjectNode=y.isWorkletizableObjectPath=y.isWorkletizableFunctionNode=y.isWorkletizableFunctionPath=y.WorkletizableObject=y.WorkletizableFunction=void 0;var B=require("@babel/types");y.WorkletizableFunction="FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ObjectMethod";y.WorkletizableObject="ObjectExpression";function st(e){return e.isFunctionDeclaration()||e.isFunctionExpression()||e.isArrowFunctionExpression()||e.isObjectMethod()}y.isWorkletizableFunctionPath=st;function at(e){return(0,B.isFunctionDeclaration)(e)||(0,B.isFunctionExpression)(e)||(0,B.isArrowFunctionExpression)(e)||(0,B.isObjectMethod)(e)}y.isWorkletizableFunctionNode=at;function lt(e){return e.isObjectExpression()}y.isWorkletizableObjectPath=lt;function ct(e){return(0,B.isObjectExpression)(e)}y.isWorkletizableObjectNode=ct;y.workletClassFactorySuffix="__classFactory"});var M=b(A=>{"use strict";Object.defineProperty(A,"__esModule",{value:!0});A.replaceWithFactoryCall=A.isRelease=void 0;var G=require("@babel/types");function ut(){var e,t;let n=/(prod|release|stag[ei])/i;return!!(!((e=process.env.BABEL_ENV)===null||e===void 0)&&e.match(n)||!((t=process.env.NODE_ENV)===null||t===void 0)&&t.match(n))}A.isRelease=ut;function dt(e,t,n){if(!t||!ft(e))e.replaceWith(n);else{let r=(0,G.variableDeclaration)("const",[(0,G.variableDeclarator)((0,G.identifier)(t),n)]);e.replaceWith(r)}}A.replaceWithFactoryCall=dt;function ft(e){return(0,G.isScopable)(e.parent)||(0,G.isExportNamedDeclaration)(e.parent)}});var ae=b(g=>{"use strict";Object.defineProperty(g,"__esModule",{value:!0});g.addCustomGlobals=g.initializeGlobals=g.globals=g.defaultGlobals=g.initializeState=void 0;var pt=["globalThis","Infinity","NaN","undefined","eval","isFinite","isNaN","parseFloat","parseInt","decodeURI","decodeURIComponent","encodeURI","encodeURIComponent","escape","unescape","Object","Function","Boolean","Symbol","Error","AggregateError","EvalError","RangeError","ReferenceError","SyntaxError","TypeError","URIError","InternalError","Number","BigInt","Math","Date","String","RegExp","Array","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","BigInt64Array","BigUint64Array","Float32Array","Float64Array","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Atomics","JSON","WeakRef","FinalizationRegistry","Iterator","AsyncIterator","Promise","GeneratorFunction","AsyncGeneratorFunction","Generator","AsyncGenerator","AsyncFunction","Reflect","Proxy","Intl","null","this","global","window","globalThis","console","performance","queueMicrotask","requestAnimationFrame","setImmediate","arguments","HermesInternal","_WORKLET","ReanimatedError","__reanimatedLoggerConfig"],bt=["_IS_FABRIC","_log","_toString","_scheduleHostFunctionOnJS","_scheduleRemoteFunctionOnJS","_scheduleOnRuntime","_makeShareableClone","_updatePropsPaper","_updatePropsFabric","_removeFromPropsRegistry","_measurePaper","_measureFabric","_scrollToPaper","_dispatchCommandPaper","_dispatchCommandFabric","_setGestureState","_notifyAboutProgress","_notifyAboutEnd","_runOnUIQueue","_getAnimationTimestamp"];function mt(e){e.workletNumber=1,e.classesToWorkletize=[],ye(),ke(e)}g.initializeState=mt;g.defaultGlobals=new Set(pt.concat(bt));function ye(){g.globals=new Set(g.defaultGlobals)}g.initializeGlobals=ye;function ke(e){e.opts&&Array.isArray(e.opts.globals)&&e.opts.globals.forEach(t=>{g.globals.add(t)})}g.addCustomGlobals=ke});var V=b(P=>{"use strict";var yt=P&&P.__rest||function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(e);i{"use strict";var vt=v&&v.__createBinding||(Object.create?function(e,t,n,r){r===void 0&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]}),ht=v&&v.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),ge=v&&v.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n in e)n!=="default"&&Object.prototype.hasOwnProperty.call(e,n)&&vt(t,e,n);return ht(t,e),t},Et=v&&v.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(v,"__esModule",{value:!0});v.buildWorkletString=void 0;var _e=require("@babel/core"),St=Et(require("@babel/generator")),c=require("@babel/types"),H=require("assert"),It=ge(require("convert-source-map")),Wt=ge(require("fs")),xt=S(),wt=M(),Ft=V(),Ct="mock source map";function jt(e,t,n,r,i){Dt(e,r);let s=e.program.body.find(_=>(0,c.isFunctionDeclaration)(_))||e.program.body.find(_=>(0,c.isExpressionStatement)(_))||void 0;(0,H.strict)(s,"[Reanimated] `draftExpression` is undefined.");let a=(0,c.isFunctionDeclaration)(s)?s:s.expression;(0,H.strict)("params"in a,"'params' property is undefined in 'expression'"),(0,H.strict)((0,c.isBlockStatement)(a.body),"[Reanimated] `expression.body` is not a `BlockStatement`");let u=new Set;(0,_e.traverse)(e,{NewExpression(_){if(!(0,c.isIdentifier)(_.node.callee))return;let x=_.node.callee.name;if(!n.some(Z=>Z.name===x)||u.has(x))return;let D=n.findIndex(Z=>Z.name===x);n.splice(D,1);let ie=x+xt.workletClassFactorySuffix;n.push((0,c.identifier)(ie)),(0,c.assertBlockStatement)(a.body),a.body.body.unshift((0,c.variableDeclaration)("const",[(0,c.variableDeclarator)((0,c.identifier)(x),(0,c.callExpression)((0,c.identifier)(ie),[]))])),u.add(x)}});let p=(0,c.functionExpression)((0,c.identifier)(r),a.params,a.body,a.generator,a.async),d=(0,St.default)(p).code;(0,H.strict)(i,"[Reanimated] `inputMap` is undefined.");let O=!((0,wt.isRelease)()||t.opts.disableSourceMaps);if(O){i.sourcesContent=[];for(let _ of i.sources)i.sourcesContent.push(Wt.readFileSync(_).toString("utf-8"))}let j=(0,Ft.workletTransformSync)(d,{filename:t.file.opts.filename,extraPlugins:[Pt(n)],compact:!0,sourceMaps:O,inputSourceMap:i,ast:!1,babelrc:!1,configFile:!1,comments:!1});(0,H.strict)(j,"[Reanimated] `transformed` is null.");let C;return O&&(Rt()?C=Ct:(C=It.fromObject(j.map).toObject(),delete C.sourcesContent)),[j.code,JSON.stringify(C)]}v.buildWorkletString=jt;function Dt(e,t){(0,_e.traverse)(e,{FunctionExpression(n){if(!n.node.id){n.stop();return}let r=n.node.id.name;n.scope.rename(r,t)}})}function Rt(){return process.env.REANIMATED_JEST_SHOULD_MOCK_SOURCE_MAP==="1"}function At(e,t,n){t.length===0||!(0,c.isProgram)(e.parent)||(0,c.isExpression)(e.node.body)||e.node.body.body.unshift(n)}function Mt(e){var t;(0,c.isProgram)(e.parent)&&!(0,c.isArrowFunctionExpression)(e.node)&&!(0,c.isObjectMethod)(e.node)&&e.node.id&&e.scope.parent&&((t=e.scope.parent.bindings[e.node.id.name])===null||t===void 0?void 0:t.references)>0&&e.node.body.body.unshift((0,c.variableDeclaration)("const",[(0,c.variableDeclarator)((0,c.identifier)(e.node.id.name),(0,c.memberExpression)((0,c.thisExpression)(),(0,c.identifier)("_recur")))]))}function Pt(e){let t=(0,c.variableDeclaration)("const",[(0,c.variableDeclarator)((0,c.objectPattern)(e.map(n=>(0,c.objectProperty)((0,c.identifier)(n.name),(0,c.identifier)(n.name),!1,!0))),(0,c.memberExpression)((0,c.thisExpression)(),(0,c.identifier)("__closure")))]);return{visitor:{"FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ObjectMethod":n=>{At(n,e,t),Mt(n)}}}}});var Ee=b(q=>{"use strict";var qt=q&&q.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(q,"__esModule",{value:!0});q.makeWorkletFactory=void 0;var zt=require("@babel/core"),Lt=qt(require("@babel/generator")),o=require("@babel/types"),w=require("assert"),he=require("path"),Tt=ae(),ve=S(),le=M(),Nt=Oe(),Ut=V(),Bt=require("../package.json").version,Gt="x.y.z";function Ht(e,t){Zt(e),(0,w.strict)(t.file.opts.filename,"[Reanimated] `state.file.opts.filename` is undefined.");let n=(0,Lt.default)(e.node,{sourceMaps:!0,sourceFileName:t.file.opts.filename});n.code="("+(e.isObjectMethod()?"function ":"")+n.code+` +)`;let r=(0,Ut.workletTransformSync)(n.code,{extraPlugins:Yt,filename:t.file.opts.filename,ast:!0,babelrc:!1,configFile:!1,inputSourceMap:n.map});(0,w.strict)(r,"[Reanimated] `transformed` is undefined."),(0,w.strict)(r.ast,"[Reanimated] `transformed.ast` is undefined.");let i=$t(r.ast,e),s=(0,o.cloneNode)(e.node),a=(0,o.isBlockStatement)(s.body)?(0,o.functionExpression)(null,s.params,s.body,s.generator,s.async):s,{workletName:u,reactName:p}=Xt(e,t),[d,O]=(0,Nt.buildWorkletString)(r.ast,t,i,u,r.map);(0,w.strict)(d,"[Reanimated] `funString` is undefined.");let j=Jt(d),C=1;i.length>0&&(C-=i.length+2);let _=e.parentPath.isProgram()?e:e.findParent(k=>{var oe,se;return(se=(oe=k.parentPath)===null||oe===void 0?void 0:oe.isProgram())!==null&&se!==void 0?se:!1});(0,w.strict)(_,"[Reanimated] `pathForStringDefinitions` is null."),(0,w.strict)(_.parentPath,"[Reanimated] `pathForStringDefinitions.parentPath` is null.");let x=_.parentPath.scope.generateUidIdentifier(`worklet_${j}_init_data`),D=(0,o.objectExpression)([(0,o.objectProperty)((0,o.identifier)("code"),(0,o.stringLiteral)(d))]);if(!(0,le.isRelease)()){let k=t.file.opts.filename;t.opts.relativeSourceLocation&&(k=(0,he.relative)(t.cwd,k),O=O==null?void 0:O.replace(t.file.opts.filename,k)),D.properties.push((0,o.objectProperty)((0,o.identifier)("location"),(0,o.stringLiteral)(k)))}O&&D.properties.push((0,o.objectProperty)((0,o.identifier)("sourceMap"),(0,o.stringLiteral)(O))),!(0,le.isRelease)()&&D.properties.push((0,o.objectProperty)((0,o.identifier)("version"),(0,o.stringLiteral)(Vt()?Gt:Bt)));let be=!t.opts.omitNativeOnlyData;be&&_.insertBefore((0,o.variableDeclaration)("const",[(0,o.variableDeclarator)(x,D)])),(0,w.strict)(!(0,o.isFunctionDeclaration)(a),"[Reanimated] `funExpression` is a `FunctionDeclaration`."),(0,w.strict)(!(0,o.isObjectMethod)(a),"[Reanimated] `funExpression` is an `ObjectMethod`.");let U=[(0,o.variableDeclaration)("const",[(0,o.variableDeclarator)((0,o.identifier)(p),a)]),(0,o.expressionStatement)((0,o.assignmentExpression)("=",(0,o.memberExpression)((0,o.identifier)(p),(0,o.identifier)("__closure"),!1),(0,o.objectExpression)(i.map(k=>k.name.endsWith(ve.workletClassFactorySuffix)?(0,o.objectProperty)((0,o.identifier)(k.name),(0,o.memberExpression)((0,o.identifier)(k.name.slice(0,k.name.length-ve.workletClassFactorySuffix.length)),(0,o.identifier)(k.name))):(0,o.objectProperty)((0,o.identifier)(k.name),k,!1,!0))))),(0,o.expressionStatement)((0,o.assignmentExpression)("=",(0,o.memberExpression)((0,o.identifier)(p),(0,o.identifier)("__workletHash"),!1),(0,o.numericLiteral)(j)))];return be&&U.push((0,o.expressionStatement)((0,o.assignmentExpression)("=",(0,o.memberExpression)((0,o.identifier)(p),(0,o.identifier)("__initData"),!1),x))),(0,le.isRelease)()||(U.unshift((0,o.variableDeclaration)("const",[(0,o.variableDeclarator)((0,o.identifier)("_e"),(0,o.arrayExpression)([(0,o.newExpression)((0,o.memberExpression)((0,o.identifier)("global"),(0,o.identifier)("Error")),[]),(0,o.numericLiteral)(C),(0,o.numericLiteral)(-27)]))])),U.push((0,o.expressionStatement)((0,o.assignmentExpression)("=",(0,o.memberExpression)((0,o.identifier)(p),(0,o.identifier)("__stackDetails"),!1),(0,o.identifier)("_e"))))),U.push((0,o.returnStatement)((0,o.identifier)(p))),(0,o.functionExpression)(void 0,[],(0,o.blockStatement)(U))}q.makeWorkletFactory=Ht;function Zt(e){e.traverse({DirectiveLiteral(t){t.node.value==="worklet"&&t.getFunctionParent()===e&&t.parentPath.remove()}})}function Vt(){return process.env.REANIMATED_JEST_SHOULD_MOCK_VERSION==="1"}function Jt(e){let t=e.length,n=5381,r=52711;for(;t--;){let i=e.charCodeAt(t);n=n*33^i,r=r*33^i}return(n>>>0)*4096+(r>>>0)}function Xt(e,t){let n="unknownFile";if(t.file.opts.filename){let a=t.file.opts.filename;n=(0,he.basename)(a);let u=a.split("/"),p=u.indexOf("node_modules");p!==-1&&(n=`${u[p+1]}_${n}`)}let r=`${n}${t.workletNumber++}`,i="";(0,o.isObjectMethod)(e.node)&&(0,o.isIdentifier)(e.node.key)?i=e.node.key.name:((0,o.isFunctionDeclaration)(e.node)||(0,o.isFunctionExpression)(e.node))&&(0,o.isIdentifier)(e.node.id)&&(i=e.node.id.name);let s=i?(0,o.toIdentifier)(`${i}_${r}`):(0,o.toIdentifier)(r);return i=i||(0,o.toIdentifier)(r),{workletName:s,reactName:i}}function $t(e,t){let n=new Map,r=new Map;return(0,zt.traverse)(e,{Identifier(i){if(!i.isReferencedIdentifier())return;let s=i.node.name;if(Tt.globals.has(s)||"id"in t.node&&t.node.id&&t.node.id.name===s)return;let a=i.parent;if((0,o.isMemberExpression)(a)&&a.property===i.node&&!a.computed||(0,o.isObjectProperty)(a)&&(0,o.isObjectExpression)(i.parentPath.parent)&&i.node!==a.value)return;let u=i.scope;for(;u!=null;){if(u.bindings[s]!=null)return;u=u.parent}n.set(s,i.node),r.set(s,!1)}}),t.traverse({Identifier(i){if(!i.isReferencedIdentifier())return;let s=n.get(i.node.name);!s||r.get(i.node.name)||(s.loc=i.node.loc,r.set(i.node.name,!0))}}),Array.from(n.values())}var Yt=[require.resolve("@babel/plugin-transform-shorthand-properties"),require.resolve("@babel/plugin-transform-arrow-functions"),require.resolve("@babel/plugin-transform-optional-chaining"),require.resolve("@babel/plugin-transform-nullish-coalescing-operator"),[require.resolve("@babel/plugin-transform-template-literals"),{loose:!0}]]});var Se=b(J=>{"use strict";Object.defineProperty(J,"__esModule",{value:!0});J.makeWorkletFactoryCall=void 0;var Kt=require("@babel/types"),Qt=Ee();function en(e,t){let n=(0,Qt.makeWorkletFactory)(e,t),r=(0,Kt.callExpression)(n,[]);return tn(e,r),r}J.makeWorkletFactoryCall=en;function tn(e,t){let n=e.node.loc;n&&(t.callee.loc={filename:n.filename,identifierName:n.identifierName,start:n.start,end:n.start})}});var X=b(F=>{"use strict";Object.defineProperty(F,"__esModule",{value:!0});F.substituteObjectMethodWithObjectProperty=F.processWorklet=F.processIfWithWorkletDirective=void 0;var ce=require("@babel/types"),nn=S(),rn=M(),on=Se();function Ie(e,t){return!(0,ce.isBlockStatement)(e.node.body)||!sn(e.node.body.directives)?!1:(We(e,t),!0)}F.processIfWithWorkletDirective=Ie;function We(e,t){t.opts.processNestedWorklets&&e.traverse({[nn.WorkletizableFunction](r,i){Ie(r,i)}},t);let n=(0,on.makeWorkletFactoryCall)(e,t);an(e,n)}F.processWorklet=We;function sn(e){return e.some(t=>(0,ce.isDirectiveLiteral)(t.value)&&t.value.value==="worklet")}function an(e,t){var n;if(e.isObjectMethod())xe(e,t);else{let r="id"in e.node?(n=e.node.id)===null||n===void 0?void 0:n.name:void 0;(0,rn.replaceWithFactoryCall)(e,r,t)}}function xe(e,t){let n=(0,ce.objectProperty)(e.node.key,t);e.replaceWith(n)}F.substituteObjectMethodWithObjectProperty=xe});var Fe=b($=>{"use strict";Object.defineProperty($,"__esModule",{value:!0});$.isGestureHandlerEventCallback=void 0;var I=require("@babel/types"),ln=new Set(["Tap","Pan","Pinch","Rotation","Fling","LongPress","ForceTouch","Native","Manual","Race","Simultaneous","Exclusive","Hover"]),cn=new Set(["onBegin","onStart","onEnd","onFinalize","onUpdate","onChange","onTouchesDown","onTouchesMove","onTouchesUp","onTouchesCancelled"]);function un(e){return(0,I.isCallExpression)(e.parent)&&(0,I.isExpression)(e.parent.callee)&&dn(e.parent.callee)}$.isGestureHandlerEventCallback=un;function dn(e){return(0,I.isMemberExpression)(e)&&(0,I.isIdentifier)(e.property)&&cn.has(e.property.name)&&we(e.object)}function we(e){return!!(fn(e)||(0,I.isCallExpression)(e)&&(0,I.isMemberExpression)(e.callee)&&we(e.callee.object))}function fn(e){return(0,I.isCallExpression)(e)&&(0,I.isMemberExpression)(e.callee)&&(0,I.isIdentifier)(e.callee.object)&&e.callee.object.name==="Gesture"&&(0,I.isIdentifier)(e.callee.property)&&ln.has(e.callee.property.name)}});var De=b(Y=>{"use strict";Object.defineProperty(Y,"__esModule",{value:!0});Y.isLayoutAnimationCallback=void 0;var W=require("@babel/types"),pn=new Set(["BounceIn","BounceInDown","BounceInLeft","BounceInRight","BounceInUp","BounceOut","BounceOutDown","BounceOutLeft","BounceOutRight","BounceOutUp","FadeIn","FadeInDown","FadeInLeft","FadeInRight","FadeInUp","FadeOut","FadeOutDown","FadeOutLeft","FadeOutRight","FadeOutUp","FlipInEasyX","FlipInEasyY","FlipInXDown","FlipInXUp","FlipInYLeft","FlipInYRight","FlipOutEasyX","FlipOutEasyY","FlipOutXDown","FlipOutXUp","FlipOutYLeft","FlipOutYRight","LightSpeedInLeft","LightSpeedInRight","LightSpeedOutLeft","LightSpeedOutRight","PinwheelIn","PinwheelOut","RollInLeft","RollInRight","RollOutLeft","RollOutRight","RotateInDownLeft","RotateInDownRight","RotateInUpLeft","RotateInUpRight","RotateOutDownLeft","RotateOutDownRight","RotateOutUpLeft","RotateOutUpRight","SlideInDown","SlideInLeft","SlideInRight","SlideInUp","SlideOutDown","SlideOutLeft","SlideOutRight","SlideOutUp","StretchInX","StretchInY","StretchOutX","StretchOutY","ZoomIn","ZoomInDown","ZoomInEasyDown","ZoomInEasyUp","ZoomInLeft","ZoomInRight","ZoomInRotate","ZoomInUp","ZoomOut","ZoomOutDown","ZoomOutEasyDown","ZoomOutEasyUp","ZoomOutLeft","ZoomOutRight","ZoomOutRotate","ZoomOutUp"]),bn=new Set(["Layout","LinearTransition","SequencedTransition","FadingTransition","JumpingTransition","CurvedTransition","EntryExitTransition"]),Ce=new Set([...pn,...bn]),mn=new Set(["build","duration","delay","getDuration","randomDelay","getDelay","getDelayFunction"]),yn=new Set(["easing","rotate","springify","damping","mass","stiffness","overshootClamping","restDisplacementThreshold","restSpeedThreshold","withInitialValues","getAnimationAndConfig"]),kn=new Set(["easingX","easingY","easingWidth","easingHeight","entering","exiting","reverse"]),gn=new Set([...mn,...yn,...kn]),_n=new Set(["withCallback"]);function On(e){return(0,W.isCallExpression)(e.parent)&&(0,W.isExpression)(e.parent.callee)&&vn(e.parent.callee)}Y.isLayoutAnimationCallback=On;function vn(e){return(0,W.isMemberExpression)(e)&&(0,W.isIdentifier)(e.property)&&_n.has(e.property.name)&&je(e.object)}function je(e){return(0,W.isIdentifier)(e)&&Ce.has(e.name)?!0:!!((0,W.isNewExpression)(e)&&(0,W.isIdentifier)(e.callee)&&Ce.has(e.callee.name)||(0,W.isCallExpression)(e)&&(0,W.isMemberExpression)(e.callee)&&(0,W.isIdentifier)(e.callee.property)&&gn.has(e.callee.property.name)&&je(e.callee.object))}});var Re=b(K=>{"use strict";Object.defineProperty(K,"__esModule",{value:!0});K.findReferencedWorklet=void 0;var z=S();function hn(e,t,n){let r=e.node.name,s=e.scope.getBinding(r);return s?t&&s.path.isFunctionDeclaration()?s.path:s.constant?En(s,t,n):Sn(s,t,n):void 0}K.findReferencedWorklet=hn;function En(e,t,n){let r=e.path;if(!r.isVariableDeclarator())return;let i=r.get("init");if(t&&(0,z.isWorkletizableFunctionPath)(i)||n&&(0,z.isWorkletizableObjectPath)(i))return i}function Sn(e,t,n){let r=e.constantViolations.reverse().find(s=>s.isAssignmentExpression()&&(t&&(0,z.isWorkletizableFunctionPath)(s.get("right"))||n&&(0,z.isWorkletizableObjectPath)(s.get("right"))));if(!r||!r.isAssignmentExpression())return;let i=r.get("right");if(t&&(0,z.isWorkletizableFunctionPath)(i)||n&&(0,z.isWorkletizableObjectPath)(i))return i}});var Me=b(Q=>{"use strict";Object.defineProperty(Q,"__esModule",{value:!0});Q.processWorkletizableObject=void 0;var In=S(),Ae=X();function Wn(e,t){let n=e.get("properties");for(let r of n)if(r.isObjectMethod())(0,Ae.processWorklet)(r,t);else if(r.isObjectProperty()){let i=r.get("value");(0,In.isWorkletizableFunctionPath)(i)&&(0,Ae.processWorklet)(i,t)}else throw new Error(`[Reanimated] '${r.type}' as to-be workletized argument is not supported for object hooks.`)}Q.processWorkletizableObject=Wn});var Le=b(L=>{"use strict";Object.defineProperty(L,"__esModule",{value:!0});L.processCalleesAutoworkletizableCallbacks=L.processIfAutoworkletizableCallback=void 0;var xn=require("@babel/types"),ee=S(),ze=X(),wn=Fe(),Fn=De(),Cn=Re(),jn=Me(),Pe=new Set(["useAnimatedGestureHandler","useAnimatedScrollHandler"]),qe=new Set(["useFrameCallback","useAnimatedStyle","useAnimatedProps","createAnimatedPropAdapter","useDerivedValue","useAnimatedScrollHandler","useAnimatedReaction","useWorkletCallback","withTiming","withSpring","withDecay","withRepeat","runOnUI","executeOnUIRuntimeSync"]),Dn=new Map([["useAnimatedGestureHandler",[0]],["useFrameCallback",[0]],["useAnimatedStyle",[0]],["useAnimatedProps",[0]],["createAnimatedPropAdapter",[0]],["useDerivedValue",[0]],["useAnimatedScrollHandler",[0]],["useAnimatedReaction",[0,1]],["useWorkletCallback",[0]],["withTiming",[2]],["withSpring",[2]],["withDecay",[1]],["withRepeat",[3]],["runOnUI",[0]],["executeOnUIRuntimeSync",[0]]]);function Rn(e,t){return(0,wn.isGestureHandlerEventCallback)(e)||(0,Fn.isLayoutAnimationCallback)(e)?((0,ze.processWorklet)(e,t),!0):!1}L.processIfAutoworkletizableCallback=Rn;function An(e,t){let n=(0,xn.isSequenceExpression)(e.node.callee)?e.node.callee.expressions[e.node.callee.expressions.length-1]:e.node.callee,r="name"in n?n.name:"property"in n&&"name"in n.property?n.property.name:void 0;if(r!==void 0&&(qe.has(r)||Pe.has(r))){let i=qe.has(r),s=Pe.has(r),a=Dn.get(r),u=e.get("arguments").filter((p,d)=>a.includes(d));Mn(u,t,i,s)}}L.processCalleesAutoworkletizableCallbacks=An;function Mn(e,t,n,r){e.forEach(i=>{let s=Pn(i,n,r);s&&((0,ee.isWorkletizableFunctionPath)(s)?(0,ze.processWorklet)(s,t):(0,ee.isWorkletizableObjectPath)(s)&&(0,jn.processWorkletizableObject)(s,t))})}function Pn(e,t,n){if(t&&(0,ee.isWorkletizableFunctionPath)(e)||n&&(0,ee.isWorkletizableObjectPath)(e))return e;if(e.isReferencedIdentifier()&&e.isIdentifier())return(0,Cn.findReferencedWorklet)(e,t,n)}});var Be=b(T=>{"use strict";var Te=T&&T.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(T,"__esModule",{value:!0});T.processIfWorkletClass=void 0;var qn=Te(require("@babel/generator")),zn=Te(require("@babel/traverse")),l=require("@babel/types"),te=require("assert"),Ln=S(),Tn=M(),Nn=V(),Ne="__workletClass";function Un(e,t){return er(e,t)?(Xn(e.node.body),Bn(e,t),!0):!1}T.processIfWorkletClass=Un;function Bn(e,t){(0,te.strict)(e.node.id);let n=e.node.id.name,r=Gn(e.node,t);$n(r),Hn(r.program.body),Zn(r.program.body,n),r.program.body.push((0,l.returnStatement)((0,l.identifier)(n)));let i=(0,l.functionExpression)(null,[],(0,l.blockStatement)([...r.program.body])),s=(0,l.callExpression)(i,[]);(0,Tn.replaceWithFactoryCall)(e,n,s)}function Gn(e,t){let n=(0,qn.default)(e).code,r=(0,Nn.workletTransformSync)(n,{extraPlugins:["@babel/plugin-transform-class-properties","@babel/plugin-transform-classes","@babel/plugin-transform-unicode-regex"],filename:t.file.opts.filename,ast:!0,babelrc:!1,configFile:!1});return(0,te.strict)(r&&r.ast),r.ast}function Hn(e){e.forEach(t=>{if((0,l.isFunctionDeclaration)(t)){let n=(0,l.directive)((0,l.directiveLiteral)("worklet"));t.body.directives.push(n)}})}function Zn(e,t){let n=t+Ln.workletClassFactorySuffix,r=Vn(e,t),s=e[r].declarations[0].init,a=(0,l.functionDeclaration)((0,l.identifier)(n),[],(0,l.blockStatement)([(0,l.variableDeclaration)("const",[(0,l.variableDeclarator)((0,l.identifier)(t),s)]),(0,l.expressionStatement)((0,l.assignmentExpression)("=",(0,l.memberExpression)((0,l.identifier)(t),(0,l.identifier)(n)),(0,l.identifier)(n))),(0,l.returnStatement)((0,l.identifier)(t))],[(0,l.directive)((0,l.directiveLiteral)("worklet"))])),u=(0,l.variableDeclaration)("const",[(0,l.variableDeclarator)((0,l.identifier)(t),(0,l.callExpression)((0,l.identifier)(n),[]))]);e.splice(r,1,a,u)}function Vn(e,t){let n=e.findIndex(r=>(0,l.isVariableDeclaration)(r)&&r.declarations.some(i=>(0,l.isIdentifier)(i.id)&&i.id.name===t));return(0,te.strict)(n>=0),n}function Jn(e){return e.body.some(t=>(0,l.isClassProperty)(t)&&(0,l.isIdentifier)(t.key)&&t.key.name===Ne)}function Xn(e){e.body=e.body.filter(t=>!(0,l.isClassProperty)(t)||!(0,l.isIdentifier)(t.key)||t.key.name!==Ne)}function $n(e){let t=Yn(e),n=Kn(t),r=t.map(u=>u.index),i=n.map(u=>u.index),s=e.program.body,a=[...s];for(let u=0;u{n.get("body").forEach((i,s)=>{var a;let u=i.getBindingIdentifiers();if(!i.isFunctionDeclaration()||!(!((a=i.node.id)===null||a===void 0)&&a.name))return;let p={name:i.node.id.name,index:s,dependencies:new Set};t.push(p),i.traverse({Identifier(d){Qn(d,u,i)&&p.dependencies.add(d.node.name)}})})}}}),t}function Kn(e){let t=[],n=new Set;for(let r of e)Ue(r,e,t,n);return t}function Ue(e,t,n,r){if(r.has(e.name))throw new Error("Cycle detected. This should never happen.");if(!n.find(i=>i.name===e.name)){r.add(e.name);for(let i of e.dependencies)if(!n.find(s=>s.name===i)){let s=t.find(a=>a.name===i);(0,te.strict)(s),Ue(s,t,n,r)}n.push(e),r.delete(e.name)}}function Qn(e,t,n){return e.isReferencedIdentifier()&&!(e.node.name in t)&&!n.scope.hasOwnBinding(e.node.name)&&n.scope.hasReference(e.node.name)}function er(e,t){var n;let r=(n=e.node.id)===null||n===void 0?void 0:n.name,i=e.node;if(!r)return!1;let s=Jn(i.body),a=t.classesToWorkletize.some(d=>d.node===i),u=e.parentPath.isProgram()&&t.classesToWorkletize.some(d=>d.name===r);return t.classesToWorkletize=t.classesToWorkletize.filter(d=>d.node!==i&&d.name!==r),s||a||u}});var ue=b(E=>{"use strict";Object.defineProperty(E,"__esModule",{value:!0});E.isContextObject=E.processIfWorkletContextObject=E.contextObjectMarker=void 0;var h=require("@babel/types");E.contextObjectMarker="__workletContextObject";function tr(e,t){return Ge(e.node)?(rr(e.node),nr(e.node),!0):!1}E.processIfWorkletContextObject=tr;function Ge(e){return e.properties.some(t=>(0,h.isObjectProperty)(t)&&(0,h.isIdentifier)(t.key)&&t.key.name===E.contextObjectMarker)}E.isContextObject=Ge;function nr(e){let t=(0,h.functionExpression)(null,[],(0,h.blockStatement)([(0,h.returnStatement)((0,h.cloneNode)(e))],[(0,h.directive)((0,h.directiveLiteral)("worklet"))]));e.properties.push((0,h.objectProperty)((0,h.identifier)(`${E.contextObjectMarker}Factory`),t))}function rr(e){e.properties=e.properties.filter(t=>!((0,h.isObjectProperty)(t)&&(0,h.isIdentifier)(t.key)&&t.key.name===E.contextObjectMarker))}});var Xe=b(N=>{"use strict";Object.defineProperty(N,"__esModule",{value:!0});N.isImplicitContextObject=N.processIfWorkletFile=void 0;var m=require("@babel/types"),He=S(),Ze=ue();function ir(e,t){return e.node.directives.some(n=>n.value.value==="worklet")?(e.node.directives=e.node.directives.filter(n=>n.value.value!=="worklet"),or(e,t),!0):!1}N.processIfWorkletFile=ir;function or(e,t){let n=e.get("body");pr(e.node),n.forEach(r=>{let i=sr(r);de(i,t)})}function sr(e){return e.isExportNamedDeclaration()||e.isExportDefaultDeclaration()?e.get("declaration"):e}function de(e,t){var n;(0,He.isWorkletizableFunctionPath)(e)?(e.isArrowFunctionExpression()&&cr(e.node),Ve(e.node.body)):(0,He.isWorkletizableObjectPath)(e)?Je(e)?ur(e.node):lr(e,t):e.isVariableDeclaration()?ar(e,t):e.isClassDeclaration()&&(fr(e.node.body),!((n=e.node.id)===null||n===void 0)&&n.name&&t.classesToWorkletize.push({node:e.node,name:e.node.id.name}))}function ar(e,t){e.get("declarations").forEach(r=>{let i=r.get("init");i.isExpression()&&de(i,t)})}function lr(e,t){e.get("properties").forEach(r=>{if(r.isObjectMethod())Ve(r.node.body);else if(r.isObjectProperty()){let i=r.get("value");de(i,t)}})}function cr(e){(0,m.isBlockStatement)(e.body)||(e.body=(0,m.blockStatement)([(0,m.returnStatement)(e.body)]))}function Ve(e){e.directives.some(t=>t.value.value==="worklet")||e.directives.push((0,m.directive)((0,m.directiveLiteral)("worklet")))}function ur(e){e.properties.some(t=>(0,m.isObjectProperty)(t)&&(0,m.isIdentifier)(t.key)&&t.key.name===Ze.contextObjectMarker)||e.properties.push((0,m.objectProperty)((0,m.identifier)(`${Ze.contextObjectMarker}`),(0,m.booleanLiteral)(!0)))}function Je(e){return e.get("properties").some(n=>n.isObjectMethod()?dr(n):!1)}N.isImplicitContextObject=Je;function dr(e){let t=!1;return e.traverse({ThisExpression(n){t=!0,n.stop()}}),t}function fr(e){e.body.push((0,m.classProperty)((0,m.identifier)("__workletClass"),(0,m.booleanLiteral)(!0)))}function pr(e){let t=e.body,n=t.length,r=0;for(;r{"use strict";Object.defineProperty(ne,"__esModule",{value:!0});ne.processInlineStylesWarning=void 0;var f=require("@babel/types"),mr=M(),fe=require("assert");function yr(e){return(0,f.callExpression)((0,f.arrowFunctionExpression)([],(0,f.blockStatement)([(0,f.expressionStatement)((0,f.callExpression)((0,f.memberExpression)((0,f.identifier)("console"),(0,f.identifier)("warn")),[(0,f.callExpression)((0,f.memberExpression)((0,f.callExpression)((0,f.identifier)("require"),[(0,f.stringLiteral)("react-native-reanimated")]),(0,f.identifier)("getUseOfValueInStyleWarning")),[])])),(0,f.returnStatement)(e.node)])),[])}function kr(e){e.isMemberExpression()&&(0,f.isIdentifier)(e.node.property)&&e.node.property.name==="value"&&e.replaceWith(yr(e))}function gr(e){if((0,f.isArrayExpression)(e.node)){let t=e.get("elements");(0,fe.strict)(Array.isArray(t),"[Reanimated] `elements` should be an array.");for(let n of t)n.isObjectExpression()&&pe(n)}}function pe(e){let t=e.get("properties");for(let n of t)if(n.isObjectProperty()){let r=n.get("value");(0,f.isIdentifier)(n.node.key)&&n.node.key.name==="transform"?gr(r):kr(r)}}function _r(e,t){if((0,mr.isRelease)()||t.opts.disableInlineStylesWarning||e.node.name.name!=="style"||!(0,f.isJSXExpressionContainer)(e.node.value))return;let n=e.get("value").get("expression");if((0,fe.strict)(!Array.isArray(n),"[Reanimated] `expression` should not be an array."),n.isArrayExpression()){let r=n.get("elements");(0,fe.strict)(Array.isArray(r),"[Reanimated] `elements` should be an array.");for(let i of r)i.isObjectExpression()&&pe(i)}else n.isObjectExpression()&&pe(n)}ne.processInlineStylesWarning=_r});var Ke=b(re=>{"use strict";Object.defineProperty(re,"__esModule",{value:!0});re.substituteWebCallExpression=void 0;var Ye=require("@babel/types");function Or(e){let t=e.node.callee;if((0,Ye.isIdentifier)(t)){let n=t.name;(n==="isWeb"||n==="shouldBeUseWeb")&&e.replaceWith((0,Ye.booleanLiteral)(!0))}}re.substituteWebCallExpression=Or});Object.defineProperty(exports,"__esModule",{value:!0});var Qe=Le(),vr=Be(),hr=ue(),Er=Xe(),Sr=ae(),Ir=$e(),Wr=S(),xr=Ke(),wr=X();module.exports=function(){function e(t){try{t()}catch(n){throw new Error(`[Reanimated] Babel plugin exception: ${n}`)}}return{name:"reanimated",pre(){e(()=>{(0,Sr.initializeState)(this)})},visitor:{CallExpression:{enter(t,n){e(()=>{(0,Qe.processCalleesAutoworkletizableCallbacks)(t,n),n.opts.substituteWebPlatformChecks&&(0,xr.substituteWebCallExpression)(t)})}},[Wr.WorkletizableFunction]:{enter(t,n){e(()=>{(0,wr.processIfWithWorkletDirective)(t,n)||(0,Qe.processIfAutoworkletizableCallback)(t,n)})}},ObjectExpression:{enter(t,n){e(()=>{(0,hr.processIfWorkletContextObject)(t,n)})}},ClassDeclaration:{enter(t,n){e(()=>{(0,vr.processIfWorkletClass)(t,n)})}},Program:{enter(t,n){e(()=>{(0,Er.processIfWorkletFile)(t,n)})}},JSXAttribute:{enter(t,n){e(()=>(0,Ir.processInlineStylesWarning)(t,n))}}}}}; //# sourceMappingURL=index.js.map diff --git a/packages/react-native-reanimated/plugin/src/class.ts b/packages/react-native-reanimated/plugin/src/class.ts index 25b97331cca..ea393e7c2fa 100644 --- a/packages/react-native-reanimated/plugin/src/class.ts +++ b/packages/react-native-reanimated/plugin/src/class.ts @@ -1,5 +1,4 @@ import type { NodePath } from '@babel/core'; -import { transformSync } from '@babel/core'; import generate from '@babel/generator'; import traverse from '@babel/traverse'; import type { @@ -36,6 +35,7 @@ import { strict as assert } from 'assert'; import type { ReanimatedPluginPass } from './types'; import { workletClassFactorySuffix } from './types'; import { replaceWithFactoryCall } from './utils'; +import { workletTransformSync } from './transform'; const classWorkletMarker = '__workletClass'; @@ -43,12 +43,7 @@ export function processIfWorkletClass( classPath: NodePath, state: ReanimatedPluginPass ): boolean { - if (!classPath.node.id) { - // We don't support unnamed classes yet. - return false; - } - - if (!hasWorkletClassMarker(classPath.node.body)) { + if (!isWorkletizableClass(classPath, state)) { return false; } @@ -96,8 +91,8 @@ function getPolyfilledAst( ) { const classCode = generate(classNode).code; - const classWithPolyfills = transformSync(classCode, { - plugins: [ + const classWithPolyfills = workletTransformSync(classCode, { + extraPlugins: [ '@babel/plugin-transform-class-properties', '@babel/plugin-transform-classes', '@babel/plugin-transform-unicode-regex', @@ -342,3 +337,42 @@ type Polyfill = { index: number; dependencies: Set; }; + +function isWorkletizableClass( + classPath: NodePath, + state: ReanimatedPluginPass +): boolean { + const className = classPath.node.id?.name; + const classNode = classPath.node; + + // We don't support unnamed classes yet. + if (!className) { + return false; + } + + // Primary method of determining if a class is workletizable. However, some + // Babel plugins might remove Class Properties. + const isMarked = hasWorkletClassMarker(classNode.body); + + // Secondary method of determining if a class is workletizable. We look for the + // reference we memoized earlier. However, some plugin could've changed the reference. + const isMemoizedNode = state.classesToWorkletize.some( + (record) => record.node === classNode + ); + + // Fallback for the name of the class. + // We bail on non-top-level declarations. + const isTopLevelMemoizedName = + classPath.parentPath.isProgram() && + state.classesToWorkletize.some((record) => record.name === className); + + // Remove the class from the list of classes to workletize. There are some edge + // cases when leaving it as is would lead to multiple workletizations. + state.classesToWorkletize = state.classesToWorkletize.filter( + (record) => record.node !== classNode && record.name !== className + ); + + const result = isMarked || isMemoizedNode || isTopLevelMemoizedName; + + return result; +} diff --git a/packages/react-native-reanimated/plugin/src/file.ts b/packages/react-native-reanimated/plugin/src/file.ts index 3e8fc1f210f..c7ddd6c260e 100644 --- a/packages/react-native-reanimated/plugin/src/file.ts +++ b/packages/react-native-reanimated/plugin/src/file.ts @@ -36,7 +36,7 @@ import { contextObjectMarker } from './contextObject'; export function processIfWorkletFile( path: NodePath, - _state: ReanimatedPluginPass + state: ReanimatedPluginPass ): boolean { if ( !path.node.directives.some( @@ -50,18 +50,21 @@ export function processIfWorkletFile( path.node.directives = path.node.directives.filter( (functionDirective) => functionDirective.value.value !== 'worklet' ); - processWorkletFile(path); + processWorkletFile(path, state); return true; } /** Adds a worklet directive to each viable top-level entity in the file. */ -function processWorkletFile(programPath: NodePath) { +function processWorkletFile( + programPath: NodePath, + state: ReanimatedPluginPass +) { const statements = programPath.get('body'); dehoistCommonJSExports(programPath.node); statements.forEach((statement) => { const candidatePath = getCandidate(statement); - processWorkletizableEntity(candidatePath); + processWorkletizableEntity(candidatePath, state); }); } @@ -76,7 +79,10 @@ function getCandidate(statementPath: NodePath) { } } -function processWorkletizableEntity(nodePath: NodePath) { +function processWorkletizableEntity( + nodePath: NodePath, + state: ReanimatedPluginPass +) { if (isWorkletizableFunctionPath(nodePath)) { if (nodePath.isArrowFunctionExpression()) { replaceImplicitReturnWithBlock(nodePath.node); @@ -86,35 +92,46 @@ function processWorkletizableEntity(nodePath: NodePath) { if (isImplicitContextObject(nodePath)) { appendWorkletContextObjectMarker(nodePath.node); } else { - processWorkletAggregator(nodePath); + processWorkletAggregator(nodePath, state); } } else if (nodePath.isVariableDeclaration()) { - processVariableDeclaration(nodePath); + processVariableDeclaration(nodePath, state); } else if (nodePath.isClassDeclaration()) { appendWorkletClassMarker(nodePath.node.body); + if (nodePath.node.id?.name) { + // We don't support unnamed classes yet. + state.classesToWorkletize.push({ + node: nodePath.node, + name: nodePath.node.id.name, + }); + } } } function processVariableDeclaration( - variableDeclarationPath: NodePath + variableDeclarationPath: NodePath, + state: ReanimatedPluginPass ) { const declarations = variableDeclarationPath.get('declarations'); declarations.forEach((declaration) => { const initPath = declaration.get('init'); if (initPath.isExpression()) { - processWorkletizableEntity(initPath); + processWorkletizableEntity(initPath, state); } }); } -function processWorkletAggregator(objectPath: NodePath) { +function processWorkletAggregator( + objectPath: NodePath, + state: ReanimatedPluginPass +) { const properties = objectPath.get('properties'); properties.forEach((property) => { if (property.isObjectMethod()) { appendWorkletDirective(property.node.body); } else if (property.isObjectProperty()) { const valuePath = property.get('value'); - processWorkletizableEntity(valuePath); + processWorkletizableEntity(valuePath, state); } }); } diff --git a/packages/react-native-reanimated/plugin/src/globals.ts b/packages/react-native-reanimated/plugin/src/globals.ts index 8650696b5eb..fca642e17b1 100644 --- a/packages/react-native-reanimated/plugin/src/globals.ts +++ b/packages/react-native-reanimated/plugin/src/globals.ts @@ -1,3 +1,5 @@ +import type { ReanimatedPluginPass } from './types'; + const notCapturedIdentifiers = [ // Based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects @@ -152,6 +154,13 @@ const notCapturedIdentifiers_DEPRECATED = [ '_getAnimationTimestamp', ]; +export function initializeState(state: ReanimatedPluginPass) { + state.workletNumber = 1; + state.classesToWorkletize = []; + initializeGlobals(); + addCustomGlobals(state); +} + export const defaultGlobals = new Set( notCapturedIdentifiers.concat(notCapturedIdentifiers_DEPRECATED) ); @@ -161,3 +170,23 @@ export let globals: Set; export function initializeGlobals() { globals = new Set(defaultGlobals); } + +/** + * This function allows to add custom globals such as host-functions. Those + * globals have to be passed as an argument for the plugin in babel.config.js. + * + * For example: + * + * ```js + * plugins: [ + * ['react-native-reanimated/plugin', { globals: ['myHostFunction'] }], + * ]; + * ``` + */ +export function addCustomGlobals(state: ReanimatedPluginPass) { + if (state.opts && Array.isArray(state.opts.globals)) { + state.opts.globals.forEach((name: string) => { + globals.add(name); + }); + } +} diff --git a/packages/react-native-reanimated/plugin/src/plugin.ts b/packages/react-native-reanimated/plugin/src/plugin.ts index ce6b056c792..25e36580e33 100644 --- a/packages/react-native-reanimated/plugin/src/plugin.ts +++ b/packages/react-native-reanimated/plugin/src/plugin.ts @@ -10,16 +10,15 @@ import { processCalleesAutoworkletizableCallbacks, processIfAutoworkletizableCallback, } from './autoworkletization'; +import { processIfWorkletClass } from './class'; import { processIfWorkletContextObject } from './contextObject'; import { processIfWorkletFile } from './file'; -import { initializeGlobals } from './globals'; +import { initializeState } from './globals'; import { processInlineStylesWarning } from './inlineStylesWarning'; import type { ReanimatedPluginPass } from './types'; import { WorkletizableFunction } from './types'; -import { addCustomGlobals } from './utils'; import { substituteWebCallExpression } from './webOptimization'; import { processIfWithWorkletDirective } from './workletSubstitution'; -import { processIfWorkletClass } from './class'; module.exports = function (): PluginItem { function runWithTaggedExceptions(fun: () => void) { @@ -31,12 +30,11 @@ module.exports = function (): PluginItem { } return { - pre(state: ReanimatedPluginPass) { + name: 'reanimated', + + pre(this: ReanimatedPluginPass) { runWithTaggedExceptions(() => { - // Initialize worklet number. - state.workletNumber = 1; - initializeGlobals(); - addCustomGlobals.call(this); + initializeState(this); }); }, visitor: { @@ -78,8 +76,6 @@ module.exports = function (): PluginItem { Program: { enter(path: NodePath, state: ReanimatedPluginPass) { runWithTaggedExceptions(() => { - // Reset worklet number. - state.workletNumber = 1; processIfWorkletFile(path, state); }); }, diff --git a/packages/react-native-reanimated/plugin/src/transform.ts b/packages/react-native-reanimated/plugin/src/transform.ts new file mode 100644 index 00000000000..44cbfa4f0ea --- /dev/null +++ b/packages/react-native-reanimated/plugin/src/transform.ts @@ -0,0 +1,28 @@ +import { transformSync } from '@babel/core'; +import type { PluginItem, TransformOptions } from '@babel/core'; + +export function workletTransformSync( + code: string, + opts: WorkletTransformOptions +) { + const { extraPlugins = [], extraPresets = [], ...rest } = opts; + + return transformSync(code, { + ...rest, + plugins: [...defaultPlugins, ...extraPlugins], + presets: [...defaultPresets, ...extraPresets], + }); +} + +const defaultPresets: PluginItem[] = [ + require.resolve('@babel/preset-typescript'), +]; + +const defaultPlugins: PluginItem[] = []; + +interface WorkletTransformOptions + extends Omit { + extraPlugins?: PluginItem[]; + extraPresets?: PluginItem[]; + filename: TransformOptions['filename']; +} diff --git a/packages/react-native-reanimated/plugin/src/types.ts b/packages/react-native-reanimated/plugin/src/types.ts index d7b96e041cd..3fabd70de62 100644 --- a/packages/react-native-reanimated/plugin/src/types.ts +++ b/packages/react-native-reanimated/plugin/src/types.ts @@ -31,10 +31,8 @@ export interface ReanimatedPluginPass { opts: ReanimatedPluginOptions; cwd: string; filename: string | undefined; - get(key: unknown): unknown; - set(key: unknown, value: unknown): void; workletNumber: number; - [key: string]: unknown; + classesToWorkletize: { node: BabelNode; name: string }[]; } export type WorkletizableFunction = diff --git a/packages/react-native-reanimated/plugin/src/utils.ts b/packages/react-native-reanimated/plugin/src/utils.ts index 0f9b9d3fec0..0246faddffc 100644 --- a/packages/react-native-reanimated/plugin/src/utils.ts +++ b/packages/react-native-reanimated/plugin/src/utils.ts @@ -7,8 +7,6 @@ import { variableDeclaration, variableDeclarator, } from '@babel/types'; -import { globals } from './globals'; -import type { ReanimatedPluginPass } from './types'; export function isRelease() { const pattern = /(prod|release|stag[ei])/i; @@ -18,26 +16,6 @@ export function isRelease() { ); } -/** - * This function allows to add custom globals such as host-functions. Those - * globals have to be passed as an argument for the plugin in babel.config.js. - * - * For example: - * - * ```js - * plugins: [ - * ['react-native-reanimated/plugin', { globals: ['myHostFunction'] }], - * ]; - * ``` - */ -export function addCustomGlobals(this: ReanimatedPluginPass) { - if (this.opts && Array.isArray(this.opts.globals)) { - this.opts.globals.forEach((name: string) => { - globals.add(name); - }); - } -} - /** * This function replaces the node with a factory call while making sure that * it's a legal operation. If the node cannot be simply replaced with a factory diff --git a/packages/react-native-reanimated/plugin/src/workletFactory.ts b/packages/react-native-reanimated/plugin/src/workletFactory.ts index d8652e446da..8a3dfe9f2e9 100644 --- a/packages/react-native-reanimated/plugin/src/workletFactory.ts +++ b/packages/react-native-reanimated/plugin/src/workletFactory.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-var-requires */ import type { NodePath } from '@babel/core'; -import { transformSync, traverse } from '@babel/core'; +import { traverse } from '@babel/core'; import generate from '@babel/generator'; import type { File as BabelFile, @@ -44,25 +44,11 @@ import type { ReanimatedPluginPass, WorkletizableFunction } from './types'; import { workletClassFactorySuffix } from './types'; import { isRelease } from './utils'; import { buildWorkletString } from './workletStringCode'; +import { workletTransformSync } from './transform'; const REAL_VERSION = require('../../package.json').version; const MOCK_VERSION = 'x.y.z'; -const workletStringTransformPresets = [ - require.resolve('@babel/preset-typescript'), -]; - -const workletStringTransformPlugins = [ - require.resolve('@babel/plugin-transform-shorthand-properties'), - require.resolve('@babel/plugin-transform-arrow-functions'), - require.resolve('@babel/plugin-transform-optional-chaining'), - require.resolve('@babel/plugin-transform-nullish-coalescing-operator'), - [ - require.resolve('@babel/plugin-transform-template-literals'), - { loose: true }, - ], -]; - export function makeWorkletFactory( fun: NodePath, state: ReanimatedPluginPass @@ -91,10 +77,9 @@ export function makeWorkletFactory( codeObject.code = '(' + (fun.isObjectMethod() ? 'function ' : '') + codeObject.code + '\n)'; - const transformed = transformSync(codeObject.code, { + const transformed = workletTransformSync(codeObject.code, { + extraPlugins, filename: state.file.opts.filename, - presets: workletStringTransformPresets, - plugins: workletStringTransformPlugins, ast: true, babelrc: false, configFile: false, @@ -469,3 +454,14 @@ function makeArrayFromCapturedBindings( return Array.from(closure.values()); } + +const extraPlugins = [ + require.resolve('@babel/plugin-transform-shorthand-properties'), + require.resolve('@babel/plugin-transform-arrow-functions'), + require.resolve('@babel/plugin-transform-optional-chaining'), + require.resolve('@babel/plugin-transform-nullish-coalescing-operator'), + [ + require.resolve('@babel/plugin-transform-template-literals'), + { loose: true }, + ], +]; diff --git a/packages/react-native-reanimated/plugin/src/workletStringCode.ts b/packages/react-native-reanimated/plugin/src/workletStringCode.ts index 113ee52f133..f1b7e108c83 100644 --- a/packages/react-native-reanimated/plugin/src/workletStringCode.ts +++ b/packages/react-native-reanimated/plugin/src/workletStringCode.ts @@ -1,5 +1,5 @@ import type { BabelFileResult, NodePath, PluginItem } from '@babel/core'; -import { transformSync, traverse } from '@babel/core'; +import { traverse } from '@babel/core'; import generate from '@babel/generator'; import type { File as BabelFile, @@ -34,6 +34,7 @@ import * as fs from 'fs'; import type { ReanimatedPluginPass, WorkletizableFunction } from './types'; import { workletClassFactorySuffix } from './types'; import { isRelease } from './utils'; +import { workletTransformSync } from './transform'; const MOCK_SOURCE_MAP = 'mock source map'; @@ -130,8 +131,9 @@ export function buildWorkletString( } } - const transformed = transformSync(code, { - plugins: [prependClosureVariablesIfNecessary(closureVariables)], + const transformed = workletTransformSync(code, { + filename: state.file.opts.filename, + extraPlugins: [getClosurePlugin(closureVariables)], compact: true, sourceMaps: includeSourceMap, inputSourceMap: inputMap, @@ -222,9 +224,8 @@ function prependRecursiveDeclaration(path: NodePath) { } } -function prependClosureVariablesIfNecessary( - closureVariables: Array -): PluginItem { +/** Prepends necessary closure variables to the worklet function. */ +function getClosurePlugin(closureVariables: Array): PluginItem { const closureDeclaration = variableDeclaration('const', [ variableDeclarator( objectPattern( diff --git a/packages/react-native-reanimated/src/animation/util.ts b/packages/react-native-reanimated/src/animation/util.ts index 0446d142532..39e4c5a5042 100644 --- a/packages/react-native-reanimated/src/animation/util.ts +++ b/packages/react-native-reanimated/src/animation/util.ts @@ -527,7 +527,9 @@ export function defineAnimation< if (_WORKLET || SHOULD_BE_USE_WEB) { return create(); } - // @ts-ignore: eslint-disable-line + create.__isAnimationDefinition = true; + + // @ts-expect-error it's fine return create; } diff --git a/packages/react-native-reanimated/src/mutables.ts b/packages/react-native-reanimated/src/mutables.ts index 617c1853f2f..4a05b56b103 100644 --- a/packages/react-native-reanimated/src/mutables.ts +++ b/packages/react-native-reanimated/src/mutables.ts @@ -58,10 +58,14 @@ function addCompilerSafeGetAndSet(mutable: PartialMutable): void { }, set: { value(newValue: Value | ((value: Value) => Value)) { - if (typeof newValue === 'function') { + if ( + typeof newValue === 'function' && + // If we have an animation definition, we don't want to call it here. + !(newValue as Record).__isAnimationDefinition + ) { mutable.value = (newValue as (value: Value) => Value)(mutable.value); } else { - mutable.value = newValue; + mutable.value = newValue as Value; } }, configurable: false, diff --git a/packages/react-native-reanimated/src/platform-specific/jsVersion.ts b/packages/react-native-reanimated/src/platform-specific/jsVersion.ts index d343a77362d..018cc1bbc6d 100644 --- a/packages/react-native-reanimated/src/platform-specific/jsVersion.ts +++ b/packages/react-native-reanimated/src/platform-specific/jsVersion.ts @@ -4,4 +4,4 @@ * version used to build the native part of the library in runtime. Remember to * keep this in sync with the version declared in `package.json` */ -export const jsVersion = '3.16.1'; +export const jsVersion = '3.16.2';