react-native-reanimated 3.9.0-rc.0 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Common/cpp/Fabric/ShadowTreeCloner.cpp +2 -1
- package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +11 -4
- package/android/src/main/java/com/swmansion/reanimated/NodesManager.java +5 -3
- package/apple/REAModule.mm +14 -29
- package/apple/REANodesManager.mm +7 -6
- package/lib/module/Animated.js.map +1 -1
- package/lib/module/ConfigHelper.js.map +1 -1
- package/lib/module/animationBuilder.js.map +1 -1
- package/lib/module/createAnimatedComponent/InlinePropManager.js +2 -2
- package/lib/module/createAnimatedComponent/InlinePropManager.js.map +1 -1
- package/lib/module/createAnimatedComponent/JSPropsUpdater.js +4 -4
- package/lib/module/createAnimatedComponent/JSPropsUpdater.js.map +1 -1
- package/lib/module/createAnimatedComponent/JSPropsUpdater.web.js.map +1 -1
- package/lib/module/createAnimatedComponent/PropsFilter.js +5 -5
- package/lib/module/createAnimatedComponent/PropsFilter.js.map +1 -1
- package/lib/module/createAnimatedComponent/commonTypes.js.map +1 -1
- package/lib/module/createAnimatedComponent/createAnimatedComponent.js +33 -33
- package/lib/module/createAnimatedComponent/createAnimatedComponent.js.map +1 -1
- package/lib/module/createAnimatedComponent/getViewInfo.js +2 -2
- package/lib/module/createAnimatedComponent/getViewInfo.js.map +1 -1
- package/lib/module/createAnimatedComponent/index.js.map +1 -1
- package/lib/module/createAnimatedComponent/setAndForwardRef.js +4 -5
- package/lib/module/createAnimatedComponent/setAndForwardRef.js.map +1 -1
- package/lib/module/createAnimatedComponent/utils.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +1 -2
- package/lib/module/index.web.js.map +1 -1
- package/lib/module/mock.js +3 -8
- package/lib/module/mock.js.map +1 -1
- package/lib/module/propsAllowlists.js.map +1 -1
- package/lib/module/reanimated2/Bezier.js.map +1 -1
- package/lib/module/reanimated2/Colors.js +4 -11
- package/lib/module/reanimated2/Colors.js.map +1 -1
- package/lib/module/reanimated2/Easing.js +3 -7
- package/lib/module/reanimated2/Easing.js.map +1 -1
- package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js +3 -3
- package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
- package/lib/module/reanimated2/NativeReanimated/index.js.map +1 -1
- package/lib/module/reanimated2/NativeReanimated/index.web.js.map +1 -1
- package/lib/module/reanimated2/PlatformChecker.js +1 -0
- package/lib/module/reanimated2/PlatformChecker.js.map +1 -1
- package/lib/module/reanimated2/PropAdapters.js +1 -1
- package/lib/module/reanimated2/PropAdapters.js.map +1 -1
- package/lib/module/reanimated2/PropsRegistry.js.map +1 -1
- package/lib/module/reanimated2/Sensor.js +2 -2
- package/lib/module/reanimated2/Sensor.js.map +1 -1
- package/lib/module/reanimated2/SensorContainer.js +2 -2
- package/lib/module/reanimated2/SensorContainer.js.map +1 -1
- package/lib/module/reanimated2/UpdateLayoutAnimations.js.map +1 -1
- package/lib/module/reanimated2/UpdateProps.js.map +1 -1
- package/lib/module/reanimated2/ViewDescriptorsSet.js.map +1 -1
- package/lib/module/reanimated2/WorkletEventHandler.js +74 -31
- package/lib/module/reanimated2/WorkletEventHandler.js.map +1 -1
- package/lib/module/reanimated2/animation/clamp.js.map +1 -1
- package/lib/module/reanimated2/animation/commonTypes.js.map +1 -1
- package/lib/module/reanimated2/animation/decay/decay.js.map +1 -1
- package/lib/module/reanimated2/animation/decay/index.js.map +1 -1
- package/lib/module/reanimated2/animation/decay/rigidDecay.js.map +1 -1
- package/lib/module/reanimated2/animation/decay/rubberBandDecay.js.map +1 -1
- package/lib/module/reanimated2/animation/decay/utils.js.map +1 -1
- package/lib/module/reanimated2/animation/delay.js.map +1 -1
- package/lib/module/reanimated2/animation/index.js.map +1 -1
- package/lib/module/reanimated2/animation/repeat.js +1 -6
- package/lib/module/reanimated2/animation/repeat.js.map +1 -1
- package/lib/module/reanimated2/animation/sequence.js +1 -5
- package/lib/module/reanimated2/animation/sequence.js.map +1 -1
- package/lib/module/reanimated2/animation/spring.js.map +1 -1
- package/lib/module/reanimated2/animation/springUtils.js +8 -10
- package/lib/module/reanimated2/animation/springUtils.js.map +1 -1
- package/lib/module/reanimated2/animation/styleAnimation.js +5 -4
- package/lib/module/reanimated2/animation/styleAnimation.js.map +1 -1
- package/lib/module/reanimated2/animation/timing.js.map +1 -1
- package/lib/module/reanimated2/animation/transformationMatrix/matrixUtils.js +1 -2
- package/lib/module/reanimated2/animation/transformationMatrix/matrixUtils.js.map +1 -1
- package/lib/module/reanimated2/animation/util.js.map +1 -1
- package/lib/module/reanimated2/commonTypes.js +2 -0
- package/lib/module/reanimated2/commonTypes.js.map +1 -1
- package/lib/module/reanimated2/component/FlatList.js +1 -0
- package/lib/module/reanimated2/component/FlatList.js.map +1 -1
- package/lib/module/reanimated2/component/Image.js +1 -0
- package/lib/module/reanimated2/component/Image.js.map +1 -1
- package/lib/module/reanimated2/component/LayoutAnimationConfig.js +1 -0
- package/lib/module/reanimated2/component/LayoutAnimationConfig.js.map +1 -1
- package/lib/module/reanimated2/component/PerformanceMonitor.js +3 -4
- package/lib/module/reanimated2/component/PerformanceMonitor.js.map +1 -1
- package/lib/module/reanimated2/component/ScrollView.js +1 -0
- package/lib/module/reanimated2/component/ScrollView.js.map +1 -1
- package/lib/module/reanimated2/component/Text.js +1 -0
- package/lib/module/reanimated2/component/Text.js.map +1 -1
- package/lib/module/reanimated2/component/View.js +1 -0
- package/lib/module/reanimated2/component/View.js.map +1 -1
- package/lib/module/reanimated2/core.js +2 -4
- package/lib/module/reanimated2/core.js.map +1 -1
- package/lib/module/reanimated2/errors.js +7 -8
- package/lib/module/reanimated2/errors.js.map +1 -1
- package/lib/module/reanimated2/fabricUtils.js +4 -4
- package/lib/module/reanimated2/fabricUtils.js.map +1 -1
- package/lib/module/reanimated2/fabricUtils.web.js.map +1 -1
- package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryJS.js +2 -2
- package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryJS.js.map +1 -1
- package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
- package/lib/module/reanimated2/frameCallback/index.js.map +1 -1
- package/lib/module/reanimated2/globals.d.js.map +1 -1
- package/lib/module/reanimated2/helperTypes.js.map +1 -1
- package/lib/module/reanimated2/hook/commonTypes.js.map +1 -1
- package/lib/module/reanimated2/hook/index.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedGestureHandler.js +1 -0
- package/lib/module/reanimated2/hook/useAnimatedGestureHandler.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedKeyboard.js +3 -4
- package/lib/module/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedProps.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedReaction.js +1 -0
- package/lib/module/reanimated2/hook/useAnimatedReaction.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedRef.js +1 -1
- package/lib/module/reanimated2/hook/useAnimatedRef.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedScrollHandler.js +3 -1
- package/lib/module/reanimated2/hook/useAnimatedScrollHandler.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedSensor.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedStyle.js +3 -6
- package/lib/module/reanimated2/hook/useAnimatedStyle.js.map +1 -1
- package/lib/module/reanimated2/hook/useDerivedValue.js +3 -1
- package/lib/module/reanimated2/hook/useDerivedValue.js.map +1 -1
- package/lib/module/reanimated2/hook/useEvent.js +4 -5
- package/lib/module/reanimated2/hook/useEvent.js.map +1 -1
- package/lib/module/reanimated2/hook/useFrameCallback.js +1 -2
- package/lib/module/reanimated2/hook/useFrameCallback.js.map +1 -1
- package/lib/module/reanimated2/hook/useHandler.js +3 -1
- package/lib/module/reanimated2/hook/useHandler.js.map +1 -1
- package/lib/module/reanimated2/hook/useReducedMotion.js.map +1 -1
- package/lib/module/reanimated2/hook/useScrollViewOffset.js +14 -6
- package/lib/module/reanimated2/hook/useScrollViewOffset.js.map +1 -1
- package/lib/module/reanimated2/hook/useSharedValue.js.map +1 -1
- package/lib/module/reanimated2/hook/useWorkletCallback.js.map +1 -1
- package/lib/module/reanimated2/hook/utils.js.map +1 -1
- package/lib/module/reanimated2/index.js.map +1 -1
- package/lib/module/reanimated2/initializers.js +1 -5
- package/lib/module/reanimated2/initializers.js.map +1 -1
- package/lib/module/reanimated2/interpolateColor.js +2 -6
- package/lib/module/reanimated2/interpolateColor.js.map +1 -1
- package/lib/module/reanimated2/interpolation.js +1 -1
- package/lib/module/reanimated2/interpolation.js.map +1 -1
- package/lib/module/reanimated2/isSharedValue.js.map +1 -1
- package/lib/module/reanimated2/jestUtils.js +3 -6
- package/lib/module/reanimated2/jestUtils.js.map +1 -1
- package/lib/module/reanimated2/jestUtils.web.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/JSReanimated.js +4 -5
- package/lib/module/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/WebSensor.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/index.js +2 -2
- package/lib/module/reanimated2/js-reanimated/index.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/react-native-web.d.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js +4 -2
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +8 -11
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/Keyframe.js +8 -9
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/Keyframe.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationsManager.js +1 -2
- package/lib/module/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +22 -22
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Fade.js +22 -22
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Fade.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Flip.js +26 -26
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Flip.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +10 -10
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +6 -6
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js +10 -10
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +18 -18
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Rotate.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js +18 -18
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +10 -10
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Stretch.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +34 -34
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +4 -4
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +4 -4
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +4 -4
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +4 -4
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +4 -4
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +4 -4
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/sharedTransitions/ProgressTransitionManager.js +4 -6
- package/lib/module/reanimated2/layoutReanimation/sharedTransitions/ProgressTransitionManager.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/sharedTransitions/SharedTransition.js +4 -6
- package/lib/module/reanimated2/layoutReanimation/sharedTransitions/SharedTransition.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/sharedTransitions/SharedTransition.web.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/web/animation/Bounce.web.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/web/animation/Fade.web.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/web/animation/Flip.web.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/web/animation/Lightspeed.web.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/web/animation/Pinwheel.web.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/web/animation/Roll.web.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/web/animation/Rotate.web.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/web/animation/Slide.web.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/web/animation/Stretch.web.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/web/animation/Zoom.web.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/web/animationParser.js +0 -2
- package/lib/module/reanimated2/layoutReanimation/web/animationParser.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/web/animationsManager.js +1 -2
- package/lib/module/reanimated2/layoutReanimation/web/animationsManager.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/web/componentStyle.js +3 -1
- package/lib/module/reanimated2/layoutReanimation/web/componentStyle.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/web/componentUtils.js +6 -7
- package/lib/module/reanimated2/layoutReanimation/web/componentUtils.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/web/config.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/web/createAnimation.js +2 -2
- package/lib/module/reanimated2/layoutReanimation/web/createAnimation.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/web/domUtils.js +4 -4
- package/lib/module/reanimated2/layoutReanimation/web/domUtils.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/web/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/web/transition/Fading.web.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/web/transition/Linear.web.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/web/transition/Sequenced.web.js.map +1 -1
- package/lib/module/reanimated2/mappers.js +2 -4
- package/lib/module/reanimated2/mappers.js.map +1 -1
- package/lib/module/reanimated2/mockedRequestAnimationFrame.js.map +1 -1
- package/lib/module/reanimated2/mutables.js +2 -4
- package/lib/module/reanimated2/mutables.js.map +1 -1
- package/lib/module/reanimated2/platform-specific/RNRenderer.js.map +1 -1
- package/lib/module/reanimated2/platform-specific/RNRenderer.web.js.map +1 -1
- package/lib/module/reanimated2/platform-specific/checkCppVersion.js.map +1 -1
- package/lib/module/reanimated2/platform-specific/jsVersion.js +1 -1
- package/lib/module/reanimated2/platform-specific/jsVersion.js.map +1 -1
- package/lib/module/reanimated2/platformFunctions/dispatchCommand.js +2 -4
- package/lib/module/reanimated2/platformFunctions/dispatchCommand.js.map +1 -1
- package/lib/module/reanimated2/platformFunctions/dispatchCommand.web.js.map +1 -1
- package/lib/module/reanimated2/platformFunctions/getRelativeCoords.js +2 -2
- package/lib/module/reanimated2/platformFunctions/getRelativeCoords.js.map +1 -1
- package/lib/module/reanimated2/platformFunctions/index.js.map +1 -1
- package/lib/module/reanimated2/platformFunctions/measure.js.map +1 -1
- package/lib/module/reanimated2/platformFunctions/measure.web.js.map +1 -1
- package/lib/module/reanimated2/platformFunctions/scrollTo.js.map +1 -1
- package/lib/module/reanimated2/platformFunctions/scrollTo.web.js +1 -1
- package/lib/module/reanimated2/platformFunctions/scrollTo.web.js.map +1 -1
- package/lib/module/reanimated2/platformFunctions/setGestureState.js.map +1 -1
- package/lib/module/reanimated2/platformFunctions/setGestureState.web.js.map +1 -1
- package/lib/module/reanimated2/platformFunctions/setNativeProps.js.map +1 -1
- package/lib/module/reanimated2/platformFunctions/setNativeProps.web.js.map +1 -1
- package/lib/module/reanimated2/pluginUtils.js.map +1 -1
- package/lib/module/reanimated2/publicGlobals.js.map +1 -1
- package/lib/module/reanimated2/runtimes.js +11 -19
- package/lib/module/reanimated2/runtimes.js.map +1 -1
- package/lib/module/reanimated2/screenTransition/RNScreensTurboModule.js.map +1 -1
- package/lib/module/reanimated2/screenTransition/animationManager.js.map +1 -1
- package/lib/module/reanimated2/screenTransition/commonTypes.js.map +1 -1
- package/lib/module/reanimated2/screenTransition/index.js.map +1 -1
- package/lib/module/reanimated2/screenTransition/presets.js.map +1 -1
- package/lib/module/reanimated2/screenTransition/styleUpdater.js.map +1 -1
- package/lib/module/reanimated2/screenTransition/swipeSimulator.js +1 -1
- package/lib/module/reanimated2/screenTransition/swipeSimulator.js.map +1 -1
- package/lib/module/reanimated2/shareableMappingCache.js.map +1 -1
- package/lib/module/reanimated2/shareables.js +2 -4
- package/lib/module/reanimated2/shareables.js.map +1 -1
- package/lib/module/reanimated2/threads.js +9 -34
- package/lib/module/reanimated2/threads.js.map +1 -1
- package/lib/module/reanimated2/valueSetter.js +1 -2
- package/lib/module/reanimated2/valueSetter.js.map +1 -1
- package/lib/module/reanimated2/valueUnpacker.js.map +1 -1
- package/lib/module/specs/NativeReanimatedModule.js.map +1 -1
- package/lib/typescript/reanimated2/WorkletEventHandler.d.ts +16 -9
- package/lib/typescript/reanimated2/component/LayoutAnimationConfig.d.ts +1 -1
- package/lib/typescript/reanimated2/component/PerformanceMonitor.d.ts +2 -1
- package/lib/typescript/reanimated2/hook/commonTypes.d.ts +5 -0
- package/lib/typescript/reanimated2/hook/useEvent.d.ts +2 -3
- package/lib/typescript/reanimated2/platform-specific/jsVersion.d.ts +1 -1
- package/package.json +18 -14
- package/plugin/build/plugin.js +7 -2
- package/src/createAnimatedComponent/PropsFilter.tsx +1 -1
- package/src/createAnimatedComponent/createAnimatedComponent.tsx +29 -33
- package/src/reanimated2/WorkletEventHandler.ts +98 -39
- package/src/reanimated2/animation/styleAnimation.ts +8 -6
- package/src/reanimated2/hook/commonTypes.ts +9 -0
- package/src/reanimated2/hook/useEvent.ts +4 -4
- package/src/reanimated2/hook/useScrollViewOffset.ts +21 -5
- package/src/reanimated2/js-reanimated/JSReanimated.ts +6 -3
- package/src/reanimated2/layoutReanimation/web/animationsManager.ts +1 -1
- package/src/reanimated2/layoutReanimation/web/componentStyle.ts +3 -1
- package/src/reanimated2/layoutReanimation/web/componentUtils.ts +1 -1
- package/src/reanimated2/layoutReanimation/web/createAnimation.ts +2 -2
- package/src/reanimated2/platform-specific/jsVersion.ts +1 -1
- package/src/reanimated2/platformFunctions/getRelativeCoords.ts +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeReanimatedModule","isWorkletFunction","shouldBeUseWeb","registerWorkletStackDetails","jsVersion","shareableMappingCache","shareableMappingFlag","SHOULD_BE_USE_WEB","MAGIC_KEY","isHostObject","value","isPlainJSObject","object","Object","getPrototypeOf","prototype","INACCESSIBLE_OBJECT","__init","Proxy","get","_","prop","Error","String","set","VALID_ARRAY_VIEWS_NAMES","DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD","processedObjectAtThresholdDepth","makeShareableCloneRecursive","shouldPersistRemote","arguments","length","undefined","depth","type","isTypeObject","isTypeFunction","cached","toAdapt","Array","isArray","map","element","__DEV__","babelVersion","__initData","version","getWorkletCode","__workletHash","__stackDetails","key","entries","RegExp","pattern","source","flags","handle","name","message","stack","error","ArrayBuffer","isView","buffer","typeName","constructor","includes","global","inaccessibleObject","freeze","adopted","makeShareableClone","WORKLET_CODE_THRESHOLD","_value$__initData","code","substring","isRemoteFunction","__remoteFunction","makeShareableCloneOnUIRecursive","cloneRecursive","_makeShareableClone","makeShareableJS","makeShareableNative","makeShareable"],"sources":["shareables.ts"],"sourcesContent":["'use strict';\nimport NativeReanimatedModule from './NativeReanimated';\nimport { isWorkletFunction } from './commonTypes';\nimport type {\n ShareableRef,\n FlatShareableRef,\n WorkletFunction,\n} from './commonTypes';\nimport { shouldBeUseWeb } from './PlatformChecker';\nimport { registerWorkletStackDetails } from './errors';\nimport { jsVersion } from './platform-specific/jsVersion';\nimport {\n shareableMappingCache,\n shareableMappingFlag,\n} from './shareableMappingCache';\n\n// for web/chrome debugger/jest environments this file provides a stub implementation\n// where no shareable references are used. Instead, the objects themselves are used\n// instead of shareable references, because of the fact that we don't have to deal with\n// runnning the code on separate VMs.\nconst SHOULD_BE_USE_WEB = shouldBeUseWeb();\n\nconst MAGIC_KEY = 'REANIMATED_MAGIC_KEY';\n\nfunction isHostObject(value: NonNullable<object>) {\n 'worklet';\n // We could use JSI to determine whether an object is a host object, however\n // the below workaround works well and is way faster than an additional JSI call.\n // We use the fact that host objects have broken implementation of `hasOwnProperty`\n // and hence return true for all `in` checks regardless of the key we ask for.\n return MAGIC_KEY in value;\n}\n\nfunction isPlainJSObject(object: object) {\n return Object.getPrototypeOf(object) === Object.prototype;\n}\n\n// The below object is used as a replacement for objects that cannot be transferred\n// as shareable values. In makeShareableCloneRecursive we detect if an object is of\n// a plain Object.prototype and only allow such objects to be transferred. This lets\n// us avoid all sorts of react internals from leaking into the UI runtime. To make it\n// possible to catch errors when someone actually tries to access such object on the UI\n// runtime, we use the below Proxy object which is instantiated on the UI runtime and\n// throws whenever someone tries to access its fields.\nconst INACCESSIBLE_OBJECT = {\n __init: () => {\n 'worklet';\n return new Proxy(\n {},\n {\n get: (_: unknown, prop: string | symbol) => {\n if (\n prop === '_isReanimatedSharedValue' ||\n prop === '__remoteFunction'\n ) {\n // not very happy about this check here, but we need to allow for\n // \"inaccessible\" objects to be tested with isSharedValue check\n // as it is being used in the mappers when extracting inputs recursively\n // as well as with isRemoteFunction when cloning objects recursively.\n // Apparently we can't check if a key exists there as HostObjects always\n // return true for such tests, so the only possibility for us is to\n // actually access that key and see if it is set to true. We therefore\n // need to allow for this key to be accessed here.\n return false;\n }\n throw new Error(\n `[Reanimated] Trying to access property \\`${String(\n prop\n )}\\` of an object which cannot be sent to the UI runtime.`\n );\n },\n set: () => {\n throw new Error(\n '[Reanimated] Trying to write to an object which cannot be sent to the UI runtime.'\n );\n },\n }\n );\n },\n};\n\nconst VALID_ARRAY_VIEWS_NAMES = [\n 'Int8Array',\n 'Uint8Array',\n 'Uint8ClampedArray',\n 'Int16Array',\n 'Uint16Array',\n 'Int32Array',\n 'Uint32Array',\n 'Float32Array',\n 'Float64Array',\n 'BigInt64Array',\n 'BigUint64Array',\n 'DataView',\n];\n\nconst DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD = 30;\n// Below variable stores object that we process in makeShareableCloneRecursive at the specified depth.\n// We use it to check if later on the function reenters with the same object\nlet processedObjectAtThresholdDepth: unknown;\n\nexport function makeShareableCloneRecursive<T>(\n value: any,\n shouldPersistRemote = false,\n depth = 0\n): ShareableRef<T> {\n if (SHOULD_BE_USE_WEB) {\n return value;\n }\n if (depth >= DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {\n // if we reach certain recursion depth we suspect that we are dealing with a cyclic object.\n // this type of objects are not supported and cannot be trasferred as shareable, so we\n // implement a simple detection mechanism that remembers the value at a given depth and\n // tests whether we try reenter this method later on with the same value. If that happens\n // we throw an appropriate error.\n if (depth === DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {\n processedObjectAtThresholdDepth = value;\n } else if (value === processedObjectAtThresholdDepth) {\n throw new Error(\n '[Reanimated] Trying to convert a cyclic object to a shareable. This is not supported.'\n );\n }\n } else {\n processedObjectAtThresholdDepth = undefined;\n }\n // This one actually may be worth to be moved to c++, we also need similar logic to run on the UI thread\n const type = typeof value;\n const isTypeObject = type === 'object';\n const isTypeFunction = type === 'function';\n if ((isTypeObject || isTypeFunction) && value !== null) {\n const cached = shareableMappingCache.get(value);\n if (cached === shareableMappingFlag) {\n return value;\n } else if (cached !== undefined) {\n return cached as ShareableRef<T>;\n } else {\n let toAdapt: any;\n if (Array.isArray(value)) {\n toAdapt = value.map((element) =>\n makeShareableCloneRecursive(element, shouldPersistRemote, depth + 1)\n );\n } else if (isTypeFunction && !isWorkletFunction(value)) {\n // this is a remote function\n toAdapt = value;\n } else if (isHostObject(value)) {\n // for host objects we pass the reference to the object as shareable and\n // then recreate new host object wrapping the same instance on the UI thread.\n // there is no point of iterating over keys as we do for regular objects.\n toAdapt = value;\n } else if (isPlainJSObject(value) || isTypeFunction) {\n toAdapt = {};\n if (isWorkletFunction(value)) {\n if (__DEV__) {\n const babelVersion = value.__initData.version;\n if (babelVersion !== undefined && babelVersion !== jsVersion) {\n throw new Error(`[Reanimated] Mismatch between JavaScript code version and Reanimated Babel plugin version (${jsVersion} vs. ${babelVersion}). \nSee \\`https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#mismatch-between-javascript-code-version-and-reanimated-babel-plugin-version\\` for more details.\nOffending code was: \\`${getWorkletCode(value)}\\``);\n }\n registerWorkletStackDetails(\n value.__workletHash,\n value.__stackDetails!\n );\n }\n if (value.__stackDetails) {\n // `Error` type of value cannot be copied to the UI thread, so we\n // remove it after we handled it in dev mode or delete it to ignore it in production mode.\n // Not removing this would cause an infinite loop in production mode and it just\n // seems more elegant to handle it this way.\n delete value.__stackDetails;\n }\n // to save on transferring static __initData field of worklet structure\n // we request shareable value to persist its UI counterpart. This means\n // that the __initData field that contains long strings represeting the\n // worklet code, source map, and location, will always be\n // serialized/deserialized once.\n toAdapt.__initData = makeShareableCloneRecursive(\n value.__initData,\n true,\n depth + 1\n );\n }\n\n for (const [key, element] of Object.entries(value)) {\n if (key === '__initData' && toAdapt.__initData !== undefined) {\n continue;\n }\n toAdapt[key] = makeShareableCloneRecursive(\n element,\n shouldPersistRemote,\n depth + 1\n );\n }\n } else if (value instanceof RegExp) {\n const pattern = value.source;\n const flags = value.flags;\n const handle = makeShareableCloneRecursive({\n __init: () => {\n 'worklet';\n return new RegExp(pattern, flags);\n },\n });\n shareableMappingCache.set(value, handle);\n return handle as ShareableRef<T>;\n } else if (value instanceof Error) {\n const { name, message, stack } = value;\n const handle = makeShareableCloneRecursive({\n __init: () => {\n 'worklet';\n const error = new Error();\n error.name = name;\n error.message = message;\n error.stack = stack;\n return error;\n },\n });\n shareableMappingCache.set(value, handle);\n return handle as ShareableRef<T>;\n } else if (value instanceof ArrayBuffer) {\n toAdapt = value;\n } else if (ArrayBuffer.isView(value)) {\n // typed array (e.g. Int32Array, Uint8ClampedArray) or DataView\n const buffer = value.buffer;\n const typeName = value.constructor.name;\n const handle = makeShareableCloneRecursive({\n __init: () => {\n 'worklet';\n if (!VALID_ARRAY_VIEWS_NAMES.includes(typeName)) {\n throw new Error(\n `[Reanimated] Invalid array view name \\`${typeName}\\`.`\n );\n }\n const constructor = global[typeName as keyof typeof global];\n if (constructor === undefined) {\n throw new Error(\n `[Reanimated] Constructor for \\`${typeName}\\` not found.`\n );\n }\n return new constructor(buffer);\n },\n });\n shareableMappingCache.set(value, handle);\n return handle as ShareableRef<T>;\n } else {\n // This is reached for object types that are not of plain Object.prototype.\n // We don't support such objects from being transferred as shareables to\n // the UI runtime and hence we replace them with \"inaccessible object\"\n // which is implemented as a Proxy object that throws on any attempt\n // of accessing its fields. We argue that such objects can sometimes leak\n // as attributes of objects being captured by worklets but should never\n // be used on the UI runtime regardless. If they are being accessed, the user\n // will get an appropriate error message.\n const inaccessibleObject =\n makeShareableCloneRecursive<T>(INACCESSIBLE_OBJECT);\n shareableMappingCache.set(value, inaccessibleObject);\n return inaccessibleObject;\n }\n if (__DEV__) {\n // we freeze objects that are transformed to shareable. This should help\n // detect issues when someone modifies data after it's been converted to\n // shareable. Meaning that they may be doing a faulty assumption in their\n // code expecting that the updates are going to automatically populate to\n // the object sent to the UI thread. If the user really wants some objects\n // to be mutable they should use shared values instead.\n Object.freeze(value);\n }\n const adopted = NativeReanimatedModule.makeShareableClone(\n toAdapt,\n shouldPersistRemote,\n value\n );\n shareableMappingCache.set(value, adopted);\n shareableMappingCache.set(adopted);\n return adopted;\n }\n }\n return NativeReanimatedModule.makeShareableClone(\n value,\n shouldPersistRemote,\n undefined\n );\n}\n\nconst WORKLET_CODE_THRESHOLD = 255;\n\nfunction getWorkletCode(value: WorkletFunction) {\n // @ts-ignore this is fine\n const code = value?.__initData?.code;\n if (!code) {\n return 'unknown';\n }\n if (code.length > WORKLET_CODE_THRESHOLD) {\n return `${code.substring(0, WORKLET_CODE_THRESHOLD)}...`;\n }\n return code;\n}\n\ntype RemoteFunction<T> = {\n __remoteFunction: FlatShareableRef<T>;\n};\n\nfunction isRemoteFunction<T>(value: {\n __remoteFunction?: unknown;\n}): value is RemoteFunction<T> {\n 'worklet';\n return !!value.__remoteFunction;\n}\n\nexport function makeShareableCloneOnUIRecursive<T>(\n value: T\n): FlatShareableRef<T> {\n 'worklet';\n if (SHOULD_BE_USE_WEB) {\n // @ts-ignore web is an interesting place where we don't run a secondary VM on the UI thread\n // see more details in the comment where USE_STUB_IMPLEMENTATION is defined.\n return value;\n }\n // eslint-disable-next-line @typescript-eslint/no-shadow\n function cloneRecursive(value: T): FlatShareableRef<T> {\n if (\n (typeof value === 'object' && value !== null) ||\n typeof value === 'function'\n ) {\n if (isHostObject(value)) {\n // We call `_makeShareableClone` to wrap the provided HostObject\n // inside ShareableJSRef.\n return global._makeShareableClone(\n value,\n undefined\n ) as FlatShareableRef<T>;\n }\n if (isRemoteFunction<T>(value)) {\n // RemoteFunctions are created by us therefore they are\n // a Shareable out of the box and there is no need to\n // call `_makeShareableClone`.\n return value.__remoteFunction;\n }\n if (Array.isArray(value)) {\n return global._makeShareableClone(\n value.map(cloneRecursive),\n undefined\n ) as FlatShareableRef<T>;\n }\n const toAdapt: Record<string, FlatShareableRef<T>> = {};\n for (const [key, element] of Object.entries(value)) {\n toAdapt[key] = cloneRecursive(element);\n }\n return global._makeShareableClone(toAdapt, value) as FlatShareableRef<T>;\n }\n return global._makeShareableClone(value, undefined);\n }\n return cloneRecursive(value);\n}\n\nfunction makeShareableJS<T extends object>(value: T): T {\n return value;\n}\n\nfunction makeShareableNative<T extends object>(value: T): T {\n if (shareableMappingCache.get(value)) {\n return value;\n }\n const handle = makeShareableCloneRecursive({\n __init: () => {\n 'worklet';\n return value;\n },\n });\n shareableMappingCache.set(value, handle);\n return value;\n}\n\n/**\n * This function creates a value on UI with persistent state - changes to it on the UI\n * thread will be seen by all worklets. Use it when you want to create a value\n * that is read and written only on the UI thread.\n */\nexport const makeShareable = SHOULD_BE_USE_WEB\n ? makeShareableJS\n : makeShareableNative;\n"],"mappings":"AAAA,YAAY;;AACZ,OAAOA,sBAAsB,MAA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vD,KAAK,MAAM,CAACY,GAAG,EAAER,OAAO,CAAC,IAAI7B,MAAM,CAACsC,OAAO,CAACzC,KAAK,CAAC,EAAE;QAClD4B,OAAO,CAACY,GAAG,CAAC,GAAG6B,cAAc,CAACrC,OAAO,CAAC;MACxC;MACA,OAAOyB,MAAM,CAACa,mBAAmB,CAAC1C,OAAO,EAAE5B,KAAK,CAAC;IACnD;IACA,OAAOyD,MAAM,CAACa,mBAAmB,CAACtE,KAAK,EAAEsB,SAAS,CAAC;EACrD;EACA,OAAO+C,cAAc,CAACrE,KAAK,CAAC;AAC9B;AAEA,SAASuE,eAAeA,CAAmBvE,KAAQ,EAAK;EACtD,OAAOA,KAAK;AACd;AAEA,SAASwE,mBAAmBA,CAAmBxE,KAAQ,EAAK;EAC1D,IAAIL,qBAAqB,CAACc,GAAG,CAACT,KAAK,CAAC,EAAE;IACpC,OAAOA,KAAK;EACd;EACA,MAAM8C,MAAM,GAAG5B,2BAA2B,CAAC;IACzCX,MAAM,EAAEA,CAAA,KAAM;MACZ,SAAS;;MACT,OAAOP,KAAK;IACd;EACF,CAAC,CAAC;EACFL,qBAAqB,CAACmB,GAAG,CAACd,KAAK,EAAE8C,MAAM,CAAC;EACxC,OAAO9C,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMyE,aAAa,GAAG5E,iBAAiB,GAC1C0E,eAAe,GACfC,mBAAmB"}
|
|
1
|
+
{"version":3,"names":["NativeReanimatedModule","isWorkletFunction","shouldBeUseWeb","registerWorkletStackDetails","jsVersion","shareableMappingCache","shareableMappingFlag","SHOULD_BE_USE_WEB","MAGIC_KEY","isHostObject","value","isPlainJSObject","object","Object","getPrototypeOf","prototype","INACCESSIBLE_OBJECT","__init","Proxy","get","_","prop","Error","String","set","VALID_ARRAY_VIEWS_NAMES","DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD","processedObjectAtThresholdDepth","makeShareableCloneRecursive","shouldPersistRemote","depth","undefined","type","isTypeObject","isTypeFunction","cached","toAdapt","Array","isArray","map","element","__DEV__","babelVersion","__initData","version","getWorkletCode","__workletHash","__stackDetails","key","entries","RegExp","pattern","source","flags","handle","name","message","stack","error","ArrayBuffer","isView","buffer","typeName","constructor","includes","global","inaccessibleObject","freeze","adopted","makeShareableClone","WORKLET_CODE_THRESHOLD","_value$__initData","code","length","substring","isRemoteFunction","__remoteFunction","makeShareableCloneOnUIRecursive","cloneRecursive","_makeShareableClone","makeShareableJS","makeShareableNative","makeShareable"],"sources":["shareables.ts"],"sourcesContent":["'use strict';\nimport NativeReanimatedModule from './NativeReanimated';\nimport { isWorkletFunction } from './commonTypes';\nimport type {\n ShareableRef,\n FlatShareableRef,\n WorkletFunction,\n} from './commonTypes';\nimport { shouldBeUseWeb } from './PlatformChecker';\nimport { registerWorkletStackDetails } from './errors';\nimport { jsVersion } from './platform-specific/jsVersion';\nimport {\n shareableMappingCache,\n shareableMappingFlag,\n} from './shareableMappingCache';\n\n// for web/chrome debugger/jest environments this file provides a stub implementation\n// where no shareable references are used. Instead, the objects themselves are used\n// instead of shareable references, because of the fact that we don't have to deal with\n// runnning the code on separate VMs.\nconst SHOULD_BE_USE_WEB = shouldBeUseWeb();\n\nconst MAGIC_KEY = 'REANIMATED_MAGIC_KEY';\n\nfunction isHostObject(value: NonNullable<object>) {\n 'worklet';\n // We could use JSI to determine whether an object is a host object, however\n // the below workaround works well and is way faster than an additional JSI call.\n // We use the fact that host objects have broken implementation of `hasOwnProperty`\n // and hence return true for all `in` checks regardless of the key we ask for.\n return MAGIC_KEY in value;\n}\n\nfunction isPlainJSObject(object: object) {\n return Object.getPrototypeOf(object) === Object.prototype;\n}\n\n// The below object is used as a replacement for objects that cannot be transferred\n// as shareable values. In makeShareableCloneRecursive we detect if an object is of\n// a plain Object.prototype and only allow such objects to be transferred. This lets\n// us avoid all sorts of react internals from leaking into the UI runtime. To make it\n// possible to catch errors when someone actually tries to access such object on the UI\n// runtime, we use the below Proxy object which is instantiated on the UI runtime and\n// throws whenever someone tries to access its fields.\nconst INACCESSIBLE_OBJECT = {\n __init: () => {\n 'worklet';\n return new Proxy(\n {},\n {\n get: (_: unknown, prop: string | symbol) => {\n if (\n prop === '_isReanimatedSharedValue' ||\n prop === '__remoteFunction'\n ) {\n // not very happy about this check here, but we need to allow for\n // \"inaccessible\" objects to be tested with isSharedValue check\n // as it is being used in the mappers when extracting inputs recursively\n // as well as with isRemoteFunction when cloning objects recursively.\n // Apparently we can't check if a key exists there as HostObjects always\n // return true for such tests, so the only possibility for us is to\n // actually access that key and see if it is set to true. We therefore\n // need to allow for this key to be accessed here.\n return false;\n }\n throw new Error(\n `[Reanimated] Trying to access property \\`${String(\n prop\n )}\\` of an object which cannot be sent to the UI runtime.`\n );\n },\n set: () => {\n throw new Error(\n '[Reanimated] Trying to write to an object which cannot be sent to the UI runtime.'\n );\n },\n }\n );\n },\n};\n\nconst VALID_ARRAY_VIEWS_NAMES = [\n 'Int8Array',\n 'Uint8Array',\n 'Uint8ClampedArray',\n 'Int16Array',\n 'Uint16Array',\n 'Int32Array',\n 'Uint32Array',\n 'Float32Array',\n 'Float64Array',\n 'BigInt64Array',\n 'BigUint64Array',\n 'DataView',\n];\n\nconst DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD = 30;\n// Below variable stores object that we process in makeShareableCloneRecursive at the specified depth.\n// We use it to check if later on the function reenters with the same object\nlet processedObjectAtThresholdDepth: unknown;\n\nexport function makeShareableCloneRecursive<T>(\n value: any,\n shouldPersistRemote = false,\n depth = 0\n): ShareableRef<T> {\n if (SHOULD_BE_USE_WEB) {\n return value;\n }\n if (depth >= DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {\n // if we reach certain recursion depth we suspect that we are dealing with a cyclic object.\n // this type of objects are not supported and cannot be trasferred as shareable, so we\n // implement a simple detection mechanism that remembers the value at a given depth and\n // tests whether we try reenter this method later on with the same value. If that happens\n // we throw an appropriate error.\n if (depth === DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {\n processedObjectAtThresholdDepth = value;\n } else if (value === processedObjectAtThresholdDepth) {\n throw new Error(\n '[Reanimated] Trying to convert a cyclic object to a shareable. This is not supported.'\n );\n }\n } else {\n processedObjectAtThresholdDepth = undefined;\n }\n // This one actually may be worth to be moved to c++, we also need similar logic to run on the UI thread\n const type = typeof value;\n const isTypeObject = type === 'object';\n const isTypeFunction = type === 'function';\n if ((isTypeObject || isTypeFunction) && value !== null) {\n const cached = shareableMappingCache.get(value);\n if (cached === shareableMappingFlag) {\n return value;\n } else if (cached !== undefined) {\n return cached as ShareableRef<T>;\n } else {\n let toAdapt: any;\n if (Array.isArray(value)) {\n toAdapt = value.map((element) =>\n makeShareableCloneRecursive(element, shouldPersistRemote, depth + 1)\n );\n } else if (isTypeFunction && !isWorkletFunction(value)) {\n // this is a remote function\n toAdapt = value;\n } else if (isHostObject(value)) {\n // for host objects we pass the reference to the object as shareable and\n // then recreate new host object wrapping the same instance on the UI thread.\n // there is no point of iterating over keys as we do for regular objects.\n toAdapt = value;\n } else if (isPlainJSObject(value) || isTypeFunction) {\n toAdapt = {};\n if (isWorkletFunction(value)) {\n if (__DEV__) {\n const babelVersion = value.__initData.version;\n if (babelVersion !== undefined && babelVersion !== jsVersion) {\n throw new Error(`[Reanimated] Mismatch between JavaScript code version and Reanimated Babel plugin version (${jsVersion} vs. ${babelVersion}). \nSee \\`https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#mismatch-between-javascript-code-version-and-reanimated-babel-plugin-version\\` for more details.\nOffending code was: \\`${getWorkletCode(value)}\\``);\n }\n registerWorkletStackDetails(\n value.__workletHash,\n value.__stackDetails!\n );\n }\n if (value.__stackDetails) {\n // `Error` type of value cannot be copied to the UI thread, so we\n // remove it after we handled it in dev mode or delete it to ignore it in production mode.\n // Not removing this would cause an infinite loop in production mode and it just\n // seems more elegant to handle it this way.\n delete value.__stackDetails;\n }\n // to save on transferring static __initData field of worklet structure\n // we request shareable value to persist its UI counterpart. This means\n // that the __initData field that contains long strings represeting the\n // worklet code, source map, and location, will always be\n // serialized/deserialized once.\n toAdapt.__initData = makeShareableCloneRecursive(\n value.__initData,\n true,\n depth + 1\n );\n }\n\n for (const [key, element] of Object.entries(value)) {\n if (key === '__initData' && toAdapt.__initData !== undefined) {\n continue;\n }\n toAdapt[key] = makeShareableCloneRecursive(\n element,\n shouldPersistRemote,\n depth + 1\n );\n }\n } else if (value instanceof RegExp) {\n const pattern = value.source;\n const flags = value.flags;\n const handle = makeShareableCloneRecursive({\n __init: () => {\n 'worklet';\n return new RegExp(pattern, flags);\n },\n });\n shareableMappingCache.set(value, handle);\n return handle as ShareableRef<T>;\n } else if (value instanceof Error) {\n const { name, message, stack } = value;\n const handle = makeShareableCloneRecursive({\n __init: () => {\n 'worklet';\n const error = new Error();\n error.name = name;\n error.message = message;\n error.stack = stack;\n return error;\n },\n });\n shareableMappingCache.set(value, handle);\n return handle as ShareableRef<T>;\n } else if (value instanceof ArrayBuffer) {\n toAdapt = value;\n } else if (ArrayBuffer.isView(value)) {\n // typed array (e.g. Int32Array, Uint8ClampedArray) or DataView\n const buffer = value.buffer;\n const typeName = value.constructor.name;\n const handle = makeShareableCloneRecursive({\n __init: () => {\n 'worklet';\n if (!VALID_ARRAY_VIEWS_NAMES.includes(typeName)) {\n throw new Error(\n `[Reanimated] Invalid array view name \\`${typeName}\\`.`\n );\n }\n const constructor = global[typeName as keyof typeof global];\n if (constructor === undefined) {\n throw new Error(\n `[Reanimated] Constructor for \\`${typeName}\\` not found.`\n );\n }\n return new constructor(buffer);\n },\n });\n shareableMappingCache.set(value, handle);\n return handle as ShareableRef<T>;\n } else {\n // This is reached for object types that are not of plain Object.prototype.\n // We don't support such objects from being transferred as shareables to\n // the UI runtime and hence we replace them with \"inaccessible object\"\n // which is implemented as a Proxy object that throws on any attempt\n // of accessing its fields. We argue that such objects can sometimes leak\n // as attributes of objects being captured by worklets but should never\n // be used on the UI runtime regardless. If they are being accessed, the user\n // will get an appropriate error message.\n const inaccessibleObject =\n makeShareableCloneRecursive<T>(INACCESSIBLE_OBJECT);\n shareableMappingCache.set(value, inaccessibleObject);\n return inaccessibleObject;\n }\n if (__DEV__) {\n // we freeze objects that are transformed to shareable. This should help\n // detect issues when someone modifies data after it's been converted to\n // shareable. Meaning that they may be doing a faulty assumption in their\n // code expecting that the updates are going to automatically populate to\n // the object sent to the UI thread. If the user really wants some objects\n // to be mutable they should use shared values instead.\n Object.freeze(value);\n }\n const adopted = NativeReanimatedModule.makeShareableClone(\n toAdapt,\n shouldPersistRemote,\n value\n );\n shareableMappingCache.set(value, adopted);\n shareableMappingCache.set(adopted);\n return adopted;\n }\n }\n return NativeReanimatedModule.makeShareableClone(\n value,\n shouldPersistRemote,\n undefined\n );\n}\n\nconst WORKLET_CODE_THRESHOLD = 255;\n\nfunction getWorkletCode(value: WorkletFunction) {\n // @ts-ignore this is fine\n const code = value?.__initData?.code;\n if (!code) {\n return 'unknown';\n }\n if (code.length > WORKLET_CODE_THRESHOLD) {\n return `${code.substring(0, WORKLET_CODE_THRESHOLD)}...`;\n }\n return code;\n}\n\ntype RemoteFunction<T> = {\n __remoteFunction: FlatShareableRef<T>;\n};\n\nfunction isRemoteFunction<T>(value: {\n __remoteFunction?: unknown;\n}): value is RemoteFunction<T> {\n 'worklet';\n return !!value.__remoteFunction;\n}\n\nexport function makeShareableCloneOnUIRecursive<T>(\n value: T\n): FlatShareableRef<T> {\n 'worklet';\n if (SHOULD_BE_USE_WEB) {\n // @ts-ignore web is an interesting place where we don't run a secondary VM on the UI thread\n // see more details in the comment where USE_STUB_IMPLEMENTATION is defined.\n return value;\n }\n // eslint-disable-next-line @typescript-eslint/no-shadow\n function cloneRecursive(value: T): FlatShareableRef<T> {\n if (\n (typeof value === 'object' && value !== null) ||\n typeof value === 'function'\n ) {\n if (isHostObject(value)) {\n // We call `_makeShareableClone` to wrap the provided HostObject\n // inside ShareableJSRef.\n return global._makeShareableClone(\n value,\n undefined\n ) as FlatShareableRef<T>;\n }\n if (isRemoteFunction<T>(value)) {\n // RemoteFunctions are created by us therefore they are\n // a Shareable out of the box and there is no need to\n // call `_makeShareableClone`.\n return value.__remoteFunction;\n }\n if (Array.isArray(value)) {\n return global._makeShareableClone(\n value.map(cloneRecursive),\n undefined\n ) as FlatShareableRef<T>;\n }\n const toAdapt: Record<string, FlatShareableRef<T>> = {};\n for (const [key, element] of Object.entries(value)) {\n toAdapt[key] = cloneRecursive(element);\n }\n return global._makeShareableClone(toAdapt, value) as FlatShareableRef<T>;\n }\n return global._makeShareableClone(value, undefined);\n }\n return cloneRecursive(value);\n}\n\nfunction makeShareableJS<T extends object>(value: T): T {\n return value;\n}\n\nfunction makeShareableNative<T extends object>(value: T): T {\n if (shareableMappingCache.get(value)) {\n return value;\n }\n const handle = makeShareableCloneRecursive({\n __init: () => {\n 'worklet';\n return value;\n },\n });\n shareableMappingCache.set(value, handle);\n return value;\n}\n\n/**\n * This function creates a value on UI with persistent state - changes to it on the UI\n * thread will be seen by all worklets. Use it when you want to create a value\n * that is read and written only on the UI thread.\n */\nexport const makeShareable = SHOULD_BE_USE_WEB\n ? makeShareableJS\n : makeShareableNative;\n"],"mappings":"AAAA,YAAY;;AACZ,OAAOA,sBAAsB,MAAM,oBAAoB;AACvD,SAASC,iBAAiB,QAAQ,eAAe;AAMjD,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,2BAA2B,QAAQ,UAAU;AACtD,SAASC,SAAS,QAAQ,+BAA+B;AACzD,SACEC,qBAAqB,EACrBC,oBAAoB,QACf,yBAAyB;;AAEhC;AACA;AACA;AACA;AACA,MAAMC,iBAAiB,GAAGL,cAAc,CAAC,CAAC;AAE1C,MAAMM,SAAS,GAAG,sBAAsB;AAExC,SAASC,YAAYA,CAACC,KAA0B,EAAE;EAChD,SAAS;;EACT;EACA;EACA;EACA;EACA,OAAOF,SAAS,IAAIE,KAAK;AAC3B;AAEA,SAASC,eAAeA,CAACC,MAAc,EAAE;EACvC,OAAOC,MAAM,CAACC,cAAc,CAACF,M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,KAAM;MACZ,SAAS;;MACT,OAAOP,KAAK;IACd;EACF,CAAC,CAAC;EACFL,qBAAqB,CAACmB,GAAG,CAACd,KAAK,EAAE4C,MAAM,CAAC;EACxC,OAAO5C,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMwE,aAAa,GAAG3E,iBAAiB,GAC1CyE,eAAe,GACfC,mBAAmB","ignoreList":[]}
|
|
@@ -58,6 +58,7 @@ export const callMicrotasks = SHOULD_BE_USE_WEB ? () => {
|
|
|
58
58
|
*/
|
|
59
59
|
// @ts-expect-error This overload is correct since it's what user sees in his code
|
|
60
60
|
// before it's transformed by Reanimated Babel plugin.
|
|
61
|
+
|
|
61
62
|
export function runOnUI(worklet) {
|
|
62
63
|
'worklet';
|
|
63
64
|
|
|
@@ -67,10 +68,7 @@ export function runOnUI(worklet) {
|
|
|
67
68
|
if (__DEV__ && !SHOULD_BE_USE_WEB && !isWorkletFunction(worklet)) {
|
|
68
69
|
throw new Error('[Reanimated] `runOnUI` can only be used on worklets.');
|
|
69
70
|
}
|
|
70
|
-
return
|
|
71
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
72
|
-
args[_key] = arguments[_key];
|
|
73
|
-
}
|
|
71
|
+
return (...args) => {
|
|
74
72
|
if (IS_JEST) {
|
|
75
73
|
// Mocking time in Jest is tricky as both requestAnimationFrame and queueMicrotask
|
|
76
74
|
// callbacks run on the same queue and can be interleaved. There is no way
|
|
@@ -106,8 +104,7 @@ export function runOnUI(worklet) {
|
|
|
106
104
|
'worklet';
|
|
107
105
|
|
|
108
106
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
109
|
-
queue.forEach(
|
|
110
|
-
let [worklet, args] = _ref;
|
|
107
|
+
queue.forEach(([worklet, args]) => {
|
|
111
108
|
worklet(...args);
|
|
112
109
|
});
|
|
113
110
|
callMicrotasks();
|
|
@@ -120,10 +117,7 @@ export function runOnUI(worklet) {
|
|
|
120
117
|
// @ts-expect-error Check `executeOnUIRuntimeSync` overload above.
|
|
121
118
|
|
|
122
119
|
export function executeOnUIRuntimeSync(worklet) {
|
|
123
|
-
return
|
|
124
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
125
|
-
args[_key2] = arguments[_key2];
|
|
126
|
-
}
|
|
120
|
+
return (...args) => {
|
|
127
121
|
return NativeReanimatedModule.executeOnUIRuntimeSync(makeShareableCloneRecursive(() => {
|
|
128
122
|
'worklet';
|
|
129
123
|
|
|
@@ -147,10 +141,7 @@ export function runOnUIImmediately(worklet) {
|
|
|
147
141
|
if (__DEV__ && !SHOULD_BE_USE_WEB && !isWorkletFunction(worklet)) {
|
|
148
142
|
throw new Error('[Reanimated] `runOnUIImmediately` can only be used on worklets.');
|
|
149
143
|
}
|
|
150
|
-
return
|
|
151
|
-
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
152
|
-
args[_key3] = arguments[_key3];
|
|
153
|
-
}
|
|
144
|
+
return (...args) => {
|
|
154
145
|
NativeReanimatedModule.scheduleOnUI(makeShareableCloneRecursive(() => {
|
|
155
146
|
'worklet';
|
|
156
147
|
|
|
@@ -158,10 +149,7 @@ export function runOnUIImmediately(worklet) {
|
|
|
158
149
|
}));
|
|
159
150
|
};
|
|
160
151
|
}
|
|
161
|
-
function runWorkletOnJS(worklet) {
|
|
162
|
-
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
163
|
-
args[_key4 - 1] = arguments[_key4];
|
|
164
|
-
}
|
|
152
|
+
function runWorkletOnJS(worklet, ...args) {
|
|
165
153
|
// remote function that calls a worklet synchronously on the JS runtime
|
|
166
154
|
worklet(...args);
|
|
167
155
|
}
|
|
@@ -179,23 +167,13 @@ export function runOnJS(fun) {
|
|
|
179
167
|
|
|
180
168
|
if (SHOULD_BE_USE_WEB || !_WORKLET) {
|
|
181
169
|
// if we are already on the JS thread, we just schedule the worklet on the JS queue
|
|
182
|
-
return
|
|
183
|
-
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
184
|
-
args[_key5] = arguments[_key5];
|
|
185
|
-
}
|
|
186
|
-
return queueMicrotask(args.length ? () => fun(...args) : fun);
|
|
187
|
-
};
|
|
170
|
+
return (...args) => queueMicrotask(args.length ? () => fun(...args) : fun);
|
|
188
171
|
}
|
|
189
172
|
if (isWorkletFunction(fun)) {
|
|
190
173
|
// If `fun` is a worklet, we schedule a call of a remote function `runWorkletOnJS`
|
|
191
174
|
// and pass the worklet as a first argument followed by original arguments.
|
|
192
175
|
|
|
193
|
-
return
|
|
194
|
-
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
195
|
-
args[_key6] = arguments[_key6];
|
|
196
|
-
}
|
|
197
|
-
return runOnJS(runWorkletOnJS)(fun, ...args);
|
|
198
|
-
};
|
|
176
|
+
return (...args) => runOnJS(runWorkletOnJS)(fun, ...args);
|
|
199
177
|
}
|
|
200
178
|
if (fun.__remoteFunction) {
|
|
201
179
|
// In development mode the function provided as `fun` throws an error message
|
|
@@ -204,10 +182,7 @@ export function runOnJS(fun) {
|
|
|
204
182
|
// reference to the original remote function in the `__remoteFunction` property.
|
|
205
183
|
fun = fun.__remoteFunction;
|
|
206
184
|
}
|
|
207
|
-
return
|
|
208
|
-
for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
|
|
209
|
-
args[_key7] = arguments[_key7];
|
|
210
|
-
}
|
|
185
|
+
return (...args) => {
|
|
211
186
|
global._scheduleOnJS(fun, args.length > 0 ?
|
|
212
187
|
// TODO TYPESCRIPT this cast is terrible but will be fixed
|
|
213
188
|
makeShareableCloneOnUIRecursive(args) : undefined);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeReanimatedModule","isJest","shouldBeUseWeb","makeShareableCloneOnUIRecursive","makeShareableCloneRecursive","isWorkletFunction","IS_JEST","SHOULD_BE_USE_WEB","_runOnUIQueue","setupMicrotasks","microtasksQueue","isExecutingMicrotasksQueue","global","queueMicrotask","callback","push","__callMicrotasks","index","length","_maybeFlushUIUpdatesQueue","callMicrotasksOnUIThread","callMicrotasks","runOnUI","worklet","__DEV__","_WORKLET","Error","_len","arguments","args","Array","_key","scheduleOnUI","queue","forEach","_ref","executeOnUIRuntimeSync","_len2","_key2","result","runOnUIImmediately","_len3","_key3","runWorkletOnJS","_len4","_key4","runOnJS","fun","_len5","_key5","_len6","_key6","__remoteFunction","_len7","_key7","_scheduleOnJS","undefined"],"sources":["threads.ts"],"sourcesContent":["'use strict';\nimport NativeReanimatedModule from './NativeReanimated';\nimport { isJest, shouldBeUseWeb } from './PlatformChecker';\nimport type { WorkletFunction } from './commonTypes';\nimport {\n makeShareableCloneOnUIRecursive,\n makeShareableCloneRecursive,\n} from './shareables';\nimport { isWorkletFunction } from './commonTypes';\n\nconst IS_JEST = isJest();\nconst SHOULD_BE_USE_WEB = shouldBeUseWeb();\n\n/**\n * An array of [worklet, args] pairs.\n * */\nlet _runOnUIQueue: Array<[WorkletFunction<unknown[], unknown>, unknown[]]> = [];\n\nexport function setupMicrotasks() {\n 'worklet';\n\n let microtasksQueue: Array<() => void> = [];\n let isExecutingMicrotasksQueue = false;\n global.queueMicrotask = (callback: () => void) => {\n microtasksQueue.push(callback);\n };\n\n global.__callMicrotasks = () => {\n if (isExecutingMicrotasksQueue) {\n return;\n }\n try {\n isExecutingMicrotasksQueue = true;\n for (let index = 0; index < microtasksQueue.length; index += 1) {\n // we use classic 'for' loop because the size of the currentTasks array may change while executing some of the callbacks due to queueMicrotask calls\n microtasksQueue[index]();\n }\n microtasksQueue = [];\n global._maybeFlushUIUpdatesQueue();\n } finally {\n isExecutingMicrotasksQueue = false;\n }\n };\n}\n\nfunction callMicrotasksOnUIThread() {\n 'worklet';\n global.__callMicrotasks();\n}\n\nexport const callMicrotasks = SHOULD_BE_USE_WEB\n ? () => {\n // on web flushing is a noop as immediates are handled by the browser\n }\n : callMicrotasksOnUIThread;\n\n/**\n * Lets you asynchronously run [workletized](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#to-workletize) functions on the [UI thread](https://docs.swmansion.com/react-native-reanimated/docs/threading/runOnUI).\n *\n * This method does not schedule the work immediately but instead waits for other worklets\n * to be scheduled within the same JS loop. It uses queueMicrotask to schedule all the worklets\n * at once making sure they will run within the same frame boundaries on the UI thread.\n *\n * @param fun - A reference to a function you want to execute on the [UI thread](https://docs.swmansion.com/react-native-reanimated/docs/threading/runOnUI) from the [JavaScript thread](https://docs.swmansion.com/react-native-reanimated/docs/threading/runOnUI).\n * @returns A function that accepts arguments for the function passed as the first argument.\n * @see https://docs.swmansion.com/react-native-reanimated/docs/threading/runOnUI\n */\n// @ts-expect-error This overload is correct since it's what user sees in his code\n// before it's transformed by Reanimated Babel plugin.\nexport function runOnUI<Args extends unknown[], ReturnValue>(\n worklet: (...args: Args) => ReturnValue\n): (...args: Args) => void;\n\nexport function runOnUI<Args extends unknown[], ReturnValue>(\n worklet: WorkletFunction<Args, ReturnValue>\n): (...args: Args) => void {\n 'worklet';\n if (__DEV__ && !SHOULD_BE_USE_WEB && _WORKLET) {\n throw new Error(\n '[Reanimated] `runOnUI` cannot be called on the UI runtime. Please call the function synchronously or use `queueMicrotask` or `requestAnimationFrame` instead.'\n );\n }\n if (__DEV__ && !SHOULD_BE_USE_WEB && !isWorkletFunction(worklet)) {\n throw new Error('[Reanimated] `runOnUI` can only be used on worklets.');\n }\n return (...args) => {\n if (IS_JEST) {\n // Mocking time in Jest is tricky as both requestAnimationFrame and queueMicrotask\n // callbacks run on the same queue and can be interleaved. There is no way\n // to flush particular queue in Jest and the only control over mocked timers\n // is by using jest.advanceTimersByTime() method which advances all types\n // of timers including immediate and animation callbacks. Ideally we'd like\n // to have some way here to schedule work along with React updates, but\n // that's not possible, and hence in Jest environment instead of using scheduling\n // mechanism we just schedule the work ommiting the queue. This is ok for the\n // uses that we currently have but may not be ok for future tests that we write.\n NativeReanimatedModule.scheduleOnUI(\n makeShareableCloneRecursive(() => {\n 'worklet';\n worklet(...args);\n })\n );\n return;\n }\n if (__DEV__) {\n // in DEV mode we call shareable conversion here because in case the object\n // can't be converted, we will get a meaningful stack-trace as opposed to the\n // situation when conversion is only done via microtask queue. This does not\n // make the app particularily less efficient as converted objects are cached\n // and for a given worklet the conversion only happens once.\n makeShareableCloneRecursive(worklet);\n makeShareableCloneRecursive(args);\n }\n _runOnUIQueue.push([worklet as WorkletFunction, args]);\n if (_runOnUIQueue.length === 1) {\n queueMicrotask(() => {\n const queue = _runOnUIQueue;\n _runOnUIQueue = [];\n NativeReanimatedModule.scheduleOnUI(\n makeShareableCloneRecursive(() => {\n 'worklet';\n // eslint-disable-next-line @typescript-eslint/no-shadow\n queue.forEach(([worklet, args]) => {\n worklet(...args);\n });\n callMicrotasks();\n })\n );\n });\n }\n };\n}\n\n// @ts-expect-error Check `executeOnUIRuntimeSync` overload above.\nexport function executeOnUIRuntimeSync<Args extends unknown[], ReturnValue>(\n worklet: (...args: Args) => ReturnValue\n): (...args: Args) => ReturnValue;\n\nexport function executeOnUIRuntimeSync<Args extends unknown[], ReturnValue>(\n worklet: WorkletFunction<Args, ReturnValue>\n): (...args: Args) => ReturnValue {\n return (...args) => {\n return NativeReanimatedModule.executeOnUIRuntimeSync(\n makeShareableCloneRecursive(() => {\n 'worklet';\n const result = worklet(...args);\n return makeShareableCloneOnUIRecursive(result);\n })\n );\n };\n}\n\n// @ts-expect-error Check `runOnUI` overload above.\nexport function runOnUIImmediately<Args extends unknown[], ReturnValue>(\n worklet: (...args: Args) => ReturnValue\n): WorkletFunction<Args, ReturnValue>;\n/**\n * Schedule a worklet to execute on the UI runtime skipping batching mechanism.\n */\nexport function runOnUIImmediately<Args extends unknown[], ReturnValue>(\n worklet: WorkletFunction<Args, ReturnValue>\n): (...args: Args) => void {\n 'worklet';\n if (__DEV__ && !SHOULD_BE_USE_WEB && _WORKLET) {\n throw new Error(\n '[Reanimated] `runOnUIImmediately` cannot be called on the UI runtime. Please call the function synchronously or use `queueMicrotask` or `requestAnimationFrame` instead.'\n );\n }\n if (__DEV__ && !SHOULD_BE_USE_WEB && !isWorkletFunction(worklet)) {\n throw new Error(\n '[Reanimated] `runOnUIImmediately` can only be used on worklets.'\n );\n }\n return (...args) => {\n NativeReanimatedModule.scheduleOnUI(\n makeShareableCloneRecursive(() => {\n 'worklet';\n worklet(...args);\n })\n );\n };\n}\n\ntype ReleaseRemoteFunction<Args extends unknown[], ReturnValue> = {\n (...args: Args): ReturnValue;\n};\n\ntype DevRemoteFunction<Args extends unknown[], ReturnValue> = {\n __remoteFunction: (...args: Args) => ReturnValue;\n};\n\ntype RemoteFunction<Args extends unknown[], ReturnValue> =\n | ReleaseRemoteFunction<Args, ReturnValue>\n | DevRemoteFunction<Args, ReturnValue>;\n\nfunction runWorkletOnJS<Args extends unknown[], ReturnValue>(\n worklet: WorkletFunction<Args, ReturnValue>,\n ...args: Args\n): void {\n // remote function that calls a worklet synchronously on the JS runtime\n worklet(...args);\n}\n\n/**\n * Lets you asynchronously run non-[workletized](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#to-workletize) functions that couldn't otherwise run on the [UI thread](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#ui-thread).\n * This applies to most external libraries as they don't have their functions marked with \"worklet\"; directive.\n *\n * @param fun - A reference to a function you want to execute on the JavaScript thread from the UI thread.\n * @returns A function that accepts arguments for the function passed as the first argument.\n * @see https://docs.swmansion.com/react-native-reanimated/docs/threading/runOnJS\n */\nexport function runOnJS<Args extends unknown[], ReturnValue>(\n fun:\n | ((...args: Args) => ReturnValue)\n | RemoteFunction<Args, ReturnValue>\n | WorkletFunction<Args, ReturnValue>\n): (...args: Args) => void {\n 'worklet';\n type FunDevRemote = Extract<typeof fun, DevRemoteFunction<Args, ReturnValue>>;\n if (SHOULD_BE_USE_WEB || !_WORKLET) {\n // if we are already on the JS thread, we just schedule the worklet on the JS queue\n return (...args) =>\n queueMicrotask(\n args.length\n ? () => (fun as (...args: Args) => ReturnValue)(...args)\n : (fun as () => ReturnValue)\n );\n }\n if (isWorkletFunction<Args, ReturnValue>(fun)) {\n // If `fun` is a worklet, we schedule a call of a remote function `runWorkletOnJS`\n // and pass the worklet as a first argument followed by original arguments.\n\n return (...args) =>\n runOnJS(runWorkletOnJS<Args, ReturnValue>)(\n fun as WorkletFunction<Args, ReturnValue>,\n ...args\n );\n }\n if ((fun as FunDevRemote).__remoteFunction) {\n // In development mode the function provided as `fun` throws an error message\n // such that when someone accidentally calls it directly on the UI runtime, they\n // see that they should use `runOnJS` instead. To facilitate that we put the\n // reference to the original remote function in the `__remoteFunction` property.\n fun = (fun as FunDevRemote).__remoteFunction;\n }\n return (...args) => {\n global._scheduleOnJS(\n fun as\n | ((...args: Args) => ReturnValue)\n | WorkletFunction<Args, ReturnValue>,\n args.length > 0\n ? // TODO TYPESCRIPT this cast is terrible but will be fixed\n (makeShareableCloneOnUIRecursive(args) as unknown as unknown[])\n : undefined\n );\n };\n}\n"],"mappings":"AAAA,YAAY;;AACZ,OAAOA,sBAAsB,MAAM,oBAAoB;AACvD,SAASC,MAAM,EAAEC,cAAc,QAAQ,mBAAmB;AAE1D,SACEC,+BAA+B,EAC/BC,2BAA2B,QACtB,cAAc;AACrB,SAASC,iBAAiB,QAAQ,eAAe;AAEjD,MAAMC,OAAO,GAAGL,MAAM,EAAE;AACxB,MAAMM,iBAAiB,GAAGL,cAAc,EAAE;;AAE1C;AACA;AACA;AACA,IAAIM,aAAsE,GAAG,EAAE;AAE/E,OAAO,SAASC,eAAeA,CAAA,EAAG;EAChC,SAAS;;EAET,IAAIC,eAAkC,GAAG,EAAE;EAC3C,IAAIC,0BAA0B,GAAG,KAAK;EACtCC,MAAM,CAACC,cAAc,GAAIC,QAAoB,IAAK;IAChDJ,eAAe,CA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atedModule","isJest","shouldBeUseWeb","makeShareableCloneOnUIRecursive","makeShareableCloneRecursive","isWorkletFunction","IS_JEST","SHOULD_BE_USE_WEB","_runOnUIQueue","setupMicrotasks","microtasksQueue","isExecutingMicrotasksQueue","global","queueMicrotask","callback","push","__callMicrotasks","index","length","_maybeFlushUIUpdatesQueue","callMicrotasksOnUIThread","callMicrotasks","runOnUI","worklet","__DEV__","_WORKLET","Error","args","scheduleOnUI","queue","forEach","executeOnUIRuntimeSync","result","runOnUIImmediately","runWorkletOnJS","runOnJS","fun","__remoteFunction","_scheduleOnJS","undefined"],"sources":["threads.ts"],"sourcesContent":["'use strict';\nimport NativeReanimatedModule from './NativeReanimated';\nimport { isJest, shouldBeUseWeb } from './PlatformChecker';\nimport type { WorkletFunction } from './commonTypes';\nimport {\n makeShareableCloneOnUIRecursive,\n makeShareableCloneRecursive,\n} from './shareables';\nimport { isWorkletFunction } from './commonTypes';\n\nconst IS_JEST = isJest();\nconst SHOULD_BE_USE_WEB = shouldBeUseWeb();\n\n/**\n * An array of [worklet, args] pairs.\n * */\nlet _runOnUIQueue: Array<[WorkletFunction<unknown[], unknown>, unknown[]]> = [];\n\nexport function setupMicrotasks() {\n 'worklet';\n\n let microtasksQueue: Array<() => void> = [];\n let isExecutingMicrotasksQueue = false;\n global.queueMicrotask = (callback: () => void) => {\n microtasksQueue.push(callback);\n };\n\n global.__callMicrotasks = () => {\n if (isExecutingMicrotasksQueue) {\n return;\n }\n try {\n isExecutingMicrotasksQueue = true;\n for (let index = 0; index < microtasksQueue.length; index += 1) {\n // we use classic 'for' loop because the size of the currentTasks array may change while executing some of the callbacks due to queueMicrotask calls\n microtasksQueue[index]();\n }\n microtasksQueue = [];\n global._maybeFlushUIUpdatesQueue();\n } finally {\n isExecutingMicrotasksQueue = false;\n }\n };\n}\n\nfunction callMicrotasksOnUIThread() {\n 'worklet';\n global.__callMicrotasks();\n}\n\nexport const callMicrotasks = SHOULD_BE_USE_WEB\n ? () => {\n // on web flushing is a noop as immediates are handled by the browser\n }\n : callMicrotasksOnUIThread;\n\n/**\n * Lets you asynchronously run [workletized](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#to-workletize) functions on the [UI thread](https://docs.swmansion.com/react-native-reanimated/docs/threading/runOnUI).\n *\n * This method does not schedule the work immediately but instead waits for other worklets\n * to be scheduled within the same JS loop. It uses queueMicrotask to schedule all the worklets\n * at once making sure they will run within the same frame boundaries on the UI thread.\n *\n * @param fun - A reference to a function you want to execute on the [UI thread](https://docs.swmansion.com/react-native-reanimated/docs/threading/runOnUI) from the [JavaScript thread](https://docs.swmansion.com/react-native-reanimated/docs/threading/runOnUI).\n * @returns A function that accepts arguments for the function passed as the first argument.\n * @see https://docs.swmansion.com/react-native-reanimated/docs/threading/runOnUI\n */\n// @ts-expect-error This overload is correct since it's what user sees in his code\n// before it's transformed by Reanimated Babel plugin.\nexport function runOnUI<Args extends unknown[], ReturnValue>(\n worklet: (...args: Args) => ReturnValue\n): (...args: Args) => void;\n\nexport function runOnUI<Args extends unknown[], ReturnValue>(\n worklet: WorkletFunction<Args, ReturnValue>\n): (...args: Args) => void {\n 'worklet';\n if (__DEV__ && !SHOULD_BE_USE_WEB && _WORKLET) {\n throw new Error(\n '[Reanimated] `runOnUI` cannot be called on the UI runtime. Please call the function synchronously or use `queueMicrotask` or `requestAnimationFrame` instead.'\n );\n }\n if (__DEV__ && !SHOULD_BE_USE_WEB && !isWorkletFunction(worklet)) {\n throw new Error('[Reanimated] `runOnUI` can only be used on worklets.');\n }\n return (...args) => {\n if (IS_JEST) {\n // Mocking time in Jest is tricky as both requestAnimationFrame and queueMicrotask\n // callbacks run on the same queue and can be interleaved. There is no way\n // to flush particular queue in Jest and the only control over mocked timers\n // is by using jest.advanceTimersByTime() method which advances all types\n // of timers including immediate and animation callbacks. Ideally we'd like\n // to have some way here to schedule work along with React updates, but\n // that's not possible, and hence in Jest environment instead of using scheduling\n // mechanism we just schedule the work ommiting the queue. This is ok for the\n // uses that we currently have but may not be ok for future tests that we write.\n NativeReanimatedModule.scheduleOnUI(\n makeShareableCloneRecursive(() => {\n 'worklet';\n worklet(...args);\n })\n );\n return;\n }\n if (__DEV__) {\n // in DEV mode we call shareable conversion here because in case the object\n // can't be converted, we will get a meaningful stack-trace as opposed to the\n // situation when conversion is only done via microtask queue. This does not\n // make the app particularily less efficient as converted objects are cached\n // and for a given worklet the conversion only happens once.\n makeShareableCloneRecursive(worklet);\n makeShareableCloneRecursive(args);\n }\n _runOnUIQueue.push([worklet as WorkletFunction, args]);\n if (_runOnUIQueue.length === 1) {\n queueMicrotask(() => {\n const queue = _runOnUIQueue;\n _runOnUIQueue = [];\n NativeReanimatedModule.scheduleOnUI(\n makeShareableCloneRecursive(() => {\n 'worklet';\n // eslint-disable-next-line @typescript-eslint/no-shadow\n queue.forEach(([worklet, args]) => {\n worklet(...args);\n });\n callMicrotasks();\n })\n );\n });\n }\n };\n}\n\n// @ts-expect-error Check `executeOnUIRuntimeSync` overload above.\nexport function executeOnUIRuntimeSync<Args extends unknown[], ReturnValue>(\n worklet: (...args: Args) => ReturnValue\n): (...args: Args) => ReturnValue;\n\nexport function executeOnUIRuntimeSync<Args extends unknown[], ReturnValue>(\n worklet: WorkletFunction<Args, ReturnValue>\n): (...args: Args) => ReturnValue {\n return (...args) => {\n return NativeReanimatedModule.executeOnUIRuntimeSync(\n makeShareableCloneRecursive(() => {\n 'worklet';\n const result = worklet(...args);\n return makeShareableCloneOnUIRecursive(result);\n })\n );\n };\n}\n\n// @ts-expect-error Check `runOnUI` overload above.\nexport function runOnUIImmediately<Args extends unknown[], ReturnValue>(\n worklet: (...args: Args) => ReturnValue\n): WorkletFunction<Args, ReturnValue>;\n/**\n * Schedule a worklet to execute on the UI runtime skipping batching mechanism.\n */\nexport function runOnUIImmediately<Args extends unknown[], ReturnValue>(\n worklet: WorkletFunction<Args, ReturnValue>\n): (...args: Args) => void {\n 'worklet';\n if (__DEV__ && !SHOULD_BE_USE_WEB && _WORKLET) {\n throw new Error(\n '[Reanimated] `runOnUIImmediately` cannot be called on the UI runtime. Please call the function synchronously or use `queueMicrotask` or `requestAnimationFrame` instead.'\n );\n }\n if (__DEV__ && !SHOULD_BE_USE_WEB && !isWorkletFunction(worklet)) {\n throw new Error(\n '[Reanimated] `runOnUIImmediately` can only be used on worklets.'\n );\n }\n return (...args) => {\n NativeReanimatedModule.scheduleOnUI(\n makeShareableCloneRecursive(() => {\n 'worklet';\n worklet(...args);\n })\n );\n };\n}\n\ntype ReleaseRemoteFunction<Args extends unknown[], ReturnValue> = {\n (...args: Args): ReturnValue;\n};\n\ntype DevRemoteFunction<Args extends unknown[], ReturnValue> = {\n __remoteFunction: (...args: Args) => ReturnValue;\n};\n\ntype RemoteFunction<Args extends unknown[], ReturnValue> =\n | ReleaseRemoteFunction<Args, ReturnValue>\n | DevRemoteFunction<Args, ReturnValue>;\n\nfunction runWorkletOnJS<Args extends unknown[], ReturnValue>(\n worklet: WorkletFunction<Args, ReturnValue>,\n ...args: Args\n): void {\n // remote function that calls a worklet synchronously on the JS runtime\n worklet(...args);\n}\n\n/**\n * Lets you asynchronously run non-[workletized](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#to-workletize) functions that couldn't otherwise run on the [UI thread](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#ui-thread).\n * This applies to most external libraries as they don't have their functions marked with \"worklet\"; directive.\n *\n * @param fun - A reference to a function you want to execute on the JavaScript thread from the UI thread.\n * @returns A function that accepts arguments for the function passed as the first argument.\n * @see https://docs.swmansion.com/react-native-reanimated/docs/threading/runOnJS\n */\nexport function runOnJS<Args extends unknown[], ReturnValue>(\n fun:\n | ((...args: Args) => ReturnValue)\n | RemoteFunction<Args, ReturnValue>\n | WorkletFunction<Args, ReturnValue>\n): (...args: Args) => void {\n 'worklet';\n type FunDevRemote = Extract<typeof fun, DevRemoteFunction<Args, ReturnValue>>;\n if (SHOULD_BE_USE_WEB || !_WORKLET) {\n // if we are already on the JS thread, we just schedule the worklet on the JS queue\n return (...args) =>\n queueMicrotask(\n args.length\n ? () => (fun as (...args: Args) => ReturnValue)(...args)\n : (fun as () => ReturnValue)\n );\n }\n if (isWorkletFunction<Args, ReturnValue>(fun)) {\n // If `fun` is a worklet, we schedule a call of a remote function `runWorkletOnJS`\n // and pass the worklet as a first argument followed by original arguments.\n\n return (...args) =>\n runOnJS(runWorkletOnJS<Args, ReturnValue>)(\n fun as WorkletFunction<Args, ReturnValue>,\n ...args\n );\n }\n if ((fun as FunDevRemote).__remoteFunction) {\n // In development mode the function provided as `fun` throws an error message\n // such that when someone accidentally calls it directly on the UI runtime, they\n // see that they should use `runOnJS` instead. To facilitate that we put the\n // reference to the original remote function in the `__remoteFunction` property.\n fun = (fun as FunDevRemote).__remoteFunction;\n }\n return (...args) => {\n global._scheduleOnJS(\n fun as\n | ((...args: Args) => ReturnValue)\n | WorkletFunction<Args, ReturnValue>,\n args.length > 0\n ? // TODO TYPESCRIPT this cast is terrible but will be fixed\n (makeShareableCloneOnUIRecursive(args) as unknown as unknown[])\n : undefined\n );\n };\n}\n"],"mappings":"AAAA,YAAY;;AACZ,OAAOA,sBAAsB,MAAM,oBAAoB;AACvD,SAASC,MAAM,EAAEC,cAAc,QAAQ,mBAAmB;AAE1D,SACEC,+BAA+B,EAC/BC,2BAA2B,QACtB,cAAc;AACrB,SAASC,iBAAiB,QAAQ,eAAe;AAEjD,MAAMC,OAAO,GAAGL,MAAM,CAAC,CAAC;AACxB,MAAMM,iBAAiB,GAAGL,cAAc,CAAC,CAAC;;AAE1C;AACA;AACA;AACA,IAAIM,aAAsE,GAAG,EAAE;AAE/E,OAAO,SAASC,eAAeA,CAAA,EAAG;EAChC,SAAS;;EAET,IAAIC,eAAkC,GAAG,EAAE;EAC3C,IAAIC,0BAA0B,GAAG,KAAK;EACtCC,MAAM,CAACC,cAAc,GAAIC,QAAoB,IAAK;IAChDJ,eAAe,CAACK,IAAI,CAACD,QAAQ,CAAC;EAChC,CAAC;EAEDF,MA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EACH;EACA,OAAO,CAAC,GAAGC,IAAI,KAAK;IAClB3B,sBAAsB,CAAC4B,YAAY,CACjCxB,2BAA2B,CAAC,MAAM;MAChC,SAAS;;MACTmB,OAAO,CAAC,GAAGI,IAAI,CAAC;IAClB,CAAC,CACH,CAAC;EACH,CAAC;AACH;AAcA,SAASO,cAAcA,CACrBX,OAA2C,EAC3C,GAAGI,IAAU,EACP;EACN;EACAJ,OAAO,CAAC,GAAGI,IAAI,CAAC;AAClB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASQ,OAAOA,CACrBC,GAGsC,EACb;EACzB,SAAS;;EAET,IAAI7B,iBAAiB,IAAI,CAACkB,QAAQ,EAAE;IAClC;IACA,OAAO,CAAC,GAAGE,IAAI,KACbd,cAAc,CACZc,IAAI,CAACT,MAAM,GACP,MAAOkB,GAAG,CAAoC,GAAGT,IAAI,CAAC,GACrDS,GACP,CAAC;EACL;EACA,IAAI/B,iBAAiB,CAAoB+B,GAAG,CAAC,EAAE;IAC7C;IACA;;IAEA,OAAO,CAAC,GAAGT,IAAI,KACbQ,OAAO,CAACD,cAAiC,CAAC,CACxCE,GAAG,EACH,GAAGT,IACL,CAAC;EACL;EACA,IAAKS,GAAG,CAAkBC,gBAAgB,EAAE;IAC1C;IACA;IACA;IACA;IACAD,GAAG,GAAIA,GAAG,CAAkBC,gBAAgB;EAC9C;EACA,OAAO,CAAC,GAAGV,IAAI,KAAK;IAClBf,MAAM,CAAC0B,aAAa,CAClBF,GAAG,EAGHT,IAAI,CAACT,MAAM,GAAG,CAAC;IACX;IACCf,+BAA+B,CAACwB,IAAI,CAAC,GACtCY,SACN,CAAC;EACH,CAAC;AACH","ignoreList":[]}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
export function valueSetter(mutable, value) {
|
|
3
|
+
export function valueSetter(mutable, value, forceUpdate = false) {
|
|
4
4
|
'worklet';
|
|
5
5
|
|
|
6
|
-
let forceUpdate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
7
6
|
const previousAnimation = mutable._animation;
|
|
8
7
|
if (previousAnimation) {
|
|
9
8
|
previousAnimation.cancelled = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["valueSetter","mutable","value","forceUpdate","
|
|
1
|
+
{"version":3,"names":["valueSetter","mutable","value","forceUpdate","previousAnimation","_animation","cancelled","onFrame","undefined","animation","_value","current","isHigherOrder","callback","initializeAnimation","timestamp","onStart","currentTimestamp","global","__frameTimestamp","_getAnimationTimestamp","step","newTimestamp","finished","requestAnimationFrame"],"sources":["valueSetter.ts"],"sourcesContent":["'use strict';\nimport type { AnimationObject, Mutable } from './commonTypes';\n\nexport function valueSetter<Value>(\n mutable: Mutable<Value>,\n value: Value,\n forceUpdate = false\n): void {\n 'worklet';\n const previousAnimation = mutable._animation;\n if (previousAnimation) {\n previousAnimation.cancelled = true;\n mutable._animation = null;\n }\n if (\n typeof value === 'function' ||\n (value !== null &&\n typeof value === 'object' &&\n // TODO TYPESCRIPT fix this after fixing AnimationObject type\n (value as unknown as AnimationObject).onFrame !== undefined)\n ) {\n const animation: AnimationObject<Value> =\n typeof value === 'function'\n ? // TODO TYPESCRIPT fix this after fixing AnimationObject type\n (value as () => AnimationObject<Value>)()\n : // TODO TYPESCRIPT fix this after fixing AnimationObject type\n (value as unknown as AnimationObject<Value>);\n // prevent setting again to the same value\n // and triggering the mappers that treat this value as an input\n // this happens when the animation's target value(stored in animation.current until animation.onStart is called) is set to the same value as a current one(this._value)\n // built in animations that are not higher order(withTiming, withSpring) hold target value in .current\n if (\n mutable._value === animation.current &&\n !animation.isHigherOrder &&\n !forceUpdate\n ) {\n animation.callback && animation.callback(true);\n return;\n }\n // animated set\n const initializeAnimation = (timestamp: number) => {\n animation.onStart(animation, mutable.value, timestamp, previousAnimation);\n };\n const currentTimestamp =\n global.__frameTimestamp || global._getAnimationTimestamp();\n initializeAnimation(currentTimestamp);\n\n const step = (newTimestamp: number) => {\n // Function `requestAnimationFrame` adds callback to an array, all the callbacks are flushed with function `__flushAnimationFrame`\n // Usually we flush them inside function `nativeRequestAnimationFrame` and then the given timestamp is the timestamp of end of the current frame.\n // However function `__flushAnimationFrame` may also be called inside `registerEventHandler` - then we get actual timestamp which is earlier than the end of the frame.\n\n const timestamp =\n newTimestamp < (animation.timestamp || 0)\n ? animation.timestamp\n : newTimestamp;\n\n if (animation.cancelled) {\n animation.callback && animation.callback(false /* finished */);\n return;\n }\n const finished = animation.onFrame(animation, timestamp);\n animation.finished = true;\n animation.timestamp = timestamp;\n // TODO TYPESCRIPT\n // For now I'll assume that `animation.current` is always defined\n // but actually need to dive into animations to understand it\n mutable._value = animation.current!;\n if (finished) {\n animation.callback && animation.callback(true /* finished */);\n } else {\n requestAnimationFrame(step);\n }\n };\n\n mutable._animation = animation;\n\n step(currentTimestamp);\n } else {\n // prevent setting again to the same value\n // and triggering the mappers that treat this value as an input\n if (mutable._value === value && !forceUpdate) {\n return;\n }\n mutable._value = value;\n }\n}\n"],"mappings":"AAAA,YAAY;;AAGZ,OAAO,SAASA,WAAWA,CACzBC,OAAuB,EACvBC,KAAY,EACZC,WAAW,GAAG,KAAK,EACb;EACN,SAAS;;EACT,MAAMC,iBAAiB,GAAGH,OAAO,CAACI,UAAU;EAC5C,IAAID,iBAAiB,EAAE;IACrBA,iBAAiB,CAACE,SAAS,GAAG,IAAI;IAClCL,OAAO,CAACI,UAAU,GAAG,IAAI;EAC3B;EACA,IACE,OAAOH,KAAK,KAAK,UAAU,IAC1BA,KAAK,KAAK,IAAI,IACb,OAAOA,KAAK,KAAK,QAAQ;EACzB;EACCA,KAAK,CAAgCK,OAAO,KAAKC,SAAU,EAC9D;IACA,MAAMC,SAAiC,GACrC,OAAOP,KAAK,KAAK,UAAU;IACvB;IACCA,KAAK,CAAkC,CAAC;IACzC;IACCA,KAA2C;IAClD;IACA;IACA;IACA;IACA,IACED,OAAO,CAACS,MAAM,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MAAM;IACL;IACA;IACA,IAAIhB,OAAO,CAACS,MAAM,KAAKR,KAAK,IAAI,CAACC,WAAW,EAAE;MAC5C;IACF;IACAF,OAAO,CAACS,MAAM,GAAGR,KAAK;EACxB;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["shouldBeUseWeb","isWorkletFunction","valueUnpacker","objectToUnpack","category","remoteFunctionName","workletsCache","global","__workletsCache","handleCache","__handleCache","undefined","Map","WeakMap","workletHash","__workletHash","workletFun","get","initData","__initData","evalWithSourceMap","code","location","sourceMap","evalWithSourceUrl","eval","set","functionInstance","bind","_recur","__init","value","fun","label","Error","__remoteFunction","_toString","__DEV__","testWorklet","closure","__closure","Object","keys","length","getValueUnpackerCode"],"sources":["valueUnpacker.ts"],"sourcesContent":["'use strict';\nimport { shouldBeUseWeb } from './PlatformChecker';\nimport { isWorkletFunction } from './commonTypes';\nimport type { WorkletFunction } from './commonTypes';\n\nfunction valueUnpacker(\n objectToUnpack: any,\n category?: string,\n remoteFunctionName?: string\n): any {\n 'worklet';\n let workletsCache = global.__workletsCache;\n let handleCache = global.__handleCache;\n if (workletsCache === undefined) {\n // init\n workletsCache = global.__workletsCache = new Map();\n handleCache = global.__handleCache = new WeakMap();\n }\n const workletHash = objectToUnpack.__workletHash;\n if (workletHash !== undefined) {\n let workletFun = workletsCache.get(workletHash);\n if (workletFun === undefined) {\n const initData = objectToUnpack.__initData;\n if (global.evalWithSourceMap) {\n // if the runtime (hermes only for now) supports loading source maps\n // we want to use the proper filename for the location as it guarantees\n // that debugger understands and loads the source code of the file where\n // the worklet is defined.\n workletFun = global.evalWithSourceMap(\n '(' + initData.code + '\\n)',\n initData.location,\n initData.sourceMap\n ) as (...args: any[]) => any;\n } else if (global.evalWithSourceUrl) {\n // if the runtime doesn't support loading source maps, in dev mode we\n // can pass source url when evaluating the worklet. Now, instead of using\n // the actual file location we use worklet hash, as it the allows us to\n // properly symbolicate traces (see errors.ts for details)\n workletFun = global.evalWithSourceUrl(\n '(' + initData.code + '\\n)',\n `worklet_${workletHash}`\n ) as (...args: any[]) => any;\n } else {\n // in release we use the regular eval to save on JSI calls\n // eslint-disable-next-line no-eval\n workletFun = eval('(' + initData.code + '\\n)') as (\n ...args: any[]\n ) => any;\n }\n workletsCache.set(workletHash, workletFun);\n }\n const functionInstance = workletFun.bind(objectToUnpack);\n objectToUnpack._recur = functionInstance;\n return functionInstance;\n } else if (objectToUnpack.__init !== undefined) {\n let value = handleCache.get(objectToUnpack);\n if (value === undefined) {\n value = objectToUnpack.__init();\n handleCache.set(objectToUnpack, value);\n }\n return value;\n } else if (category === 'RemoteFunction') {\n const fun = () => {\n const label = remoteFunctionName\n ? `function \\`${remoteFunctionName}\\``\n : 'anonymous function';\n throw new Error(`[Reanimated] Tried to synchronously call a non-worklet ${label} on the UI thread.\nSee https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#tried-to-synchronously-call-a-non-worklet-function-on-the-ui-thread for more details.`);\n };\n fun.__remoteFunction = objectToUnpack;\n return fun;\n } else {\n throw new Error(\n `[Reanimated] Data type in category \"${category}\" not recognized by value unpacker: \"${_toString(\n objectToUnpack\n )}\".`\n );\n }\n}\n\ntype ValueUnpacker = WorkletFunction<\n [objectToUnpack: any, category?: string],\n any\n>;\n\nif (__DEV__ && !shouldBeUseWeb()) {\n const testWorklet = (() => {\n 'worklet';\n }) as WorkletFunction<[], void>;\n if (!isWorkletFunction(testWorklet)) {\n throw new Error(\n `[Reanimated] Failed to create a worklet. See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#failed-to-create-a-worklet for more details.`\n );\n }\n if (!isWorkletFunction(valueUnpacker)) {\n throw new Error('[Reanimated] `valueUnpacker` is not a worklet');\n }\n const closure = (valueUnpacker as ValueUnpacker).__closure;\n if (closure === undefined) {\n throw new Error('[Reanimated] `valueUnpacker` closure is undefined');\n }\n if (Object.keys(closure).length !== 0) {\n throw new Error('[Reanimated] `valueUnpacker` must have empty closure');\n }\n}\n\nexport function getValueUnpackerCode() {\n return (valueUnpacker as ValueUnpacker).__initData.code;\n}\n"],"mappings":"AAAA,YAAY;;AACZ,SAASA,cAAc,QAAQ,mBAAmB;AAClD,SAASC,iBAAiB,QAAQ,eAAe;AAGjD,SAASC,aAAaA,CACpBC,cAAmB,EACnBC,QAAiB,EACjBC,kBAA2B,EACtB;EACL,SAAS;;EACT,IAAIC,aAAa,GAAGC,MAAM,CAACC,eAAe;EAC1C,IAAIC,WAAW,GAAGF,MAAM,CAACG,aAAa;EACtC,IAAIJ,aAAa,KAAKK,SAAS,EAAE;IAC/B;IACAL,aAAa,GAAGC,MAAM,CAACC,eAAe,GAAG,IAAII,GAAG,
|
|
1
|
+
{"version":3,"names":["shouldBeUseWeb","isWorkletFunction","valueUnpacker","objectToUnpack","category","remoteFunctionName","workletsCache","global","__workletsCache","handleCache","__handleCache","undefined","Map","WeakMap","workletHash","__workletHash","workletFun","get","initData","__initData","evalWithSourceMap","code","location","sourceMap","evalWithSourceUrl","eval","set","functionInstance","bind","_recur","__init","value","fun","label","Error","__remoteFunction","_toString","__DEV__","testWorklet","closure","__closure","Object","keys","length","getValueUnpackerCode"],"sources":["valueUnpacker.ts"],"sourcesContent":["'use strict';\nimport { shouldBeUseWeb } from './PlatformChecker';\nimport { isWorkletFunction } from './commonTypes';\nimport type { WorkletFunction } from './commonTypes';\n\nfunction valueUnpacker(\n objectToUnpack: any,\n category?: string,\n remoteFunctionName?: string\n): any {\n 'worklet';\n let workletsCache = global.__workletsCache;\n let handleCache = global.__handleCache;\n if (workletsCache === undefined) {\n // init\n workletsCache = global.__workletsCache = new Map();\n handleCache = global.__handleCache = new WeakMap();\n }\n const workletHash = objectToUnpack.__workletHash;\n if (workletHash !== undefined) {\n let workletFun = workletsCache.get(workletHash);\n if (workletFun === undefined) {\n const initData = objectToUnpack.__initData;\n if (global.evalWithSourceMap) {\n // if the runtime (hermes only for now) supports loading source maps\n // we want to use the proper filename for the location as it guarantees\n // that debugger understands and loads the source code of the file where\n // the worklet is defined.\n workletFun = global.evalWithSourceMap(\n '(' + initData.code + '\\n)',\n initData.location,\n initData.sourceMap\n ) as (...args: any[]) => any;\n } else if (global.evalWithSourceUrl) {\n // if the runtime doesn't support loading source maps, in dev mode we\n // can pass source url when evaluating the worklet. Now, instead of using\n // the actual file location we use worklet hash, as it the allows us to\n // properly symbolicate traces (see errors.ts for details)\n workletFun = global.evalWithSourceUrl(\n '(' + initData.code + '\\n)',\n `worklet_${workletHash}`\n ) as (...args: any[]) => any;\n } else {\n // in release we use the regular eval to save on JSI calls\n // eslint-disable-next-line no-eval\n workletFun = eval('(' + initData.code + '\\n)') as (\n ...args: any[]\n ) => any;\n }\n workletsCache.set(workletHash, workletFun);\n }\n const functionInstance = workletFun.bind(objectToUnpack);\n objectToUnpack._recur = functionInstance;\n return functionInstance;\n } else if (objectToUnpack.__init !== undefined) {\n let value = handleCache.get(objectToUnpack);\n if (value === undefined) {\n value = objectToUnpack.__init();\n handleCache.set(objectToUnpack, value);\n }\n return value;\n } else if (category === 'RemoteFunction') {\n const fun = () => {\n const label = remoteFunctionName\n ? `function \\`${remoteFunctionName}\\``\n : 'anonymous function';\n throw new Error(`[Reanimated] Tried to synchronously call a non-worklet ${label} on the UI thread.\nSee https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#tried-to-synchronously-call-a-non-worklet-function-on-the-ui-thread for more details.`);\n };\n fun.__remoteFunction = objectToUnpack;\n return fun;\n } else {\n throw new Error(\n `[Reanimated] Data type in category \"${category}\" not recognized by value unpacker: \"${_toString(\n objectToUnpack\n )}\".`\n );\n }\n}\n\ntype ValueUnpacker = WorkletFunction<\n [objectToUnpack: any, category?: string],\n any\n>;\n\nif (__DEV__ && !shouldBeUseWeb()) {\n const testWorklet = (() => {\n 'worklet';\n }) as WorkletFunction<[], void>;\n if (!isWorkletFunction(testWorklet)) {\n throw new Error(\n `[Reanimated] Failed to create a worklet. See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#failed-to-create-a-worklet for more details.`\n );\n }\n if (!isWorkletFunction(valueUnpacker)) {\n throw new Error('[Reanimated] `valueUnpacker` is not a worklet');\n }\n const closure = (valueUnpacker as ValueUnpacker).__closure;\n if (closure === undefined) {\n throw new Error('[Reanimated] `valueUnpacker` closure is undefined');\n }\n if (Object.keys(closure).length !== 0) {\n throw new Error('[Reanimated] `valueUnpacker` must have empty closure');\n }\n}\n\nexport function getValueUnpackerCode() {\n return (valueUnpacker as ValueUnpacker).__initData.code;\n}\n"],"mappings":"AAAA,YAAY;;AACZ,SAASA,cAAc,QAAQ,mBAAmB;AAClD,SAASC,iBAAiB,QAAQ,eAAe;AAGjD,SAASC,aAAaA,CACpBC,cAAmB,EACnBC,QAAiB,EACjBC,kBAA2B,EACtB;EACL,SAAS;;EACT,IAAIC,aAAa,GAAGC,MAAM,CAACC,eAAe;EAC1C,IAAIC,WAAW,GAAGF,MAAM,CAACG,aAAa;EACtC,IAAIJ,aAAa,KAAKK,SAAS,EAAE;IAC/B;IACAL,aAAa,GAAGC,MAAM,CAACC,eAAe,GAAG,IAAII,GAAG,CAAC,CAAC;IAClDH,WAAW,GAAGF,MAAM,CAACG,aAAa,GAAG,IAAIG,OAAO,CAAC,CAAC;EACpD;EACA,MAAMC,WAAW,GAAGX,cAAc,CAACY,aAAa;EAChD,IAAID,WAAW,KAAKH,SAAS,EAAE;IAC7B,IAAIK,UAAU,GAAGV,aAAa,CAACW,GAAG,CAACH,WAAW,CAAC;IAC/C,IAAIE,UAAU,KAAKL,SAAS,EAAE;MAC5B,MAAMO,QAAQ,GAAGf,cAAc,CAACgB,UAAU;MAC1C,IAAIZ,MAAM,CAACa,iBAAiB,EAAE;QAC5B;QACA;QACA;QACA;QACAJ,UAAU,GAAGT,MAAM,CAACa,iBAAiB,CACnC,GAAG,GAAGF,QAAQ,CAACG,IAAI,GAAG,KAAK,EAC3BH,QAAQ,CAACI,QAAQ,EACjBJ,QAAQ,CAACK,SACX,CAA4B;MAC9B,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,CAAE,IACJ,CAAC;EACH;AACF;AAOA,IAAIkC,OAAO,IAAI,CAACrC,cAAc,CAAC,CAAC,EAAE;EAChC,MAAMsC,WAAW,GAAIA,CAAA,KAAM;IACzB,SAAS;EACX,CAA+B;EAC/B,IAAI,CAACrC,iBAAiB,CAACqC,WAAW,CAAC,EAAE;IACnC,MAAM,IAAIJ,KAAK,CACZ,0KACH,CAAC;EACH;EACA,IAAI,CAACjC,iBAAiB,CAACC,aAAa,CAAC,EAAE;IACrC,MAAM,IAAIgC,KAAK,CAAC,+CAA+C,CAAC;EAClE;EACA,MAAMK,OAAO,GAAIrC,aAAa,CAAmBsC,SAAS;EAC1D,IAAID,OAAO,KAAK5B,SAAS,EAAE;IACzB,MAAM,IAAIuB,KAAK,CAAC,mDAAmD,CAAC;EACtE;EACA,IAAIO,MAAM,CAACC,IAAI,CAACH,OAAO,CAAC,CAACI,MAAM,KAAK,CAAC,EAAE;IACrC,MAAM,IAAIT,KAAK,CAAC,sDAAsD,CAAC;EACzE;AACF;AAEA,OAAO,SAASU,oBAAoBA,CAAA,EAAG;EACrC,OAAQ1C,aAAa,CAAmBiB,UAAU,CAACE,IAAI;AACzD","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TurboModuleRegistry","get"],"sources":["NativeReanimatedModule.ts"],"sourcesContent":["'use strict';\nimport type { TurboModule } from 'react-native';\nimport { TurboModuleRegistry } from 'react-native';\n\ninterface Spec extends TurboModule {\n installTurboModule: (valueUnpackerCode: string) => boolean;\n}\n\nexport default TurboModuleRegistry.get<Spec>('ReanimatedModule');\n"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,mBAAmB,QAAQ,cAAc;AAMlD,eAAeA,mBAAmB,CAACC,GAAG,CAAO,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","get"],"sources":["NativeReanimatedModule.ts"],"sourcesContent":["'use strict';\nimport type { TurboModule } from 'react-native';\nimport { TurboModuleRegistry } from 'react-native';\n\ninterface Spec extends TurboModule {\n installTurboModule: (valueUnpackerCode: string) => boolean;\n}\n\nexport default TurboModuleRegistry.get<Spec>('ReanimatedModule');\n"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,mBAAmB,QAAQ,cAAc;AAMlD,eAAeA,mBAAmB,CAACC,GAAG,CAAO,kBAAkB,CAAC","ignoreList":[]}
|
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import type { NativeSyntheticEvent } from 'react-native';
|
|
2
|
-
import type { EventPayload, ReanimatedEvent } from './hook/commonTypes';
|
|
2
|
+
import type { EventPayload, ReanimatedEvent, IWorkletEventHandler } from './hook/commonTypes';
|
|
3
3
|
type JSEvent<Event extends object> = NativeSyntheticEvent<EventPayload<Event>>;
|
|
4
|
-
|
|
4
|
+
declare class WorkletEventHandlerNative<Event extends object> implements IWorkletEventHandler<Event> {
|
|
5
|
+
#private;
|
|
6
|
+
eventNames: string[];
|
|
5
7
|
worklet: (event: ReanimatedEvent<Event>) => void;
|
|
8
|
+
constructor(worklet: (event: ReanimatedEvent<Event>) => void, eventNames: string[]);
|
|
9
|
+
updateEventHandler(newWorklet: (event: ReanimatedEvent<Event>) => void, newEvents: string[]): void;
|
|
10
|
+
registerForEvents(viewTag: number, fallbackEventName?: string): void;
|
|
11
|
+
unregisterFromEvents(viewTag: number): void;
|
|
12
|
+
}
|
|
13
|
+
declare class WorkletEventHandlerWeb<Event extends object> implements IWorkletEventHandler<Event> {
|
|
6
14
|
eventNames: string[];
|
|
7
|
-
reattachNeeded: boolean;
|
|
8
15
|
listeners: Record<string, (event: ReanimatedEvent<ReanimatedEvent<Event>>) => void> | Record<string, (event: JSEvent<Event>) => void>;
|
|
9
|
-
|
|
10
|
-
registrations: number[];
|
|
16
|
+
worklet: (event: ReanimatedEvent<Event>) => void;
|
|
11
17
|
constructor(worklet: (event: ReanimatedEvent<Event>) => void, eventNames?: string[]);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
unregisterFromEvents(): void;
|
|
18
|
+
setupWebListeners(): void;
|
|
19
|
+
updateEventHandler(newWorklet: (event: ReanimatedEvent<Event>) => void, newEvents: string[]): void;
|
|
20
|
+
registerForEvents(_viewTag: number, _fallbackEventName?: string): void;
|
|
21
|
+
unregisterFromEvents(_viewTag: number): void;
|
|
16
22
|
}
|
|
23
|
+
export declare const WorkletEventHandler: typeof WorkletEventHandlerNative | typeof WorkletEventHandlerWeb;
|
|
17
24
|
export {};
|
|
@@ -14,7 +14,7 @@ interface LayoutAnimationConfigProps {
|
|
|
14
14
|
* @see https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/layout-animation-config/
|
|
15
15
|
*/
|
|
16
16
|
export declare class LayoutAnimationConfig extends Component<LayoutAnimationConfigProps> {
|
|
17
|
-
getMaybeWrappedChildren(): string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.
|
|
17
|
+
getMaybeWrappedChildren(): string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.JSX.Element[] | null | undefined;
|
|
18
18
|
setShouldAnimateExiting(): void;
|
|
19
19
|
componentWillUnmount(): void;
|
|
20
20
|
render(): ReactNode;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare function PerformanceMonitor(): React.JSX.Element;
|
|
@@ -45,6 +45,11 @@ export type NativeEventWrapper<Event extends object> = {
|
|
|
45
45
|
export type DefaultStyle = ViewStyle | ImageStyle | TextStyle;
|
|
46
46
|
export type RNNativeScrollEvent = NativeSyntheticEvent<NativeScrollEvent>;
|
|
47
47
|
export type ReanimatedScrollEvent = ReanimatedEvent<RNNativeScrollEvent>;
|
|
48
|
+
export interface IWorkletEventHandler<Event extends object> {
|
|
49
|
+
updateEventHandler: (newWorklet: (event: ReanimatedEvent<Event>) => void, newEvents: string[]) => void;
|
|
50
|
+
registerForEvents: (viewTag: number, fallbackEventName?: string) => void;
|
|
51
|
+
unregisterFromEvents: (viewTag: number) => void;
|
|
52
|
+
}
|
|
48
53
|
export interface AnimatedStyleHandle<Style extends DefaultStyle = DefaultStyle> {
|
|
49
54
|
viewDescriptors: ViewDescriptorsSet;
|
|
50
55
|
initial: {
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { ReanimatedEvent } from './commonTypes';
|
|
1
|
+
import type { IWorkletEventHandler, ReanimatedEvent } from './commonTypes';
|
|
3
2
|
/**
|
|
4
3
|
* Worklet to provide as an argument to `useEvent` hook.
|
|
5
4
|
*/
|
|
6
5
|
export type EventHandler<Event extends object, Context extends Record<string, unknown> = never> = (event: ReanimatedEvent<Event>, context?: Context) => void;
|
|
7
6
|
export type EventHandlerProcessed<Event extends object, Context extends Record<string, unknown> = never> = (event: Event, context?: Context) => void;
|
|
8
7
|
export type EventHandlerInternal<Event extends object> = {
|
|
9
|
-
workletEventHandler:
|
|
8
|
+
workletEventHandler: IWorkletEventHandler<Event>;
|
|
10
9
|
};
|
|
11
10
|
/**
|
|
12
11
|
* Lets you run a function whenever a specified native event occurs.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-reanimated",
|
|
3
|
-
"version": "3.9.0
|
|
3
|
+
"version": "3.9.0",
|
|
4
4
|
"description": "More powerful alternative to Animated library for React Native.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "yarn run format:js && yarn run lint:js && yarn run test:unit",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"format:js": "prettier --write --list-different src __tests__ __typetests__",
|
|
19
19
|
"format:plugin": "cd plugin && yarn format && cd ..",
|
|
20
20
|
"format:java": "node ./scripts/format-java.js",
|
|
21
|
-
"format:ios": "find apple/ -iname *.h -o -iname *.m -o -iname *.mm -o -iname *.cpp | xargs clang-format -i --Werror",
|
|
21
|
+
"format:ios": "find apple/ -iname \"*.h\" -o -iname \"*.m\" -o -iname \"*.mm\" -o -iname \"*.cpp\" | xargs clang-format -i --Werror",
|
|
22
22
|
"format:android": "find android/src/ -iname *.h -o -iname *.cpp | xargs clang-format -i",
|
|
23
23
|
"format:common": "find Common/ -iname *.h -o -iname *.cpp | xargs clang-format -i",
|
|
24
24
|
"format:docs": "cd docs && yarn format && cd ..",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"type:check:tests:0.72+": "./scripts/test-ts.sh __typetests__/0.72+",
|
|
31
31
|
"type:check:tests:legacy": "./scripts/test-ts.sh __typetests__/legacy",
|
|
32
32
|
"type:check:all": "yarn type:check:src && yarn type:check:plugin && ./scripts/test-ts.sh app/src/App.tsx __typetests__/common __typetests__/0.72+ __typetests__/legacy",
|
|
33
|
-
"
|
|
33
|
+
"build": "yarn build:plugin && bob build && husky install && yarn build:app",
|
|
34
|
+
"build:app": "cd app && yarn install && yarn build",
|
|
35
|
+
"build:plugin": "cd plugin && yarn install && yarn build",
|
|
34
36
|
"circular_dependency_check": "yarn madge --extensions js,ts,tsx --circular src lib",
|
|
35
|
-
"use_strict_check": "node ./scripts/validate-use-strict.js"
|
|
36
|
-
"plugin": "cd plugin && yarn && cd ..",
|
|
37
|
-
"app": "cd app && yarn && cd .."
|
|
37
|
+
"use_strict_check": "node ./scripts/validate-use-strict.js"
|
|
38
38
|
},
|
|
39
39
|
"main": "lib/module/index",
|
|
40
40
|
"module": "lib/module/index",
|
|
@@ -101,7 +101,10 @@
|
|
|
101
101
|
"@babel/core": "^7.20.0",
|
|
102
102
|
"@babel/preset-env": "^7.20.0",
|
|
103
103
|
"@babel/types": "^7.20.0",
|
|
104
|
-
"@react-native/
|
|
104
|
+
"@react-native/babel-preset": "0.74.81",
|
|
105
|
+
"@react-native/eslint-config": "0.74.81",
|
|
106
|
+
"@react-native/metro-config": "0.74.81",
|
|
107
|
+
"@react-native/typescript-config": "0.74.81",
|
|
105
108
|
"@testing-library/jest-native": "^4.0.4",
|
|
106
109
|
"@testing-library/react-hooks": "^8.0.0",
|
|
107
110
|
"@testing-library/react-native": "^7.1.0",
|
|
@@ -137,13 +140,13 @@
|
|
|
137
140
|
"eslint-plugin-tsdoc": "^0.2.17",
|
|
138
141
|
"husky": "^7.0.4",
|
|
139
142
|
"jest": "^29.0.0",
|
|
140
|
-
"lint-staged": "^
|
|
143
|
+
"lint-staged": "^15.2.2",
|
|
141
144
|
"madge": "^5.0.1",
|
|
142
145
|
"prettier": "^2.5.1",
|
|
143
146
|
"react": "18.2.0",
|
|
144
|
-
"react-native": "0.74.0
|
|
147
|
+
"react-native": "0.74.0",
|
|
145
148
|
"react-native-builder-bob": "^0.18.3",
|
|
146
|
-
"react-native-gesture-handler": "
|
|
149
|
+
"react-native-gesture-handler": "^2.16.0",
|
|
147
150
|
"react-native-web": "~0.18.12",
|
|
148
151
|
"react-test-renderer": "18.2.0",
|
|
149
152
|
"shelljs": "^0.8.5",
|
|
@@ -152,9 +155,9 @@
|
|
|
152
155
|
},
|
|
153
156
|
"lint-staged": {
|
|
154
157
|
"*.(js|ts|tsx)": [
|
|
155
|
-
"eslint",
|
|
156
|
-
"eslint --quiet --ext '.js,.ts,.tsx' src/",
|
|
157
|
-
"prettier --write"
|
|
158
|
+
"yarn eslint",
|
|
159
|
+
"yarn eslint --quiet --ext '.js,.ts,.tsx' src/",
|
|
160
|
+
"yarn prettier --write"
|
|
158
161
|
],
|
|
159
162
|
"plugin/**/*.ts": "yarn lint:plugin",
|
|
160
163
|
"**/*.{h,cpp}": "yarn lint:cpp",
|
|
@@ -182,5 +185,6 @@
|
|
|
182
185
|
"sideEffects": [
|
|
183
186
|
"./lib/reanimated2/core",
|
|
184
187
|
"./lib/index"
|
|
185
|
-
]
|
|
188
|
+
],
|
|
189
|
+
"packageManager": "yarn@4.1.1"
|
|
186
190
|
}
|
package/plugin/build/plugin.js
CHANGED
|
@@ -344,7 +344,7 @@ var require_workletFactory = __commonJS({
|
|
|
344
344
|
sourceMaps: true,
|
|
345
345
|
sourceFileName: state.file.opts.filename
|
|
346
346
|
});
|
|
347
|
-
codeObject.code = "(" + (
|
|
347
|
+
codeObject.code = "(" + (fun.isObjectMethod() ? "function " : "") + codeObject.code + "\n)";
|
|
348
348
|
const transformed = (0, core_1.transformSync)(codeObject.code, {
|
|
349
349
|
filename: state.file.opts.filename,
|
|
350
350
|
presets: workletStringTransformPresets,
|
|
@@ -368,7 +368,10 @@ var require_workletFactory = __commonJS({
|
|
|
368
368
|
if (variables.length > 0) {
|
|
369
369
|
lineOffset -= variables.length + 2;
|
|
370
370
|
}
|
|
371
|
-
const pathForStringDefinitions = fun.parentPath.isProgram() ? fun : fun.findParent((path) =>
|
|
371
|
+
const pathForStringDefinitions = fun.parentPath.isProgram() ? fun : fun.findParent((path) => {
|
|
372
|
+
var _a, _b;
|
|
373
|
+
return (_b = (_a = path.parentPath) === null || _a === void 0 ? void 0 : _a.isProgram()) !== null && _b !== void 0 ? _b : false;
|
|
374
|
+
});
|
|
372
375
|
(0, assert_1.strict)(pathForStringDefinitions, "[Reanimated] `pathForStringDefinitions` is null.");
|
|
373
376
|
(0, assert_1.strict)(pathForStringDefinitions.parentPath, "[Reanimated] `pathForStringDefinitions.parentPath` is null.");
|
|
374
377
|
const initDataId = pathForStringDefinitions.parentPath.scope.generateUidIdentifier(`worklet_${workletHash}_init_data`);
|
|
@@ -530,6 +533,8 @@ var require_workletFactoryCall = __commonJS({
|
|
|
530
533
|
const originalWorkletLocation = path.node.loc;
|
|
531
534
|
if (originalWorkletLocation) {
|
|
532
535
|
workletFactoryCall.callee.loc = {
|
|
536
|
+
filename: originalWorkletLocation.filename,
|
|
537
|
+
identifierName: originalWorkletLocation.identifierName,
|
|
533
538
|
start: originalWorkletLocation.start,
|
|
534
539
|
end: originalWorkletLocation.start
|
|
535
540
|
};
|
|
@@ -4,7 +4,7 @@ import { shallowEqual } from '../reanimated2/hook/utils';
|
|
|
4
4
|
import type { StyleProps } from '../reanimated2/commonTypes';
|
|
5
5
|
import { isSharedValue } from '../reanimated2/isSharedValue';
|
|
6
6
|
import { isChromeDebugger } from '../reanimated2/PlatformChecker';
|
|
7
|
-
import WorkletEventHandler from '../reanimated2/WorkletEventHandler';
|
|
7
|
+
import { WorkletEventHandler } from '../reanimated2/WorkletEventHandler';
|
|
8
8
|
import { initialUpdaterRun } from '../reanimated2/animation';
|
|
9
9
|
import { hasInlineStyles, getInlineStyle } from './InlinePropManager';
|
|
10
10
|
import type {
|