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
|
@@ -3,26 +3,16 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.SensorType = void 0;
|
|
7
6
|
exports.useAnimatedSensor = useAnimatedSensor;
|
|
8
7
|
|
|
9
8
|
var _react = require("react");
|
|
10
9
|
|
|
11
10
|
var _core = require("../core");
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
exports.SensorType = SensorType;
|
|
15
|
-
|
|
16
|
-
(function (SensorType) {
|
|
17
|
-
SensorType[SensorType["ACCELEROMETER"] = 1] = "ACCELEROMETER";
|
|
18
|
-
SensorType[SensorType["GYROSCOPE"] = 2] = "GYROSCOPE";
|
|
19
|
-
SensorType[SensorType["GRAVITY"] = 3] = "GRAVITY";
|
|
20
|
-
SensorType[SensorType["MAGNETIC_FIELD"] = 4] = "MAGNETIC_FIELD";
|
|
21
|
-
SensorType[SensorType["ROTATION"] = 5] = "ROTATION";
|
|
22
|
-
})(SensorType || (exports.SensorType = SensorType = {}));
|
|
12
|
+
var _commonTypes = require("../commonTypes");
|
|
23
13
|
|
|
24
14
|
function initSensorData(sensorType) {
|
|
25
|
-
if (sensorType === SensorType.ROTATION) {
|
|
15
|
+
if (sensorType === _commonTypes.SensorType.ROTATION) {
|
|
26
16
|
return (0, _core.makeMutable)({
|
|
27
17
|
qw: 0,
|
|
28
18
|
qx: 0,
|
|
@@ -30,15 +20,86 @@ function initSensorData(sensorType) {
|
|
|
30
20
|
qz: 0,
|
|
31
21
|
yaw: 0,
|
|
32
22
|
pitch: 0,
|
|
33
|
-
roll: 0
|
|
23
|
+
roll: 0,
|
|
24
|
+
interfaceOrientation: 0
|
|
34
25
|
});
|
|
35
26
|
} else {
|
|
36
27
|
return (0, _core.makeMutable)({
|
|
37
28
|
x: 0,
|
|
38
29
|
y: 0,
|
|
39
|
-
z: 0
|
|
30
|
+
z: 0,
|
|
31
|
+
interfaceOrientation: 0
|
|
40
32
|
});
|
|
41
33
|
}
|
|
34
|
+
} // euler angles are in order ZXY, z = yaw, x = pitch, y = roll
|
|
35
|
+
// https://github.com/mrdoob/three.js/blob/dev/src/math/Quaternion.js#L237
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
function eulerToQuaternion(pitch, roll, yaw) {
|
|
39
|
+
'worklet';
|
|
40
|
+
|
|
41
|
+
const c1 = Math.cos(pitch / 2);
|
|
42
|
+
const s1 = Math.sin(pitch / 2);
|
|
43
|
+
const c2 = Math.cos(roll / 2);
|
|
44
|
+
const s2 = Math.sin(roll / 2);
|
|
45
|
+
const c3 = Math.cos(yaw / 2);
|
|
46
|
+
const s3 = Math.sin(yaw / 2);
|
|
47
|
+
return [s1 * c2 * c3 - c1 * s2 * s3, c1 * s2 * c3 + s1 * c2 * s3, c1 * c2 * s3 + s1 * s2 * c3, c1 * c2 * c3 - s1 * s2 * s3];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function adjustRotationToInterfaceOrientation(data) {
|
|
51
|
+
'worklet';
|
|
52
|
+
|
|
53
|
+
const {
|
|
54
|
+
interfaceOrientation,
|
|
55
|
+
pitch,
|
|
56
|
+
roll,
|
|
57
|
+
yaw
|
|
58
|
+
} = data;
|
|
59
|
+
|
|
60
|
+
if (interfaceOrientation === 90) {
|
|
61
|
+
data.pitch = roll;
|
|
62
|
+
data.roll = -pitch;
|
|
63
|
+
data.yaw = yaw - Math.PI / 2;
|
|
64
|
+
} else if (interfaceOrientation === 270) {
|
|
65
|
+
data.pitch = -roll;
|
|
66
|
+
data.roll = pitch;
|
|
67
|
+
data.yaw = yaw + Math.PI / 2;
|
|
68
|
+
} else if (interfaceOrientation === 180) {
|
|
69
|
+
data.pitch *= -1;
|
|
70
|
+
data.roll *= -1;
|
|
71
|
+
data.yaw *= -1;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const q = eulerToQuaternion(data.pitch, data.roll, data.yaw);
|
|
75
|
+
data.qx = q[0];
|
|
76
|
+
data.qy = q[1];
|
|
77
|
+
data.qz = q[2];
|
|
78
|
+
data.qw = q[3];
|
|
79
|
+
return data;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function adjustVectorToInterfaceOrientation(data) {
|
|
83
|
+
'worklet';
|
|
84
|
+
|
|
85
|
+
const {
|
|
86
|
+
interfaceOrientation,
|
|
87
|
+
x,
|
|
88
|
+
y
|
|
89
|
+
} = data;
|
|
90
|
+
|
|
91
|
+
if (interfaceOrientation === 90) {
|
|
92
|
+
data.x = -y;
|
|
93
|
+
data.y = x;
|
|
94
|
+
} else if (interfaceOrientation === 270) {
|
|
95
|
+
data.x = y;
|
|
96
|
+
data.y = -x;
|
|
97
|
+
} else if (interfaceOrientation === 180) {
|
|
98
|
+
data.x *= -1;
|
|
99
|
+
data.y *= -1;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return data;
|
|
42
103
|
}
|
|
43
104
|
|
|
44
105
|
function useAnimatedSensor(sensorType, userConfig) {
|
|
@@ -48,18 +109,30 @@ function useAnimatedSensor(sensorType, userConfig) {
|
|
|
48
109
|
},
|
|
49
110
|
isAvailable: false,
|
|
50
111
|
config: {
|
|
51
|
-
interval: 0
|
|
112
|
+
interval: 0,
|
|
113
|
+
adjustToInterfaceOrientation: true,
|
|
114
|
+
iosReferenceFrame: _commonTypes.IOSReferenceFrame.Auto
|
|
52
115
|
}
|
|
53
116
|
});
|
|
54
117
|
(0, _react.useEffect)(() => {
|
|
55
118
|
ref.current.config = {
|
|
56
119
|
interval: 'auto',
|
|
120
|
+
adjustToInterfaceOrientation: true,
|
|
121
|
+
iosReferenceFrame: _commonTypes.IOSReferenceFrame.Auto,
|
|
57
122
|
...userConfig
|
|
58
123
|
};
|
|
59
124
|
const sensorData = ref.current.sensor;
|
|
60
|
-
const id = (0, _core.registerSensor)(sensorType, ref.current.config.interval === 'auto' ? -1 : ref.current.config.interval, data => {
|
|
125
|
+
const id = (0, _core.registerSensor)(sensorType, ref.current.config.interval === 'auto' ? -1 : ref.current.config.interval, ref.current.config.iosReferenceFrame, data => {
|
|
61
126
|
'worklet';
|
|
62
127
|
|
|
128
|
+
if (ref.current.config.adjustToInterfaceOrientation) {
|
|
129
|
+
if (sensorType === _commonTypes.SensorType.ROTATION) {
|
|
130
|
+
data = adjustRotationToInterfaceOrientation(data);
|
|
131
|
+
} else {
|
|
132
|
+
data = adjustVectorToInterfaceOrientation(data);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
63
136
|
sensorData.value = data;
|
|
64
137
|
});
|
|
65
138
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["initSensorData","sensorType","SensorType","ROTATION","makeMutable","qw","qx","qy","qz","yaw","pitch","roll","interfaceOrientation","x","y","z","eulerToQuaternion","c1","Math","cos","s1","sin","c2","s2","c3","s3","adjustRotationToInterfaceOrientation","data","PI","q","adjustVectorToInterfaceOrientation","useAnimatedSensor","userConfig","ref","useRef","sensor","unregister","isAvailable","config","interval","adjustToInterfaceOrientation","iosReferenceFrame","IOSReferenceFrame","Auto","useEffect","current","sensorData","id","registerSensor","value","unregisterSensor"],"sources":["useAnimatedSensor.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { makeMutable, registerSensor, unregisterSensor } from '../core';\nimport {\n SensorType,\n SharedValue,\n Value3D,\n ValueRotation,\n IOSReferenceFrame,\n} from '../commonTypes';\n\nexport type SensorConfig = {\n interval: number | 'auto';\n adjustToInterfaceOrientation: boolean;\n iosReferenceFrame: IOSReferenceFrame;\n};\n\nexport type AnimatedSensor = {\n sensor: SharedValue<Value3D | ValueRotation>;\n unregister: () => void;\n isAvailable: boolean;\n config: SensorConfig;\n};\n\nfunction initSensorData(\n sensorType: SensorType\n): SharedValue<Value3D | ValueRotation> {\n if (sensorType === SensorType.ROTATION) {\n return makeMutable<Value3D | ValueRotation>({\n qw: 0,\n qx: 0,\n qy: 0,\n qz: 0,\n yaw: 0,\n pitch: 0,\n roll: 0,\n interfaceOrientation: 0,\n });\n } else {\n return makeMutable<Value3D | ValueRotation>({\n x: 0,\n y: 0,\n z: 0,\n interfaceOrientation: 0,\n });\n }\n}\n\n// euler angles are in order ZXY, z = yaw, x = pitch, y = roll\n// https://github.com/mrdoob/three.js/blob/dev/src/math/Quaternion.js#L237\nfunction eulerToQuaternion(pitch: number, roll: number, yaw: number) {\n 'worklet';\n const c1 = Math.cos(pitch / 2);\n const s1 = Math.sin(pitch / 2);\n const c2 = Math.cos(roll / 2);\n const s2 = Math.sin(roll / 2);\n const c3 = Math.cos(yaw / 2);\n const s3 = Math.sin(yaw / 2);\n\n return [\n s1 * c2 * c3 - c1 * s2 * s3,\n c1 * s2 * c3 + s1 * c2 * s3,\n c1 * c2 * s3 + s1 * s2 * c3,\n c1 * c2 * c3 - s1 * s2 * s3,\n ];\n}\n\nfunction adjustRotationToInterfaceOrientation(data: ValueRotation) {\n 'worklet';\n const { interfaceOrientation, pitch, roll, yaw } = data;\n if (interfaceOrientation === 90) {\n data.pitch = roll;\n data.roll = -pitch;\n data.yaw = yaw - Math.PI / 2;\n } else if (interfaceOrientation === 270) {\n data.pitch = -roll;\n data.roll = pitch;\n data.yaw = yaw + Math.PI / 2;\n } else if (interfaceOrientation === 180) {\n data.pitch *= -1;\n data.roll *= -1;\n data.yaw *= -1;\n }\n\n const q = eulerToQuaternion(data.pitch, data.roll, data.yaw);\n data.qx = q[0];\n data.qy = q[1];\n data.qz = q[2];\n data.qw = q[3];\n return data;\n}\n\nfunction adjustVectorToInterfaceOrientation(data: Value3D) {\n 'worklet';\n const { interfaceOrientation, x, y } = data;\n if (interfaceOrientation === 90) {\n data.x = -y;\n data.y = x;\n } else if (interfaceOrientation === 270) {\n data.x = y;\n data.y = -x;\n } else if (interfaceOrientation === 180) {\n data.x *= -1;\n data.y *= -1;\n }\n return data;\n}\n\nexport function useAnimatedSensor(\n sensorType: SensorType,\n userConfig?: Partial<SensorConfig>\n): AnimatedSensor {\n const ref = useRef<AnimatedSensor>({\n sensor: initSensorData(sensorType),\n unregister: () => {\n // NOOP\n },\n isAvailable: false,\n config: {\n interval: 0,\n adjustToInterfaceOrientation: true,\n iosReferenceFrame: IOSReferenceFrame.Auto,\n },\n });\n\n useEffect(() => {\n ref.current.config = {\n interval: 'auto',\n adjustToInterfaceOrientation: true,\n iosReferenceFrame: IOSReferenceFrame.Auto,\n ...userConfig,\n };\n const sensorData = ref.current.sensor!;\n const id = registerSensor(\n sensorType,\n ref.current.config.interval === 'auto' ? -1 : ref.current.config.interval,\n ref.current.config.iosReferenceFrame,\n (data) => {\n 'worklet';\n if (ref.current.config.adjustToInterfaceOrientation) {\n if (sensorType === SensorType.ROTATION) {\n data = adjustRotationToInterfaceOrientation(data as ValueRotation);\n } else {\n data = adjustVectorToInterfaceOrientation(data as Value3D);\n }\n }\n sensorData.value = data;\n }\n );\n\n if (id !== -1) {\n // if sensor is available\n ref.current.unregister = () => unregisterSensor(id);\n ref.current.isAvailable = true;\n } else {\n // if sensor is unavailable\n ref.current.unregister = () => {\n // NOOP\n };\n ref.current.isAvailable = false;\n }\n\n return () => {\n ref.current.unregister();\n };\n }, [sensorType, userConfig]);\n\n return ref.current;\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAqBA,SAASA,cAAT,CACEC,UADF,EAEwC;EACtC,IAAIA,UAAU,KAAKC,uBAAA,CAAWC,QAA9B,EAAwC;IACtC,OAAO,IAAAC,iBAAA,EAAqC;MAC1CC,EAAE,EAAE,CADsC;MAE1CC,EAAE,EAAE,CAFsC;MAG1CC,EAAE,EAAE,CAHsC;MAI1CC,EAAE,EAAE,CAJsC;MAK1CC,GAAG,EAAE,CALqC;MAM1CC,KAAK,EAAE,CANmC;MAO1CC,IAAI,EAAE,CAPoC;MAQ1CC,oBAAoB,EAAE;IARoB,CAArC,CAAP;EAUD,CAXD,MAWO;IACL,OAAO,IAAAR,iBAAA,EAAqC;MAC1CS,CAAC,EAAE,CADuC;MAE1CC,CAAC,EAAE,CAFuC;MAG1CC,CAAC,EAAE,CAHuC;MAI1CH,oBAAoB,EAAE;IAJoB,CAArC,CAAP;EAMD;AACF,C,CAED;AACA;;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ACD;MACF;;MACDmB,UAAU,CAACG,KAAX,GAAmBtB,IAAnB;IACD,CAdQ,CAAX;;IAiBA,IAAIoB,EAAE,KAAK,CAAC,CAAZ,EAAe;MACb;MACAd,GAAG,CAACY,OAAJ,CAAYT,UAAZ,GAAyB,MAAM,IAAAc,sBAAA,EAAiBH,EAAjB,CAA/B;;MACAd,GAAG,CAACY,OAAJ,CAAYR,WAAZ,GAA0B,IAA1B;IACD,CAJD,MAIO;MACL;MACAJ,GAAG,CAACY,OAAJ,CAAYT,UAAZ,GAAyB,MAAM,CAC7B;MACD,CAFD;;MAGAH,GAAG,CAACY,OAAJ,CAAYR,WAAZ,GAA0B,KAA1B;IACD;;IAED,OAAO,MAAM;MACXJ,GAAG,CAACY,OAAJ,CAAYT,UAAZ;IACD,CAFD;EAGD,CAxCD,EAwCG,CAACnC,UAAD,EAAa+B,UAAb,CAxCH;EA0CA,OAAOC,GAAG,CAACY,OAAX;AACD"}
|
|
@@ -29,13 +29,12 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
29
29
|
|
|
30
30
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
function prepareAnimation(animatedProp, lastAnimation, lastValue) {
|
|
32
|
+
function prepareAnimation(frameTimestamp, animatedProp, lastAnimation, lastValue) {
|
|
34
33
|
'worklet';
|
|
35
34
|
|
|
36
35
|
if (Array.isArray(animatedProp)) {
|
|
37
36
|
animatedProp.forEach((prop, index) => {
|
|
38
|
-
prepareAnimation(prop, lastAnimation && lastAnimation[index], lastValue && lastValue[index]);
|
|
37
|
+
prepareAnimation(frameTimestamp, prop, lastAnimation && lastAnimation[index], lastValue && lastValue[index]);
|
|
39
38
|
}); // return animatedProp;
|
|
40
39
|
}
|
|
41
40
|
|
|
@@ -67,11 +66,11 @@ function prepareAnimation(animatedProp, lastAnimation, lastValue) {
|
|
|
67
66
|
animation.onStart(animation, value, timestamp, lastAnimation);
|
|
68
67
|
};
|
|
69
68
|
|
|
70
|
-
animation.callStart(
|
|
69
|
+
animation.callStart(frameTimestamp);
|
|
71
70
|
animation.callStart = null;
|
|
72
71
|
} else if (typeof animatedProp === 'object') {
|
|
73
72
|
// it is an object
|
|
74
|
-
Object.keys(animatedProp).forEach(key => prepareAnimation(animatedProp[key], lastAnimation && lastAnimation[key], lastValue && lastValue[key]));
|
|
73
|
+
Object.keys(animatedProp).forEach(key => prepareAnimation(frameTimestamp, animatedProp[key], lastAnimation && lastAnimation[key], lastValue && lastValue[key]));
|
|
75
74
|
}
|
|
76
75
|
}
|
|
77
76
|
|
|
@@ -134,30 +133,34 @@ function styleUpdater(viewDescriptors, updater, state, maybeViewRef, animationsA
|
|
|
134
133
|
const animations = state.animations ?? {};
|
|
135
134
|
const newValues = updater() ?? {};
|
|
136
135
|
const oldValues = state.last;
|
|
136
|
+
const nonAnimatedNewValues = {};
|
|
137
137
|
let hasAnimations = false;
|
|
138
|
+
let frameTimestamp;
|
|
139
|
+
let hasNonAnimatedValues = false;
|
|
138
140
|
|
|
139
141
|
for (const key in newValues) {
|
|
140
142
|
const value = newValues[key];
|
|
141
143
|
|
|
142
144
|
if ((0, _utils.isAnimated)(value)) {
|
|
143
|
-
|
|
145
|
+
frameTimestamp = global.__frameTimestamp || performance.now();
|
|
146
|
+
prepareAnimation(frameTimestamp, value, animations[key], oldValues[key]);
|
|
144
147
|
animations[key] = value;
|
|
145
148
|
hasAnimations = true;
|
|
146
149
|
} else {
|
|
150
|
+
hasNonAnimatedValues = true;
|
|
151
|
+
nonAnimatedNewValues[key] = value;
|
|
147
152
|
delete animations[key];
|
|
148
153
|
}
|
|
149
154
|
}
|
|
150
155
|
|
|
151
156
|
if (hasAnimations) {
|
|
152
|
-
const frame =
|
|
157
|
+
const frame = timestamp => {
|
|
153
158
|
const {
|
|
154
159
|
animations,
|
|
155
160
|
last,
|
|
156
161
|
isAnimationCancelled
|
|
157
162
|
} = state;
|
|
158
163
|
|
|
159
|
-
const timestamp = _timestamp ?? (0, _core.getTimestamp)();
|
|
160
|
-
|
|
161
164
|
if (isAnimationCancelled) {
|
|
162
165
|
state.isAnimationRunning = false;
|
|
163
166
|
return;
|
|
@@ -193,30 +196,22 @@ function styleUpdater(viewDescriptors, updater, state, maybeViewRef, animationsA
|
|
|
193
196
|
if (!state.isAnimationRunning) {
|
|
194
197
|
state.isAnimationCancelled = false;
|
|
195
198
|
state.isAnimationRunning = true;
|
|
196
|
-
|
|
197
|
-
if (_frameTimestamp) {
|
|
198
|
-
frame(_frameTimestamp);
|
|
199
|
-
} else {
|
|
200
|
-
requestAnimationFrame(frame);
|
|
201
|
-
}
|
|
199
|
+
frame(frameTimestamp);
|
|
202
200
|
}
|
|
203
201
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if (style) {
|
|
208
|
-
(0, _UpdateProps.default)(viewDescriptors, style, maybeViewRef);
|
|
202
|
+
if (hasNonAnimatedValues) {
|
|
203
|
+
(0, _UpdateProps.default)(viewDescriptors, nonAnimatedNewValues, maybeViewRef);
|
|
209
204
|
}
|
|
210
205
|
} else {
|
|
211
206
|
state.isAnimationCancelled = true;
|
|
212
207
|
state.animations = [];
|
|
213
|
-
const diff = (0, _utils.styleDiff)(oldValues, newValues);
|
|
214
|
-
state.last = Object.assign({}, oldValues, newValues);
|
|
215
208
|
|
|
216
|
-
if (
|
|
209
|
+
if (!(0, _utils.shallowEqual)(oldValues, newValues)) {
|
|
217
210
|
(0, _UpdateProps.default)(viewDescriptors, newValues, maybeViewRef);
|
|
218
211
|
}
|
|
219
212
|
}
|
|
213
|
+
|
|
214
|
+
state.last = newValues;
|
|
220
215
|
}
|
|
221
216
|
|
|
222
217
|
function jestStyleUpdater(viewDescriptors, updater, state, maybeViewRef, animationsActive, animatedStyle) {
|
|
@@ -228,6 +223,7 @@ function jestStyleUpdater(viewDescriptors, updater, state, maybeViewRef, animati
|
|
|
228
223
|
const oldValues = state.last; // extract animated props
|
|
229
224
|
|
|
230
225
|
let hasAnimations = false;
|
|
226
|
+
let frameTimestamp;
|
|
231
227
|
Object.keys(animations).forEach(key => {
|
|
232
228
|
const value = newValues[key];
|
|
233
229
|
|
|
@@ -239,21 +235,20 @@ function jestStyleUpdater(viewDescriptors, updater, state, maybeViewRef, animati
|
|
|
239
235
|
const value = newValues[key];
|
|
240
236
|
|
|
241
237
|
if ((0, _utils.isAnimated)(value)) {
|
|
242
|
-
|
|
238
|
+
frameTimestamp = global.__frameTimestamp || performance.now();
|
|
239
|
+
prepareAnimation(frameTimestamp, value, animations[key], oldValues[key]);
|
|
243
240
|
animations[key] = value;
|
|
244
241
|
hasAnimations = true;
|
|
245
242
|
}
|
|
246
243
|
});
|
|
247
244
|
|
|
248
|
-
function frame(
|
|
245
|
+
function frame(timestamp) {
|
|
249
246
|
const {
|
|
250
247
|
animations,
|
|
251
248
|
last,
|
|
252
249
|
isAnimationCancelled
|
|
253
250
|
} = state;
|
|
254
251
|
|
|
255
|
-
const timestamp = _timestamp ?? (0, _core.getTimestamp)();
|
|
256
|
-
|
|
257
252
|
if (isAnimationCancelled) {
|
|
258
253
|
state.isAnimationRunning = false;
|
|
259
254
|
return;
|
|
@@ -289,12 +284,7 @@ function jestStyleUpdater(viewDescriptors, updater, state, maybeViewRef, animati
|
|
|
289
284
|
if (!state.isAnimationRunning) {
|
|
290
285
|
state.isAnimationCancelled = false;
|
|
291
286
|
state.isAnimationRunning = true;
|
|
292
|
-
|
|
293
|
-
if (_frameTimestamp) {
|
|
294
|
-
frame(_frameTimestamp);
|
|
295
|
-
} else {
|
|
296
|
-
requestAnimationFrame(frame);
|
|
297
|
-
}
|
|
287
|
+
frame(frameTimestamp);
|
|
298
288
|
}
|
|
299
289
|
} else {
|
|
300
290
|
state.isAnimationCancelled = true;
|
|
@@ -302,11 +292,10 @@ function jestStyleUpdater(viewDescriptors, updater, state, maybeViewRef, animati
|
|
|
302
292
|
} // calculate diff
|
|
303
293
|
|
|
304
294
|
|
|
305
|
-
|
|
306
|
-
state.last = Object.assign({}, oldValues, newValues);
|
|
295
|
+
state.last = newValues;
|
|
307
296
|
|
|
308
|
-
if (
|
|
309
|
-
(0, _UpdateProps.updatePropsJestWrapper)(viewDescriptors,
|
|
297
|
+
if (!(0, _utils.shallowEqual)(oldValues, newValues)) {
|
|
298
|
+
(0, _UpdateProps.updatePropsJestWrapper)(viewDescriptors, newValues, maybeViewRef, animatedStyle, adapters);
|
|
310
299
|
}
|
|
311
300
|
} // check for invalid usage of shared values in returned object
|
|
312
301
|
|
|
@@ -331,7 +320,23 @@ function checkSharedValueUsage(prop, currentKey) {
|
|
|
331
320
|
function useAnimatedStyle(updater, dependencies, adapters) {
|
|
332
321
|
const viewsRef = (0, _ViewDescriptorsSet.makeViewsRefSet)();
|
|
333
322
|
const initRef = (0, _react.useRef)();
|
|
334
|
-
|
|
323
|
+
let inputs = Object.values(updater._closure ?? {});
|
|
324
|
+
|
|
325
|
+
if ((0, _PlatformChecker.shouldBeUseWeb)()) {
|
|
326
|
+
var _dependencies;
|
|
327
|
+
|
|
328
|
+
if (!inputs.length && (_dependencies = dependencies) !== null && _dependencies !== void 0 && _dependencies.length) {
|
|
329
|
+
// let web work without a Babel/SWC plugin
|
|
330
|
+
inputs = dependencies;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (__DEV__ && !inputs.length && !dependencies && !updater.__workletHash) {
|
|
334
|
+
throw new Error(`useAnimatedStyle was used without a dependency array or Babel plugin. Please explicitly pass a dependency array, or enable the Babel/SWC plugin.
|
|
335
|
+
|
|
336
|
+
For more, see the docs: https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/web-support#web-without-a-babel-plugin`);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
335
340
|
const adaptersArray = adapters ? Array.isArray(adapters) ? adapters : [adapters] : [];
|
|
336
341
|
const adaptersHash = adapters ? (0, _utils.buildWorkletsHash)(adaptersArray) : null;
|
|
337
342
|
const animationsActive = (0, _useSharedValue.useSharedValue)(true);
|
|
@@ -410,8 +415,6 @@ function useAnimatedStyle(updater, dependencies, adapters) {
|
|
|
410
415
|
(0, _react.useEffect)(() => {
|
|
411
416
|
animationsActive.value = true;
|
|
412
417
|
return () => {
|
|
413
|
-
// initRef.current = null;
|
|
414
|
-
// viewsRef = null;
|
|
415
418
|
animationsActive.value = false;
|
|
416
419
|
};
|
|
417
420
|
}, []);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["prepareAnimation","animatedProp","lastAnimation","lastValue","Array","isArray","forEach","prop","index","onFrame","animation","value","current","undefined","callStart","timestamp","onStart","getTimestamp","Object","keys","key","runAnimations","result","animationsActive","allFinished","entry","finished","callback","k","styleUpdater","viewDescriptors","updater","state","maybeViewRef","animations","newValues","oldValues","last","hasAnimations","isAnimated","frame","_timestamp","isAnimationCancelled","isAnimationRunning","updates","propName","updateProps","requestAnimationFrame","_frameTimestamp","assign","style","getStyleWithoutAnimations","diff","styleDiff","jestStyleUpdater","animatedStyle","adapters","length","updatePropsJestWrapper","checkSharedValueUsage","currentKey","element","Error","useAnimatedStyle","dependencies","viewsRef","makeViewsRefSet","initRef","useRef","inputs","values","_closure","adaptersArray","adaptersHash","buildWorkletsHash","useSharedValue","__workletHash","push","initialStyle","initialUpdaterRun","validateAnimatedStyles","initial","remoteState","makeRemote","makeViewDescriptorsSet","sharableViewDescriptors","NativeReanimatedModule","native","useEffect","fun","updaterFn","adapter","isJest","mapperId","startMapper","stopMapper","process","env","JEST_WORKER_ID"],"sources":["useAnimatedStyle.ts"],"sourcesContent":["/* global _frameTimestamp */\nimport { MutableRefObject, useEffect, useRef } from 'react';\n\nimport { startMapper, stopMapper, makeRemote, getTimestamp } from '../core';\nimport updateProps, { updatePropsJestWrapper } from '../UpdateProps';\nimport { initialUpdaterRun } from '../animation';\nimport NativeReanimatedModule from '../NativeReanimated';\nimport { useSharedValue } from './useSharedValue';\nimport {\n buildWorkletsHash,\n getStyleWithoutAnimations,\n isAnimated,\n styleDiff,\n validateAnimatedStyles,\n} from './utils';\nimport { DependencyList, Descriptor } from './commonTypes';\nimport {\n makeViewDescriptorsSet,\n makeViewsRefSet,\n ViewDescriptorsSet,\n ViewRefSet,\n} from '../ViewDescriptorsSet';\nimport { isJest } from '../PlatformChecker';\nimport {\n AnimationObject,\n Timestamp,\n AdapterWorkletFunction,\n AnimatedStyle,\n BasicWorkletFunction,\n BasicWorkletFunctionOptional,\n NestedObjectValues,\n SharedValue,\n} from '../commonTypes';\nexport interface AnimatedStyleResult {\n viewDescriptors: ViewDescriptorsSet;\n initial: AnimatedStyle;\n viewsRef: ViewRefSet<any>;\n animatedStyle?: MutableRefObject<AnimatedStyle>;\n}\n\ninterface AnimatedState {\n last: AnimatedStyle;\n animations: AnimatedStyle;\n isAnimationRunning: boolean;\n isAnimationCancelled: boolean;\n}\n\ninterface AnimationRef {\n initial: {\n value: AnimatedStyle;\n updater: () => AnimatedStyle;\n };\n remoteState: AnimatedState;\n viewDescriptors: ViewDescriptorsSet;\n}\n\nfunction prepareAnimation(\n animatedProp: AnimatedStyle,\n lastAnimation: AnimatedStyle,\n lastValue: AnimatedStyle\n): void {\n 'worklet';\n if (Array.isArray(animatedProp)) {\n animatedProp.forEach((prop, index) => {\n prepareAnimation(\n prop,\n lastAnimation && lastAnimation[index],\n lastValue && lastValue[index]\n );\n });\n // return animatedProp;\n }\n if (typeof animatedProp === 'object' && animatedProp.onFrame) {\n const animation = animatedProp;\n\n let value = animation.current;\n if (lastValue !== undefined) {\n if (typeof lastValue === 'object') {\n if (lastValue.value !== undefined) {\n // previously it was a shared value\n value = lastValue.value;\n } else if (lastValue.onFrame !== undefined) {\n if (lastAnimation?.current !== undefined) {\n // it was an animation before, copy its state\n value = lastAnimation.current;\n } else if (lastValue?.current !== undefined) {\n // it was initialized\n value = lastValue.current;\n }\n }\n } else {\n // previously it was a plain value, just set it as starting point\n value = lastValue;\n }\n }\n\n animation.callStart = (timestamp: Timestamp) => {\n animation.onStart(animation, value, timestamp, lastAnimation);\n };\n animation.callStart(getTimestamp());\n animation.callStart = null;\n } else if (typeof animatedProp === 'object') {\n // it is an object\n Object.keys(animatedProp).forEach((key) =>\n prepareAnimation(\n animatedProp[key],\n lastAnimation && lastAnimation[key],\n lastValue && lastValue[key]\n )\n );\n }\n}\n\nfunction runAnimations(\n animation: AnimatedStyle,\n timestamp: Timestamp,\n key: number | string,\n result: AnimatedStyle,\n animationsActive: SharedValue<boolean>\n): boolean {\n 'worklet';\n if (!animationsActive.value) {\n return true;\n }\n if (Array.isArray(animation)) {\n result[key] = [];\n let allFinished = true;\n animation.forEach((entry, index) => {\n if (\n !runAnimations(entry, timestamp, index, result[key], animationsActive)\n ) {\n allFinished = false;\n }\n });\n return allFinished;\n } else if (typeof animation === 'object' && animation.onFrame) {\n let finished = true;\n if (!animation.finished) {\n if (animation.callStart) {\n animation.callStart(timestamp);\n animation.callStart = null;\n }\n finished = animation.onFrame(animation, timestamp);\n animation.timestamp = timestamp;\n if (finished) {\n animation.finished = true;\n animation.callback && animation.callback(true /* finished */);\n }\n }\n result[key] = animation.current;\n return finished;\n } else if (typeof animation === 'object') {\n result[key] = {};\n let allFinished = true;\n Object.keys(animation).forEach((k) => {\n if (\n !runAnimations(\n animation[k],\n timestamp,\n k,\n result[key],\n animationsActive\n )\n ) {\n allFinished = false;\n }\n });\n return allFinished;\n } else {\n result[key] = animation;\n return true;\n }\n}\n\nfunction styleUpdater(\n viewDescriptors: SharedValue<Descriptor[]>,\n updater: BasicWorkletFunction<AnimatedStyle>,\n state: AnimatedState,\n maybeViewRef: ViewRefSet<any> | undefined,\n animationsActive: SharedValue<boolean>\n): void {\n 'worklet';\n const animations = state.animations ?? {};\n const newValues = updater() ?? {};\n const oldValues = state.last;\n\n let hasAnimations = false;\n for (const key in newValues) {\n const value = newValues[key];\n if (isAnimated(value)) {\n prepareAnimation(value, animations[key], oldValues[key]);\n animations[key] = value;\n hasAnimations = true;\n } else {\n delete animations[key];\n }\n }\n\n if (hasAnimations) {\n const frame = (_timestamp?: Timestamp) => {\n const { animations, last, isAnimationCancelled } = state;\n const timestamp = _timestamp ?? getTimestamp();\n if (isAnimationCancelled) {\n state.isAnimationRunning = false;\n return;\n }\n\n const updates: AnimatedStyle = {};\n let allFinished = true;\n for (const propName in animations) {\n const finished = runAnimations(\n animations[propName],\n timestamp,\n propName,\n updates,\n animationsActive\n );\n if (finished) {\n last[propName] = updates[propName];\n delete animations[propName];\n } else {\n allFinished = false;\n }\n }\n\n if (updates) {\n updateProps(viewDescriptors, updates, maybeViewRef);\n }\n\n if (!allFinished) {\n requestAnimationFrame(frame);\n } else {\n state.isAnimationRunning = false;\n }\n };\n\n state.animations = animations;\n if (!state.isAnimationRunning) {\n state.isAnimationCancelled = false;\n state.isAnimationRunning = true;\n if (_frameTimestamp) {\n frame(_frameTimestamp);\n } else {\n requestAnimationFrame(frame);\n }\n }\n state.last = Object.assign({}, oldValues, newValues);\n const style = getStyleWithoutAnimations(state.last);\n if (style) {\n updateProps(viewDescriptors, style, maybeViewRef);\n }\n } else {\n state.isAnimationCancelled = true;\n state.animations = [];\n\n const diff = styleDiff(oldValues, newValues);\n state.last = Object.assign({}, oldValues, newValues);\n if (diff) {\n updateProps(viewDescriptors, newValues, maybeViewRef);\n }\n }\n}\n\nfunction jestStyleUpdater(\n viewDescriptors: SharedValue<Descriptor[]>,\n updater: BasicWorkletFunction<AnimatedStyle>,\n state: AnimatedState,\n maybeViewRef: ViewRefSet<any> | undefined,\n animationsActive: SharedValue<boolean>,\n animatedStyle: MutableRefObject<AnimatedStyle>,\n adapters: AdapterWorkletFunction[] = []\n): void {\n 'worklet';\n const animations: AnimatedStyle = state.animations ?? {};\n const newValues = updater() ?? {};\n const oldValues = state.last;\n\n // extract animated props\n let hasAnimations = false;\n Object.keys(animations).forEach((key) => {\n const value = newValues[key];\n if (!isAnimated(value)) {\n delete animations[key];\n }\n });\n Object.keys(newValues).forEach((key) => {\n const value = newValues[key];\n if (isAnimated(value)) {\n prepareAnimation(value, animations[key], oldValues[key]);\n animations[key] = value;\n hasAnimations = true;\n }\n });\n\n function frame(_timestamp?: Timestamp) {\n const { animations, last, isAnimationCancelled } = state;\n const timestamp = _timestamp ?? getTimestamp();\n if (isAnimationCancelled) {\n state.isAnimationRunning = false;\n return;\n }\n\n const updates: AnimatedStyle = {};\n let allFinished = true;\n Object.keys(animations).forEach((propName) => {\n const finished = runAnimations(\n animations[propName],\n timestamp,\n propName,\n updates,\n animationsActive\n );\n if (finished) {\n last[propName] = updates[propName];\n delete animations[propName];\n } else {\n allFinished = false;\n }\n });\n\n if (Object.keys(updates).length) {\n updatePropsJestWrapper(\n viewDescriptors,\n updates,\n maybeViewRef,\n animatedStyle,\n adapters\n );\n }\n\n if (!allFinished) {\n requestAnimationFrame(frame);\n } else {\n state.isAnimationRunning = false;\n }\n }\n\n if (hasAnimations) {\n state.animations = animations;\n if (!state.isAnimationRunning) {\n state.isAnimationCancelled = false;\n state.isAnimationRunning = true;\n if (_frameTimestamp) {\n frame(_frameTimestamp);\n } else {\n requestAnimationFrame(frame);\n }\n }\n } else {\n state.isAnimationCancelled = true;\n state.animations = [];\n }\n\n // calculate diff\n const diff = styleDiff(oldValues, newValues);\n state.last = Object.assign({}, oldValues, newValues);\n\n if (Object.keys(diff).length !== 0) {\n updatePropsJestWrapper(\n viewDescriptors,\n diff,\n maybeViewRef,\n animatedStyle,\n adapters\n );\n }\n}\n\n// check for invalid usage of shared values in returned object\nfunction checkSharedValueUsage(\n prop: NestedObjectValues<AnimationObject>,\n currentKey?: string\n): void {\n if (Array.isArray(prop)) {\n // if it's an array (i.ex. transform) validate all its elements\n for (const element of prop) {\n checkSharedValueUsage(element, currentKey);\n }\n } else if (typeof prop === 'object' && prop.value === undefined) {\n // if it's a nested object, run validation for all its props\n for (const key of Object.keys(prop)) {\n checkSharedValueUsage(prop[key], key);\n }\n } else if (\n currentKey !== undefined &&\n typeof prop === 'object' &&\n prop.value !== undefined\n ) {\n // if shared value is passed insted of its value, throw an error\n throw new Error(\n `invalid value passed to \\`${currentKey}\\`, maybe you forgot to use \\`.value\\`?`\n );\n }\n}\n\nexport function useAnimatedStyle<T extends AnimatedStyle>(\n updater: BasicWorkletFunction<T>,\n dependencies?: DependencyList,\n adapters?: AdapterWorkletFunction | AdapterWorkletFunction[]\n): AnimatedStyleResult {\n const viewsRef: ViewRefSet<any> = makeViewsRefSet();\n const initRef = useRef<AnimationRef>();\n const inputs = Object.values(updater._closure ?? {});\n const adaptersArray: AdapterWorkletFunction[] = adapters\n ? Array.isArray(adapters)\n ? adapters\n : [adapters]\n : [];\n const adaptersHash = adapters ? buildWorkletsHash(adaptersArray) : null;\n const animationsActive = useSharedValue<boolean>(true);\n const animatedStyle: MutableRefObject<AnimatedStyle> = useRef<AnimatedStyle>(\n {}\n );\n\n // build dependencies\n if (!dependencies) {\n dependencies = [...inputs, updater.__workletHash];\n } else {\n dependencies.push(updater.__workletHash);\n }\n adaptersHash && dependencies.push(adaptersHash);\n\n if (!initRef.current) {\n const initialStyle: AnimatedStyle = initialUpdaterRun(updater);\n validateAnimatedStyles(initialStyle);\n initRef.current = {\n initial: {\n value: initialStyle,\n updater: updater,\n },\n remoteState: makeRemote<AnimatedState>({\n last: initialStyle,\n animations: {},\n isAnimationCancelled: false,\n isAnimationRunning: false,\n }),\n viewDescriptors: makeViewDescriptorsSet(),\n };\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const { initial, remoteState, viewDescriptors } = initRef.current!;\n const sharableViewDescriptors = viewDescriptors.sharableViewDescriptors;\n const maybeViewRef = NativeReanimatedModule.native ? undefined : viewsRef;\n\n dependencies.push(sharableViewDescriptors);\n\n useEffect(() => {\n let fun;\n let updaterFn = updater as BasicWorkletFunctionOptional<T>;\n if (adapters) {\n updaterFn = () => {\n 'worklet';\n const newValues = updater();\n adaptersArray.forEach((adapter) => {\n adapter(newValues);\n });\n return newValues;\n };\n }\n\n if (isJest()) {\n fun = () => {\n 'worklet';\n jestStyleUpdater(\n sharableViewDescriptors,\n updater,\n remoteState,\n maybeViewRef,\n animationsActive,\n animatedStyle,\n adaptersArray\n );\n };\n } else {\n fun = () => {\n 'worklet';\n styleUpdater(\n sharableViewDescriptors,\n updaterFn,\n remoteState,\n maybeViewRef,\n animationsActive\n );\n };\n }\n const mapperId = startMapper(fun, inputs);\n return () => {\n stopMapper(mapperId);\n };\n }, dependencies);\n\n useEffect(() => {\n animationsActive.value = true;\n return () => {\n // initRef.current = null;\n // viewsRef = null;\n animationsActive.value = false;\n };\n }, []);\n\n checkSharedValueUsage(initial.value);\n\n if (process.env.JEST_WORKER_ID) {\n return { viewDescriptors, initial: initial, viewsRef, animatedStyle };\n } else {\n return { viewDescriptors, initial: initial, viewsRef };\n }\n}\n"],"mappings":";;;;;;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAQA;;AAMA;;;;;;;;AAtBA;AAwDA,SAASA,gBAAT,CACEC,YADF,EAEEC,aAFF,EAGEC,SAHF,EAIQ;EACN;;EACA,IAAIC,KAAK,CAACC,OAAN,CAAcJ,YAAd,CAAJ,EAAiC;IAC/BA,YAAY,CAACK,OAAb,CAAqB,CAACC,IAAD,EAAOC,KAAP,KAAiB;MACpCR,gBAAgB,CACdO,IADc,EAEdL,aAAa,IAAIA,aAAa,CAACM,KAAD,CAFhB,EAGdL,SAAS,IAAIA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,GAAJ,EAAc;MACZH,GAAG,GAAG,MAAM;QACV;;QACAnC,gBAAgB,CACd+B,uBADc,EAEdtD,OAFc,EAGdmD,WAHc,EAIdjD,YAJc,EAKdV,gBALc,EAMdgC,aANc,EAOdiB,aAPc,CAAhB;MASD,CAXD;IAYD,CAbD,MAaO;MACLiB,GAAG,GAAG,MAAM;QACV;;QACA5D,YAAY,CACVwD,uBADU,EAEVK,SAFU,EAGVR,WAHU,EAIVjD,YAJU,EAKVV,gBALU,CAAZ;MAOD,CATD;IAUD;;IACD,MAAMsE,QAAQ,GAAG,IAAAC,iBAAA,EAAYL,GAAZ,EAAiBpB,MAAjB,CAAjB;IACA,OAAO,MAAM;MACX,IAAA0B,gBAAA,EAAWF,QAAX;IACD,CAFD;EAGD,CA3CD,EA2CG7B,YA3CH;EA6CA,IAAAwB,gBAAA,EAAU,MAAM;IACdjE,gBAAgB,CAACZ,KAAjB,GAAyB,IAAzB;IACA,OAAO,MAAM;MACX;MACA;MACAY,gBAAgB,CAACZ,KAAjB,GAAyB,KAAzB;IACD,CAJD;EAKD,CAPD,EAOG,EAPH;EASAgD,qBAAqB,CAACsB,OAAO,CAACtE,KAAT,CAArB;;EAEA,IAAIqF,OAAO,CAACC,GAAR,CAAYC,cAAhB,EAAgC;IAC9B,OAAO;MAAEpE,eAAF;MAAmBmD,OAAO,EAAEA,OAA5B;MAAqChB,QAArC;MAA+CV;IAA/C,CAAP;EACD,CAFD,MAEO;IACL,OAAO;MAAEzB,eAAF;MAAmBmD,OAAO,EAAEA,OAA5B;MAAqChB;IAArC,CAAP;EACD;AACF"}
|
|
1
|
+
{"version":3,"names":["prepareAnimation","frameTimestamp","animatedProp","lastAnimation","lastValue","Array","isArray","forEach","prop","index","onFrame","animation","value","current","undefined","callStart","timestamp","onStart","Object","keys","key","runAnimations","result","animationsActive","allFinished","entry","finished","callback","k","styleUpdater","viewDescriptors","updater","state","maybeViewRef","animations","newValues","oldValues","last","nonAnimatedNewValues","hasAnimations","hasNonAnimatedValues","isAnimated","global","__frameTimestamp","performance","now","frame","isAnimationCancelled","isAnimationRunning","updates","propName","updateProps","requestAnimationFrame","shallowEqual","jestStyleUpdater","animatedStyle","adapters","length","updatePropsJestWrapper","checkSharedValueUsage","currentKey","element","Error","useAnimatedStyle","dependencies","viewsRef","makeViewsRefSet","initRef","useRef","inputs","values","_closure","shouldBeUseWeb","__DEV__","__workletHash","adaptersArray","adaptersHash","buildWorkletsHash","useSharedValue","push","initialStyle","initialUpdaterRun","validateAnimatedStyles","initial","remoteState","makeRemote","makeViewDescriptorsSet","sharableViewDescriptors","NativeReanimatedModule","native","useEffect","fun","updaterFn","adapter","isJest","mapperId","startMapper","stopMapper","process","env","JEST_WORKER_ID"],"sources":["useAnimatedStyle.ts"],"sourcesContent":["import { MutableRefObject, useEffect, useRef } from 'react';\n\nimport { startMapper, stopMapper, makeRemote } from '../core';\nimport updateProps, { updatePropsJestWrapper } from '../UpdateProps';\nimport { initialUpdaterRun } from '../animation';\nimport NativeReanimatedModule from '../NativeReanimated';\nimport { useSharedValue } from './useSharedValue';\nimport {\n buildWorkletsHash,\n isAnimated,\n shallowEqual,\n validateAnimatedStyles,\n} from './utils';\nimport { DependencyList, Descriptor } from './commonTypes';\nimport {\n makeViewDescriptorsSet,\n makeViewsRefSet,\n ViewDescriptorsSet,\n ViewRefSet,\n} from '../ViewDescriptorsSet';\nimport { isJest, shouldBeUseWeb } from '../PlatformChecker';\nimport {\n AnimationObject,\n Timestamp,\n AdapterWorkletFunction,\n AnimatedStyle,\n BasicWorkletFunction,\n BasicWorkletFunctionOptional,\n NestedObjectValues,\n SharedValue,\n StyleProps,\n} from '../commonTypes';\nexport interface AnimatedStyleResult {\n viewDescriptors: ViewDescriptorsSet;\n initial: AnimatedStyle;\n viewsRef: ViewRefSet<any>;\n animatedStyle?: MutableRefObject<AnimatedStyle>;\n}\n\ninterface AnimatedState {\n last: AnimatedStyle;\n animations: AnimatedStyle;\n isAnimationRunning: boolean;\n isAnimationCancelled: boolean;\n}\n\ninterface AnimationRef {\n initial: {\n value: AnimatedStyle;\n updater: () => AnimatedStyle;\n };\n remoteState: AnimatedState;\n viewDescriptors: ViewDescriptorsSet;\n}\n\nfunction prepareAnimation(\n frameTimestamp: number,\n animatedProp: AnimatedStyle,\n lastAnimation: AnimatedStyle,\n lastValue: AnimatedStyle\n): void {\n 'worklet';\n if (Array.isArray(animatedProp)) {\n animatedProp.forEach((prop, index) => {\n prepareAnimation(\n frameTimestamp,\n prop,\n lastAnimation && lastAnimation[index],\n lastValue && lastValue[index]\n );\n });\n // return animatedProp;\n }\n if (typeof animatedProp === 'object' && animatedProp.onFrame) {\n const animation = animatedProp;\n\n let value = animation.current;\n if (lastValue !== undefined) {\n if (typeof lastValue === 'object') {\n if (lastValue.value !== undefined) {\n // previously it was a shared value\n value = lastValue.value;\n } else if (lastValue.onFrame !== undefined) {\n if (lastAnimation?.current !== undefined) {\n // it was an animation before, copy its state\n value = lastAnimation.current;\n } else if (lastValue?.current !== undefined) {\n // it was initialized\n value = lastValue.current;\n }\n }\n } else {\n // previously it was a plain value, just set it as starting point\n value = lastValue;\n }\n }\n\n animation.callStart = (timestamp: Timestamp) => {\n animation.onStart(animation, value, timestamp, lastAnimation);\n };\n animation.callStart(frameTimestamp);\n animation.callStart = null;\n } else if (typeof animatedProp === 'object') {\n // it is an object\n Object.keys(animatedProp).forEach((key) =>\n prepareAnimation(\n frameTimestamp,\n animatedProp[key],\n lastAnimation && lastAnimation[key],\n lastValue && lastValue[key]\n )\n );\n }\n}\n\nfunction runAnimations(\n animation: AnimatedStyle,\n timestamp: Timestamp,\n key: number | string,\n result: AnimatedStyle,\n animationsActive: SharedValue<boolean>\n): boolean {\n 'worklet';\n if (!animationsActive.value) {\n return true;\n }\n if (Array.isArray(animation)) {\n result[key] = [];\n let allFinished = true;\n animation.forEach((entry, index) => {\n if (\n !runAnimations(entry, timestamp, index, result[key], animationsActive)\n ) {\n allFinished = false;\n }\n });\n return allFinished;\n } else if (typeof animation === 'object' && animation.onFrame) {\n let finished = true;\n if (!animation.finished) {\n if (animation.callStart) {\n animation.callStart(timestamp);\n animation.callStart = null;\n }\n finished = animation.onFrame(animation, timestamp);\n animation.timestamp = timestamp;\n if (finished) {\n animation.finished = true;\n animation.callback && animation.callback(true /* finished */);\n }\n }\n result[key] = animation.current;\n return finished;\n } else if (typeof animation === 'object') {\n result[key] = {};\n let allFinished = true;\n Object.keys(animation).forEach((k) => {\n if (\n !runAnimations(\n animation[k],\n timestamp,\n k,\n result[key],\n animationsActive\n )\n ) {\n allFinished = false;\n }\n });\n return allFinished;\n } else {\n result[key] = animation;\n return true;\n }\n}\n\nfunction styleUpdater(\n viewDescriptors: SharedValue<Descriptor[]>,\n updater: BasicWorkletFunction<AnimatedStyle>,\n state: AnimatedState,\n maybeViewRef: ViewRefSet<any> | undefined,\n animationsActive: SharedValue<boolean>\n): void {\n 'worklet';\n const animations = state.animations ?? {};\n const newValues = updater() ?? {};\n const oldValues = state.last;\n const nonAnimatedNewValues: StyleProps = {};\n\n let hasAnimations = false;\n let frameTimestamp: number | undefined;\n let hasNonAnimatedValues = false;\n for (const key in newValues) {\n const value = newValues[key];\n if (isAnimated(value)) {\n frameTimestamp = global.__frameTimestamp || performance.now();\n prepareAnimation(frameTimestamp, value, animations[key], oldValues[key]);\n animations[key] = value;\n hasAnimations = true;\n } else {\n hasNonAnimatedValues = true;\n nonAnimatedNewValues[key] = value;\n delete animations[key];\n }\n }\n\n if (hasAnimations) {\n const frame = (timestamp: Timestamp) => {\n const { animations, last, isAnimationCancelled } = state;\n if (isAnimationCancelled) {\n state.isAnimationRunning = false;\n return;\n }\n\n const updates: AnimatedStyle = {};\n let allFinished = true;\n for (const propName in animations) {\n const finished = runAnimations(\n animations[propName],\n timestamp,\n propName,\n updates,\n animationsActive\n );\n if (finished) {\n last[propName] = updates[propName];\n delete animations[propName];\n } else {\n allFinished = false;\n }\n }\n\n if (updates) {\n updateProps(viewDescriptors, updates, maybeViewRef);\n }\n\n if (!allFinished) {\n requestAnimationFrame(frame);\n } else {\n state.isAnimationRunning = false;\n }\n };\n\n state.animations = animations;\n if (!state.isAnimationRunning) {\n state.isAnimationCancelled = false;\n state.isAnimationRunning = true;\n frame(frameTimestamp!);\n }\n\n if (hasNonAnimatedValues) {\n updateProps(viewDescriptors, nonAnimatedNewValues, maybeViewRef);\n }\n } else {\n state.isAnimationCancelled = true;\n state.animations = [];\n\n if (!shallowEqual(oldValues, newValues)) {\n updateProps(viewDescriptors, newValues, maybeViewRef);\n }\n }\n state.last = newValues;\n}\n\nfunction jestStyleUpdater(\n viewDescriptors: SharedValue<Descriptor[]>,\n updater: BasicWorkletFunction<AnimatedStyle>,\n state: AnimatedState,\n maybeViewRef: ViewRefSet<any> | undefined,\n animationsActive: SharedValue<boolean>,\n animatedStyle: MutableRefObject<AnimatedStyle>,\n adapters: AdapterWorkletFunction[] = []\n): void {\n 'worklet';\n const animations: AnimatedStyle = state.animations ?? {};\n const newValues = updater() ?? {};\n const oldValues = state.last;\n\n // extract animated props\n let hasAnimations = false;\n let frameTimestamp: number | undefined;\n Object.keys(animations).forEach((key) => {\n const value = newValues[key];\n if (!isAnimated(value)) {\n delete animations[key];\n }\n });\n Object.keys(newValues).forEach((key) => {\n const value = newValues[key];\n if (isAnimated(value)) {\n frameTimestamp = global.__frameTimestamp || performance.now();\n prepareAnimation(frameTimestamp, value, animations[key], oldValues[key]);\n animations[key] = value;\n hasAnimations = true;\n }\n });\n\n function frame(timestamp: Timestamp) {\n const { animations, last, isAnimationCancelled } = state;\n if (isAnimationCancelled) {\n state.isAnimationRunning = false;\n return;\n }\n\n const updates: AnimatedStyle = {};\n let allFinished = true;\n Object.keys(animations).forEach((propName) => {\n const finished = runAnimations(\n animations[propName],\n timestamp,\n propName,\n updates,\n animationsActive\n );\n if (finished) {\n last[propName] = updates[propName];\n delete animations[propName];\n } else {\n allFinished = false;\n }\n });\n\n if (Object.keys(updates).length) {\n updatePropsJestWrapper(\n viewDescriptors,\n updates,\n maybeViewRef,\n animatedStyle,\n adapters\n );\n }\n\n if (!allFinished) {\n requestAnimationFrame(frame);\n } else {\n state.isAnimationRunning = false;\n }\n }\n\n if (hasAnimations) {\n state.animations = animations;\n if (!state.isAnimationRunning) {\n state.isAnimationCancelled = false;\n state.isAnimationRunning = true;\n frame(frameTimestamp!);\n }\n } else {\n state.isAnimationCancelled = true;\n state.animations = [];\n }\n\n // calculate diff\n state.last = newValues;\n\n if (!shallowEqual(oldValues, newValues)) {\n updatePropsJestWrapper(\n viewDescriptors,\n newValues,\n maybeViewRef,\n animatedStyle,\n adapters\n );\n }\n}\n\n// check for invalid usage of shared values in returned object\nfunction checkSharedValueUsage(\n prop: NestedObjectValues<AnimationObject>,\n currentKey?: string\n): void {\n if (Array.isArray(prop)) {\n // if it's an array (i.ex. transform) validate all its elements\n for (const element of prop) {\n checkSharedValueUsage(element, currentKey);\n }\n } else if (typeof prop === 'object' && prop.value === undefined) {\n // if it's a nested object, run validation for all its props\n for (const key of Object.keys(prop)) {\n checkSharedValueUsage(prop[key], key);\n }\n } else if (\n currentKey !== undefined &&\n typeof prop === 'object' &&\n prop.value !== undefined\n ) {\n // if shared value is passed insted of its value, throw an error\n throw new Error(\n `invalid value passed to \\`${currentKey}\\`, maybe you forgot to use \\`.value\\`?`\n );\n }\n}\n\nexport function useAnimatedStyle<T extends AnimatedStyle>(\n updater: BasicWorkletFunction<T>,\n dependencies?: DependencyList,\n adapters?: AdapterWorkletFunction | AdapterWorkletFunction[]\n): AnimatedStyleResult {\n const viewsRef: ViewRefSet<any> = makeViewsRefSet();\n const initRef = useRef<AnimationRef>();\n let inputs = Object.values(updater._closure ?? {});\n if (shouldBeUseWeb()) {\n if (!inputs.length && dependencies?.length) {\n // let web work without a Babel/SWC plugin\n inputs = dependencies;\n }\n if (__DEV__ && !inputs.length && !dependencies && !updater.__workletHash) {\n throw new Error(\n `useAnimatedStyle was used without a dependency array or Babel plugin. Please explicitly pass a dependency array, or enable the Babel/SWC plugin.\n\nFor more, see the docs: https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/web-support#web-without-a-babel-plugin`\n );\n }\n }\n const adaptersArray: AdapterWorkletFunction[] = adapters\n ? Array.isArray(adapters)\n ? adapters\n : [adapters]\n : [];\n const adaptersHash = adapters ? buildWorkletsHash(adaptersArray) : null;\n const animationsActive = useSharedValue<boolean>(true);\n const animatedStyle: MutableRefObject<AnimatedStyle> = useRef<AnimatedStyle>(\n {}\n );\n\n // build dependencies\n if (!dependencies) {\n dependencies = [...inputs, updater.__workletHash];\n } else {\n dependencies.push(updater.__workletHash);\n }\n adaptersHash && dependencies.push(adaptersHash);\n\n if (!initRef.current) {\n const initialStyle: AnimatedStyle = initialUpdaterRun(updater);\n validateAnimatedStyles(initialStyle);\n initRef.current = {\n initial: {\n value: initialStyle,\n updater: updater,\n },\n remoteState: makeRemote<AnimatedState>({\n last: initialStyle,\n animations: {},\n isAnimationCancelled: false,\n isAnimationRunning: false,\n }),\n viewDescriptors: makeViewDescriptorsSet(),\n };\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const { initial, remoteState, viewDescriptors } = initRef.current!;\n const sharableViewDescriptors = viewDescriptors.sharableViewDescriptors;\n const maybeViewRef = NativeReanimatedModule.native ? undefined : viewsRef;\n\n dependencies.push(sharableViewDescriptors);\n\n useEffect(() => {\n let fun;\n let updaterFn = updater as BasicWorkletFunctionOptional<T>;\n if (adapters) {\n updaterFn = () => {\n 'worklet';\n const newValues = updater();\n adaptersArray.forEach((adapter) => {\n adapter(newValues);\n });\n return newValues;\n };\n }\n\n if (isJest()) {\n fun = () => {\n 'worklet';\n jestStyleUpdater(\n sharableViewDescriptors,\n updater,\n remoteState,\n maybeViewRef,\n animationsActive,\n animatedStyle,\n adaptersArray\n );\n };\n } else {\n fun = () => {\n 'worklet';\n styleUpdater(\n sharableViewDescriptors,\n updaterFn,\n remoteState,\n maybeViewRef,\n animationsActive\n );\n };\n }\n const mapperId = startMapper(fun, inputs);\n return () => {\n stopMapper(mapperId);\n };\n }, dependencies);\n\n useEffect(() => {\n animationsActive.value = true;\n return () => {\n animationsActive.value = false;\n };\n }, []);\n\n checkSharedValueUsage(initial.value);\n\n if (process.env.JEST_WORKER_ID) {\n return { viewDescriptors, initial: initial, viewsRef, animatedStyle };\n } else {\n return { viewDescriptors, initial: initial, viewsRef };\n }\n}\n"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAOA;;AAMA;;;;;;;;AAmCA,SAASA,gBAAT,CACEC,cADF,EAEEC,YAFF,EAGEC,aAHF,EAIEC,SAJF,EAKQ;EACN;;EACA,IAAIC,KAAK,CAACC,OAAN,CAAcJ,YAAd,CAAJ,EAAiC;IAC/BA,YAAY,CAACK,OAAb,CAAqB,CAACC,IAAD,EAAOC,KAAP,KAAiB;MACpCT,gBAAgB,CACdC,cADc,EAEdO,IAFc,EAGdL,aAAa,IAAIA,aAAa,CAACM,KAAD,CAHhB,EAIdL,SAAS,IAAIA,SAAS,CAACK,KAAD,CAJR,CAAhB;IAMD,CAPD,EAD+B,CAS/B;EACD;;EACD,IAAI,OAAOP,YAAP,KAAwB,QAAxB,IAAoCA,YAAY,CAACQ,OAArD,EAA8D;IAC5D,MAAMC,SAAS,GAAGT,YAAlB;IAEA,IAAIU,KAAK,GAAGD,SAAS,CAACE,OAAtB;;IACA,IAAIT,SAAS,KAAKU,SAAlB,EAA6B;MAC3B,IAAI,OAAOV,SAAP,KAAqB,QAAzB,EAAmC;QACjC,IAAIA,SAAS,CAACQ,KAAV,KAAoBE,SAAxB,EAAmC;UACjC;UACAF,KAAK,GAAGR,SAAS,CAACQ,KAAlB;QACD,CAHD,MAGO,IAAIR,SAAS,CAACM,OAAV,KAAsBI,SAA1B,EAAqC;UAC1C,IAAI,CAAAX,aAAa,SAAb,IAAAA,aAAa,WAAb,YAAAA,aAAa,CAAEU,OAAf,MAA2BC,SAA/B,EAA0C;YACxC;YACAF,KAAK,GAAGT,aAAa,CA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AAyB,IAAzB;IACA,OAAO,MAAM;MACXW,gBAAgB,CAACX,KAAjB,GAAyB,KAAzB;IACD,CAFD;EAGD,CALD,EAKG,EALH;EAOA+C,qBAAqB,CAACwB,OAAO,CAACvE,KAAT,CAArB;;EAEA,IAAIsF,OAAO,CAACC,GAAR,CAAYC,cAAhB,EAAgC;IAC9B,OAAO;MAAEtE,eAAF;MAAmBqD,OAAO,EAAEA,OAA5B;MAAqClB,QAArC;MAA+CV;IAA/C,CAAP;EACD,CAFD,MAEO;IACL,OAAO;MAAEzB,eAAF;MAAmBqD,OAAO,EAAEA,OAA5B;MAAqClB;IAArC,CAAP;EACD;AACF"}
|
|
@@ -11,9 +11,21 @@ var _animation = require("../animation");
|
|
|
11
11
|
|
|
12
12
|
var _core = require("../core");
|
|
13
13
|
|
|
14
|
+
var _PlatformChecker = require("../PlatformChecker");
|
|
15
|
+
|
|
14
16
|
function useDerivedValue(processor, dependencies) {
|
|
15
17
|
const initRef = (0, _react.useRef)(null);
|
|
16
|
-
|
|
18
|
+
let inputs = Object.values(processor._closure ?? {});
|
|
19
|
+
|
|
20
|
+
if ((0, _PlatformChecker.shouldBeUseWeb)()) {
|
|
21
|
+
var _dependencies;
|
|
22
|
+
|
|
23
|
+
if (!inputs.length && (_dependencies = dependencies) !== null && _dependencies !== void 0 && _dependencies.length) {
|
|
24
|
+
// let web work without a Babel/SWC plugin
|
|
25
|
+
inputs = dependencies;
|
|
26
|
+
}
|
|
27
|
+
} // build dependencies
|
|
28
|
+
|
|
17
29
|
|
|
18
30
|
if (dependencies === undefined) {
|
|
19
31
|
dependencies = [...inputs, processor.__workletHash];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useDerivedValue","processor","dependencies","initRef","useRef","inputs","Object","values","_closure","undefined","__workletHash","push","current","makeMutable","initialUpdaterRun","sharedValue","useEffect","fun","value","mapperId","startMapper","stopMapper"],"sources":["useDerivedValue.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { initialUpdaterRun } from '../animation';\nimport { BasicWorkletFunction, SharedValue } from '../commonTypes';\nimport { makeMutable, startMapper, stopMapper } from '../core';\nimport { DependencyList } from './commonTypes';\n\nexport type DerivedValue<T> = Readonly<SharedValue<T>>;\n\nexport function useDerivedValue<T>(\n processor: BasicWorkletFunction<T>,\n dependencies: DependencyList\n): DerivedValue<T> {\n const initRef = useRef<SharedValue<T> | null>(null);\n
|
|
1
|
+
{"version":3,"names":["useDerivedValue","processor","dependencies","initRef","useRef","inputs","Object","values","_closure","shouldBeUseWeb","length","undefined","__workletHash","push","current","makeMutable","initialUpdaterRun","sharedValue","useEffect","fun","value","mapperId","startMapper","stopMapper"],"sources":["useDerivedValue.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { initialUpdaterRun } from '../animation';\nimport { BasicWorkletFunction, SharedValue } from '../commonTypes';\nimport { makeMutable, startMapper, stopMapper } from '../core';\nimport { DependencyList } from './commonTypes';\nimport { shouldBeUseWeb } from '../PlatformChecker';\n\nexport type DerivedValue<T> = Readonly<SharedValue<T>>;\n\nexport function useDerivedValue<T>(\n processor: BasicWorkletFunction<T>,\n dependencies: DependencyList\n): DerivedValue<T> {\n const initRef = useRef<SharedValue<T> | null>(null);\n let inputs = Object.values(processor._closure ?? {});\n if (shouldBeUseWeb()) {\n if (!inputs.length && dependencies?.length) {\n // let web work without a Babel/SWC plugin\n inputs = dependencies;\n }\n }\n\n // build dependencies\n if (dependencies === undefined) {\n dependencies = [...inputs, processor.__workletHash];\n } else {\n dependencies.push(processor.__workletHash);\n }\n\n if (initRef.current === null) {\n initRef.current = makeMutable(initialUpdaterRun(processor));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const sharedValue: SharedValue<T> = initRef.current!;\n\n useEffect(() => {\n const fun = () => {\n 'worklet';\n sharedValue.value = processor();\n };\n const mapperId = startMapper(fun, inputs, [sharedValue]);\n return () => {\n stopMapper(mapperId);\n };\n }, dependencies);\n\n useEffect(() => {\n return () =>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AM;IACd,OAAO,MAAM;MACXf,OAAO,CAACW,OAAR,GAAkB,IAAlB;IACD,CAFD;EAGD,CAJD,EAIG,EAJH;EAMA,OAAOG,WAAP;AACD"}
|
|
@@ -13,7 +13,7 @@ var _utils = require("./utils");
|
|
|
13
13
|
|
|
14
14
|
var _useSharedValue = require("./useSharedValue");
|
|
15
15
|
|
|
16
|
-
const
|
|
16
|
+
const scrollEventNames = ['onScroll', 'onScrollBeginDrag', 'onScrollEndDrag', 'onMomentumScrollBegin', 'onMomentumScrollEnd'];
|
|
17
17
|
|
|
18
18
|
function useScrollViewOffset(aref) {
|
|
19
19
|
const offsetRef = (0, _react.useRef)((0, _useSharedValue.useSharedValue)(0));
|
|
@@ -21,7 +21,7 @@ function useScrollViewOffset(aref) {
|
|
|
21
21
|
'worklet';
|
|
22
22
|
|
|
23
23
|
offsetRef.current.value = event.contentOffset.x === 0 ? event.contentOffset.y : event.contentOffset.x;
|
|
24
|
-
},
|
|
24
|
+
}, scrollEventNames);
|
|
25
25
|
(0, _react.useEffect)(() => {
|
|
26
26
|
var _event$current;
|
|
27
27
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["scrollEventNames","useScrollViewOffset","aref","offsetRef","useRef","useSharedValue","event","useEvent","current","value","contentOffset","x","y","useEffect","viewTag","findNodeHandle","registerForEvents"],"sources":["useScrollViewOffset.ts"],"sourcesContent":["import { RefObject, useEffect, useRef } from 'react';\n\nimport type Animated from 'react-native-reanimated';\nimport { ScrollEvent } from './useAnimatedScrollHandler';\nimport { SharedValue } from '../commonTypes';\nimport { findNodeHandle } from 'react-native';\nimport { useEvent } from './utils';\nimport { useSharedValue } from './useSharedValue';\n\nconst scrollEventNames = [\n 'onScroll',\n 'onScrollBeginDrag',\n 'onScrollEndDrag',\n 'onMomentumScrollBegin',\n 'onMomentumScrollEnd',\n];\n\nexport function useScrollViewOffset(\n aref: RefObject<Animated.ScrollView>\n): SharedValue<number> {\n const offsetRef = useRef(useSharedValue(0));\n\n const event = useEvent<ScrollEvent>((event: ScrollEvent) => {\n 'worklet';\n offsetRef.current.value =\n event.contentOffset.x === 0\n ? event.contentOffset.y\n : event.contentOffset.x;\n }, scrollEventNames);\n\n useEffect(() => {\n const viewTag = findNodeHandle(aref.current);\n event.current?.registerForEvents(viewTag as number);\n }, [aref.current]);\n\n return offsetRef.current;\n}\n"],"mappings":";;;;;;;AAAA;;AAKA;;AACA;;AACA;;AAEA,MAAMA,gBAAgB,GAAG,CACvB,UADuB,EAEvB,mBAFuB,EAGvB,iBAHuB,EAIvB,uBAJuB,EAKvB,qBALuB,CAAzB;;AAQO,SAASC,mBAAT,CACLC,IADK,EAEgB;EACrB,MAAMC,SAAS,GAAG,IAAAC,aAAA,EAAO,IAAAC,8BAAA,EAAe,CAAf,CAAP,CAAlB;EAEA,MAAMC,KAAK,GAAG,IAAAC,eAAA,EAAuBD,KAAD,IAAwB;IAC1D;;IACAH,SAAS,CAACK,OAAV,CAAkBC,KAAlB,GACEH,KAAK,CAACI,aAAN,CAAoBC,CAApB,KAA0B,CAA1B,GACIL,KAAK,CAACI,aAAN,CAAoBE,CADxB,GAEIN,KAAK,CAACI,aAAN,CAAoBC,CAH1B;EAID,CANa,EAMXX,gBANW,CAAd;EAQA,IAAAa,gBAAA,EAAU,MAAM;IAAA;;IACd,MAAMC,OAAO,GAAG,IAAAC,2BAAA,EAAeb,IAAI,CAACM,OAApB,CAAhB;IACA,kBAAAF,KAAK,CAACE,OAAN,kEAAeQ,iBAAf,CAAiCF,OAAjC;EACD,CAHD,EAGG,CAACZ,IAAI,CAACM,OAAN,CAHH;EAKA,OAAOL,SAAS,CAACK,OAAjB;AACD"}
|