react-native-reanimated 3.0.0-rc.8 → 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 +122 -121
- package/Common/cpp/NativeModules/NativeReanimatedModule.h +21 -14
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +15 -7
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.h +8 -4
- package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.cpp +50 -1
- package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.h +10 -1
- 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 +11 -63
- package/Common/cpp/SharedItems/Shareables.h +113 -93
- 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 +67 -247
- package/Common/cpp/Tools/RuntimeDecorator.h +2 -3
- 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 +31 -5
- package/ios/LayoutReanimation/REAAnimationsManager.m +265 -77
- 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 +67 -60
- 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 +18 -35
- 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/component/FlatList.js +19 -3
- package/lib/commonjs/reanimated2/component/FlatList.js.map +1 -1
- package/lib/commonjs/reanimated2/core.js +34 -83
- package/lib/commonjs/reanimated2/core.js.map +1 -1
- package/lib/commonjs/reanimated2/errors.js +66 -0
- package/lib/commonjs/reanimated2/errors.js.map +1 -0
- 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 -50
- 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 +196 -0
- package/lib/commonjs/reanimated2/initializers.js.map +1 -0
- 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 +101 -16
- 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 +4 -9
- 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 +16 -12
- 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 +45 -0
- 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 +38 -11
- 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 +18 -34
- 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/component/FlatList.js +18 -4
- package/lib/module/reanimated2/component/FlatList.js.map +1 -1
- package/lib/module/reanimated2/core.js +30 -76
- package/lib/module/reanimated2/core.js.map +1 -1
- package/lib/module/reanimated2/errors.js +58 -0
- package/lib/module/reanimated2/errors.js.map +1 -0
- 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 +45 -52
- 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 +182 -0
- package/lib/module/reanimated2/initializers.js.map +1 -0
- 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 +101 -16
- 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 +4 -9
- 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 -10
- 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 +45 -0
- 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 +38 -9
- 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 +9 -8
- package/{plugin.js → plugin/index.js} +173 -228
- 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 +63 -41
- 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/component/FlatList.tsx +30 -5
- package/src/reanimated2/core.ts +45 -75
- package/src/reanimated2/errors.ts +57 -0
- package/src/reanimated2/frameCallback/FrameCallbackRegistryUI.ts +2 -2
- package/src/reanimated2/globals.d.ts +34 -18
- 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 +43 -45
- 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 +184 -0
- package/src/reanimated2/interpolateColor.ts +104 -20
- package/src/reanimated2/jestUtils.ts +1 -1
- package/src/reanimated2/js-reanimated/JSReanimated.ts +105 -18
- 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 +4 -8
- 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 -12
- 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 +128 -0
- 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 +47 -11
- 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
|
@@ -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
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { reportFatalErrorOnJS } from './errors';
|
|
2
|
+
import NativeReanimatedModule from './NativeReanimated';
|
|
3
|
+
import { isJest } from './PlatformChecker';
|
|
4
|
+
import {
|
|
5
|
+
runOnJS,
|
|
6
|
+
setupSetImmediate,
|
|
7
|
+
flushImmediates,
|
|
8
|
+
runOnUIImmediately,
|
|
9
|
+
} from './threads';
|
|
10
|
+
|
|
11
|
+
// callGuard is only used with debug builds
|
|
12
|
+
function callGuardDEV<T extends Array<any>, U>(
|
|
13
|
+
fn: (...args: T) => U,
|
|
14
|
+
...args: T
|
|
15
|
+
): void {
|
|
16
|
+
'worklet';
|
|
17
|
+
try {
|
|
18
|
+
fn(...args);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
if (global.ErrorUtils) {
|
|
21
|
+
global.ErrorUtils.reportFatalError(e as Error);
|
|
22
|
+
} else {
|
|
23
|
+
throw e;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function valueUnpacker(objectToUnpack: any, category?: string): any {
|
|
29
|
+
'worklet';
|
|
30
|
+
let workletsCache = global.__workletsCache;
|
|
31
|
+
let handleCache = global.__handleCache;
|
|
32
|
+
if (workletsCache === undefined) {
|
|
33
|
+
// init
|
|
34
|
+
workletsCache = global.__workletsCache = new Map();
|
|
35
|
+
handleCache = global.__handleCache = new WeakMap();
|
|
36
|
+
}
|
|
37
|
+
const workletHash = objectToUnpack.__workletHash;
|
|
38
|
+
if (workletHash !== undefined) {
|
|
39
|
+
let workletFun = workletsCache.get(workletHash);
|
|
40
|
+
if (workletFun === undefined) {
|
|
41
|
+
const initData = objectToUnpack.__initData;
|
|
42
|
+
if (global.evalWithSourceMap) {
|
|
43
|
+
// if the runtime (hermes only for now) supports loading source maps
|
|
44
|
+
// we want to use the proper filename for the location as it guarantees
|
|
45
|
+
// that debugger understands and loads the source code of the file where
|
|
46
|
+
// the worklet is defined.
|
|
47
|
+
workletFun = global.evalWithSourceMap(
|
|
48
|
+
'(' + initData.code + '\n)',
|
|
49
|
+
initData.location,
|
|
50
|
+
initData.sourceMap
|
|
51
|
+
) as (...args: any[]) => any;
|
|
52
|
+
} else if (global.evalWithSourceUrl) {
|
|
53
|
+
// if the runtime doesn't support loading source maps, in dev mode we
|
|
54
|
+
// can pass source url when evaluating the worklet. Now, instead of using
|
|
55
|
+
// the actual file location we use worklet hash, as it the allows us to
|
|
56
|
+
// properly symbolicate traces (see errors.ts for details)
|
|
57
|
+
workletFun = global.evalWithSourceUrl(
|
|
58
|
+
'(' + initData.code + '\n)',
|
|
59
|
+
`worklet_${workletHash}`
|
|
60
|
+
) as (...args: any[]) => any;
|
|
61
|
+
} else {
|
|
62
|
+
// in release we use the regular eval to save on JSI calls
|
|
63
|
+
// eslint-disable-next-line no-eval
|
|
64
|
+
workletFun = eval('(' + initData.code + '\n)') as (
|
|
65
|
+
...args: any[]
|
|
66
|
+
) => any;
|
|
67
|
+
}
|
|
68
|
+
workletsCache.set(workletHash, workletFun);
|
|
69
|
+
}
|
|
70
|
+
const functionInstance = workletFun.bind(objectToUnpack);
|
|
71
|
+
objectToUnpack._recur = functionInstance;
|
|
72
|
+
return functionInstance;
|
|
73
|
+
} else if (objectToUnpack.__init) {
|
|
74
|
+
let value = handleCache!.get(objectToUnpack);
|
|
75
|
+
if (value === undefined) {
|
|
76
|
+
value = objectToUnpack.__init();
|
|
77
|
+
handleCache!.set(objectToUnpack, value);
|
|
78
|
+
}
|
|
79
|
+
return value;
|
|
80
|
+
} else if (category === 'RemoteFunction') {
|
|
81
|
+
const fun = () => {
|
|
82
|
+
throw new Error(`Tried to synchronously call a non-worklet function on the UI thread.
|
|
83
|
+
|
|
84
|
+
Possible solutions are:
|
|
85
|
+
a) If you want to synchronously execute this method, mark it as a worklet
|
|
86
|
+
b) If you want to execute this function on the JS thread, wrap it using \`runOnJS\``);
|
|
87
|
+
};
|
|
88
|
+
fun.__remoteFunction = objectToUnpack;
|
|
89
|
+
return fun;
|
|
90
|
+
} else {
|
|
91
|
+
throw new Error('data type not recognized by unpack method');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
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
|
+
|
|
139
|
+
export function initializeUIRuntime() {
|
|
140
|
+
NativeReanimatedModule.installCoreFunctions(callGuardDEV, valueUnpacker);
|
|
141
|
+
|
|
142
|
+
const IS_JEST = isJest();
|
|
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
|
+
|
|
156
|
+
const capturableConsole = console;
|
|
157
|
+
runOnUIImmediately(() => {
|
|
158
|
+
'worklet';
|
|
159
|
+
// setup error handler
|
|
160
|
+
global.ErrorUtils = {
|
|
161
|
+
reportFatalError: (error: Error) => {
|
|
162
|
+
runOnJS(reportFatalErrorOnJS)({
|
|
163
|
+
message: error.message,
|
|
164
|
+
stack: error.stack,
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// setup console
|
|
170
|
+
// @ts-ignore TypeScript doesn't like that there are missing methods in console object, but we don't provide all the methods for the UI runtime console version
|
|
171
|
+
global.console = {
|
|
172
|
+
debug: runOnJS(capturableConsole.debug),
|
|
173
|
+
log: runOnJS(capturableConsole.log),
|
|
174
|
+
warn: runOnJS(capturableConsole.warn),
|
|
175
|
+
error: runOnJS(capturableConsole.error),
|
|
176
|
+
info: runOnJS(capturableConsole.info),
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
if (!IS_JEST) {
|
|
180
|
+
setupSetImmediate();
|
|
181
|
+
setupRequestAnimationFrame();
|
|
182
|
+
}
|
|
183
|
+
})();
|
|
184
|
+
}
|
|
@@ -19,29 +19,96 @@ export const Extrapolate = {
|
|
|
19
19
|
IDENTITY: 'identity',
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
export type InterpolationOptions = {
|
|
23
|
+
gamma?: number;
|
|
24
|
+
useCorrectedHSVInterpolation?: boolean;
|
|
25
|
+
};
|
|
26
|
+
|
|
22
27
|
const interpolateColorsHSV = (
|
|
23
28
|
value: number,
|
|
24
29
|
inputRange: readonly number[],
|
|
25
|
-
colors: InterpolateHSV
|
|
30
|
+
colors: InterpolateHSV,
|
|
31
|
+
options: InterpolationOptions
|
|
26
32
|
) => {
|
|
27
33
|
'worklet';
|
|
28
|
-
|
|
34
|
+
let h = 0;
|
|
35
|
+
const { useCorrectedHSVInterpolation = true } = options;
|
|
36
|
+
if (useCorrectedHSVInterpolation) {
|
|
37
|
+
// if the difference between hues in a range is > 180 deg
|
|
38
|
+
// then move the hue at the right end of the range +/- 360 deg
|
|
39
|
+
// and add the next point in the original place + 0.00001 with original hue
|
|
40
|
+
// to not break the next range
|
|
41
|
+
const correctedInputRange = [inputRange[0]];
|
|
42
|
+
const originalH = colors.h;
|
|
43
|
+
const correctedH = [originalH[0]];
|
|
44
|
+
|
|
45
|
+
for (let i = 1; i < originalH.length; ++i) {
|
|
46
|
+
const d = originalH[i] - originalH[i - 1];
|
|
47
|
+
if (originalH[i] > originalH[i - 1] && d > 0.5) {
|
|
48
|
+
correctedInputRange.push(inputRange[i]);
|
|
49
|
+
correctedInputRange.push(inputRange[i] + 0.00001);
|
|
50
|
+
correctedH.push(originalH[i] - 1);
|
|
51
|
+
correctedH.push(originalH[i]);
|
|
52
|
+
} else if (originalH[i] < originalH[i - 1] && d < -0.5) {
|
|
53
|
+
correctedInputRange.push(inputRange[i]);
|
|
54
|
+
correctedInputRange.push(inputRange[i] + 0.00001);
|
|
55
|
+
correctedH.push(originalH[i] + 1);
|
|
56
|
+
correctedH.push(originalH[i]);
|
|
57
|
+
} else {
|
|
58
|
+
correctedInputRange.push(inputRange[i]);
|
|
59
|
+
correctedH.push(originalH[i]);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
h =
|
|
63
|
+
(interpolate(value, correctedInputRange, correctedH, Extrapolate.CLAMP) +
|
|
64
|
+
1) %
|
|
65
|
+
1;
|
|
66
|
+
} else {
|
|
67
|
+
h = interpolate(value, inputRange, colors.h, Extrapolate.CLAMP);
|
|
68
|
+
}
|
|
29
69
|
const s = interpolate(value, inputRange, colors.s, Extrapolate.CLAMP);
|
|
30
70
|
const v = interpolate(value, inputRange, colors.v, Extrapolate.CLAMP);
|
|
31
|
-
|
|
71
|
+
const a = interpolate(value, inputRange, colors.a, Extrapolate.CLAMP);
|
|
72
|
+
return hsvToColor(h, s, v, a);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const toLinearSpace = (x: number[], gamma: number): number[] => {
|
|
76
|
+
'worklet';
|
|
77
|
+
return x.map((v) => Math.pow(v / 255, gamma));
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const toGammaSpace = (x: number, gamma: number): number => {
|
|
81
|
+
'worklet';
|
|
82
|
+
return Math.round(Math.pow(x, 1 / gamma) * 255);
|
|
32
83
|
};
|
|
33
84
|
|
|
34
85
|
const interpolateColorsRGB = (
|
|
35
86
|
value: number,
|
|
36
87
|
inputRange: readonly number[],
|
|
37
|
-
colors: InterpolateRGB
|
|
88
|
+
colors: InterpolateRGB,
|
|
89
|
+
options: InterpolationOptions
|
|
38
90
|
) => {
|
|
39
91
|
'worklet';
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
92
|
+
const { gamma = 2.2 } = options;
|
|
93
|
+
let { r: outputR, g: outputG, b: outputB } = colors;
|
|
94
|
+
if (gamma !== 1) {
|
|
95
|
+
outputR = toLinearSpace(outputR, gamma);
|
|
96
|
+
outputG = toLinearSpace(outputG, gamma);
|
|
97
|
+
outputB = toLinearSpace(outputB, gamma);
|
|
98
|
+
}
|
|
99
|
+
const r = interpolate(value, inputRange, outputR, Extrapolate.CLAMP);
|
|
100
|
+
const g = interpolate(value, inputRange, outputG, Extrapolate.CLAMP);
|
|
101
|
+
const b = interpolate(value, inputRange, outputB, Extrapolate.CLAMP);
|
|
43
102
|
const a = interpolate(value, inputRange, colors.a, Extrapolate.CLAMP);
|
|
44
|
-
|
|
103
|
+
if (gamma === 1) {
|
|
104
|
+
return rgbaColor(r, g, b, a);
|
|
105
|
+
}
|
|
106
|
+
return rgbaColor(
|
|
107
|
+
toGammaSpace(r, gamma),
|
|
108
|
+
toGammaSpace(g, gamma),
|
|
109
|
+
toGammaSpace(b, gamma),
|
|
110
|
+
a
|
|
111
|
+
);
|
|
45
112
|
};
|
|
46
113
|
|
|
47
114
|
interface InterpolateRGB {
|
|
@@ -78,6 +145,7 @@ interface InterpolateHSV {
|
|
|
78
145
|
h: number[];
|
|
79
146
|
s: number[];
|
|
80
147
|
v: number[];
|
|
148
|
+
a: number[];
|
|
81
149
|
}
|
|
82
150
|
|
|
83
151
|
const getInterpolateHSV = (
|
|
@@ -87,36 +155,47 @@ const getInterpolateHSV = (
|
|
|
87
155
|
const h = [];
|
|
88
156
|
const s = [];
|
|
89
157
|
const v = [];
|
|
158
|
+
const a = [];
|
|
90
159
|
for (let i = 0; i < colors.length; ++i) {
|
|
91
160
|
const color = colors[i];
|
|
92
|
-
const processedColor =
|
|
93
|
-
if (processedColor) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
161
|
+
const processedColor = processColor(color) as any;
|
|
162
|
+
if (typeof processedColor === 'number') {
|
|
163
|
+
const processedHSVColor = RGBtoHSV(
|
|
164
|
+
red(processedColor),
|
|
165
|
+
green(processedColor),
|
|
166
|
+
blue(processedColor)
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
h.push(processedHSVColor.h);
|
|
170
|
+
s.push(processedHSVColor.s);
|
|
171
|
+
v.push(processedHSVColor.v);
|
|
172
|
+
a.push(opacity(processedColor));
|
|
97
173
|
}
|
|
98
174
|
}
|
|
99
|
-
return { h, s, v };
|
|
175
|
+
return { h, s, v, a };
|
|
100
176
|
};
|
|
101
177
|
|
|
102
178
|
export const interpolateColor = (
|
|
103
179
|
value: number,
|
|
104
180
|
inputRange: readonly number[],
|
|
105
181
|
outputRange: readonly (string | number)[],
|
|
106
|
-
colorSpace: 'RGB' | 'HSV' = 'RGB'
|
|
182
|
+
colorSpace: 'RGB' | 'HSV' = 'RGB',
|
|
183
|
+
options: InterpolationOptions = {}
|
|
107
184
|
): string | number => {
|
|
108
185
|
'worklet';
|
|
109
186
|
if (colorSpace === 'HSV') {
|
|
110
187
|
return interpolateColorsHSV(
|
|
111
188
|
value,
|
|
112
189
|
inputRange,
|
|
113
|
-
getInterpolateHSV(outputRange)
|
|
190
|
+
getInterpolateHSV(outputRange),
|
|
191
|
+
options
|
|
114
192
|
);
|
|
115
193
|
} else if (colorSpace === 'RGB') {
|
|
116
194
|
return interpolateColorsRGB(
|
|
117
195
|
value,
|
|
118
196
|
inputRange,
|
|
119
|
-
getInterpolateRGB(outputRange)
|
|
197
|
+
getInterpolateRGB(outputRange),
|
|
198
|
+
options
|
|
120
199
|
);
|
|
121
200
|
}
|
|
122
201
|
throw new Error(
|
|
@@ -134,18 +213,21 @@ export interface InterpolateConfig {
|
|
|
134
213
|
outputRange: readonly (string | number)[];
|
|
135
214
|
colorSpace: ColorSpace;
|
|
136
215
|
cache: SharedValue<InterpolateRGB | InterpolateHSV | null>;
|
|
216
|
+
options: InterpolationOptions;
|
|
137
217
|
}
|
|
138
218
|
|
|
139
219
|
export function useInterpolateConfig(
|
|
140
220
|
inputRange: readonly number[],
|
|
141
221
|
outputRange: readonly (string | number)[],
|
|
142
|
-
colorSpace = ColorSpace.RGB
|
|
222
|
+
colorSpace = ColorSpace.RGB,
|
|
223
|
+
options: InterpolationOptions = {}
|
|
143
224
|
): SharedValue<InterpolateConfig> {
|
|
144
225
|
return useSharedValue<InterpolateConfig>({
|
|
145
226
|
inputRange,
|
|
146
227
|
outputRange,
|
|
147
228
|
colorSpace,
|
|
148
229
|
cache: makeMutable<InterpolateRGB | InterpolateHSV | null>(null),
|
|
230
|
+
options,
|
|
149
231
|
});
|
|
150
232
|
}
|
|
151
233
|
|
|
@@ -163,7 +245,8 @@ export const interpolateSharableColor = (
|
|
|
163
245
|
return interpolateColorsRGB(
|
|
164
246
|
value,
|
|
165
247
|
interpolateConfig.value.inputRange,
|
|
166
|
-
colors as InterpolateRGB
|
|
248
|
+
colors as InterpolateRGB,
|
|
249
|
+
interpolateConfig.value.options
|
|
167
250
|
);
|
|
168
251
|
} else if (interpolateConfig.value.colorSpace === ColorSpace.HSV) {
|
|
169
252
|
if (!colors) {
|
|
@@ -173,7 +256,8 @@ export const interpolateSharableColor = (
|
|
|
173
256
|
return interpolateColorsHSV(
|
|
174
257
|
value,
|
|
175
258
|
interpolateConfig.value.inputRange,
|
|
176
|
-
colors as InterpolateHSV
|
|
259
|
+
colors as InterpolateHSV,
|
|
260
|
+
interpolateConfig.value.options
|
|
177
261
|
);
|
|
178
262
|
}
|
|
179
263
|
throw new Error(
|
|
@@ -149,7 +149,7 @@ const afterTest = () => {
|
|
|
149
149
|
|
|
150
150
|
export const withReanimatedTimer = (animationTest) => {
|
|
151
151
|
console.warn(
|
|
152
|
-
'This method is deprecated, you
|
|
152
|
+
'This method is deprecated, you should define your own before and after test hooks to enable jest.useFakeTimers(). Check out the documentation for details on testing'
|
|
153
153
|
);
|
|
154
154
|
beforeTest();
|
|
155
155
|
animationTest();
|
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
import { NativeReanimated } from '../NativeReanimated/NativeReanimated';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
SensorType,
|
|
4
|
+
ShareableRef,
|
|
5
|
+
Value3D,
|
|
6
|
+
ValueRotation,
|
|
7
|
+
} from '../commonTypes';
|
|
8
|
+
import { WebSensor } from './WebSensor';
|
|
4
9
|
|
|
5
10
|
export default class JSReanimated extends NativeReanimated {
|
|
6
|
-
|
|
11
|
+
nextSensorId = 0;
|
|
12
|
+
sensors = new Map<number, WebSensor>();
|
|
7
13
|
|
|
8
14
|
constructor() {
|
|
9
15
|
super(false);
|
|
10
|
-
if (isJest()) {
|
|
11
|
-
// on node < 16 jest have problems mocking performance.now method which
|
|
12
|
-
// results in the tests failing, since date precision isn't that important
|
|
13
|
-
// for tests, we use Date.now instead
|
|
14
|
-
this.getTimestamp = () => Date.now();
|
|
15
|
-
} else {
|
|
16
|
-
this.getTimestamp = () => window.performance.now();
|
|
17
|
-
}
|
|
18
16
|
}
|
|
19
17
|
|
|
20
18
|
makeShareableClone<T>(value: T): ShareableRef<T> {
|
|
21
19
|
return { __hostObjectShareableJSRef: value };
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
installCoreFunctions(
|
|
25
|
-
|
|
22
|
+
installCoreFunctions(
|
|
23
|
+
_callGuard: <T extends Array<any>, U>(
|
|
24
|
+
fn: (...args: T) => U,
|
|
25
|
+
...args: T
|
|
26
|
+
) => void,
|
|
27
|
+
_valueUnpacker: <T>(value: T) => T
|
|
28
|
+
): void {
|
|
29
|
+
// noop
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
scheduleOnUI<T>(worklet: ShareableRef<T>) {
|
|
@@ -48,13 +52,62 @@ export default class JSReanimated extends NativeReanimated {
|
|
|
48
52
|
);
|
|
49
53
|
}
|
|
50
54
|
|
|
51
|
-
registerSensor(
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
registerSensor(
|
|
56
|
+
sensorType: SensorType,
|
|
57
|
+
interval: number,
|
|
58
|
+
iosReferenceFrame: number,
|
|
59
|
+
eventHandler: (data: Value3D | ValueRotation) => void
|
|
60
|
+
): number {
|
|
61
|
+
if (!(this.getSensorName(sensorType) in window)) {
|
|
62
|
+
return -1;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const sensor: WebSensor = this.initializeSensor(sensorType, interval);
|
|
66
|
+
let callback;
|
|
67
|
+
if (sensorType === SensorType.ROTATION) {
|
|
68
|
+
callback = () => {
|
|
69
|
+
const [qw, qx, qy, qz] = sensor.quaternion;
|
|
70
|
+
|
|
71
|
+
// reference: https://stackoverflow.com/questions/5782658/extracting-yaw-from-a-quaternion
|
|
72
|
+
const yaw = Math.atan2(
|
|
73
|
+
2.0 * (qy * qz + qw * qx),
|
|
74
|
+
qw * qw - qx * qx - qy * qy + qz * qz
|
|
75
|
+
);
|
|
76
|
+
const pitch = Math.sin(-2.0 * (qx * qz - qw * qy));
|
|
77
|
+
const roll = Math.atan2(
|
|
78
|
+
2.0 * (qx * qy + qw * qz),
|
|
79
|
+
qw * qw + qx * qx - qy * qy - qz * qz
|
|
80
|
+
);
|
|
81
|
+
eventHandler({
|
|
82
|
+
qw,
|
|
83
|
+
qx,
|
|
84
|
+
qy,
|
|
85
|
+
qz,
|
|
86
|
+
yaw,
|
|
87
|
+
pitch,
|
|
88
|
+
roll,
|
|
89
|
+
interfaceOrientation: 0,
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
} else {
|
|
93
|
+
callback = () => {
|
|
94
|
+
const { x, y, z } = sensor;
|
|
95
|
+
eventHandler({ x, y, z, interfaceOrientation: 0 });
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
sensor.addEventListener('reading', callback);
|
|
99
|
+
sensor.start();
|
|
100
|
+
|
|
101
|
+
this.sensors.set(this.nextSensorId, sensor);
|
|
102
|
+
return this.nextSensorId++;
|
|
54
103
|
}
|
|
55
104
|
|
|
56
|
-
unregisterSensor(): void {
|
|
57
|
-
|
|
105
|
+
unregisterSensor(id: number): void {
|
|
106
|
+
const sensor: WebSensor | undefined = this.sensors.get(id);
|
|
107
|
+
if (sensor !== undefined) {
|
|
108
|
+
sensor.stop();
|
|
109
|
+
this.sensors.delete(id);
|
|
110
|
+
}
|
|
58
111
|
}
|
|
59
112
|
|
|
60
113
|
subscribeForKeyboardEvents(_: ShareableRef<number>): number {
|
|
@@ -67,4 +120,38 @@ export default class JSReanimated extends NativeReanimated {
|
|
|
67
120
|
unsubscribeFromKeyboardEvents(_: number): void {
|
|
68
121
|
// noop
|
|
69
122
|
}
|
|
123
|
+
|
|
124
|
+
initializeSensor(sensorType: SensorType, interval: number): WebSensor {
|
|
125
|
+
const config =
|
|
126
|
+
interval <= 0
|
|
127
|
+
? { referenceFrame: 'device' }
|
|
128
|
+
: { frequency: 1000 / interval };
|
|
129
|
+
switch (sensorType) {
|
|
130
|
+
case SensorType.ACCELEROMETER:
|
|
131
|
+
return new window.Accelerometer(config);
|
|
132
|
+
case SensorType.GYROSCOPE:
|
|
133
|
+
return new window.Gyroscope(config);
|
|
134
|
+
case SensorType.GRAVITY:
|
|
135
|
+
return new window.GravitySensor(config);
|
|
136
|
+
case SensorType.MAGNETIC_FIELD:
|
|
137
|
+
return new window.Magnetometer(config);
|
|
138
|
+
case SensorType.ROTATION:
|
|
139
|
+
return new window.AbsoluteOrientationSensor(config);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
getSensorName(sensorType: SensorType): string {
|
|
144
|
+
switch (sensorType) {
|
|
145
|
+
case SensorType.ACCELEROMETER:
|
|
146
|
+
return 'Accelerometer';
|
|
147
|
+
case SensorType.GRAVITY:
|
|
148
|
+
return 'GravitySensor';
|
|
149
|
+
case SensorType.GYROSCOPE:
|
|
150
|
+
return 'Gyroscope';
|
|
151
|
+
case SensorType.MAGNETIC_FIELD:
|
|
152
|
+
return 'Magnetometer';
|
|
153
|
+
case SensorType.ROTATION:
|
|
154
|
+
return 'AbsoluteOrientationSensor';
|
|
155
|
+
}
|
|
156
|
+
}
|
|
70
157
|
}
|