react-native-reanimated 3.0.0-rc.9 → 3.0.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/AnimatedSensor/AnimatedSensorModule.cpp +30 -12
- package/Common/cpp/AnimatedSensor/AnimatedSensorModule.h +2 -0
- package/Common/cpp/Fabric/FabricUtils.cpp +3 -107
- package/Common/cpp/Fabric/FabricUtils.h +3 -24
- package/Common/cpp/Fabric/ReanimatedUIManagerBinding.cpp +54 -37
- package/Common/cpp/LayoutAnimations/LayoutAnimationType.h +8 -0
- package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.cpp +81 -26
- package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.h +20 -3
- package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +105 -109
- package/Common/cpp/NativeModules/NativeReanimatedModule.h +19 -12
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +15 -7
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.h +6 -2
- package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.cpp +20 -1
- package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.h +9 -0
- package/Common/cpp/ReanimatedRuntime/ReanimatedRuntime.cpp +5 -1
- package/Common/cpp/Registries/EventHandlerRegistry.cpp +8 -34
- package/Common/cpp/Registries/EventHandlerRegistry.h +7 -13
- package/Common/cpp/SharedItems/Shareables.cpp +9 -63
- package/Common/cpp/SharedItems/Shareables.h +77 -72
- package/Common/cpp/Tools/CollectionUtils.h +14 -0
- package/Common/cpp/Tools/JsiUtils.cpp +26 -0
- package/Common/cpp/Tools/JsiUtils.h +176 -0
- package/Common/cpp/Tools/PlatformDepMethodsHolder.h +5 -5
- package/Common/cpp/Tools/ReanimatedVersion.cpp +17 -0
- package/Common/cpp/Tools/ReanimatedVersion.h +11 -0
- package/Common/cpp/Tools/RuntimeDecorator.cpp +49 -230
- package/Common/cpp/Tools/RuntimeDecorator.h +0 -2
- package/Common/cpp/Tools/WorkletEventHandler.cpp +3 -2
- package/Common/cpp/Tools/WorkletEventHandler.h +14 -6
- package/RNReanimated.podspec +2 -1
- package/android/CMakeLists.txt +188 -181
- package/android/build.gradle +362 -311
- package/android/proguard-rules.pro +2 -0
- package/android/src/fabric/java/com/swmansion/reanimated/NativeProxy.java +63 -295
- package/android/src/main/cpp/LayoutAnimations.cpp +35 -5
- package/android/src/main/cpp/LayoutAnimations.h +23 -6
- package/android/src/main/cpp/NativeProxy.cpp +143 -98
- package/android/src/main/cpp/NativeProxy.h +22 -28
- package/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java +5 -4
- package/android/src/main/java/com/swmansion/reanimated/Utils.java +7 -1
- package/android/src/main/java/com/swmansion/reanimated/keyboardObserver/ReanimatedKeyboardEventListener.java +10 -3
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java +218 -35
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/LayoutAnimations.java +43 -17
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/NativeMethodsHolder.java +6 -2
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/SharedElement.java +19 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/SharedTransitionManager.java +610 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/Snapshot.java +93 -23
- package/android/src/main/java/com/swmansion/reanimated/nativeProxy/AnimationFrameCallback.java +19 -0
- package/android/src/main/java/com/swmansion/reanimated/nativeProxy/EventHandler.java +35 -0
- package/android/src/main/java/com/swmansion/reanimated/nativeProxy/KeyboardEventDataUpdater.java +16 -0
- package/android/src/main/java/com/swmansion/reanimated/nativeProxy/NativeProxyCommon.java +206 -0
- package/android/src/main/java/com/swmansion/reanimated/nativeProxy/SensorSetter.java +17 -0
- package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensor.java +9 -3
- package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorContainer.java +3 -4
- package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.java +31 -7
- package/android/src/paper/java/com/swmansion/reanimated/NativeProxy.java +90 -307
- package/android/src/reactNativeVersionPatch/ReanimatedUIManager/70/com/swmansion/reanimated/ReanimatedUIManagerFactory.java +16 -0
- package/android/src/reactNativeVersionPatch/ReanimatedUIManager/latest/com/swmansion/reanimated/ReanimatedUIManagerFactory.java +63 -0
- package/android/src/reactNativeVersionPatch/ReanimatedUIManager/latest/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +271 -0
- package/android/src/reactNativeVersionPatch/nativeHierarchyManager/latest/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +76 -20
- package/ios/LayoutReanimation/REAAnimationsManager.h +28 -4
- package/ios/LayoutReanimation/REAAnimationsManager.m +216 -61
- package/ios/LayoutReanimation/REAFrame.h +10 -0
- package/ios/LayoutReanimation/REAFrame.m +15 -0
- package/ios/LayoutReanimation/REAScreensHelper.h +19 -0
- package/ios/LayoutReanimation/REAScreensHelper.m +106 -0
- package/ios/LayoutReanimation/REASharedElement.h +15 -0
- package/ios/LayoutReanimation/REASharedElement.m +16 -0
- package/ios/LayoutReanimation/REASharedTransitionManager.h +17 -0
- package/ios/LayoutReanimation/REASharedTransitionManager.m +632 -0
- package/ios/LayoutReanimation/REASnapshot.h +1 -0
- package/ios/LayoutReanimation/REASnapshot.m +96 -11
- package/ios/LayoutReanimation/REAUIManager.mm +64 -17
- package/ios/REAModule.mm +2 -7
- package/ios/REANodesManager.mm +1 -21
- package/ios/keyboardObserver/REAKeyboardEventObserver.m +72 -36
- package/ios/native/NativeProxy.mm +75 -114
- package/ios/native/REAInitializer.mm +2 -7
- package/ios/native/REAJSIUtils.h +60 -2
- package/ios/sensor/ReanimatedSensor.h +6 -2
- package/ios/sensor/ReanimatedSensor.m +43 -7
- package/ios/sensor/ReanimatedSensorContainer.h +4 -1
- package/ios/sensor/ReanimatedSensorContainer.m +8 -2
- package/lib/commonjs/createAnimatedComponent.js +232 -28
- package/lib/commonjs/createAnimatedComponent.js.map +1 -1
- package/lib/commonjs/reanimated2/Colors.js +43 -22
- package/lib/commonjs/reanimated2/Colors.js.map +1 -1
- package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js +16 -33
- package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
- package/lib/commonjs/reanimated2/animation/styleAnimation.js +5 -1
- package/lib/commonjs/reanimated2/animation/styleAnimation.js.map +1 -1
- package/lib/commonjs/reanimated2/animation/util.js +17 -15
- package/lib/commonjs/reanimated2/animation/util.js.map +1 -1
- package/lib/commonjs/reanimated2/commonTypes.js +33 -1
- package/lib/commonjs/reanimated2/commonTypes.js.map +1 -1
- package/lib/commonjs/reanimated2/core.js +33 -14
- package/lib/commonjs/reanimated2/core.js.map +1 -1
- package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js +2 -2
- package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
- package/lib/commonjs/reanimated2/globals.d.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/index.js +0 -6
- package/lib/commonjs/reanimated2/hook/index.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js +5 -2
- package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedReaction.js +13 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedReaction.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedRef.js +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedRef.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js +89 -16
- package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js +43 -40
- package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useDerivedValue.js +13 -1
- package/lib/commonjs/reanimated2/hook/useDerivedValue.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js +2 -2
- package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/utils.js +18 -65
- package/lib/commonjs/reanimated2/hook/utils.js.map +1 -1
- package/lib/commonjs/reanimated2/index.js +13 -0
- package/lib/commonjs/reanimated2/index.js.map +1 -1
- package/lib/commonjs/reanimated2/initializers.js +71 -32
- package/lib/commonjs/reanimated2/initializers.js.map +1 -1
- package/lib/commonjs/reanimated2/interpolateColor.js +96 -19
- package/lib/commonjs/reanimated2/interpolateColor.js.map +1 -1
- package/lib/commonjs/reanimated2/jestUtils.js +1 -1
- package/lib/commonjs/reanimated2/jestUtils.js.map +1 -1
- package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js +103 -13
- package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
- package/lib/commonjs/reanimated2/js-reanimated/Mapper.js +22 -0
- package/lib/commonjs/reanimated2/js-reanimated/Mapper.js.map +1 -1
- package/lib/commonjs/reanimated2/js-reanimated/WebSensor.js +2 -0
- package/lib/commonjs/reanimated2/js-reanimated/WebSensor.js.map +1 -0
- package/lib/commonjs/reanimated2/js-reanimated/commonTypes.js.map +1 -1
- package/lib/commonjs/reanimated2/js-reanimated/global.js +0 -2
- package/lib/commonjs/reanimated2/js-reanimated/global.js.map +1 -1
- package/lib/commonjs/reanimated2/js-reanimated/index.js +0 -1
- package/lib/commonjs/reanimated2/js-reanimated/index.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +11 -0
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js +8 -0
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js +17 -9
- package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +16 -23
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -14
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -14
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Slide.js +8 -15
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +16 -23
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/index.js +13 -0
- package/lib/commonjs/reanimated2/layoutReanimation/index.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/sharedTransitions/index.js +94 -0
- package/lib/commonjs/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -0
- package/lib/commonjs/reanimated2/mappers.js +18 -6
- package/lib/commonjs/reanimated2/mappers.js.map +1 -1
- package/lib/commonjs/reanimated2/mock.js +20 -1
- package/lib/commonjs/reanimated2/mock.js.map +1 -1
- package/lib/commonjs/reanimated2/mutables.js +4 -2
- package/lib/commonjs/reanimated2/mutables.js.map +1 -1
- package/lib/commonjs/reanimated2/platform-specific/checkVersion.js +42 -0
- package/lib/commonjs/reanimated2/platform-specific/checkVersion.js.map +1 -0
- package/lib/commonjs/reanimated2/platform-specific/checkVersion.web.js +15 -0
- package/lib/commonjs/reanimated2/platform-specific/checkVersion.web.js.map +1 -0
- package/lib/commonjs/reanimated2/pluginUtils.js +11 -0
- package/lib/commonjs/reanimated2/pluginUtils.js.map +1 -0
- package/lib/commonjs/reanimated2/shareables.js +36 -15
- package/lib/commonjs/reanimated2/shareables.js.map +1 -1
- package/lib/commonjs/reanimated2/threads.js +114 -4
- package/lib/commonjs/reanimated2/threads.js.map +1 -1
- package/lib/commonjs/reanimated2/utils.js +7 -0
- package/lib/commonjs/reanimated2/utils.js.map +1 -1
- package/lib/commonjs/reanimated2/valueSetter.js +1 -3
- package/lib/commonjs/reanimated2/valueSetter.js.map +1 -1
- package/lib/module/createAnimatedComponent.js +229 -29
- package/lib/module/createAnimatedComponent.js.map +1 -1
- package/lib/module/reanimated2/Colors.js +35 -19
- package/lib/module/reanimated2/Colors.js.map +1 -1
- package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js +16 -32
- package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
- package/lib/module/reanimated2/animation/styleAnimation.js +5 -1
- package/lib/module/reanimated2/animation/styleAnimation.js.map +1 -1
- package/lib/module/reanimated2/animation/util.js +17 -16
- package/lib/module/reanimated2/animation/util.js.map +1 -1
- package/lib/module/reanimated2/commonTypes.js +29 -0
- package/lib/module/reanimated2/commonTypes.js.map +1 -1
- package/lib/module/reanimated2/core.js +32 -7
- package/lib/module/reanimated2/core.js.map +1 -1
- package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js +2 -2
- package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
- package/lib/module/reanimated2/globals.d.js.map +1 -1
- package/lib/module/reanimated2/hook/index.js +1 -1
- package/lib/module/reanimated2/hook/index.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedKeyboard.js +5 -2
- package/lib/module/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedReaction.js +12 -1
- package/lib/module/reanimated2/hook/useAnimatedReaction.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedRef.js +2 -2
- package/lib/module/reanimated2/hook/useAnimatedRef.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedSensor.js +88 -13
- package/lib/module/reanimated2/hook/useAnimatedSensor.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedStyle.js +46 -43
- package/lib/module/reanimated2/hook/useAnimatedStyle.js.map +1 -1
- package/lib/module/reanimated2/hook/useDerivedValue.js +12 -1
- package/lib/module/reanimated2/hook/useDerivedValue.js.map +1 -1
- package/lib/module/reanimated2/hook/useScrollViewOffset.js +2 -2
- package/lib/module/reanimated2/hook/useScrollViewOffset.js.map +1 -1
- package/lib/module/reanimated2/hook/utils.js +17 -60
- package/lib/module/reanimated2/hook/utils.js.map +1 -1
- package/lib/module/reanimated2/index.js +1 -0
- package/lib/module/reanimated2/index.js.map +1 -1
- package/lib/module/reanimated2/initializers.js +72 -33
- package/lib/module/reanimated2/initializers.js.map +1 -1
- package/lib/module/reanimated2/interpolateColor.js +96 -19
- package/lib/module/reanimated2/interpolateColor.js.map +1 -1
- package/lib/module/reanimated2/jestUtils.js +1 -1
- package/lib/module/reanimated2/jestUtils.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/JSReanimated.js +103 -13
- package/lib/module/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/Mapper.js +21 -0
- package/lib/module/reanimated2/js-reanimated/Mapper.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/WebSensor.js +2 -0
- package/lib/module/reanimated2/js-reanimated/WebSensor.js.map +1 -0
- package/lib/module/reanimated2/js-reanimated/commonTypes.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/global.js +0 -2
- package/lib/module/reanimated2/js-reanimated/global.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/index.js +0 -1
- package/lib/module/reanimated2/js-reanimated/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +9 -1
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js +1 -0
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationsManager.js +15 -8
- package/lib/module/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +16 -21
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -12
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -12
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js +8 -13
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +16 -21
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/index.js +1 -0
- package/lib/module/reanimated2/layoutReanimation/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js +82 -0
- package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -0
- package/lib/module/reanimated2/mappers.js +16 -6
- package/lib/module/reanimated2/mappers.js.map +1 -1
- package/lib/module/reanimated2/mock.js +20 -1
- package/lib/module/reanimated2/mock.js.map +1 -1
- package/lib/module/reanimated2/mutables.js +4 -2
- package/lib/module/reanimated2/mutables.js.map +1 -1
- package/lib/module/reanimated2/platform-specific/checkVersion.js +35 -0
- package/lib/module/reanimated2/platform-specific/checkVersion.js.map +1 -0
- package/lib/module/reanimated2/platform-specific/checkVersion.web.js +8 -0
- package/lib/module/reanimated2/platform-specific/checkVersion.web.js.map +1 -0
- package/lib/module/reanimated2/pluginUtils.js +4 -0
- package/lib/module/reanimated2/pluginUtils.js.map +1 -0
- package/lib/module/reanimated2/shareables.js +36 -12
- package/lib/module/reanimated2/shareables.js.map +1 -1
- package/lib/module/reanimated2/threads.js +105 -4
- package/lib/module/reanimated2/threads.js.map +1 -1
- package/lib/module/reanimated2/utils.js +5 -0
- package/lib/module/reanimated2/utils.js.map +1 -1
- package/lib/module/reanimated2/valueSetter.js +1 -2
- package/lib/module/reanimated2/valueSetter.js.map +1 -1
- package/package.json +10 -10
- package/{plugin.js → plugin/index.js} +128 -249
- package/react-native-reanimated.d.ts +57 -10
- package/scripts/reanimated_utils.rb +15 -2
- package/src/createAnimatedComponent.tsx +238 -28
- package/src/reanimated2/Colors.ts +38 -11
- package/src/reanimated2/NativeReanimated/NativeReanimated.ts +52 -39
- package/src/reanimated2/animation/styleAnimation.ts +8 -1
- package/src/reanimated2/animation/util.ts +29 -16
- package/src/reanimated2/commonTypes.ts +28 -1
- package/src/reanimated2/core.ts +42 -9
- package/src/reanimated2/frameCallback/FrameCallbackRegistryUI.ts +2 -2
- package/src/reanimated2/globals.d.ts +12 -15
- package/src/reanimated2/hook/index.ts +1 -1
- package/src/reanimated2/hook/useAnimatedKeyboard.ts +10 -4
- package/src/reanimated2/hook/useAnimatedReaction.ts +12 -5
- package/src/reanimated2/hook/useAnimatedRef.ts +1 -4
- package/src/reanimated2/hook/useAnimatedSensor.ts +88 -11
- package/src/reanimated2/hook/useAnimatedStyle.ts +44 -36
- package/src/reanimated2/hook/useDerivedValue.ts +8 -1
- package/src/reanimated2/hook/useScrollViewOffset.ts +2 -2
- package/src/reanimated2/hook/utils.ts +15 -61
- package/src/reanimated2/index.ts +1 -0
- package/src/reanimated2/initializers.ts +76 -35
- package/src/reanimated2/interpolateColor.ts +104 -20
- package/src/reanimated2/jestUtils.ts +1 -1
- package/src/reanimated2/js-reanimated/JSReanimated.ts +98 -15
- package/src/reanimated2/js-reanimated/Mapper.ts +32 -0
- package/src/reanimated2/js-reanimated/WebSensor.ts +34 -0
- package/src/reanimated2/js-reanimated/commonTypes.ts +0 -1
- package/src/reanimated2/js-reanimated/global.ts +0 -1
- package/src/reanimated2/js-reanimated/index.ts +0 -1
- package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +13 -1
- package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +1 -0
- package/src/reanimated2/layoutReanimation/animationsManager.ts +17 -9
- package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +16 -19
- package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +14 -11
- package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +21 -11
- package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +32 -11
- package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +36 -19
- package/src/reanimated2/layoutReanimation/index.ts +1 -0
- package/src/reanimated2/layoutReanimation/sharedTransitions/index.ts +87 -0
- package/src/reanimated2/mappers.ts +17 -6
- package/src/reanimated2/mock.ts +24 -1
- package/src/reanimated2/mutables.ts +2 -0
- package/src/reanimated2/platform-specific/checkVersion.ts +39 -0
- package/src/reanimated2/platform-specific/checkVersion.web.ts +6 -0
- package/src/reanimated2/pluginUtils.ts +8 -0
- package/src/reanimated2/shareables.ts +45 -16
- package/src/reanimated2/threads.ts +103 -1
- package/src/reanimated2/utils.ts +6 -0
- package/src/reanimated2/valueSetter.ts +1 -2
- package/lib/commonjs/reanimated2/time.js +0 -55
- package/lib/commonjs/reanimated2/time.js.map +0 -1
- package/lib/module/reanimated2/time.js +0 -37
- package/lib/module/reanimated2/time.js.map +0 -1
- package/src/reanimated2/time.ts +0 -30
- /package/android/src/{main/java → reactNativeVersionPatch/ReanimatedUIManager/70}/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +0 -0
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
2
|
import { makeMutable, registerSensor, unregisterSensor } from '../core';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
ROTATION = 5,
|
|
11
|
-
}
|
|
3
|
+
import {
|
|
4
|
+
SensorType,
|
|
5
|
+
SharedValue,
|
|
6
|
+
Value3D,
|
|
7
|
+
ValueRotation,
|
|
8
|
+
IOSReferenceFrame,
|
|
9
|
+
} from '../commonTypes';
|
|
12
10
|
|
|
13
11
|
export type SensorConfig = {
|
|
14
12
|
interval: number | 'auto';
|
|
13
|
+
adjustToInterfaceOrientation: boolean;
|
|
14
|
+
iosReferenceFrame: IOSReferenceFrame;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export type AnimatedSensor = {
|
|
@@ -33,19 +33,81 @@ function initSensorData(
|
|
|
33
33
|
yaw: 0,
|
|
34
34
|
pitch: 0,
|
|
35
35
|
roll: 0,
|
|
36
|
+
interfaceOrientation: 0,
|
|
36
37
|
});
|
|
37
38
|
} else {
|
|
38
39
|
return makeMutable<Value3D | ValueRotation>({
|
|
39
40
|
x: 0,
|
|
40
41
|
y: 0,
|
|
41
42
|
z: 0,
|
|
43
|
+
interfaceOrientation: 0,
|
|
42
44
|
});
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
|
|
48
|
+
// euler angles are in order ZXY, z = yaw, x = pitch, y = roll
|
|
49
|
+
// https://github.com/mrdoob/three.js/blob/dev/src/math/Quaternion.js#L237
|
|
50
|
+
function eulerToQuaternion(pitch: number, roll: number, yaw: number) {
|
|
51
|
+
'worklet';
|
|
52
|
+
const c1 = Math.cos(pitch / 2);
|
|
53
|
+
const s1 = Math.sin(pitch / 2);
|
|
54
|
+
const c2 = Math.cos(roll / 2);
|
|
55
|
+
const s2 = Math.sin(roll / 2);
|
|
56
|
+
const c3 = Math.cos(yaw / 2);
|
|
57
|
+
const s3 = Math.sin(yaw / 2);
|
|
58
|
+
|
|
59
|
+
return [
|
|
60
|
+
s1 * c2 * c3 - c1 * s2 * s3,
|
|
61
|
+
c1 * s2 * c3 + s1 * c2 * s3,
|
|
62
|
+
c1 * c2 * s3 + s1 * s2 * c3,
|
|
63
|
+
c1 * c2 * c3 - s1 * s2 * s3,
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function adjustRotationToInterfaceOrientation(data: ValueRotation) {
|
|
68
|
+
'worklet';
|
|
69
|
+
const { interfaceOrientation, pitch, roll, yaw } = data;
|
|
70
|
+
if (interfaceOrientation === 90) {
|
|
71
|
+
data.pitch = roll;
|
|
72
|
+
data.roll = -pitch;
|
|
73
|
+
data.yaw = yaw - Math.PI / 2;
|
|
74
|
+
} else if (interfaceOrientation === 270) {
|
|
75
|
+
data.pitch = -roll;
|
|
76
|
+
data.roll = pitch;
|
|
77
|
+
data.yaw = yaw + Math.PI / 2;
|
|
78
|
+
} else if (interfaceOrientation === 180) {
|
|
79
|
+
data.pitch *= -1;
|
|
80
|
+
data.roll *= -1;
|
|
81
|
+
data.yaw *= -1;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const q = eulerToQuaternion(data.pitch, data.roll, data.yaw);
|
|
85
|
+
data.qx = q[0];
|
|
86
|
+
data.qy = q[1];
|
|
87
|
+
data.qz = q[2];
|
|
88
|
+
data.qw = q[3];
|
|
89
|
+
return data;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function adjustVectorToInterfaceOrientation(data: Value3D) {
|
|
93
|
+
'worklet';
|
|
94
|
+
const { interfaceOrientation, x, y } = data;
|
|
95
|
+
if (interfaceOrientation === 90) {
|
|
96
|
+
data.x = -y;
|
|
97
|
+
data.y = x;
|
|
98
|
+
} else if (interfaceOrientation === 270) {
|
|
99
|
+
data.x = y;
|
|
100
|
+
data.y = -x;
|
|
101
|
+
} else if (interfaceOrientation === 180) {
|
|
102
|
+
data.x *= -1;
|
|
103
|
+
data.y *= -1;
|
|
104
|
+
}
|
|
105
|
+
return data;
|
|
106
|
+
}
|
|
107
|
+
|
|
46
108
|
export function useAnimatedSensor(
|
|
47
109
|
sensorType: SensorType,
|
|
48
|
-
userConfig?: SensorConfig
|
|
110
|
+
userConfig?: Partial<SensorConfig>
|
|
49
111
|
): AnimatedSensor {
|
|
50
112
|
const ref = useRef<AnimatedSensor>({
|
|
51
113
|
sensor: initSensorData(sensorType),
|
|
@@ -55,17 +117,32 @@ export function useAnimatedSensor(
|
|
|
55
117
|
isAvailable: false,
|
|
56
118
|
config: {
|
|
57
119
|
interval: 0,
|
|
120
|
+
adjustToInterfaceOrientation: true,
|
|
121
|
+
iosReferenceFrame: IOSReferenceFrame.Auto,
|
|
58
122
|
},
|
|
59
123
|
});
|
|
60
124
|
|
|
61
125
|
useEffect(() => {
|
|
62
|
-
ref.current.config = {
|
|
126
|
+
ref.current.config = {
|
|
127
|
+
interval: 'auto',
|
|
128
|
+
adjustToInterfaceOrientation: true,
|
|
129
|
+
iosReferenceFrame: IOSReferenceFrame.Auto,
|
|
130
|
+
...userConfig,
|
|
131
|
+
};
|
|
63
132
|
const sensorData = ref.current.sensor!;
|
|
64
133
|
const id = registerSensor(
|
|
65
134
|
sensorType,
|
|
66
135
|
ref.current.config.interval === 'auto' ? -1 : ref.current.config.interval,
|
|
136
|
+
ref.current.config.iosReferenceFrame,
|
|
67
137
|
(data) => {
|
|
68
138
|
'worklet';
|
|
139
|
+
if (ref.current.config.adjustToInterfaceOrientation) {
|
|
140
|
+
if (sensorType === SensorType.ROTATION) {
|
|
141
|
+
data = adjustRotationToInterfaceOrientation(data as ValueRotation);
|
|
142
|
+
} else {
|
|
143
|
+
data = adjustVectorToInterfaceOrientation(data as Value3D);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
69
146
|
sensorData.value = data;
|
|
70
147
|
}
|
|
71
148
|
);
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
/* global _frameTimestamp */
|
|
2
1
|
import { MutableRefObject, useEffect, useRef } from 'react';
|
|
3
2
|
|
|
4
|
-
import { startMapper, stopMapper, makeRemote
|
|
3
|
+
import { startMapper, stopMapper, makeRemote } from '../core';
|
|
5
4
|
import updateProps, { updatePropsJestWrapper } from '../UpdateProps';
|
|
6
5
|
import { initialUpdaterRun } from '../animation';
|
|
7
6
|
import NativeReanimatedModule from '../NativeReanimated';
|
|
8
7
|
import { useSharedValue } from './useSharedValue';
|
|
9
8
|
import {
|
|
10
9
|
buildWorkletsHash,
|
|
11
|
-
getStyleWithoutAnimations,
|
|
12
10
|
isAnimated,
|
|
13
|
-
|
|
11
|
+
shallowEqual,
|
|
14
12
|
validateAnimatedStyles,
|
|
15
13
|
} from './utils';
|
|
16
14
|
import { DependencyList, Descriptor } from './commonTypes';
|
|
@@ -20,7 +18,7 @@ import {
|
|
|
20
18
|
ViewDescriptorsSet,
|
|
21
19
|
ViewRefSet,
|
|
22
20
|
} from '../ViewDescriptorsSet';
|
|
23
|
-
import { isJest } from '../PlatformChecker';
|
|
21
|
+
import { isJest, shouldBeUseWeb } from '../PlatformChecker';
|
|
24
22
|
import {
|
|
25
23
|
AnimationObject,
|
|
26
24
|
Timestamp,
|
|
@@ -30,6 +28,7 @@ import {
|
|
|
30
28
|
BasicWorkletFunctionOptional,
|
|
31
29
|
NestedObjectValues,
|
|
32
30
|
SharedValue,
|
|
31
|
+
StyleProps,
|
|
33
32
|
} from '../commonTypes';
|
|
34
33
|
export interface AnimatedStyleResult {
|
|
35
34
|
viewDescriptors: ViewDescriptorsSet;
|
|
@@ -55,6 +54,7 @@ interface AnimationRef {
|
|
|
55
54
|
}
|
|
56
55
|
|
|
57
56
|
function prepareAnimation(
|
|
57
|
+
frameTimestamp: number,
|
|
58
58
|
animatedProp: AnimatedStyle,
|
|
59
59
|
lastAnimation: AnimatedStyle,
|
|
60
60
|
lastValue: AnimatedStyle
|
|
@@ -63,6 +63,7 @@ function prepareAnimation(
|
|
|
63
63
|
if (Array.isArray(animatedProp)) {
|
|
64
64
|
animatedProp.forEach((prop, index) => {
|
|
65
65
|
prepareAnimation(
|
|
66
|
+
frameTimestamp,
|
|
66
67
|
prop,
|
|
67
68
|
lastAnimation && lastAnimation[index],
|
|
68
69
|
lastValue && lastValue[index]
|
|
@@ -97,12 +98,13 @@ function prepareAnimation(
|
|
|
97
98
|
animation.callStart = (timestamp: Timestamp) => {
|
|
98
99
|
animation.onStart(animation, value, timestamp, lastAnimation);
|
|
99
100
|
};
|
|
100
|
-
animation.callStart(
|
|
101
|
+
animation.callStart(frameTimestamp);
|
|
101
102
|
animation.callStart = null;
|
|
102
103
|
} else if (typeof animatedProp === 'object') {
|
|
103
104
|
// it is an object
|
|
104
105
|
Object.keys(animatedProp).forEach((key) =>
|
|
105
106
|
prepareAnimation(
|
|
107
|
+
frameTimestamp,
|
|
106
108
|
animatedProp[key],
|
|
107
109
|
lastAnimation && lastAnimation[key],
|
|
108
110
|
lastValue && lastValue[key]
|
|
@@ -183,23 +185,28 @@ function styleUpdater(
|
|
|
183
185
|
const animations = state.animations ?? {};
|
|
184
186
|
const newValues = updater() ?? {};
|
|
185
187
|
const oldValues = state.last;
|
|
188
|
+
const nonAnimatedNewValues: StyleProps = {};
|
|
186
189
|
|
|
187
190
|
let hasAnimations = false;
|
|
191
|
+
let frameTimestamp: number | undefined;
|
|
192
|
+
let hasNonAnimatedValues = false;
|
|
188
193
|
for (const key in newValues) {
|
|
189
194
|
const value = newValues[key];
|
|
190
195
|
if (isAnimated(value)) {
|
|
191
|
-
|
|
196
|
+
frameTimestamp = global.__frameTimestamp || performance.now();
|
|
197
|
+
prepareAnimation(frameTimestamp, value, animations[key], oldValues[key]);
|
|
192
198
|
animations[key] = value;
|
|
193
199
|
hasAnimations = true;
|
|
194
200
|
} else {
|
|
201
|
+
hasNonAnimatedValues = true;
|
|
202
|
+
nonAnimatedNewValues[key] = value;
|
|
195
203
|
delete animations[key];
|
|
196
204
|
}
|
|
197
205
|
}
|
|
198
206
|
|
|
199
207
|
if (hasAnimations) {
|
|
200
|
-
const frame = (
|
|
208
|
+
const frame = (timestamp: Timestamp) => {
|
|
201
209
|
const { animations, last, isAnimationCancelled } = state;
|
|
202
|
-
const timestamp = _timestamp ?? getTimestamp();
|
|
203
210
|
if (isAnimationCancelled) {
|
|
204
211
|
state.isAnimationRunning = false;
|
|
205
212
|
return;
|
|
@@ -238,27 +245,21 @@ function styleUpdater(
|
|
|
238
245
|
if (!state.isAnimationRunning) {
|
|
239
246
|
state.isAnimationCancelled = false;
|
|
240
247
|
state.isAnimationRunning = true;
|
|
241
|
-
|
|
242
|
-
frame(_frameTimestamp);
|
|
243
|
-
} else {
|
|
244
|
-
requestAnimationFrame(frame);
|
|
245
|
-
}
|
|
248
|
+
frame(frameTimestamp!);
|
|
246
249
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
updateProps(viewDescriptors, style, maybeViewRef);
|
|
250
|
+
|
|
251
|
+
if (hasNonAnimatedValues) {
|
|
252
|
+
updateProps(viewDescriptors, nonAnimatedNewValues, maybeViewRef);
|
|
251
253
|
}
|
|
252
254
|
} else {
|
|
253
255
|
state.isAnimationCancelled = true;
|
|
254
256
|
state.animations = [];
|
|
255
257
|
|
|
256
|
-
|
|
257
|
-
state.last = Object.assign({}, oldValues, newValues);
|
|
258
|
-
if (diff) {
|
|
258
|
+
if (!shallowEqual(oldValues, newValues)) {
|
|
259
259
|
updateProps(viewDescriptors, newValues, maybeViewRef);
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
|
+
state.last = newValues;
|
|
262
263
|
}
|
|
263
264
|
|
|
264
265
|
function jestStyleUpdater(
|
|
@@ -277,6 +278,7 @@ function jestStyleUpdater(
|
|
|
277
278
|
|
|
278
279
|
// extract animated props
|
|
279
280
|
let hasAnimations = false;
|
|
281
|
+
let frameTimestamp: number | undefined;
|
|
280
282
|
Object.keys(animations).forEach((key) => {
|
|
281
283
|
const value = newValues[key];
|
|
282
284
|
if (!isAnimated(value)) {
|
|
@@ -286,15 +288,15 @@ function jestStyleUpdater(
|
|
|
286
288
|
Object.keys(newValues).forEach((key) => {
|
|
287
289
|
const value = newValues[key];
|
|
288
290
|
if (isAnimated(value)) {
|
|
289
|
-
|
|
291
|
+
frameTimestamp = global.__frameTimestamp || performance.now();
|
|
292
|
+
prepareAnimation(frameTimestamp, value, animations[key], oldValues[key]);
|
|
290
293
|
animations[key] = value;
|
|
291
294
|
hasAnimations = true;
|
|
292
295
|
}
|
|
293
296
|
});
|
|
294
297
|
|
|
295
|
-
function frame(
|
|
298
|
+
function frame(timestamp: Timestamp) {
|
|
296
299
|
const { animations, last, isAnimationCancelled } = state;
|
|
297
|
-
const timestamp = _timestamp ?? getTimestamp();
|
|
298
300
|
if (isAnimationCancelled) {
|
|
299
301
|
state.isAnimationRunning = false;
|
|
300
302
|
return;
|
|
@@ -340,11 +342,7 @@ function jestStyleUpdater(
|
|
|
340
342
|
if (!state.isAnimationRunning) {
|
|
341
343
|
state.isAnimationCancelled = false;
|
|
342
344
|
state.isAnimationRunning = true;
|
|
343
|
-
|
|
344
|
-
frame(_frameTimestamp);
|
|
345
|
-
} else {
|
|
346
|
-
requestAnimationFrame(frame);
|
|
347
|
-
}
|
|
345
|
+
frame(frameTimestamp!);
|
|
348
346
|
}
|
|
349
347
|
} else {
|
|
350
348
|
state.isAnimationCancelled = true;
|
|
@@ -352,13 +350,12 @@ function jestStyleUpdater(
|
|
|
352
350
|
}
|
|
353
351
|
|
|
354
352
|
// calculate diff
|
|
355
|
-
|
|
356
|
-
state.last = Object.assign({}, oldValues, newValues);
|
|
353
|
+
state.last = newValues;
|
|
357
354
|
|
|
358
|
-
if (
|
|
355
|
+
if (!shallowEqual(oldValues, newValues)) {
|
|
359
356
|
updatePropsJestWrapper(
|
|
360
357
|
viewDescriptors,
|
|
361
|
-
|
|
358
|
+
newValues,
|
|
362
359
|
maybeViewRef,
|
|
363
360
|
animatedStyle,
|
|
364
361
|
adapters
|
|
@@ -400,7 +397,20 @@ export function useAnimatedStyle<T extends AnimatedStyle>(
|
|
|
400
397
|
): AnimatedStyleResult {
|
|
401
398
|
const viewsRef: ViewRefSet<any> = makeViewsRefSet();
|
|
402
399
|
const initRef = useRef<AnimationRef>();
|
|
403
|
-
|
|
400
|
+
let inputs = Object.values(updater._closure ?? {});
|
|
401
|
+
if (shouldBeUseWeb()) {
|
|
402
|
+
if (!inputs.length && dependencies?.length) {
|
|
403
|
+
// let web work without a Babel/SWC plugin
|
|
404
|
+
inputs = dependencies;
|
|
405
|
+
}
|
|
406
|
+
if (__DEV__ && !inputs.length && !dependencies && !updater.__workletHash) {
|
|
407
|
+
throw new Error(
|
|
408
|
+
`useAnimatedStyle was used without a dependency array or Babel plugin. Please explicitly pass a dependency array, or enable the Babel/SWC plugin.
|
|
409
|
+
|
|
410
|
+
For more, see the docs: https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/web-support#web-without-a-babel-plugin`
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
404
414
|
const adaptersArray: AdapterWorkletFunction[] = adapters
|
|
405
415
|
? Array.isArray(adapters)
|
|
406
416
|
? adapters
|
|
@@ -493,8 +503,6 @@ export function useAnimatedStyle<T extends AnimatedStyle>(
|
|
|
493
503
|
useEffect(() => {
|
|
494
504
|
animationsActive.value = true;
|
|
495
505
|
return () => {
|
|
496
|
-
// initRef.current = null;
|
|
497
|
-
// viewsRef = null;
|
|
498
506
|
animationsActive.value = false;
|
|
499
507
|
};
|
|
500
508
|
}, []);
|
|
@@ -3,6 +3,7 @@ import { initialUpdaterRun } from '../animation';
|
|
|
3
3
|
import { BasicWorkletFunction, SharedValue } from '../commonTypes';
|
|
4
4
|
import { makeMutable, startMapper, stopMapper } from '../core';
|
|
5
5
|
import { DependencyList } from './commonTypes';
|
|
6
|
+
import { shouldBeUseWeb } from '../PlatformChecker';
|
|
6
7
|
|
|
7
8
|
export type DerivedValue<T> = Readonly<SharedValue<T>>;
|
|
8
9
|
|
|
@@ -11,7 +12,13 @@ export function useDerivedValue<T>(
|
|
|
11
12
|
dependencies: DependencyList
|
|
12
13
|
): DerivedValue<T> {
|
|
13
14
|
const initRef = useRef<SharedValue<T> | null>(null);
|
|
14
|
-
|
|
15
|
+
let inputs = Object.values(processor._closure ?? {});
|
|
16
|
+
if (shouldBeUseWeb()) {
|
|
17
|
+
if (!inputs.length && dependencies?.length) {
|
|
18
|
+
// let web work without a Babel/SWC plugin
|
|
19
|
+
inputs = dependencies;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
15
22
|
|
|
16
23
|
// build dependencies
|
|
17
24
|
if (dependencies === undefined) {
|
|
@@ -7,7 +7,7 @@ import { findNodeHandle } from 'react-native';
|
|
|
7
7
|
import { useEvent } from './utils';
|
|
8
8
|
import { useSharedValue } from './useSharedValue';
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const scrollEventNames = [
|
|
11
11
|
'onScroll',
|
|
12
12
|
'onScrollBeginDrag',
|
|
13
13
|
'onScrollEndDrag',
|
|
@@ -26,7 +26,7 @@ export function useScrollViewOffset(
|
|
|
26
26
|
event.contentOffset.x === 0
|
|
27
27
|
? event.contentOffset.y
|
|
28
28
|
: event.contentOffset.x;
|
|
29
|
-
},
|
|
29
|
+
}, scrollEventNames);
|
|
30
30
|
|
|
31
31
|
useEffect(() => {
|
|
32
32
|
const viewTag = findNodeHandle(aref.current);
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
Context,
|
|
6
6
|
NativeEvent,
|
|
7
7
|
NestedObjectValues,
|
|
8
|
-
StyleProps,
|
|
9
8
|
WorkletFunction,
|
|
10
9
|
AnimationObject,
|
|
11
10
|
} from '../commonTypes';
|
|
@@ -164,78 +163,33 @@ export function parseColors(updates: AnimatedStyle): void {
|
|
|
164
163
|
}
|
|
165
164
|
}
|
|
166
165
|
|
|
167
|
-
export function canApplyOptimalisation(upadterFn: WorkletFunction): number {
|
|
168
|
-
const FUNCTIONLESS_FLAG = 0b00000001;
|
|
169
|
-
const STATEMENTLESS_FLAG = 0b00000010;
|
|
170
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
171
|
-
const optimalization = upadterFn.__optimalization!;
|
|
172
|
-
return (
|
|
173
|
-
optimalization & FUNCTIONLESS_FLAG && optimalization & STATEMENTLESS_FLAG
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
166
|
export function isAnimated(prop: NestedObjectValues<AnimationObject>): boolean {
|
|
178
167
|
'worklet';
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (Array.isArray(currentProp)) {
|
|
184
|
-
for (const item of currentProp) {
|
|
185
|
-
propsToCheck.push(item);
|
|
186
|
-
}
|
|
187
|
-
} else if (currentProp?.onFrame !== undefined) {
|
|
168
|
+
if (Array.isArray(prop)) {
|
|
169
|
+
return prop.some(isAnimated);
|
|
170
|
+
} else if (typeof prop === 'object') {
|
|
171
|
+
if (prop.onFrame !== undefined) {
|
|
188
172
|
return true;
|
|
189
|
-
} else
|
|
190
|
-
|
|
191
|
-
propsToCheck.push(item);
|
|
192
|
-
}
|
|
173
|
+
} else {
|
|
174
|
+
return Object.values(prop).some(isAnimated);
|
|
193
175
|
}
|
|
194
|
-
// if none of the above, it's not the animated prop, check next one
|
|
195
176
|
}
|
|
196
|
-
|
|
197
|
-
// when none of the props were animated return false
|
|
198
177
|
return false;
|
|
199
178
|
}
|
|
200
179
|
|
|
201
|
-
export function
|
|
202
|
-
oldStyle: AnimatedStyle,
|
|
203
|
-
newStyle: AnimatedStyle
|
|
204
|
-
): Partial<T> {
|
|
180
|
+
export function shallowEqual(a: any, b: any) {
|
|
205
181
|
'worklet';
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
for (const key in newStyle) {
|
|
213
|
-
const value = newStyle[key];
|
|
214
|
-
const oldValue = oldStyle[key];
|
|
215
|
-
|
|
216
|
-
if (isAnimated(value)) {
|
|
217
|
-
// do nothing
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
if (oldValue !== value) {
|
|
221
|
-
diff[key] = value;
|
|
222
|
-
}
|
|
182
|
+
const aKeys = Object.keys(a);
|
|
183
|
+
const bKeys = Object.keys(b);
|
|
184
|
+
if (aKeys.length !== bKeys.length) {
|
|
185
|
+
return false;
|
|
223
186
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
export function getStyleWithoutAnimations(newStyle: AnimatedStyle): StyleProps {
|
|
228
|
-
'worklet';
|
|
229
|
-
const diff: StyleProps = {};
|
|
230
|
-
|
|
231
|
-
for (const key in newStyle) {
|
|
232
|
-
const value = newStyle[key];
|
|
233
|
-
if (isAnimated(value)) {
|
|
234
|
-
continue;
|
|
187
|
+
for (let i = 0; i < aKeys.length; i++) {
|
|
188
|
+
if (a[aKeys[i]] !== b[aKeys[i]]) {
|
|
189
|
+
return false;
|
|
235
190
|
}
|
|
236
|
-
diff[key] = value;
|
|
237
191
|
}
|
|
238
|
-
return
|
|
192
|
+
return true;
|
|
239
193
|
}
|
|
240
194
|
|
|
241
195
|
export const validateAnimatedStyles = (styles: AnimatedStyle): void => {
|
package/src/reanimated2/index.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { reportFatalErrorOnJS } from './errors';
|
|
2
2
|
import NativeReanimatedModule from './NativeReanimated';
|
|
3
3
|
import { isJest } from './PlatformChecker';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
runOnJS,
|
|
6
|
+
setupSetImmediate,
|
|
7
|
+
flushImmediates,
|
|
8
|
+
runOnUIImmediately,
|
|
9
|
+
} from './threads';
|
|
5
10
|
|
|
6
11
|
// callGuard is only used with debug builds
|
|
7
12
|
function callGuardDEV<T extends Array<any>, U>(
|
|
@@ -29,18 +34,20 @@ function valueUnpacker(objectToUnpack: any, category?: string): any {
|
|
|
29
34
|
workletsCache = global.__workletsCache = new Map();
|
|
30
35
|
handleCache = global.__handleCache = new WeakMap();
|
|
31
36
|
}
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
const workletHash = objectToUnpack.__workletHash;
|
|
38
|
+
if (workletHash !== undefined) {
|
|
39
|
+
let workletFun = workletsCache.get(workletHash);
|
|
34
40
|
if (workletFun === undefined) {
|
|
41
|
+
const initData = objectToUnpack.__initData;
|
|
35
42
|
if (global.evalWithSourceMap) {
|
|
36
43
|
// if the runtime (hermes only for now) supports loading source maps
|
|
37
44
|
// we want to use the proper filename for the location as it guarantees
|
|
38
45
|
// that debugger understands and loads the source code of the file where
|
|
39
46
|
// the worklet is defined.
|
|
40
47
|
workletFun = global.evalWithSourceMap(
|
|
41
|
-
'(' +
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
'(' + initData.code + '\n)',
|
|
49
|
+
initData.location,
|
|
50
|
+
initData.sourceMap
|
|
44
51
|
) as (...args: any[]) => any;
|
|
45
52
|
} else if (global.evalWithSourceUrl) {
|
|
46
53
|
// if the runtime doesn't support loading source maps, in dev mode we
|
|
@@ -48,17 +55,17 @@ function valueUnpacker(objectToUnpack: any, category?: string): any {
|
|
|
48
55
|
// the actual file location we use worklet hash, as it the allows us to
|
|
49
56
|
// properly symbolicate traces (see errors.ts for details)
|
|
50
57
|
workletFun = global.evalWithSourceUrl(
|
|
51
|
-
'(' +
|
|
52
|
-
`worklet_${
|
|
58
|
+
'(' + initData.code + '\n)',
|
|
59
|
+
`worklet_${workletHash}`
|
|
53
60
|
) as (...args: any[]) => any;
|
|
54
61
|
} else {
|
|
55
62
|
// in release we use the regular eval to save on JSI calls
|
|
56
63
|
// eslint-disable-next-line no-eval
|
|
57
|
-
workletFun = eval('(' +
|
|
64
|
+
workletFun = eval('(' + initData.code + '\n)') as (
|
|
58
65
|
...args: any[]
|
|
59
66
|
) => any;
|
|
60
67
|
}
|
|
61
|
-
workletsCache.set(
|
|
68
|
+
workletsCache.set(workletHash, workletFun);
|
|
62
69
|
}
|
|
63
70
|
const functionInstance = workletFun.bind(objectToUnpack);
|
|
64
71
|
objectToUnpack._recur = functionInstance;
|
|
@@ -85,13 +92,69 @@ Possible solutions are:
|
|
|
85
92
|
}
|
|
86
93
|
}
|
|
87
94
|
|
|
95
|
+
function setupRequestAnimationFrame() {
|
|
96
|
+
'worklet';
|
|
97
|
+
|
|
98
|
+
// Jest mocks requestAnimationFrame API and it does not like if that mock gets overridden
|
|
99
|
+
// so we avoid doing requestAnimationFrame batching in Jest environment.
|
|
100
|
+
const nativeRequestAnimationFrame = global.requestAnimationFrame;
|
|
101
|
+
|
|
102
|
+
let animationFrameCallbacks: Array<(timestamp: number) => void> = [];
|
|
103
|
+
let lastNativeAnimationFrameTimestamp = -1;
|
|
104
|
+
|
|
105
|
+
global.__flushAnimationFrame = (frameTimestamp: number) => {
|
|
106
|
+
const currentCallbacks = animationFrameCallbacks;
|
|
107
|
+
animationFrameCallbacks = [];
|
|
108
|
+
currentCallbacks.forEach((f) => f(frameTimestamp));
|
|
109
|
+
flushImmediates();
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
global.requestAnimationFrame = (
|
|
113
|
+
callback: (timestamp: number) => void
|
|
114
|
+
): number => {
|
|
115
|
+
animationFrameCallbacks.push(callback);
|
|
116
|
+
if (animationFrameCallbacks.length === 1) {
|
|
117
|
+
// We schedule native requestAnimationFrame only when the first callback
|
|
118
|
+
// is added and then use it to execute all the enqueued callbacks. Once
|
|
119
|
+
// the callbacks are run, we clear the array.
|
|
120
|
+
nativeRequestAnimationFrame((timestamp) => {
|
|
121
|
+
if (lastNativeAnimationFrameTimestamp >= timestamp) {
|
|
122
|
+
// Make sure we only execute the callbacks once for a given frame
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
lastNativeAnimationFrameTimestamp = timestamp;
|
|
126
|
+
global.__frameTimestamp = timestamp;
|
|
127
|
+
global.__flushAnimationFrame(timestamp);
|
|
128
|
+
global.__frameTimestamp = undefined;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
// Reanimated currently does not support cancelling calbacks requested with
|
|
132
|
+
// requestAnimationFrame. We return -1 as identifier which isn't in line
|
|
133
|
+
// with the spec but it should give users better clue in case they actually
|
|
134
|
+
// attempt to store the value returned from rAF and use it for cancelling.
|
|
135
|
+
return -1;
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
88
139
|
export function initializeUIRuntime() {
|
|
89
140
|
NativeReanimatedModule.installCoreFunctions(callGuardDEV, valueUnpacker);
|
|
90
141
|
|
|
91
142
|
const IS_JEST = isJest();
|
|
92
143
|
|
|
144
|
+
if (IS_JEST) {
|
|
145
|
+
// requestAnimationFrame react-native jest's setup is incorrect as it polyfills
|
|
146
|
+
// the method directly using setTimeout, therefore the callback doesn't get the
|
|
147
|
+
// expected timestamp as the only argument: https://github.com/facebook/react-native/blob/main/jest/setup.js#L28
|
|
148
|
+
// We override this setup here to make sure that callbacks get the proper timestamps
|
|
149
|
+
// when executed. For non-jest environments we define requestAnimationFrame in setupRequestAnimationFrame
|
|
150
|
+
// @ts-ignore TypeScript uses Node definition for rAF, setTimeout, etc which returns a Timeout object rather than a number
|
|
151
|
+
global.requestAnimationFrame = (callback: (timestamp: number) => void) => {
|
|
152
|
+
return setTimeout(() => callback(performance.now()), 0);
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
93
156
|
const capturableConsole = console;
|
|
94
|
-
|
|
157
|
+
runOnUIImmediately(() => {
|
|
95
158
|
'worklet';
|
|
96
159
|
// setup error handler
|
|
97
160
|
global.ErrorUtils = {
|
|
@@ -114,30 +177,8 @@ export function initializeUIRuntime() {
|
|
|
114
177
|
};
|
|
115
178
|
|
|
116
179
|
if (!IS_JEST) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const nativeRequestAnimationFrame = global.requestAnimationFrame;
|
|
120
|
-
let callbacks: Array<(time: number) => void> = [];
|
|
121
|
-
global.requestAnimationFrame = (
|
|
122
|
-
callback: (timestamp: number) => void
|
|
123
|
-
): number => {
|
|
124
|
-
callbacks.push(callback);
|
|
125
|
-
if (callbacks.length === 1) {
|
|
126
|
-
// We schedule native requestAnimationFrame only when the first callback
|
|
127
|
-
// is added and then use it to execute all the enqueued callbacks. Once
|
|
128
|
-
// the callbacks are run, we clear the array.
|
|
129
|
-
nativeRequestAnimationFrame((timestamp) => {
|
|
130
|
-
const currentCallbacks = callbacks;
|
|
131
|
-
callbacks = [];
|
|
132
|
-
currentCallbacks.forEach((f) => f(timestamp));
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
// Reanimated currently does not support cancelling calbacks requested with
|
|
136
|
-
// requestAnimationFrame. We return -1 as identifier which isn't in line
|
|
137
|
-
// with the spec but it should give users better clue in case they actually
|
|
138
|
-
// attempt to store the value returned from rAF and use it for cancelling.
|
|
139
|
-
return -1;
|
|
140
|
-
};
|
|
180
|
+
setupSetImmediate();
|
|
181
|
+
setupRequestAnimationFrame();
|
|
141
182
|
}
|
|
142
183
|
})();
|
|
143
184
|
}
|