react-native-reanimated 3.0.2 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Common/cpp/Fabric/FabricUtils.h +1 -1
- package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +38 -27
- package/Common/cpp/SharedItems/Shareables.h +22 -0
- package/Common/cpp/Tools/PlatformDepMethodsHolder.h +2 -0
- package/Common/cpp/Tools/RuntimeDecorator.cpp +4 -1
- package/Common/cpp/Tools/RuntimeDecorator.h +2 -1
- package/Common/cpp/Tools/SingleInstanceChecker.h +14 -2
- package/RNReanimated.podspec +5 -2
- package/android/CMakeLists.txt +4 -0
- package/android/build.gradle +18 -10
- package/android/src/main/cpp/NativeProxy.cpp +316 -337
- package/android/src/main/cpp/NativeProxy.h +53 -11
- package/android/src/main/java/com/swmansion/reanimated/NativeMethodsHelper.java +7 -12
- package/android/src/main/java/com/swmansion/reanimated/NodesManager.java +11 -8
- package/android/src/main/java/com/swmansion/reanimated/nativeProxy/NativeProxyCommon.java +21 -14
- package/android/src/paper/java/com/swmansion/reanimated/NativeProxy.java +0 -3
- package/ios/Fabric/REAInitializerRCTFabricSurface.mm +1 -0
- package/ios/REANodesManager.h +1 -0
- package/ios/REANodesManager.mm +30 -4
- package/ios/keyboardObserver/REAKeyboardEventObserver.m +51 -130
- package/ios/native/NativeMethods.mm +1 -1
- package/ios/native/NativeProxy.mm +4 -1
- package/ios/native/REAIOSErrorHandler.mm +1 -1
- package/ios/native/REAIOSLogger.mm +1 -1
- package/ios/native/REAIOSScheduler.mm +1 -1
- package/ios/native/REAInitializer.mm +1 -1
- package/ios/native/REAMessageThread.mm +2 -2
- package/lib/commonjs/Animated.js +0 -8
- package/lib/commonjs/Animated.js.map +1 -1
- package/lib/commonjs/ConfigHelper.js +8 -19
- package/lib/commonjs/ConfigHelper.js.map +1 -1
- package/lib/commonjs/createAnimatedComponent.js +20 -158
- package/lib/commonjs/createAnimatedComponent.js.map +1 -1
- package/lib/commonjs/index.js +0 -9
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/index.web.js +0 -7
- package/lib/commonjs/index.web.js.map +1 -1
- package/lib/commonjs/reanimated2/Bezier.js +14 -34
- package/lib/commonjs/reanimated2/Bezier.js.map +1 -1
- package/lib/commonjs/reanimated2/Colors.js +60 -132
- package/lib/commonjs/reanimated2/Colors.js.map +1 -1
- package/lib/commonjs/reanimated2/Easing.js +81 -34
- package/lib/commonjs/reanimated2/Easing.js.map +1 -1
- package/lib/commonjs/reanimated2/NativeMethods.js +8 -20
- package/lib/commonjs/reanimated2/NativeMethods.js.map +1 -1
- package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js +5 -31
- package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
- package/lib/commonjs/reanimated2/NativeReanimated/index.js +0 -7
- package/lib/commonjs/reanimated2/NativeReanimated/index.js.map +1 -1
- package/lib/commonjs/reanimated2/PlatformChecker.js +0 -6
- package/lib/commonjs/reanimated2/PlatformChecker.js.map +1 -1
- package/lib/commonjs/reanimated2/PropAdapters.js +10 -12
- package/lib/commonjs/reanimated2/PropAdapters.js.map +1 -1
- package/lib/commonjs/reanimated2/UpdateProps.js +3 -12
- package/lib/commonjs/reanimated2/UpdateProps.js.map +1 -1
- package/lib/commonjs/reanimated2/ViewDescriptorsSet.js +0 -10
- package/lib/commonjs/reanimated2/ViewDescriptorsSet.js.map +1 -1
- package/lib/commonjs/reanimated2/WorkletEventHandler.js +5 -22
- package/lib/commonjs/reanimated2/WorkletEventHandler.js.map +1 -1
- package/lib/commonjs/reanimated2/animation/decay.js +7 -18
- package/lib/commonjs/reanimated2/animation/decay.js.map +1 -1
- package/lib/commonjs/reanimated2/animation/delay.js +0 -11
- package/lib/commonjs/reanimated2/animation/delay.js.map +1 -1
- package/lib/commonjs/reanimated2/animation/index.js +0 -8
- package/lib/commonjs/reanimated2/animation/index.js.map +1 -1
- package/lib/commonjs/reanimated2/animation/repeat.js +6 -22
- package/lib/commonjs/reanimated2/animation/repeat.js.map +1 -1
- package/lib/commonjs/reanimated2/animation/sequence.js +3 -20
- package/lib/commonjs/reanimated2/animation/sequence.js.map +1 -1
- package/lib/commonjs/reanimated2/animation/spring.js +11 -23
- package/lib/commonjs/reanimated2/animation/spring.js.map +1 -1
- package/lib/commonjs/reanimated2/animation/styleAnimation.js +3 -35
- package/lib/commonjs/reanimated2/animation/styleAnimation.js.map +1 -1
- package/lib/commonjs/reanimated2/animation/timing.js +0 -11
- package/lib/commonjs/reanimated2/animation/timing.js.map +1 -1
- package/lib/commonjs/reanimated2/animation/util.js +11 -41
- package/lib/commonjs/reanimated2/animation/util.js.map +1 -1
- package/lib/commonjs/reanimated2/commonTypes.js +16 -23
- package/lib/commonjs/reanimated2/commonTypes.js.map +1 -1
- package/lib/commonjs/reanimated2/component/FlatList.js +0 -16
- package/lib/commonjs/reanimated2/component/FlatList.js.map +1 -1
- package/lib/commonjs/reanimated2/component/Image.js +0 -4
- package/lib/commonjs/reanimated2/component/Image.js.map +1 -1
- package/lib/commonjs/reanimated2/component/ScrollView.js +0 -4
- package/lib/commonjs/reanimated2/component/ScrollView.js.map +1 -1
- package/lib/commonjs/reanimated2/component/Text.js +0 -4
- package/lib/commonjs/reanimated2/component/Text.js.map +1 -1
- package/lib/commonjs/reanimated2/component/View.js +0 -4
- package/lib/commonjs/reanimated2/component/View.js.map +1 -1
- package/lib/commonjs/reanimated2/core.js +6 -48
- package/lib/commonjs/reanimated2/core.js.map +1 -1
- package/lib/commonjs/reanimated2/errors.js +3 -14
- package/lib/commonjs/reanimated2/errors.js.map +1 -1
- package/lib/commonjs/reanimated2/fabricUtils.js +3 -5
- package/lib/commonjs/reanimated2/fabricUtils.js.map +1 -1
- package/lib/commonjs/reanimated2/fabricUtils.web.js +1 -3
- package/lib/commonjs/reanimated2/fabricUtils.web.js.map +1 -1
- package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryJS.js +3 -12
- package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryJS.js.map +1 -1
- package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js +13 -17
- 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/Hooks.js +0 -5
- package/lib/commonjs/reanimated2/hook/Hooks.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/commonTypes.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/index.js +0 -12
- package/lib/commonjs/reanimated2/hook/index.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedGestureHandler.js +4 -17
- package/lib/commonjs/reanimated2/hook/useAnimatedGestureHandler.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js +2 -9
- package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedReaction.js +1 -11
- package/lib/commonjs/reanimated2/hook/useAnimatedReaction.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedRef.js +0 -12
- package/lib/commonjs/reanimated2/hook/useAnimatedRef.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedScrollHandler.js +2 -9
- package/lib/commonjs/reanimated2/hook/useAnimatedScrollHandler.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js +8 -23
- package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js +13 -71
- package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useDerivedValue.js +4 -13
- package/lib/commonjs/reanimated2/hook/useDerivedValue.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useFrameCallback.js +0 -5
- package/lib/commonjs/reanimated2/hook/useFrameCallback.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js +0 -7
- package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useSharedValue.js +2 -7
- package/lib/commonjs/reanimated2/hook/useSharedValue.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/utils.js +8 -39
- package/lib/commonjs/reanimated2/hook/utils.js.map +1 -1
- package/lib/commonjs/reanimated2/index.js +0 -26
- package/lib/commonjs/reanimated2/index.js.map +1 -1
- package/lib/commonjs/reanimated2/initializers.js +21 -43
- package/lib/commonjs/reanimated2/initializers.js.map +1 -1
- package/lib/commonjs/reanimated2/interpolateColor.js +6 -43
- package/lib/commonjs/reanimated2/interpolateColor.js.map +1 -1
- package/lib/commonjs/reanimated2/interpolation.js +14 -29
- package/lib/commonjs/reanimated2/interpolation.js.map +1 -1
- package/lib/commonjs/reanimated2/jestUtils.js +11 -44
- package/lib/commonjs/reanimated2/jestUtils.js.map +1 -1
- package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js +15 -39
- package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
- package/lib/commonjs/reanimated2/js-reanimated/Mapper.js +9 -28
- package/lib/commonjs/reanimated2/js-reanimated/Mapper.js.map +1 -1
- package/lib/commonjs/reanimated2/js-reanimated/MapperRegistry.js +7 -37
- package/lib/commonjs/reanimated2/js-reanimated/MapperRegistry.js.map +1 -1
- package/lib/commonjs/reanimated2/js-reanimated/MutableValue.js +5 -18
- package/lib/commonjs/reanimated2/js-reanimated/MutableValue.js.map +1 -1
- package/lib/commonjs/reanimated2/js-reanimated/global.js +2 -9
- package/lib/commonjs/reanimated2/js-reanimated/global.js.map +1 -1
- package/lib/commonjs/reanimated2/js-reanimated/index.js +3 -14
- package/lib/commonjs/reanimated2/js-reanimated/index.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js +7 -26
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +3 -49
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/Keyframe.js +7 -43
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/Keyframe.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +4 -5
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js +0 -4
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js +4 -23
- package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +3 -74
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Fade.js +3 -53
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Fade.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Flip.js +3 -63
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Flip.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +7 -26
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +3 -13
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Roll.js +3 -23
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +3 -43
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Rotate.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Slide.js +3 -43
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +3 -23
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Stretch.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +3 -83
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/index.js +0 -20
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/index.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +3 -22
- package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +5 -29
- package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +3 -9
- package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +5 -11
- package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +3 -8
- package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +3 -12
- package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/index.js +0 -12
- package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/index.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/index.js +0 -9
- package/lib/commonjs/reanimated2/layoutReanimation/index.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/sharedTransitions/index.js +3 -17
- package/lib/commonjs/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -1
- package/lib/commonjs/reanimated2/mappers.js +26 -32
- package/lib/commonjs/reanimated2/mappers.js.map +1 -1
- package/lib/commonjs/reanimated2/mock.js +5 -15
- package/lib/commonjs/reanimated2/mock.js.map +1 -1
- package/lib/commonjs/reanimated2/mutables.js +2 -28
- package/lib/commonjs/reanimated2/mutables.js.map +1 -1
- package/lib/commonjs/reanimated2/platform-specific/RNRenderer.js +0 -2
- package/lib/commonjs/reanimated2/platform-specific/RNRenderer.js.map +1 -1
- package/lib/commonjs/reanimated2/platform-specific/RNRenderer.web.js.map +1 -1
- package/lib/commonjs/reanimated2/platform-specific/checkCppVersion.js +31 -0
- package/lib/commonjs/reanimated2/platform-specific/checkCppVersion.js.map +1 -0
- package/lib/commonjs/reanimated2/platform-specific/checkVersion.web.js +0 -2
- package/lib/commonjs/reanimated2/platform-specific/checkVersion.web.js.map +1 -1
- package/lib/commonjs/reanimated2/platform-specific/jsVersion.js +14 -0
- package/lib/commonjs/reanimated2/platform-specific/jsVersion.js.map +1 -0
- package/lib/commonjs/reanimated2/pluginUtils.js +0 -1
- package/lib/commonjs/reanimated2/pluginUtils.js.map +1 -1
- package/lib/commonjs/reanimated2/shareables.js +92 -49
- package/lib/commonjs/reanimated2/shareables.js.map +1 -1
- package/lib/commonjs/reanimated2/threads.js +42 -46
- package/lib/commonjs/reanimated2/threads.js.map +1 -1
- package/lib/commonjs/reanimated2/utils.js +0 -5
- package/lib/commonjs/reanimated2/utils.js.map +1 -1
- package/lib/commonjs/reanimated2/valueSetter.js +6 -21
- package/lib/commonjs/reanimated2/valueSetter.js.map +1 -1
- package/lib/commonjs/setAndForwardRef.js +3 -3
- package/lib/commonjs/setAndForwardRef.js.map +1 -1
- package/lib/module/Animated.js.map +1 -1
- package/lib/module/ConfigHelper.js +9 -15
- package/lib/module/ConfigHelper.js.map +1 -1
- package/lib/module/createAnimatedComponent.js +20 -139
- package/lib/module/createAnimatedComponent.js.map +1 -1
- package/lib/module/index.js +0 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js.map +1 -1
- package/lib/module/reanimated2/Bezier.js +14 -33
- package/lib/module/reanimated2/Bezier.js.map +1 -1
- package/lib/module/reanimated2/Colors.js +59 -109
- package/lib/module/reanimated2/Colors.js.map +1 -1
- package/lib/module/reanimated2/Easing.js +37 -33
- package/lib/module/reanimated2/Easing.js.map +1 -1
- package/lib/module/reanimated2/NativeMethods.js +8 -15
- package/lib/module/reanimated2/NativeMethods.js.map +1 -1
- package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js +5 -27
- package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
- package/lib/module/reanimated2/NativeReanimated/index.js +0 -2
- package/lib/module/reanimated2/NativeReanimated/index.js.map +1 -1
- package/lib/module/reanimated2/PlatformChecker.js.map +1 -1
- package/lib/module/reanimated2/PropAdapters.js +12 -10
- package/lib/module/reanimated2/PropAdapters.js.map +1 -1
- package/lib/module/reanimated2/UpdateProps.js +3 -5
- package/lib/module/reanimated2/UpdateProps.js.map +1 -1
- package/lib/module/reanimated2/ViewDescriptorsSet.js +0 -6
- package/lib/module/reanimated2/ViewDescriptorsSet.js.map +1 -1
- package/lib/module/reanimated2/WorkletEventHandler.js +5 -18
- package/lib/module/reanimated2/WorkletEventHandler.js.map +1 -1
- package/lib/module/reanimated2/animation/decay.js +7 -15
- package/lib/module/reanimated2/animation/decay.js.map +1 -1
- package/lib/module/reanimated2/animation/delay.js +0 -9
- package/lib/module/reanimated2/animation/delay.js.map +1 -1
- package/lib/module/reanimated2/animation/index.js.map +1 -1
- package/lib/module/reanimated2/animation/repeat.js +6 -20
- package/lib/module/reanimated2/animation/repeat.js.map +1 -1
- package/lib/module/reanimated2/animation/sequence.js +3 -18
- package/lib/module/reanimated2/animation/sequence.js.map +1 -1
- package/lib/module/reanimated2/animation/spring.js +11 -21
- package/lib/module/reanimated2/animation/spring.js.map +1 -1
- package/lib/module/reanimated2/animation/styleAnimation.js +7 -31
- package/lib/module/reanimated2/animation/styleAnimation.js.map +1 -1
- package/lib/module/reanimated2/animation/timing.js +0 -8
- package/lib/module/reanimated2/animation/timing.js.map +1 -1
- package/lib/module/reanimated2/animation/util.js +10 -33
- package/lib/module/reanimated2/animation/util.js.map +1 -1
- package/lib/module/reanimated2/commonTypes.js +12 -19
- package/lib/module/reanimated2/commonTypes.js.map +1 -1
- package/lib/module/reanimated2/component/FlatList.js +0 -4
- package/lib/module/reanimated2/component/FlatList.js.map +1 -1
- package/lib/module/reanimated2/component/Image.js.map +1 -1
- package/lib/module/reanimated2/component/ScrollView.js.map +1 -1
- package/lib/module/reanimated2/component/Text.js.map +1 -1
- package/lib/module/reanimated2/component/View.js.map +1 -1
- package/lib/module/reanimated2/core.js +6 -22
- package/lib/module/reanimated2/core.js.map +1 -1
- package/lib/module/reanimated2/errors.js +3 -13
- package/lib/module/reanimated2/errors.js.map +1 -1
- package/lib/module/reanimated2/fabricUtils.js +3 -3
- package/lib/module/reanimated2/fabricUtils.js.map +1 -1
- package/lib/module/reanimated2/fabricUtils.web.js +1 -1
- package/lib/module/reanimated2/fabricUtils.web.js.map +1 -1
- package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryJS.js +3 -8
- package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryJS.js.map +1 -1
- package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js +13 -15
- 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/Hooks.js +3 -2
- package/lib/module/reanimated2/hook/Hooks.js.map +1 -1
- package/lib/module/reanimated2/hook/commonTypes.js.map +1 -1
- package/lib/module/reanimated2/hook/index.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedGestureHandler.js +3 -14
- package/lib/module/reanimated2/hook/useAnimatedGestureHandler.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedKeyboard.js +2 -5
- package/lib/module/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedReaction.js +1 -7
- package/lib/module/reanimated2/hook/useAnimatedReaction.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedRef.js +0 -6
- package/lib/module/reanimated2/hook/useAnimatedRef.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedScrollHandler.js +2 -7
- package/lib/module/reanimated2/hook/useAnimatedScrollHandler.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedSensor.js +9 -20
- package/lib/module/reanimated2/hook/useAnimatedSensor.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedStyle.js +13 -59
- package/lib/module/reanimated2/hook/useAnimatedStyle.js.map +1 -1
- package/lib/module/reanimated2/hook/useDerivedValue.js +4 -8
- package/lib/module/reanimated2/hook/useDerivedValue.js.map +1 -1
- package/lib/module/reanimated2/hook/useFrameCallback.js.map +1 -1
- package/lib/module/reanimated2/hook/useScrollViewOffset.js +0 -1
- package/lib/module/reanimated2/hook/useScrollViewOffset.js.map +1 -1
- package/lib/module/reanimated2/hook/useSharedValue.js +2 -3
- package/lib/module/reanimated2/hook/useSharedValue.js.map +1 -1
- package/lib/module/reanimated2/hook/utils.js +8 -21
- package/lib/module/reanimated2/hook/utils.js.map +1 -1
- package/lib/module/reanimated2/index.js.map +1 -1
- package/lib/module/reanimated2/initializers.js +23 -37
- package/lib/module/reanimated2/initializers.js.map +1 -1
- package/lib/module/reanimated2/interpolateColor.js +5 -34
- package/lib/module/reanimated2/interpolateColor.js.map +1 -1
- package/lib/module/reanimated2/interpolation.js +13 -28
- package/lib/module/reanimated2/interpolation.js.map +1 -1
- package/lib/module/reanimated2/jestUtils.js +11 -35
- package/lib/module/reanimated2/jestUtils.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/JSReanimated.js +15 -35
- package/lib/module/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/Mapper.js +9 -23
- package/lib/module/reanimated2/js-reanimated/Mapper.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/MapperRegistry.js +7 -35
- package/lib/module/reanimated2/js-reanimated/MapperRegistry.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/MutableValue.js +5 -16
- package/lib/module/reanimated2/js-reanimated/MutableValue.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/global.js +2 -6
- package/lib/module/reanimated2/js-reanimated/global.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/index.js +3 -9
- package/lib/module/reanimated2/js-reanimated/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js +7 -23
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +3 -45
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/Keyframe.js +7 -39
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/Keyframe.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +3 -3
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationsManager.js +4 -19
- package/lib/module/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +3 -52
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Fade.js +3 -32
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Fade.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Flip.js +3 -38
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Flip.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +7 -16
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +3 -8
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js +3 -14
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +3 -26
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Rotate.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js +3 -26
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +3 -14
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Stretch.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +3 -50
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +3 -17
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +5 -23
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +3 -5
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +5 -6
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +3 -5
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +3 -8
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultTransitions/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js +3 -13
- package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -1
- package/lib/module/reanimated2/mappers.js +26 -25
- package/lib/module/reanimated2/mappers.js.map +1 -1
- package/lib/module/reanimated2/mock.js +5 -15
- package/lib/module/reanimated2/mock.js.map +1 -1
- package/lib/module/reanimated2/mutables.js +2 -19
- package/lib/module/reanimated2/mutables.js.map +1 -1
- package/lib/module/reanimated2/platform-specific/RNRenderer.js.map +1 -1
- package/lib/module/reanimated2/platform-specific/RNRenderer.web.js.map +1 -1
- package/lib/module/reanimated2/platform-specific/checkCppVersion.js +24 -0
- package/lib/module/reanimated2/platform-specific/checkCppVersion.js.map +1 -0
- package/lib/module/reanimated2/platform-specific/checkVersion.web.js +0 -1
- package/lib/module/reanimated2/platform-specific/checkVersion.web.js.map +1 -1
- package/lib/module/reanimated2/platform-specific/jsVersion.js +7 -0
- package/lib/module/reanimated2/platform-specific/jsVersion.js.map +1 -0
- package/lib/module/reanimated2/pluginUtils.js.map +1 -1
- package/lib/module/reanimated2/shareables.js +96 -44
- package/lib/module/reanimated2/shareables.js.map +1 -1
- package/lib/module/reanimated2/threads.js +39 -33
- package/lib/module/reanimated2/threads.js.map +1 -1
- package/lib/module/reanimated2/utils.js +0 -3
- package/lib/module/reanimated2/utils.js.map +1 -1
- package/lib/module/reanimated2/valueSetter.js +6 -19
- package/lib/module/reanimated2/valueSetter.js.map +1 -1
- package/lib/module/setAndForwardRef.js +3 -2
- package/lib/module/setAndForwardRef.js.map +1 -1
- package/package.json +46 -40
- package/plugin/.eslintrc.js +7 -0
- package/plugin/README.md +241 -0
- package/plugin/build/plugin.js +714 -0
- package/plugin/build/plugin.js.map +7 -0
- package/plugin/index.js +1 -807
- package/plugin/package.json +23 -0
- package/plugin/src/buildWorkletString.ts +213 -0
- package/plugin/src/commonObjects.ts +60 -0
- package/plugin/src/injectVersion.ts +37 -0
- package/plugin/src/makeWorklet.ts +375 -0
- package/plugin/src/plugin.ts +49 -0
- package/plugin/src/processForCalleesWorklets.ts +106 -0
- package/plugin/src/processIfGestureHandlerEventCallbackFunctionNode.ts +156 -0
- package/plugin/src/processIfWorkletFunction.ts +55 -0
- package/plugin/src/processIfWorkletNode.ts +44 -0
- package/plugin/src/processInlineStylesWarning.ts +129 -0
- package/plugin/src/processWorkletObjectMethod.ts +31 -0
- package/plugin/src/types.ts +15 -0
- package/plugin/src/utils.ts +6 -0
- package/plugin/tsconfig.json +15 -0
- package/plugin/yarn.lock +2193 -0
- package/react-native-reanimated.d.ts +1 -0
- package/scripts/reanimated_utils.rb +2 -2
- package/src/createAnimatedComponent.tsx +2 -3
- package/src/reanimated2/Easing.ts +19 -0
- package/src/reanimated2/NativeMethods.ts +9 -4
- package/src/reanimated2/NativeReanimated/NativeReanimated.ts +2 -2
- package/src/reanimated2/UpdateProps.ts +2 -2
- package/src/reanimated2/animation/decay.ts +7 -1
- package/src/reanimated2/animation/styleAnimation.ts +5 -1
- package/src/reanimated2/core.ts +4 -4
- package/src/reanimated2/errors.ts +1 -0
- package/src/reanimated2/frameCallback/FrameCallbackRegistryUI.ts +12 -4
- package/src/reanimated2/globals.d.ts +71 -112
- package/src/reanimated2/hook/commonTypes.ts +1 -1
- package/src/reanimated2/hook/useAnimatedReaction.ts +2 -2
- package/src/reanimated2/hook/useAnimatedSensor.ts +2 -2
- package/src/reanimated2/initializers.ts +11 -8
- package/src/reanimated2/jestUtils.ts +0 -1
- package/src/reanimated2/js-reanimated/JSReanimated.ts +5 -1
- package/src/reanimated2/js-reanimated/index.ts +1 -1
- package/src/reanimated2/mappers.ts +26 -4
- package/src/reanimated2/mock.ts +1 -0
- package/src/reanimated2/platform-specific/checkCppVersion.ts +29 -0
- package/src/reanimated2/platform-specific/jsVersion.ts +6 -0
- package/src/reanimated2/shareables.ts +107 -8
- package/src/reanimated2/threads.ts +36 -17
- package/lib/commonjs/reanimated2/platform-specific/checkVersion.js +0 -42
- package/lib/commonjs/reanimated2/platform-specific/checkVersion.js.map +0 -1
- package/lib/module/reanimated2/platform-specific/checkVersion.js +0 -35
- package/lib/module/reanimated2/platform-specific/checkVersion.js.map +0 -1
- package/src/reanimated2/platform-specific/checkVersion.ts +0 -39
|
@@ -4,17 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.withSpring = withSpring;
|
|
7
|
-
|
|
8
7
|
var _util = require("./util");
|
|
9
|
-
|
|
10
8
|
function withSpring(toValue, userConfig, callback) {
|
|
11
9
|
'worklet';
|
|
12
10
|
|
|
13
11
|
return (0, _util.defineAnimation)(toValue, () => {
|
|
14
|
-
'worklet';
|
|
12
|
+
'worklet';
|
|
13
|
+
|
|
14
|
+
// TODO: figure out why we can't use spread or Object.assign here
|
|
15
15
|
// when user config is "frozen object" we can't enumerate it (perhaps
|
|
16
16
|
// something is wrong with the object prototype).
|
|
17
|
-
|
|
18
17
|
const config = {
|
|
19
18
|
damping: 10,
|
|
20
19
|
mass: 1,
|
|
@@ -24,11 +23,9 @@ function withSpring(toValue, userConfig, callback) {
|
|
|
24
23
|
restSpeedThreshold: 2,
|
|
25
24
|
velocity: 0
|
|
26
25
|
};
|
|
27
|
-
|
|
28
26
|
if (userConfig) {
|
|
29
27
|
Object.keys(userConfig).forEach(key => config[key] = userConfig[key]);
|
|
30
28
|
}
|
|
31
|
-
|
|
32
29
|
function spring(animation, now) {
|
|
33
30
|
const {
|
|
34
31
|
toValue,
|
|
@@ -44,25 +41,24 @@ function withSpring(toValue, userConfig, callback) {
|
|
|
44
41
|
const v0 = -velocity;
|
|
45
42
|
const x0 = toValue - current;
|
|
46
43
|
const zeta = c / (2 * Math.sqrt(k * m)); // damping ratio
|
|
47
|
-
|
|
48
44
|
const omega0 = Math.sqrt(k / m); // undamped angular frequency of the oscillator (rad/ms)
|
|
49
|
-
|
|
50
45
|
const omega1 = omega0 * Math.sqrt(1 - zeta ** 2); // exponential decay
|
|
51
46
|
|
|
52
47
|
const t = deltaTime / 1000;
|
|
53
48
|
const sin1 = Math.sin(omega1 * t);
|
|
54
|
-
const cos1 = Math.cos(omega1 * t);
|
|
49
|
+
const cos1 = Math.cos(omega1 * t);
|
|
55
50
|
|
|
51
|
+
// under damped
|
|
56
52
|
const underDampedEnvelope = Math.exp(-zeta * omega0 * t);
|
|
57
53
|
const underDampedFrag1 = underDampedEnvelope * (sin1 * ((v0 + zeta * omega0 * x0) / omega1) + x0 * cos1);
|
|
58
|
-
const underDampedPosition = toValue - underDampedFrag1;
|
|
59
|
-
|
|
60
|
-
const underDampedVelocity = zeta * omega0 * underDampedFrag1 - underDampedEnvelope * (cos1 * (v0 + zeta * omega0 * x0) - omega1 * x0 * sin1);
|
|
54
|
+
const underDampedPosition = toValue - underDampedFrag1;
|
|
55
|
+
// This looks crazy -- it's actually just the derivative of the oscillation function
|
|
56
|
+
const underDampedVelocity = zeta * omega0 * underDampedFrag1 - underDampedEnvelope * (cos1 * (v0 + zeta * omega0 * x0) - omega1 * x0 * sin1);
|
|
61
57
|
|
|
58
|
+
// critically damped
|
|
62
59
|
const criticallyDampedEnvelope = Math.exp(-omega0 * t);
|
|
63
60
|
const criticallyDampedPosition = toValue - criticallyDampedEnvelope * (x0 + (v0 + omega0 * x0) * t);
|
|
64
61
|
const criticallyDampedVelocity = criticallyDampedEnvelope * (v0 * (t * omega0 - 1) + t * x0 * omega0 * omega0);
|
|
65
|
-
|
|
66
62
|
const isOvershooting = () => {
|
|
67
63
|
if (config.overshootClamping && config.stiffness !== 0) {
|
|
68
64
|
return current < toValue ? animation.current > toValue : animation.current < toValue;
|
|
@@ -70,10 +66,8 @@ function withSpring(toValue, userConfig, callback) {
|
|
|
70
66
|
return false;
|
|
71
67
|
}
|
|
72
68
|
};
|
|
73
|
-
|
|
74
69
|
const isVelocity = Math.abs(velocity) < config.restSpeedThreshold;
|
|
75
70
|
const isDisplacement = config.stiffness === 0 || Math.abs(toValue - current) < config.restDisplacementThreshold;
|
|
76
|
-
|
|
77
71
|
if (zeta < 1) {
|
|
78
72
|
animation.current = underDampedPosition;
|
|
79
73
|
animation.velocity = underDampedVelocity;
|
|
@@ -81,24 +75,19 @@ function withSpring(toValue, userConfig, callback) {
|
|
|
81
75
|
animation.current = criticallyDampedPosition;
|
|
82
76
|
animation.velocity = criticallyDampedVelocity;
|
|
83
77
|
}
|
|
84
|
-
|
|
85
78
|
if (isOvershooting() || isVelocity && isDisplacement) {
|
|
86
79
|
if (config.stiffness !== 0) {
|
|
87
80
|
animation.velocity = 0;
|
|
88
81
|
animation.current = toValue;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
82
|
+
}
|
|
83
|
+
// clear lastTimestamp to avoid using stale value by the next spring animation that starts after this one
|
|
92
84
|
animation.lastTimestamp = 0;
|
|
93
85
|
return true;
|
|
94
86
|
}
|
|
95
|
-
|
|
96
87
|
return false;
|
|
97
88
|
}
|
|
98
|
-
|
|
99
89
|
function onStart(animation, value, now, previousAnimation) {
|
|
100
90
|
animation.current = value;
|
|
101
|
-
|
|
102
91
|
if (previousAnimation) {
|
|
103
92
|
animation.velocity = previousAnimation.velocity || animation.velocity || 0;
|
|
104
93
|
animation.lastTimestamp = previousAnimation.lastTimestamp || now;
|
|
@@ -106,7 +95,6 @@ function withSpring(toValue, userConfig, callback) {
|
|
|
106
95
|
animation.lastTimestamp = now;
|
|
107
96
|
}
|
|
108
97
|
}
|
|
109
|
-
|
|
110
98
|
return {
|
|
111
99
|
onFrame: spring,
|
|
112
100
|
onStart,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["withSpring","toValue","userConfig","callback","defineAnimation","config","damping","mass","stiffness","overshootClamping","restDisplacementThreshold","restSpeedThreshold","velocity","Object","keys","forEach","key","spring","animation","now","lastTimestamp","current","deltaTime","Math","min","c","m","k","v0","x0","zeta","sqrt","omega0","omega1","t","sin1","sin","cos1","cos","underDampedEnvelope","exp","underDampedFrag1","underDampedPosition","underDampedVelocity","criticallyDampedEnvelope","criticallyDampedPosition","criticallyDampedVelocity","isOvershooting","isVelocity","abs","isDisplacement","onStart","value","previousAnimation","onFrame"],"sources":["spring.ts"],"sourcesContent":["import { defineAnimation } from './util';\nimport {\n Animation,\n AnimationCallback,\n AnimatableValue,\n Timestamp,\n} from '../commonTypes';\n\ninterface SpringConfig {\n mass?: number;\n stiffness?: number;\n overshootClamping?: boolean;\n restDisplacementThreshold?: number;\n restSpeedThreshold?: number;\n velocity?: number;\n damping?: number;\n}\n\nexport interface SpringAnimation extends Animation<SpringAnimation> {\n current: AnimatableValue;\n toValue: AnimatableValue;\n velocity: number;\n lastTimestamp: Timestamp;\n}\n\nexport interface InnerSpringAnimation\n extends Omit<SpringAnimation, 'toValue' | 'current'> {\n toValue: number;\n current: number;\n}\n\nexport function withSpring(\n toValue: AnimatableValue,\n userConfig?: SpringConfig,\n callback?: AnimationCallback\n): Animation<SpringAnimation> {\n 'worklet';\n\n return defineAnimation<SpringAnimation>(toValue, () => {\n 'worklet';\n\n // TODO: figure out why we can't use spread or Object.assign here\n // when user config is \"frozen object\" we can't enumerate it (perhaps\n // something is wrong with the object prototype).\n const config: Required<SpringConfig> = {\n damping: 10,\n mass: 1,\n stiffness: 100,\n overshootClamping: false,\n restDisplacementThreshold: 0.01,\n restSpeedThreshold: 2,\n velocity: 0,\n };\n if (userConfig) {\n Object.keys(userConfig).forEach(\n (key) =>\n ((config as any)[key] = userConfig[key as keyof typeof userConfig])\n );\n }\n\n function spring(animation: InnerSpringAnimation, now: Timestamp): boolean {\n const { toValue, lastTimestamp, current, velocity } = animation;\n\n const deltaTime = Math.min(now - lastTimestamp, 64);\n animation.lastTimestamp = now;\n\n const c = config.damping;\n const m = config.mass;\n const k = config.stiffness;\n\n const v0 = -velocity;\n const x0 = toValue - current;\n\n const zeta = c / (2 * Math.sqrt(k * m)); // damping ratio\n const omega0 = Math.sqrt(k / m); // undamped angular frequency of the oscillator (rad/ms)\n const omega1 = omega0 * Math.sqrt(1 - zeta ** 2); // exponential decay\n\n const t = deltaTime / 1000;\n\n const sin1 = Math.sin(omega1 * t);\n const cos1 = Math.cos(omega1 * t);\n\n // under damped\n const underDampedEnvelope = Math.exp(-zeta * omega0 * t);\n const underDampedFrag1 =\n underDampedEnvelope *\n (sin1 * ((v0 + zeta * omega0 * x0) / omega1) + x0 * cos1);\n\n const underDampedPosition = toValue - underDampedFrag1;\n // This looks crazy -- it's actually just the derivative of the oscillation function\n const underDampedVelocity =\n zeta * omega0 * underDampedFrag1 -\n underDampedEnvelope *\n (cos1 * (v0 + zeta * omega0 * x0) - omega1 * x0 * sin1);\n\n // critically damped\n const criticallyDampedEnvelope = Math.exp(-omega0 * t);\n const criticallyDampedPosition =\n toValue - criticallyDampedEnvelope * (x0 + (v0 + omega0 * x0) * t);\n\n const criticallyDampedVelocity =\n criticallyDampedEnvelope *\n (v0 * (t * omega0 - 1) + t * x0 * omega0 * omega0);\n\n const isOvershooting = () => {\n if (config.overshootClamping && config.stiffness !== 0) {\n return current < toValue\n ? animation.current > toValue\n : animation.current < toValue;\n } else {\n return false;\n }\n };\n\n const isVelocity = Math.abs(velocity) < config.restSpeedThreshold;\n const isDisplacement =\n config.stiffness === 0 ||\n Math.abs(toValue - current) < config.restDisplacementThreshold;\n\n if (zeta < 1) {\n animation.current = underDampedPosition;\n animation.velocity = underDampedVelocity;\n } else {\n animation.current = criticallyDampedPosition;\n animation.velocity = criticallyDampedVelocity;\n }\n\n if (isOvershooting() || (isVelocity && isDisplacement)) {\n if (config.stiffness !== 0) {\n animation.velocity = 0;\n animation.current = toValue;\n }\n // clear lastTimestamp to avoid using stale value by the next spring animation that starts after this one\n animation.lastTimestamp = 0;\n return true;\n }\n return false;\n }\n\n function onStart(\n animation: SpringAnimation,\n value: number,\n now: Timestamp,\n previousAnimation: SpringAnimation\n ): void {\n animation.current = value;\n if (previousAnimation) {\n animation.velocity =\n previousAnimation.velocity || animation.velocity || 0;\n animation.lastTimestamp = previousAnimation.lastTimestamp || now;\n } else {\n animation.lastTimestamp = now;\n }\n }\n\n return {\n onFrame: spring,\n onStart,\n toValue,\n velocity: config.velocity || 0,\n current: toValue,\n callback,\n lastTimestamp: 0,\n } as SpringAnimation;\n });\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_util","require","withSpring","toValue","userConfig","callback","defineAnimation","config","damping","mass","stiffness","overshootClamping","restDisplacementThreshold","restSpeedThreshold","velocity","Object","keys","forEach","key","spring","animation","now","lastTimestamp","current","deltaTime","Math","min","c","m","k","v0","x0","zeta","sqrt","omega0","omega1","t","sin1","sin","cos1","cos","underDampedEnvelope","exp","underDampedFrag1","underDampedPosition","underDampedVelocity","criticallyDampedEnvelope","criticallyDampedPosition","criticallyDampedVelocity","isOvershooting","isVelocity","abs","isDisplacement","onStart","value","previousAnimation","onFrame"],"sources":["spring.ts"],"sourcesContent":["import { defineAnimation } from './util';\nimport {\n Animation,\n AnimationCallback,\n AnimatableValue,\n Timestamp,\n} from '../commonTypes';\n\ninterface SpringConfig {\n mass?: number;\n stiffness?: number;\n overshootClamping?: boolean;\n restDisplacementThreshold?: number;\n restSpeedThreshold?: number;\n velocity?: number;\n damping?: number;\n}\n\nexport interface SpringAnimation extends Animation<SpringAnimation> {\n current: AnimatableValue;\n toValue: AnimatableValue;\n velocity: number;\n lastTimestamp: Timestamp;\n}\n\nexport interface InnerSpringAnimation\n extends Omit<SpringAnimation, 'toValue' | 'current'> {\n toValue: number;\n current: number;\n}\n\nexport function withSpring(\n toValue: AnimatableValue,\n userConfig?: SpringConfig,\n callback?: AnimationCallback\n): Animation<SpringAnimation> {\n 'worklet';\n\n return defineAnimation<SpringAnimation>(toValue, () => {\n 'worklet';\n\n // TODO: figure out why we can't use spread or Object.assign here\n // when user config is \"frozen object\" we can't enumerate it (perhaps\n // something is wrong with the object prototype).\n const config: Required<SpringConfig> = {\n damping: 10,\n mass: 1,\n stiffness: 100,\n overshootClamping: false,\n restDisplacementThreshold: 0.01,\n restSpeedThreshold: 2,\n velocity: 0,\n };\n if (userConfig) {\n Object.keys(userConfig).forEach(\n (key) =>\n ((config as any)[key] = userConfig[key as keyof typeof userConfig])\n );\n }\n\n function spring(animation: InnerSpringAnimation, now: Timestamp): boolean {\n const { toValue, lastTimestamp, current, velocity } = animation;\n\n const deltaTime = Math.min(now - lastTimestamp, 64);\n animation.lastTimestamp = now;\n\n const c = config.damping;\n const m = config.mass;\n const k = config.stiffness;\n\n const v0 = -velocity;\n const x0 = toValue - current;\n\n const zeta = c / (2 * Math.sqrt(k * m)); // damping ratio\n const omega0 = Math.sqrt(k / m); // undamped angular frequency of the oscillator (rad/ms)\n const omega1 = omega0 * Math.sqrt(1 - zeta ** 2); // exponential decay\n\n const t = deltaTime / 1000;\n\n const sin1 = Math.sin(omega1 * t);\n const cos1 = Math.cos(omega1 * t);\n\n // under damped\n const underDampedEnvelope = Math.exp(-zeta * omega0 * t);\n const underDampedFrag1 =\n underDampedEnvelope *\n (sin1 * ((v0 + zeta * omega0 * x0) / omega1) + x0 * cos1);\n\n const underDampedPosition = toValue - underDampedFrag1;\n // This looks crazy -- it's actually just the derivative of the oscillation function\n const underDampedVelocity =\n zeta * omega0 * underDampedFrag1 -\n underDampedEnvelope *\n (cos1 * (v0 + zeta * omega0 * x0) - omega1 * x0 * sin1);\n\n // critically damped\n const criticallyDampedEnvelope = Math.exp(-omega0 * t);\n const criticallyDampedPosition =\n toValue - criticallyDampedEnvelope * (x0 + (v0 + omega0 * x0) * t);\n\n const criticallyDampedVelocity =\n criticallyDampedEnvelope *\n (v0 * (t * omega0 - 1) + t * x0 * omega0 * omega0);\n\n const isOvershooting = () => {\n if (config.overshootClamping && config.stiffness !== 0) {\n return current < toValue\n ? animation.current > toValue\n : animation.current < toValue;\n } else {\n return false;\n }\n };\n\n const isVelocity = Math.abs(velocity) < config.restSpeedThreshold;\n const isDisplacement =\n config.stiffness === 0 ||\n Math.abs(toValue - current) < config.restDisplacementThreshold;\n\n if (zeta < 1) {\n animation.current = underDampedPosition;\n animation.velocity = underDampedVelocity;\n } else {\n animation.current = criticallyDampedPosition;\n animation.velocity = criticallyDampedVelocity;\n }\n\n if (isOvershooting() || (isVelocity && isDisplacement)) {\n if (config.stiffness !== 0) {\n animation.velocity = 0;\n animation.current = toValue;\n }\n // clear lastTimestamp to avoid using stale value by the next spring animation that starts after this one\n animation.lastTimestamp = 0;\n return true;\n }\n return false;\n }\n\n function onStart(\n animation: SpringAnimation,\n value: number,\n now: Timestamp,\n previousAnimation: SpringAnimation\n ): void {\n animation.current = value;\n if (previousAnimation) {\n animation.velocity =\n previousAnimation.velocity || animation.velocity || 0;\n animation.lastTimestamp = previousAnimation.lastTimestamp || now;\n } else {\n animation.lastTimestamp = now;\n }\n }\n\n return {\n onFrame: spring,\n onStart,\n toValue,\n velocity: config.velocity || 0,\n current: toValue,\n callback,\n lastTimestamp: 0,\n } as SpringAnimation;\n });\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AA+BO,SAASC,UAAUA,CACxBC,OAAwB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,CAACzC,QAAQ,IAAIM,SAAS,CAACN,QAAQ,IAAI,CAAC;QACvDM,SAAS,CAACE,aAAa,GAAGiC,iBAAiB,CAACjC,aAAa,IAAID,GAAG;MAClE,CAAC,MAAM;QACLD,SAAS,CAACE,aAAa,GAAGD,GAAG;MAC/B;IACF;IAEA,OAAO;MACLmC,OAAO,EAAErC,MAAM;MACfkC,OAAO;MACPlD,OAAO;MACPW,QAAQ,EAAEP,MAAM,CAACO,QAAQ,IAAI,CAAC;MAC9BS,OAAO,EAAEpB,OAAO;MAChBE,QAAQ;MACRiB,aAAa,EAAE;IACjB,CAAC;EACH,CAAC,CAAC;AACJ"}
|
|
@@ -6,15 +6,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.resolvePath = resolvePath;
|
|
7
7
|
exports.setPath = setPath;
|
|
8
8
|
exports.withStyleAnimation = withStyleAnimation;
|
|
9
|
-
|
|
10
9
|
var _util = require("./util");
|
|
11
|
-
|
|
12
10
|
var _timing = require("./timing");
|
|
13
|
-
|
|
14
11
|
var _UpdateProps = require("../UpdateProps");
|
|
15
|
-
|
|
16
12
|
var _Colors = require("../Colors");
|
|
17
|
-
|
|
18
13
|
// resolves path to value for nested objects
|
|
19
14
|
// if path cannot be resolved returns undefined
|
|
20
15
|
function resolvePath(obj, path) {
|
|
@@ -24,25 +19,23 @@ function resolvePath(obj, path) {
|
|
|
24
19
|
return keys.reduce((acc, current) => {
|
|
25
20
|
if (Array.isArray(acc) && typeof current === 'number') {
|
|
26
21
|
return acc[current];
|
|
27
|
-
} else if (typeof acc === 'object' && current in acc) {
|
|
22
|
+
} else if (acc !== null && typeof acc === 'object' && current in acc) {
|
|
28
23
|
return acc[current];
|
|
29
24
|
}
|
|
30
|
-
|
|
31
25
|
return undefined;
|
|
32
26
|
}, obj);
|
|
33
|
-
}
|
|
27
|
+
}
|
|
34
28
|
|
|
29
|
+
// set value at given path
|
|
35
30
|
|
|
36
31
|
function setPath(obj, path, value) {
|
|
37
32
|
'worklet';
|
|
38
33
|
|
|
39
34
|
const keys = Array.isArray(path) ? path : [path];
|
|
40
35
|
let currObj = obj;
|
|
41
|
-
|
|
42
36
|
for (let i = 0; i < keys.length - 1; i++) {
|
|
43
37
|
// creates entry if there isn't one
|
|
44
38
|
currObj = currObj;
|
|
45
|
-
|
|
46
39
|
if (!(keys[i] in currObj)) {
|
|
47
40
|
// if next key is a number create an array
|
|
48
41
|
if (typeof keys[i + 1] === 'number') {
|
|
@@ -51,13 +44,10 @@ function setPath(obj, path, value) {
|
|
|
51
44
|
currObj[keys[i]] = {};
|
|
52
45
|
}
|
|
53
46
|
}
|
|
54
|
-
|
|
55
47
|
currObj = currObj[keys[i]];
|
|
56
48
|
}
|
|
57
|
-
|
|
58
49
|
currObj[keys[keys.length - 1]] = value;
|
|
59
50
|
}
|
|
60
|
-
|
|
61
51
|
function withStyleAnimation(styleAnimations) {
|
|
62
52
|
'worklet';
|
|
63
53
|
|
|
@@ -70,10 +60,8 @@ function withStyleAnimation(styleAnimations) {
|
|
|
70
60
|
value: animation.styleAnimations,
|
|
71
61
|
path: []
|
|
72
62
|
}];
|
|
73
|
-
|
|
74
63
|
while (entriesToCheck.length > 0) {
|
|
75
64
|
const currentEntry = entriesToCheck.pop();
|
|
76
|
-
|
|
77
65
|
if (Array.isArray(currentEntry.value)) {
|
|
78
66
|
for (let index = 0; index < currentEntry.value.length; index++) {
|
|
79
67
|
entriesToCheck.push({
|
|
@@ -91,43 +79,33 @@ function withStyleAnimation(styleAnimations) {
|
|
|
91
79
|
}
|
|
92
80
|
} else {
|
|
93
81
|
const currentStyleAnimation = currentEntry.value;
|
|
94
|
-
|
|
95
82
|
if (currentStyleAnimation.finished) {
|
|
96
83
|
continue;
|
|
97
84
|
}
|
|
98
|
-
|
|
99
85
|
const finished = currentStyleAnimation.onFrame(currentStyleAnimation, now);
|
|
100
|
-
|
|
101
86
|
if (finished) {
|
|
102
87
|
currentStyleAnimation.finished = true;
|
|
103
|
-
|
|
104
88
|
if (currentStyleAnimation.callback) {
|
|
105
89
|
currentStyleAnimation.callback(true);
|
|
106
90
|
}
|
|
107
91
|
} else {
|
|
108
92
|
stillGoing = true;
|
|
109
93
|
}
|
|
110
|
-
|
|
111
94
|
if (_UpdateProps.ColorProperties.includes(currentEntry.path[0])) {
|
|
112
95
|
currentStyleAnimation.current = (0, _Colors.processColor)(currentStyleAnimation.current);
|
|
113
96
|
}
|
|
114
|
-
|
|
115
97
|
setPath(animation.current, currentEntry.path, currentStyleAnimation.current);
|
|
116
98
|
}
|
|
117
99
|
}
|
|
118
|
-
|
|
119
100
|
return !stillGoing;
|
|
120
101
|
};
|
|
121
|
-
|
|
122
102
|
const onStart = (animation, value, now, previousAnimation) => {
|
|
123
103
|
const entriesToCheck = [{
|
|
124
104
|
value: styleAnimations,
|
|
125
105
|
path: []
|
|
126
106
|
}];
|
|
127
|
-
|
|
128
107
|
while (entriesToCheck.length > 0) {
|
|
129
108
|
const currentEntry = entriesToCheck.pop();
|
|
130
|
-
|
|
131
109
|
if (Array.isArray(currentEntry.value)) {
|
|
132
110
|
for (let index = 0; index < currentEntry.value.length; index++) {
|
|
133
111
|
entriesToCheck.push({
|
|
@@ -145,18 +123,14 @@ function withStyleAnimation(styleAnimations) {
|
|
|
145
123
|
} else {
|
|
146
124
|
const prevAnimation = resolvePath(previousAnimation === null || previousAnimation === void 0 ? void 0 : previousAnimation.styleAnimations, currentEntry.path);
|
|
147
125
|
let prevVal = resolvePath(value, currentEntry.path);
|
|
148
|
-
|
|
149
126
|
if (prevAnimation && !prevVal) {
|
|
150
127
|
prevVal = prevAnimation.current;
|
|
151
128
|
}
|
|
152
|
-
|
|
153
129
|
if (prevVal === undefined) {
|
|
154
130
|
console.warn(`Initial values for animation are missing for property ${currentEntry.path.join('.')}`);
|
|
155
131
|
}
|
|
156
|
-
|
|
157
132
|
setPath(animation.current, currentEntry.path, prevVal);
|
|
158
133
|
let currentAnimation;
|
|
159
|
-
|
|
160
134
|
if (typeof currentEntry.value !== 'object' || !currentEntry.value.onStart) {
|
|
161
135
|
currentAnimation = (0, _timing.withTiming)(currentEntry.value, {
|
|
162
136
|
duration: 0
|
|
@@ -165,19 +139,15 @@ function withStyleAnimation(styleAnimations) {
|
|
|
165
139
|
} else {
|
|
166
140
|
currentAnimation = currentEntry.value;
|
|
167
141
|
}
|
|
168
|
-
|
|
169
142
|
currentAnimation.onStart(currentAnimation, prevVal, now, prevAnimation);
|
|
170
143
|
}
|
|
171
144
|
}
|
|
172
145
|
};
|
|
173
|
-
|
|
174
146
|
const callback = finished => {
|
|
175
147
|
if (!finished) {
|
|
176
148
|
const animationsToCheck = [styleAnimations];
|
|
177
|
-
|
|
178
149
|
while (animationsToCheck.length > 0) {
|
|
179
150
|
const currentAnimation = animationsToCheck.pop();
|
|
180
|
-
|
|
181
151
|
if (Array.isArray(currentAnimation)) {
|
|
182
152
|
for (const element of currentAnimation) {
|
|
183
153
|
animationsToCheck.push(element);
|
|
@@ -188,7 +158,6 @@ function withStyleAnimation(styleAnimations) {
|
|
|
188
158
|
}
|
|
189
159
|
} else {
|
|
190
160
|
const currentStyleAnimation = currentAnimation;
|
|
191
|
-
|
|
192
161
|
if (!currentStyleAnimation.finished && currentStyleAnimation.callback) {
|
|
193
162
|
currentStyleAnimation.callback(false);
|
|
194
163
|
}
|
|
@@ -196,7 +165,6 @@ function withStyleAnimation(styleAnimations) {
|
|
|
196
165
|
}
|
|
197
166
|
}
|
|
198
167
|
};
|
|
199
|
-
|
|
200
168
|
return {
|
|
201
169
|
isHigherOrder: true,
|
|
202
170
|
onFrame,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["resolvePath","obj","path","keys","Array","isArray","reduce","acc","current","undefined","setPath","value","currObj","i","length","withStyleAnimation","styleAnimations","defineAnimation","onFrame","animation","now","stillGoing","entriesToCheck","currentEntry","pop","index","push","concat","key","Object","currentStyleAnimation","finished","callback","ColorProperties","includes","processColor","onStart","previousAnimation","prevAnimation","prevVal","console","warn","join","currentAnimation","withTiming","duration","animationsToCheck","element","values","isHigherOrder"],"sources":["styleAnimation.ts"],"sourcesContent":["import { defineAnimation } from './util';\nimport {\n Timestamp,\n AnimatableValue,\n AnimationObject,\n Animation,\n AnimatedStyle,\n NestedObject,\n NestedObjectValues,\n} from '../commonTypes';\nimport { StyleLayoutAnimation } from './commonTypes';\nimport { withTiming } from './timing';\nimport { ColorProperties } from '../UpdateProps';\nimport { processColor } from '../Colors';\n\n// resolves path to value for nested objects\n// if path cannot be resolved returns undefined\nexport function resolvePath<T>(\n obj: NestedObject<T>,\n path: AnimatableValue[] | AnimatableValue\n): NestedObjectValues<T> | undefined {\n 'worklet';\n const keys: AnimatableValue[] = Array.isArray(path) ? path : [path];\n return keys.reduce<NestedObjectValues<T> | undefined>((acc, current) => {\n if (Array.isArray(acc) && typeof current === 'number') {\n return acc[current];\n } else if (typeof acc === 'object' && (current as number | string) in acc) {\n return (acc as { [key: string]: NestedObjectValues<T> })[\n current as number | string\n ];\n }\n return undefined;\n }, obj);\n}\n\n// set value at given path\ntype Path = Array<string | number> | string | number;\nexport function setPath<T>(\n obj: NestedObject<T>,\n path: Path,\n value: NestedObjectValues<T>\n): void {\n 'worklet';\n const keys: Path = Array.isArray(path) ? path : [path];\n let currObj: NestedObjectValues<T> = obj;\n for (let i = 0; i < keys.length - 1; i++) {\n // creates entry if there isn't one\n currObj = currObj as { [key: string]: NestedObjectValues<T> };\n if (!(keys[i] in currObj)) {\n // if next key is a number create an array\n if (typeof keys[i + 1] === 'number') {\n currObj[keys[i]] = [];\n } else {\n currObj[keys[i]] = {};\n }\n }\n currObj = currObj[keys[i]];\n }\n\n (currObj as { [key: string]: NestedObjectValues<T> })[keys[keys.length - 1]] =\n value;\n}\n\ninterface NestedObjectEntry<T> {\n value: NestedObjectValues<T>;\n path: (string | number)[];\n}\n\nexport function withStyleAnimation(\n styleAnimations: AnimatedStyle\n): StyleLayoutAnimation {\n 'worklet';\n return defineAnimation<StyleLayoutAnimation>({}, () => {\n 'worklet';\n\n const onFrame = (\n animation: StyleLayoutAnimation,\n now: Timestamp\n ): boolean => {\n let stillGoing = false;\n const entriesToCheck: NestedObjectEntry<AnimationObject>[] = [\n { value: animation.styleAnimations, path: [] },\n ];\n while (entriesToCheck.length > 0) {\n const currentEntry: NestedObjectEntry<AnimationObject> =\n entriesToCheck.pop() as NestedObjectEntry<AnimationObject>;\n if (Array.isArray(currentEntry.value)) {\n for (let index = 0; index < currentEntry.value.length; index++) {\n entriesToCheck.push({\n value: currentEntry.value[index],\n path: currentEntry.path.concat(index),\n });\n }\n } else if (\n typeof currentEntry.value === 'object' &&\n currentEntry.value.onFrame === undefined\n ) {\n // nested object\n for (const key of Object.keys(currentEntry.value)) {\n entriesToCheck.push({\n value: currentEntry.value[key],\n path: currentEntry.path.concat(key),\n });\n }\n } else {\n const currentStyleAnimation: AnimationObject =\n currentEntry.value as AnimationObject;\n if (currentStyleAnimation.finished) {\n continue;\n }\n const finished = currentStyleAnimation.onFrame(\n currentStyleAnimation,\n now\n );\n if (finished) {\n currentStyleAnimation.finished = true;\n if (currentStyleAnimation.callback) {\n currentStyleAnimation.callback(true);\n }\n } else {\n stillGoing = true;\n }\n\n if (ColorProperties.includes(currentEntry.path[0] as string)) {\n currentStyleAnimation.current = processColor(\n currentStyleAnimation.current\n ) as number;\n }\n\n setPath(\n animation.current,\n currentEntry.path,\n currentStyleAnimation.current\n );\n }\n }\n return !stillGoing;\n };\n\n const onStart = (\n animation: StyleLayoutAnimation,\n value: AnimatedStyle,\n now: Timestamp,\n previousAnimation: StyleLayoutAnimation\n ): void => {\n const entriesToCheck: NestedObjectEntry<\n AnimationObject | AnimatableValue\n >[] = [{ value: styleAnimations, path: [] }];\n while (entriesToCheck.length > 0) {\n const currentEntry: NestedObjectEntry<\n AnimationObject | AnimatableValue\n > = entriesToCheck.pop() as NestedObjectEntry<\n AnimationObject | AnimatableValue\n >;\n if (Array.isArray(currentEntry.value)) {\n for (let index = 0; index < currentEntry.value.length; index++) {\n entriesToCheck.push({\n value: currentEntry.value[index],\n path: currentEntry.path.concat(index),\n });\n }\n } else if (\n typeof currentEntry.value === 'object' &&\n currentEntry.value.onStart === undefined\n ) {\n for (const key of Object.keys(currentEntry.value)) {\n entriesToCheck.push({\n value: currentEntry.value[key],\n path: currentEntry.path.concat(key),\n });\n }\n } else {\n const prevAnimation = resolvePath(\n previousAnimation?.styleAnimations,\n currentEntry.path\n );\n let prevVal = resolvePath(value, currentEntry.path);\n if (prevAnimation && !prevVal) {\n prevVal = prevAnimation.current;\n }\n if (prevVal === undefined) {\n console.warn(\n `Initial values for animation are missing for property ${currentEntry.path.join(\n '.'\n )}`\n );\n }\n setPath(animation.current, currentEntry.path, prevVal);\n let currentAnimation: AnimationObject;\n if (\n typeof currentEntry.value !== 'object' ||\n !currentEntry.value.onStart\n ) {\n currentAnimation = withTiming(\n currentEntry.value as AnimatableValue,\n { duration: 0 }\n );\n setPath(\n animation.styleAnimations,\n currentEntry.path,\n currentAnimation\n );\n } else {\n currentAnimation = currentEntry.value as Animation<AnimationObject>;\n }\n currentAnimation.onStart(\n currentAnimation,\n prevVal,\n now,\n prevAnimation\n );\n }\n }\n };\n\n const callback = (finished: boolean): void => {\n if (!finished) {\n const animationsToCheck: NestedObjectValues<AnimationObject>[] = [\n styleAnimations,\n ];\n while (animationsToCheck.length > 0) {\n const currentAnimation: NestedObjectValues<AnimationObject> =\n animationsToCheck.pop() as NestedObjectValues<AnimationObject>;\n if (Array.isArray(currentAnimation)) {\n for (const element of currentAnimation) {\n animationsToCheck.push(element);\n }\n } else if (\n typeof currentAnimation === 'object' &&\n currentAnimation.onStart === undefined\n ) {\n for (const value of Object.values(currentAnimation)) {\n animationsToCheck.push(value);\n }\n } else {\n const currentStyleAnimation: AnimationObject =\n currentAnimation as AnimationObject;\n if (\n !currentStyleAnimation.finished &&\n currentStyleAnimation.callback\n ) {\n currentStyleAnimation.callback(false);\n }\n }\n }\n }\n };\n\n return {\n isHigherOrder: true,\n onFrame,\n onStart,\n current: {},\n styleAnimations,\n callback,\n } as StyleLayoutAnimation;\n });\n}\n"],"mappings":";;;;;;;;;AAAA;;AAWA;;AACA;;AACA;;AAEA;AACA;AACO,SAASA,WAAT,CACLC,GADK,EAELC,IAFK,EAG8B;EACnC;;EACA,MAAMC,IAAuB,GAAGC,KAAK,CAACC,OAAN,CAAcH,IAAd,IAAsBA,IAAtB,GAA6B,CAACA,IAAD,CAA7D;EACA,OAAOC,IAAI,CAACG,MAAL,CAA+C,CAACC,GAAD,EAAMC,OAAN,KAAkB;IACtE,IAAIJ,KAAK,CAACC,OAAN,CAAcE,GAAd,KAAsB,OAAOC,OAAP,KAAmB,QAA7C,EAAuD;MACrD,OAAOD,GAAG,CAACC,OAAD,CAAV;IACD,CAFD,MAEO,IAAI,OAAOD,GAAP,KAAe,QAAf,IAA4BC,OAAD,IAAgCD,GAA/D,EAAoE;MACzE,OAAQA,GAAD,CACLC,OADK,CAAP;IAGD;;IACD,OAAOC,SAAP;EACD,CATM,EASJR,GATI,CAAP;AAUD,C,CAED;;;AAEO,SAASS,OAAT,CACLT,GADK,EAELC,IAFK,EAGLS,KAHK,EAIC;EACN;;EACA,MAAMR,IAAU,GAAGC,KAAK,CAACC,OAAN,CAAcH,IAAd,IAAsBA,IAAtB,GAA6B,CAACA,IAAD,CAAhD;EACA,IAAIU,OAA8B,GAAGX,GAArC;;EACA,KAAK,IAAIY,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGV,IAAI,CAACW,MAAL,GAAc,CAAlC,EAAqCD,CAAC,EAAtC,EAA0C;IACxC;IACAD,OAAO,GAAGA,OAAV;;IACA,IAAI,EAAET,IAAI,CAACU,CAAD,CAAJ,IAAWD,OAAb,CAAJ,EAA2B;MACzB;MACA,IAAI,OAAOT,IAAI,CAACU,CAAC,GAAG,CAAL,CAAX,KAAuB,QAA3B,EAAqC;QACnCD,OAAO,CAACT,IAAI,CAACU,CAAD,CAAL,CAAP,GAAmB,EAAnB;MACD,CAFD,MA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;cACnDG,iBAAiB,CAACpB,IAAlB,CAAuBf,KAAvB;YACD;UACF,CAPM,MAOA;YACL,MAAMmB,qBAAsC,GAC1Ca,gBADF;;YAEA,IACE,CAACb,qBAAqB,CAACC,QAAvB,IACAD,qBAAqB,CAACE,QAFxB,EAGE;cACAF,qBAAqB,CAACE,QAAtB,CAA+B,KAA/B;YACD;UACF;QACF;MACF;IACF,CA/BD;;IAiCA,OAAO;MACLiB,aAAa,EAAE,IADV;MAEL/B,OAFK;MAGLkB,OAHK;MAIL5B,OAAO,EAAE,EAJJ;MAKLQ,eALK;MAMLgB;IANK,CAAP;EAQD,CAxLM,CAAP;AAyLD"}
|
|
1
|
+
{"version":3,"names":["_util","require","_timing","_UpdateProps","_Colors","resolvePath","obj","path","keys","Array","isArray","reduce","acc","current","undefined","setPath","value","currObj","i","length","withStyleAnimation","styleAnimations","defineAnimation","onFrame","animation","now","stillGoing","entriesToCheck","currentEntry","pop","index","push","concat","key","Object","currentStyleAnimation","finished","callback","ColorProperties","includes","processColor","onStart","previousAnimation","prevAnimation","prevVal","console","warn","join","currentAnimation","withTiming","duration","animationsToCheck","element","values","isHigherOrder"],"sources":["styleAnimation.ts"],"sourcesContent":["import { defineAnimation } from './util';\nimport {\n Timestamp,\n AnimatableValue,\n AnimationObject,\n Animation,\n AnimatedStyle,\n NestedObject,\n NestedObjectValues,\n} from '../commonTypes';\nimport { StyleLayoutAnimation } from './commonTypes';\nimport { withTiming } from './timing';\nimport { ColorProperties } from '../UpdateProps';\nimport { processColor } from '../Colors';\n\n// resolves path to value for nested objects\n// if path cannot be resolved returns undefined\nexport function resolvePath<T>(\n obj: NestedObject<T>,\n path: AnimatableValue[] | AnimatableValue\n): NestedObjectValues<T> | undefined {\n 'worklet';\n const keys: AnimatableValue[] = Array.isArray(path) ? path : [path];\n return keys.reduce<NestedObjectValues<T> | undefined>((acc, current) => {\n if (Array.isArray(acc) && typeof current === 'number') {\n return acc[current];\n } else if (\n acc !== null &&\n typeof acc === 'object' &&\n (current as number | string) in acc\n ) {\n return (acc as { [key: string]: NestedObjectValues<T> })[\n current as number | string\n ];\n }\n return undefined;\n }, obj);\n}\n\n// set value at given path\ntype Path = Array<string | number> | string | number;\nexport function setPath<T>(\n obj: NestedObject<T>,\n path: Path,\n value: NestedObjectValues<T>\n): void {\n 'worklet';\n const keys: Path = Array.isArray(path) ? path : [path];\n let currObj: NestedObjectValues<T> = obj;\n for (let i = 0; i < keys.length - 1; i++) {\n // creates entry if there isn't one\n currObj = currObj as { [key: string]: NestedObjectValues<T> };\n if (!(keys[i] in currObj)) {\n // if next key is a number create an array\n if (typeof keys[i + 1] === 'number') {\n currObj[keys[i]] = [];\n } else {\n currObj[keys[i]] = {};\n }\n }\n currObj = currObj[keys[i]];\n }\n\n (currObj as { [key: string]: NestedObjectValues<T> })[keys[keys.length - 1]] =\n value;\n}\n\ninterface NestedObjectEntry<T> {\n value: NestedObjectValues<T>;\n path: (string | number)[];\n}\n\nexport function withStyleAnimation(\n styleAnimations: AnimatedStyle\n): StyleLayoutAnimation {\n 'worklet';\n return defineAnimation<StyleLayoutAnimation>({}, () => {\n 'worklet';\n\n const onFrame = (\n animation: StyleLayoutAnimation,\n now: Timestamp\n ): boolean => {\n let stillGoing = false;\n const entriesToCheck: NestedObjectEntry<AnimationObject>[] = [\n { value: animation.styleAnimations, path: [] },\n ];\n while (entriesToCheck.length > 0) {\n const currentEntry: NestedObjectEntry<AnimationObject> =\n entriesToCheck.pop() as NestedObjectEntry<AnimationObject>;\n if (Array.isArray(currentEntry.value)) {\n for (let index = 0; index < currentEntry.value.length; index++) {\n entriesToCheck.push({\n value: currentEntry.value[index],\n path: currentEntry.path.concat(index),\n });\n }\n } else if (\n typeof currentEntry.value === 'object' &&\n currentEntry.value.onFrame === undefined\n ) {\n // nested object\n for (const key of Object.keys(currentEntry.value)) {\n entriesToCheck.push({\n value: currentEntry.value[key],\n path: currentEntry.path.concat(key),\n });\n }\n } else {\n const currentStyleAnimation: AnimationObject =\n currentEntry.value as AnimationObject;\n if (currentStyleAnimation.finished) {\n continue;\n }\n const finished = currentStyleAnimation.onFrame(\n currentStyleAnimation,\n now\n );\n if (finished) {\n currentStyleAnimation.finished = true;\n if (currentStyleAnimation.callback) {\n currentStyleAnimation.callback(true);\n }\n } else {\n stillGoing = true;\n }\n\n if (ColorProperties.includes(currentEntry.path[0] as string)) {\n currentStyleAnimation.current = processColor(\n currentStyleAnimation.current\n ) as number;\n }\n\n setPath(\n animation.current,\n currentEntry.path,\n currentStyleAnimation.current\n );\n }\n }\n return !stillGoing;\n };\n\n const onStart = (\n animation: StyleLayoutAnimation,\n value: AnimatedStyle,\n now: Timestamp,\n previousAnimation: StyleLayoutAnimation\n ): void => {\n const entriesToCheck: NestedObjectEntry<\n AnimationObject | AnimatableValue\n >[] = [{ value: styleAnimations, path: [] }];\n while (entriesToCheck.length > 0) {\n const currentEntry: NestedObjectEntry<\n AnimationObject | AnimatableValue\n > = entriesToCheck.pop() as NestedObjectEntry<\n AnimationObject | AnimatableValue\n >;\n if (Array.isArray(currentEntry.value)) {\n for (let index = 0; index < currentEntry.value.length; index++) {\n entriesToCheck.push({\n value: currentEntry.value[index],\n path: currentEntry.path.concat(index),\n });\n }\n } else if (\n typeof currentEntry.value === 'object' &&\n currentEntry.value.onStart === undefined\n ) {\n for (const key of Object.keys(currentEntry.value)) {\n entriesToCheck.push({\n value: currentEntry.value[key],\n path: currentEntry.path.concat(key),\n });\n }\n } else {\n const prevAnimation = resolvePath(\n previousAnimation?.styleAnimations,\n currentEntry.path\n );\n let prevVal = resolvePath(value, currentEntry.path);\n if (prevAnimation && !prevVal) {\n prevVal = prevAnimation.current;\n }\n if (prevVal === undefined) {\n console.warn(\n `Initial values for animation are missing for property ${currentEntry.path.join(\n '.'\n )}`\n );\n }\n setPath(animation.current, currentEntry.path, prevVal);\n let currentAnimation: AnimationObject;\n if (\n typeof currentEntry.value !== 'object' ||\n !currentEntry.value.onStart\n ) {\n currentAnimation = withTiming(\n currentEntry.value as AnimatableValue,\n { duration: 0 }\n );\n setPath(\n animation.styleAnimations,\n currentEntry.path,\n currentAnimation\n );\n } else {\n currentAnimation = currentEntry.value as Animation<AnimationObject>;\n }\n currentAnimation.onStart(\n currentAnimation,\n prevVal,\n now,\n prevAnimation\n );\n }\n }\n };\n\n const callback = (finished: boolean): void => {\n if (!finished) {\n const animationsToCheck: NestedObjectValues<AnimationObject>[] = [\n styleAnimations,\n ];\n while (animationsToCheck.length > 0) {\n const currentAnimation: NestedObjectValues<AnimationObject> =\n animationsToCheck.pop() as NestedObjectValues<AnimationObject>;\n if (Array.isArray(currentAnimation)) {\n for (const element of currentAnimation) {\n animationsToCheck.push(element);\n }\n } else if (\n typeof currentAnimation === 'object' &&\n currentAnimation.onStart === undefined\n ) {\n for (const value of Object.values(currentAnimation)) {\n animationsToCheck.push(value);\n }\n } else {\n const currentStyleAnimation: AnimationObject =\n currentAnimation as AnimationObject;\n if (\n !currentStyleAnimation.finished &&\n currentStyleAnimation.callback\n ) {\n currentStyleAnimation.callback(false);\n }\n }\n }\n }\n };\n\n return {\n isHigherOrder: true,\n onFrame,\n onStart,\n current: {},\n styleAnimations,\n callback,\n } as StyleLayoutAnimation;\n });\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAWA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAEA;AACA;AACO,SAASI,WAAWA,CACzBC,GAAoB,EACpBC,IAAyC,EACN;EACnC,SAAS;;EACT,MAAMC,IAAuB,GAAGC,KAAK,CAACC,OAAO,CAACH,IAAI,CAAC,GAAGA,IAAI,GAAG,CAACA,IAAI,CAAC;EACnE,OAAOC,IAAI,CAACG,MAAM,CAAoC,CAACC,GAAG,EAAEC,OAAO,KAAK;IACtE,IAAIJ,KAAK,CAACC,OAAO,CAACE,GAAG,CAAC,IAAI,OAAOC,OAAO,KAAK,QAAQ,EAAE;MAC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6
6
|
exports.withTiming = withTiming;
|
|
7
|
-
|
|
8
7
|
var _Easing = require("../Easing");
|
|
9
|
-
|
|
10
8
|
var _util = require("./util");
|
|
11
|
-
|
|
12
9
|
function withTiming(toValue, userConfig, callback) {
|
|
13
10
|
'worklet';
|
|
14
11
|
|
|
@@ -19,11 +16,9 @@ function withTiming(toValue, userConfig, callback) {
|
|
|
19
16
|
duration: 300,
|
|
20
17
|
easing: _Easing.Easing.inOut(_Easing.Easing.quad)
|
|
21
18
|
};
|
|
22
|
-
|
|
23
19
|
if (userConfig) {
|
|
24
20
|
Object.keys(userConfig).forEach(key => config[key] = userConfig[key]);
|
|
25
21
|
}
|
|
26
|
-
|
|
27
22
|
function timing(animation, now) {
|
|
28
23
|
const {
|
|
29
24
|
toValue,
|
|
@@ -31,19 +26,16 @@ function withTiming(toValue, userConfig, callback) {
|
|
|
31
26
|
startValue
|
|
32
27
|
} = animation;
|
|
33
28
|
const runtime = now - startTime;
|
|
34
|
-
|
|
35
29
|
if (runtime >= config.duration) {
|
|
36
30
|
// reset startTime to avoid reusing finished animation config in `start` method
|
|
37
31
|
animation.startTime = 0;
|
|
38
32
|
animation.current = toValue;
|
|
39
33
|
return true;
|
|
40
34
|
}
|
|
41
|
-
|
|
42
35
|
const progress = animation.easing(runtime / config.duration);
|
|
43
36
|
animation.current = startValue + (toValue - startValue) * progress;
|
|
44
37
|
return false;
|
|
45
38
|
}
|
|
46
|
-
|
|
47
39
|
function onStart(animation, value, now, previousAnimation) {
|
|
48
40
|
if (previousAnimation && previousAnimation.type === 'timing' && previousAnimation.toValue === toValue && previousAnimation.startTime) {
|
|
49
41
|
// to maintain continuity of timing animations we check if we are starting
|
|
@@ -55,16 +47,13 @@ function withTiming(toValue, userConfig, callback) {
|
|
|
55
47
|
animation.startTime = now;
|
|
56
48
|
animation.startValue = value;
|
|
57
49
|
}
|
|
58
|
-
|
|
59
50
|
animation.current = value;
|
|
60
|
-
|
|
61
51
|
if (typeof config.easing === 'object') {
|
|
62
52
|
animation.easing = config.easing.factory();
|
|
63
53
|
} else {
|
|
64
54
|
animation.easing = config.easing;
|
|
65
55
|
}
|
|
66
56
|
}
|
|
67
|
-
|
|
68
57
|
return {
|
|
69
58
|
type: 'timing',
|
|
70
59
|
onFrame: timing,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["withTiming","toValue","userConfig","callback","defineAnimation","config","duration","easing","Easing","inOut","quad","Object","keys","forEach","key","timing","animation","now","startTime","startValue","runtime","current","progress","onStart","value","previousAnimation","type","factory","onFrame"],"sources":["timing.ts"],"sourcesContent":["import { Easing, EasingFn, EasingFactoryFn } from '../Easing';\nimport { defineAnimation } from './util';\nimport {\n Animation,\n AnimationCallback,\n Timestamp,\n AnimatableValue,\n} from '../commonTypes';\n\ninterface TimingConfig {\n duration?: number;\n easing?: EasingFn | EasingFactoryFn;\n}\n\nexport interface TimingAnimation extends Animation<TimingAnimation> {\n type: string;\n easing: EasingFn;\n startValue: AnimatableValue;\n startTime: Timestamp;\n progress: number;\n toValue: AnimatableValue;\n current: AnimatableValue;\n}\n\nexport interface InnerTimingAnimation\n extends Omit<TimingAnimation, 'toValue' | 'current'> {\n toValue: number;\n current: number;\n}\n\nexport function withTiming(\n toValue: AnimatableValue,\n userConfig?: TimingConfig,\n callback?: AnimationCallback\n): Animation<TimingAnimation> {\n 'worklet';\n\n return defineAnimation<TimingAnimation>(toValue, () => {\n 'worklet';\n const config: Required<TimingConfig> = {\n duration: 300,\n easing: Easing.inOut(Easing.quad),\n };\n if (userConfig) {\n Object.keys(userConfig).forEach(\n (key) =>\n ((config as any)[key] = userConfig[key as keyof typeof userConfig])\n );\n }\n\n function timing(animation: InnerTimingAnimation, now: Timestamp): boolean {\n const { toValue, startTime, startValue } = animation;\n const runtime = now - startTime;\n\n if (runtime >= config.duration) {\n // reset startTime to avoid reusing finished animation config in `start` method\n animation.startTime = 0;\n animation.current = toValue;\n return true;\n }\n const progress = animation.easing(runtime / config.duration);\n animation.current =\n (startValue as number) + (toValue - (startValue as number)) * progress;\n return false;\n }\n\n function onStart(\n animation: TimingAnimation,\n value: number,\n now: Timestamp,\n previousAnimation: Animation<TimingAnimation>\n ): void {\n if (\n previousAnimation &&\n (previousAnimation as TimingAnimation).type === 'timing' &&\n (previousAnimation as TimingAnimation).toValue === toValue &&\n (previousAnimation as TimingAnimation).startTime\n ) {\n // to maintain continuity of timing animations we check if we are starting\n // new timing over the old one with the same parameters. If so, we want\n // to copy animation timeline properties\n animation.startTime = (previousAnimation as TimingAnimation).startTime;\n animation.startValue = (\n previousAnimation as TimingAnimation\n ).startValue;\n } else {\n animation.startTime = now;\n animation.startValue = value;\n }\n animation.current = value;\n if (typeof config.easing === 'object') {\n animation.easing = config.easing.factory();\n } else {\n animation.easing = config.easing;\n }\n }\n\n return {\n type: 'timing',\n onFrame: timing,\n onStart: onStart as (animation: TimingAnimation, now: number) => boolean,\n progress: 0,\n toValue,\n startValue: 0,\n startTime: 0,\n easing: () => 0,\n current: toValue,\n callback,\n } as TimingAnimation;\n });\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_Easing","require","_util","withTiming","toValue","userConfig","callback","defineAnimation","config","duration","easing","Easing","inOut","quad","Object","keys","forEach","key","timing","animation","now","startTime","startValue","runtime","current","progress","onStart","value","previousAnimation","type","factory","onFrame"],"sources":["timing.ts"],"sourcesContent":["import { Easing, EasingFn, EasingFactoryFn } from '../Easing';\nimport { defineAnimation } from './util';\nimport {\n Animation,\n AnimationCallback,\n Timestamp,\n AnimatableValue,\n} from '../commonTypes';\n\ninterface TimingConfig {\n duration?: number;\n easing?: EasingFn | EasingFactoryFn;\n}\n\nexport interface TimingAnimation extends Animation<TimingAnimation> {\n type: string;\n easing: EasingFn;\n startValue: AnimatableValue;\n startTime: Timestamp;\n progress: number;\n toValue: AnimatableValue;\n current: AnimatableValue;\n}\n\nexport interface InnerTimingAnimation\n extends Omit<TimingAnimation, 'toValue' | 'current'> {\n toValue: number;\n current: number;\n}\n\nexport function withTiming(\n toValue: AnimatableValue,\n userConfig?: TimingConfig,\n callback?: AnimationCallback\n): Animation<TimingAnimation> {\n 'worklet';\n\n return defineAnimation<TimingAnimation>(toValue, () => {\n 'worklet';\n const config: Required<TimingConfig> = {\n duration: 300,\n easing: Easing.inOut(Easing.quad),\n };\n if (userConfig) {\n Object.keys(userConfig).forEach(\n (key) =>\n ((config as any)[key] = userConfig[key as keyof typeof userConfig])\n );\n }\n\n function timing(animation: InnerTimingAnimation, now: Timestamp): boolean {\n const { toValue, startTime, startValue } = animation;\n const runtime = now - startTime;\n\n if (runtime >= config.duration) {\n // reset startTime to avoid reusing finished animation config in `start` method\n animation.startTime = 0;\n animation.current = toValue;\n return true;\n }\n const progress = animation.easing(runtime / config.duration);\n animation.current =\n (startValue as number) + (toValue - (startValue as number)) * progress;\n return false;\n }\n\n function onStart(\n animation: TimingAnimation,\n value: number,\n now: Timestamp,\n previousAnimation: Animation<TimingAnimation>\n ): void {\n if (\n previousAnimation &&\n (previousAnimation as TimingAnimation).type === 'timing' &&\n (previousAnimation as TimingAnimation).toValue === toValue &&\n (previousAnimation as TimingAnimation).startTime\n ) {\n // to maintain continuity of timing animations we check if we are starting\n // new timing over the old one with the same parameters. If so, we want\n // to copy animation timeline properties\n animation.startTime = (previousAnimation as TimingAnimation).startTime;\n animation.startValue = (\n previousAnimation as TimingAnimation\n ).startValue;\n } else {\n animation.startTime = now;\n animation.startValue = value;\n }\n animation.current = value;\n if (typeof config.easing === 'object') {\n animation.easing = config.easing.factory();\n } else {\n animation.easing = config.easing;\n }\n }\n\n return {\n type: 'timing',\n onFrame: timing,\n onStart: onStart as (animation: TimingAnimation, now: number) => boolean,\n progress: 0,\n toValue,\n startValue: 0,\n startTime: 0,\n easing: () => 0,\n current: toValue,\n callback,\n } as TimingAnimation;\n });\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AA6BO,SAASE,UAAUA,CACxBC,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