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
|
@@ -8,19 +8,22 @@ export function withDecay(userConfig, callback) {
|
|
|
8
8
|
|
|
9
9
|
const config = {
|
|
10
10
|
deceleration: 0.998,
|
|
11
|
-
velocityFactor:
|
|
11
|
+
velocityFactor: 1,
|
|
12
12
|
velocity: 0,
|
|
13
13
|
rubberBandFactor: 0.6
|
|
14
14
|
};
|
|
15
|
-
|
|
16
15
|
if (userConfig) {
|
|
17
16
|
Object.keys(userConfig).forEach(key => config[key] = userConfig[key]);
|
|
18
17
|
}
|
|
19
|
-
|
|
20
18
|
const VELOCITY_EPS = Platform.OS !== 'web' ? 1 : 1 / 20;
|
|
21
19
|
const SLOPE_FACTOR = 0.1;
|
|
22
|
-
let decay;
|
|
23
20
|
|
|
21
|
+
// @piaskowyk: Velocity is expressed in pixels per second
|
|
22
|
+
// but pixels on Web are handled differently than on native
|
|
23
|
+
if (Platform.OS === 'web') {
|
|
24
|
+
config.velocity *= 1000;
|
|
25
|
+
}
|
|
26
|
+
let decay;
|
|
24
27
|
if (config.rubberBandEffect) {
|
|
25
28
|
decay = (animation, now) => {
|
|
26
29
|
const {
|
|
@@ -33,18 +36,15 @@ export function withDecay(userConfig, callback) {
|
|
|
33
36
|
const deltaTime = Math.min(now - lastTimestamp, 64);
|
|
34
37
|
const clampIndex = initialVelocity > 0 ? 1 : 0;
|
|
35
38
|
let derivative = 0;
|
|
36
|
-
|
|
37
39
|
if (current < config.clamp[0] || current > config.clamp[1]) {
|
|
38
40
|
derivative = current - config.clamp[clampIndex];
|
|
39
41
|
}
|
|
40
|
-
|
|
41
42
|
if (derivative !== 0) {
|
|
42
43
|
animation.springActive = true;
|
|
43
44
|
} else if (derivative === 0 && animation.springActive) {
|
|
44
45
|
animation.current = config.clamp[clampIndex];
|
|
45
46
|
return true;
|
|
46
47
|
}
|
|
47
|
-
|
|
48
48
|
const v = velocity * Math.exp(-(1 - config.deceleration) * (now - startTimestamp) * SLOPE_FACTOR) - derivative * config.rubberBandFactor;
|
|
49
49
|
animation.current = current + v * config.velocityFactor * deltaTime / 1000;
|
|
50
50
|
animation.velocity = v;
|
|
@@ -65,7 +65,6 @@ export function withDecay(userConfig, callback) {
|
|
|
65
65
|
animation.current = current + v * config.velocityFactor * deltaTime / 1000;
|
|
66
66
|
animation.velocity = v;
|
|
67
67
|
animation.lastTimestamp = now;
|
|
68
|
-
|
|
69
68
|
if (config.clamp) {
|
|
70
69
|
if (initialVelocity < 0 && animation.current <= config.clamp[0]) {
|
|
71
70
|
animation.current = config.clamp[0];
|
|
@@ -75,31 +74,25 @@ export function withDecay(userConfig, callback) {
|
|
|
75
74
|
return true;
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
|
-
|
|
79
77
|
return Math.abs(v) < VELOCITY_EPS;
|
|
80
78
|
};
|
|
81
79
|
}
|
|
82
|
-
|
|
83
80
|
function validateConfig() {
|
|
84
81
|
if (config.clamp) {
|
|
85
82
|
if (!Array.isArray(config.clamp)) {
|
|
86
83
|
throw Error(`config.clamp must be an array but is ${typeof config.clamp}`);
|
|
87
84
|
}
|
|
88
|
-
|
|
89
85
|
if (config.clamp.length !== 2) {
|
|
90
86
|
throw Error(`clamp array must contain 2 items but is given ${config.clamp.length}`);
|
|
91
87
|
}
|
|
92
88
|
}
|
|
93
|
-
|
|
94
89
|
if (config.velocityFactor <= 0) {
|
|
95
90
|
throw Error(`config.velocityFactor must be greather then 0 but is ${config.velocityFactor}`);
|
|
96
91
|
}
|
|
97
|
-
|
|
98
92
|
if (config.rubberBandEffect && !config.clamp) {
|
|
99
93
|
throw Error('You need to set `clamp` property when using `rubberBandEffect`.');
|
|
100
94
|
}
|
|
101
95
|
}
|
|
102
|
-
|
|
103
96
|
function onStart(animation, value, now) {
|
|
104
97
|
animation.current = value;
|
|
105
98
|
animation.lastTimestamp = now;
|
|
@@ -107,7 +100,6 @@ export function withDecay(userConfig, callback) {
|
|
|
107
100
|
animation.initialVelocity = config.velocity;
|
|
108
101
|
validateConfig();
|
|
109
102
|
}
|
|
110
|
-
|
|
111
103
|
return {
|
|
112
104
|
onFrame: decay,
|
|
113
105
|
onStart,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["defineAnimation","Platform","withDecay","userConfig","callback","config","deceleration","velocityFactor","
|
|
1
|
+
{"version":3,"names":["defineAnimation","Platform","withDecay","userConfig","callback","config","deceleration","velocityFactor","velocity","rubberBandFactor","Object","keys","forEach","key","VELOCITY_EPS","OS","SLOPE_FACTOR","decay","rubberBandEffect","animation","now","lastTimestamp","startTimestamp","current","initialVelocity","deltaTime","Math","min","clampIndex","derivative","clamp","springActive","v","exp","abs","validateConfig","Array","isArray","Error","length","onStart","value","onFrame"],"sources":["decay.ts"],"sourcesContent":["import { defineAnimation } from './util';\nimport {\n Animation,\n AnimationCallback,\n AnimationObject,\n AnimatableValue,\n Timestamp,\n} from '../commonTypes';\nimport { Platform } from 'react-native';\n\ninterface DecayConfig {\n deceleration?: number;\n velocityFactor?: number;\n clamp?: number[];\n velocity?: number;\n}\n\ninterface DefaultDecayConfig {\n deceleration: number;\n velocityFactor: number;\n clamp?: number[];\n velocity: number;\n rubberBandEffect?: boolean;\n rubberBandFactor: number;\n}\n\nexport interface DecayAnimation extends Animation<DecayAnimation> {\n lastTimestamp: Timestamp;\n startTimestamp: Timestamp;\n initialVelocity: number;\n velocity: number;\n current: AnimatableValue;\n}\n\nexport interface InnerDecayAnimation\n extends Omit<DecayAnimation, 'current'>,\n AnimationObject {\n current: number;\n}\n\nexport function withDecay(\n userConfig: DecayConfig,\n callback?: AnimationCallback\n): Animation<DecayAnimation> {\n 'worklet';\n\n return defineAnimation<DecayAnimation>(0, () => {\n 'worklet';\n const config: DefaultDecayConfig = {\n deceleration: 0.998,\n velocityFactor: 1,\n velocity: 0,\n rubberBandFactor: 0.6,\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 const VELOCITY_EPS = Platform.OS !== 'web' ? 1 : 1 / 20;\n const SLOPE_FACTOR = 0.1;\n\n // @piaskowyk: Velocity is expressed in pixels per second\n // but pixels on Web are handled differently than on native\n if (Platform.OS === 'web') {\n config.velocity *= 1000;\n }\n\n let decay: (animation: InnerDecayAnimation, now: number) => boolean;\n\n if (config.rubberBandEffect) {\n decay = (animation: InnerDecayAnimation, now: number): boolean => {\n const {\n lastTimestamp,\n startTimestamp,\n current,\n initialVelocity,\n velocity,\n } = animation;\n\n const deltaTime = Math.min(now - lastTimestamp, 64);\n const clampIndex = initialVelocity > 0 ? 1 : 0;\n let derivative = 0;\n if (current < config.clamp![0] || current > config.clamp![1]) {\n derivative = current - config.clamp![clampIndex];\n }\n\n if (derivative !== 0) {\n animation.springActive = true;\n } else if (derivative === 0 && animation.springActive) {\n animation.current = config.clamp![clampIndex];\n return true;\n }\n\n const v =\n velocity *\n Math.exp(\n -(1 - config.deceleration) * (now - startTimestamp) * SLOPE_FACTOR\n ) -\n derivative * config.rubberBandFactor;\n\n animation.current =\n current + (v * config.velocityFactor * deltaTime) / 1000;\n animation.velocity = v;\n animation.lastTimestamp = now;\n return false;\n };\n } else {\n decay = (animation: InnerDecayAnimation, now: number): boolean => {\n const {\n lastTimestamp,\n startTimestamp,\n initialVelocity,\n current,\n velocity,\n } = animation;\n\n const deltaTime = Math.min(now - lastTimestamp, 64);\n const v =\n velocity *\n Math.exp(\n -(1 - config.deceleration) * (now - startTimestamp) * SLOPE_FACTOR\n );\n animation.current =\n current + (v * config.velocityFactor * deltaTime) / 1000;\n animation.velocity = v;\n animation.lastTimestamp = now;\n\n if (config.clamp) {\n if (initialVelocity < 0 && animation.current <= config.clamp[0]) {\n animation.current = config.clamp[0];\n return true;\n } else if (\n initialVelocity > 0 &&\n animation.current >= config.clamp[1]\n ) {\n animation.current = config.clamp[1];\n return true;\n }\n }\n\n return Math.abs(v) < VELOCITY_EPS;\n };\n }\n\n function validateConfig(): void {\n if (config.clamp) {\n if (!Array.isArray(config.clamp)) {\n throw Error(\n `config.clamp must be an array but is ${typeof config.clamp}`\n );\n }\n if (config.clamp.length !== 2) {\n throw Error(\n `clamp array must contain 2 items but is given ${config.clamp.length}`\n );\n }\n }\n if (config.velocityFactor <= 0) {\n throw Error(\n `config.velocityFactor must be greather then 0 but is ${config.velocityFactor}`\n );\n }\n if (config.rubberBandEffect && !config.clamp) {\n throw Error(\n 'You need to set `clamp` property when using `rubberBandEffect`.'\n );\n }\n }\n\n function onStart(\n animation: DecayAnimation,\n value: number,\n now: Timestamp\n ): void {\n animation.current = value;\n animation.lastTimestamp = now;\n animation.startTimestamp = now;\n animation.initialVelocity = config.velocity;\n validateConfig();\n }\n\n return {\n onFrame: decay,\n onStart,\n callback,\n velocity: config.velocity ?? 0,\n initialVelocity: 0,\n current: 0,\n lastTimestamp: 0,\n start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AACa,gBAAgB,IAAI,CAACb,MAAM,CAACyB,KAAK,EAAE;QAC5C,MAAMQ,KAAK,CACT,iEAAiE,CAClE;MACH;IACF;IAEA,SAASE,OAAOA,CACdrB,SAAyB,EACzBsB,KAAa,EACbrB,GAAc,EACR;MACND,SAAS,CAACI,OAAO,GAAGkB,KAAK;MACzBtB,SAAS,CAACE,aAAa,GAAGD,GAAG;MAC7BD,SAAS,CAACG,cAAc,GAAGF,GAAG;MAC9BD,SAAS,CAACK,eAAe,GAAGnB,MAAM,CAACG,QAAQ;MAC3C2B,cAAc,EAAE;IAClB;IAEA,OAAO;MACLO,OAAO,EAAEzB,KAAK;MACduB,OAAO;MACPpC,QAAQ;MACRI,QAAQ,EAAEH,MAAM,CAACG,QAAQ,IAAI,CAAC;MAC9BgB,eAAe,EAAE,CAAC;MAClBD,OAAO,EAAE,CAAC;MACVF,aAAa,EAAE,CAAC;MAChBC,cAAc,EAAE;IAClB,CAAC;EACH,CAAC,CAAC;AACJ"}
|
|
@@ -6,54 +6,45 @@ export function withDelay(delayMs, _nextAnimation) {
|
|
|
6
6
|
'worklet';
|
|
7
7
|
|
|
8
8
|
const nextAnimation = typeof _nextAnimation === 'function' ? _nextAnimation() : _nextAnimation;
|
|
9
|
-
|
|
10
9
|
function delay(animation, now) {
|
|
11
10
|
const {
|
|
12
11
|
startTime,
|
|
13
12
|
started,
|
|
14
13
|
previousAnimation
|
|
15
14
|
} = animation;
|
|
16
|
-
|
|
17
15
|
if (now - startTime > delayMs) {
|
|
18
16
|
if (!started) {
|
|
19
17
|
nextAnimation.onStart(nextAnimation, animation.current, now, previousAnimation);
|
|
20
18
|
animation.previousAnimation = null;
|
|
21
19
|
animation.started = true;
|
|
22
20
|
}
|
|
23
|
-
|
|
24
21
|
const finished = nextAnimation.onFrame(nextAnimation, now);
|
|
25
22
|
animation.current = nextAnimation.current;
|
|
26
23
|
return finished;
|
|
27
24
|
} else if (previousAnimation) {
|
|
28
25
|
const finished = previousAnimation.finished || previousAnimation.onFrame(previousAnimation, now);
|
|
29
26
|
animation.current = previousAnimation.current;
|
|
30
|
-
|
|
31
27
|
if (finished) {
|
|
32
28
|
animation.previousAnimation = null;
|
|
33
29
|
}
|
|
34
30
|
}
|
|
35
|
-
|
|
36
31
|
return false;
|
|
37
32
|
}
|
|
38
|
-
|
|
39
33
|
function onStart(animation, value, now, previousAnimation) {
|
|
40
34
|
animation.startTime = now;
|
|
41
35
|
animation.started = false;
|
|
42
36
|
animation.current = value;
|
|
43
|
-
|
|
44
37
|
if (previousAnimation === animation) {
|
|
45
38
|
animation.previousAnimation = previousAnimation.previousAnimation;
|
|
46
39
|
} else {
|
|
47
40
|
animation.previousAnimation = previousAnimation;
|
|
48
41
|
}
|
|
49
42
|
}
|
|
50
|
-
|
|
51
43
|
const callback = finished => {
|
|
52
44
|
if (nextAnimation.callback) {
|
|
53
45
|
nextAnimation.callback(finished);
|
|
54
46
|
}
|
|
55
47
|
};
|
|
56
|
-
|
|
57
48
|
return {
|
|
58
49
|
isHigherOrder: true,
|
|
59
50
|
onFrame: delay,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["defineAnimation","withDelay","delayMs","_nextAnimation","nextAnimation","delay","animation","now","startTime","started","previousAnimation","onStart","current","finished","onFrame","value","callback","isHigherOrder"],"sources":["delay.ts"],"sourcesContent":["import { defineAnimation } from './util';\nimport { Animation, Timestamp, AnimatableValue } from '../commonTypes';\nimport { NextAnimation, DelayAnimation } from './commonTypes';\n\nexport function withDelay(\n delayMs: number,\n _nextAnimation: NextAnimation<DelayAnimation>\n): Animation<DelayAnimation> {\n 'worklet';\n return defineAnimation<DelayAnimation>(_nextAnimation, () => {\n 'worklet';\n const nextAnimation =\n typeof _nextAnimation === 'function' ? _nextAnimation() : _nextAnimation;\n\n function delay(animation: DelayAnimation, now: Timestamp): boolean {\n const { startTime, started, previousAnimation } = animation;\n\n if (now - startTime > delayMs) {\n if (!started) {\n nextAnimation.onStart(\n nextAnimation,\n animation.current,\n now,\n previousAnimation as DelayAnimation\n );\n animation.previousAnimation = null;\n animation.started = true;\n }\n const finished = nextAnimation.onFrame(nextAnimation, now);\n animation.current = nextAnimation.current;\n return finished;\n } else if (previousAnimation) {\n const finished =\n previousAnimation.finished ||\n previousAnimation.onFrame(previousAnimation, now);\n animation.current = previousAnimation.current;\n if (finished) {\n animation.previousAnimation = null;\n }\n }\n return false;\n }\n\n function onStart(\n animation: DelayAnimation,\n value: AnimatableValue,\n now: Timestamp,\n previousAnimation: DelayAnimation\n ): void {\n animation.startTime = now;\n animation.started = false;\n animation.current = value;\n if (previousAnimation === animation) {\n animation.previousAnimation = previousAnimation.previousAnimation;\n } else {\n animation.previousAnimation = previousAnimation;\n }\n }\n\n const callback = (finished?: boolean): void => {\n if (nextAnimation.callback) {\n nextAnimation.callback(finished);\n }\n };\n\n return {\n isHigherOrder: true,\n onFrame: delay,\n onStart,\n current: nextAnimation.current,\n callback,\n previousAnimation: null,\n startTime: 0,\n started: false,\n };\n });\n}\n"],"mappings":"AAAA,SAASA,
|
|
1
|
+
{"version":3,"names":["defineAnimation","withDelay","delayMs","_nextAnimation","nextAnimation","delay","animation","now","startTime","started","previousAnimation","onStart","current","finished","onFrame","value","callback","isHigherOrder"],"sources":["delay.ts"],"sourcesContent":["import { defineAnimation } from './util';\nimport { Animation, Timestamp, AnimatableValue } from '../commonTypes';\nimport { NextAnimation, DelayAnimation } from './commonTypes';\n\nexport function withDelay(\n delayMs: number,\n _nextAnimation: NextAnimation<DelayAnimation>\n): Animation<DelayAnimation> {\n 'worklet';\n return defineAnimation<DelayAnimation>(_nextAnimation, () => {\n 'worklet';\n const nextAnimation =\n typeof _nextAnimation === 'function' ? _nextAnimation() : _nextAnimation;\n\n function delay(animation: DelayAnimation, now: Timestamp): boolean {\n const { startTime, started, previousAnimation } = animation;\n\n if (now - startTime > delayMs) {\n if (!started) {\n nextAnimation.onStart(\n nextAnimation,\n animation.current,\n now,\n previousAnimation as DelayAnimation\n );\n animation.previousAnimation = null;\n animation.started = true;\n }\n const finished = nextAnimation.onFrame(nextAnimation, now);\n animation.current = nextAnimation.current;\n return finished;\n } else if (previousAnimation) {\n const finished =\n previousAnimation.finished ||\n previousAnimation.onFrame(previousAnimation, now);\n animation.current = previousAnimation.current;\n if (finished) {\n animation.previousAnimation = null;\n }\n }\n return false;\n }\n\n function onStart(\n animation: DelayAnimation,\n value: AnimatableValue,\n now: Timestamp,\n previousAnimation: DelayAnimation\n ): void {\n animation.startTime = now;\n animation.started = false;\n animation.current = value;\n if (previousAnimation === animation) {\n animation.previousAnimation = previousAnimation.previousAnimation;\n } else {\n animation.previousAnimation = previousAnimation;\n }\n }\n\n const callback = (finished?: boolean): void => {\n if (nextAnimation.callback) {\n nextAnimation.callback(finished);\n }\n };\n\n return {\n isHigherOrder: true,\n onFrame: delay,\n onStart,\n current: nextAnimation.current,\n callback,\n previousAnimation: null,\n startTime: 0,\n started: false,\n };\n });\n}\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,QAAQ;AAIxC,OAAO,SAASC,SAASA,CACvBC,OAAe,EACfC,cAA6C,EAClB;EAC3B,SAAS;;EACT,OAAOH,eAAe,CAAiBG,cAAc,EAAE,MAAM;IAC3D,SAAS;;IACT,MAAMC,aAAa,GACjB,OAAOD,cAAc,KAAK,UAAU,GAAGA,cAAc,EAAE,GAAGA,cAAc;IAE1E,SAASE,KAAKA,CAACC,SAAyB,EAAEC,GAAc,EAAW;MACjE,MAAM;QAAEC,SAAS;QAAEC,OAAO;QAAEC;MAAkB,CAAC,GAAGJ,SAAS;MAE3D,IAAIC,GAAG,GAAGC,SAAS,GAAGN,OAAO,EAAE;QAC7B,IAAI,CAACO,OAAO,EAAE;UACZL,aAAa,CAACO,OAAO,CACnBP,aAAa,EACbE,SAAS,CAACM,OAAO,EACjBL,GAAG,EACHG,iBAAiB,CAClB;UACDJ,SAAS,CAACI,iBAAiB,GAAG,IAAI;UAClCJ,SAAS,CAACG,OAAO,GAAG,IAAI;QAC1B;QAC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version":3,"names":["cancelAnimation","defineAnimation","initialUpdaterRun","withTiming","withSpring","withDecay","withDelay","withRepeat","withSequence","withStyleAnimation"],"sources":["index.ts"],"sourcesContent":["export type {\n HigherOrderAnimation,\n NextAnimation,\n DelayAnimation,\n RepeatAnimation,\n SequenceAnimation,\n StyleLayoutAnimation,\n} from './commonTypes';\nexport { cancelAnimation, defineAnimation, initialUpdaterRun } from './util';\nexport { withTiming } from './timing';\nexport type { TimingAnimation } from './timing';\nexport { withSpring } from './spring';\nexport type { SpringAnimation } from './spring';\nexport { withDecay } from './decay';\nexport type { DecayAnimation } from './decay';\nexport { withDelay } from './delay';\nexport { withRepeat } from './repeat';\nexport { withSequence } from './sequence';\nexport { withStyleAnimation } from './styleAnimation';\n"],"mappings":"AAQA,SAASA,
|
|
1
|
+
{"version":3,"names":["cancelAnimation","defineAnimation","initialUpdaterRun","withTiming","withSpring","withDecay","withDelay","withRepeat","withSequence","withStyleAnimation"],"sources":["index.ts"],"sourcesContent":["export type {\n HigherOrderAnimation,\n NextAnimation,\n DelayAnimation,\n RepeatAnimation,\n SequenceAnimation,\n StyleLayoutAnimation,\n} from './commonTypes';\nexport { cancelAnimation, defineAnimation, initialUpdaterRun } from './util';\nexport { withTiming } from './timing';\nexport type { TimingAnimation } from './timing';\nexport { withSpring } from './spring';\nexport type { SpringAnimation } from './spring';\nexport { withDecay } from './decay';\nexport type { DecayAnimation } from './decay';\nexport { withDelay } from './delay';\nexport { withRepeat } from './repeat';\nexport { withSequence } from './sequence';\nexport { withStyleAnimation } from './styleAnimation';\n"],"mappings":"AAQA,SAASA,eAAe,EAAEC,eAAe,EAAEC,iBAAiB,QAAQ,QAAQ;AAC5E,SAASC,UAAU,QAAQ,UAAU;AAErC,SAASC,UAAU,QAAQ,UAAU;AAErC,SAASC,SAAS,QAAQ,SAAS;AAEnC,SAASC,SAAS,QAAQ,SAAS;AACnC,SAASC,UAAU,QAAQ,UAAU;AACrC,SAASC,YAAY,QAAQ,YAAY;AACzC,SAASC,kBAAkB,QAAQ,kBAAkB"}
|
|
@@ -9,49 +9,36 @@ export function withRepeat(_nextAnimation) {
|
|
|
9
9
|
'worklet';
|
|
10
10
|
|
|
11
11
|
const nextAnimation = typeof _nextAnimation === 'function' ? _nextAnimation() : _nextAnimation;
|
|
12
|
-
|
|
13
12
|
function repeat(animation, now) {
|
|
14
13
|
const finished = nextAnimation.onFrame(nextAnimation, now);
|
|
15
14
|
animation.current = nextAnimation.current;
|
|
16
|
-
|
|
17
15
|
if (finished) {
|
|
18
|
-
animation.reps += 1;
|
|
16
|
+
animation.reps += 1;
|
|
17
|
+
// call inner animation's callback on every repetition
|
|
19
18
|
// as the second argument the animation's current value is passed
|
|
20
|
-
|
|
21
19
|
if (nextAnimation.callback) {
|
|
22
|
-
nextAnimation.callback(true
|
|
23
|
-
/* finished */
|
|
24
|
-
, animation.current);
|
|
20
|
+
nextAnimation.callback(true /* finished */, animation.current);
|
|
25
21
|
}
|
|
26
|
-
|
|
27
22
|
if (numberOfReps > 0 && animation.reps >= numberOfReps) {
|
|
28
23
|
return true;
|
|
29
24
|
}
|
|
30
|
-
|
|
31
25
|
const startValue = reverse ? nextAnimation.current : animation.startValue;
|
|
32
|
-
|
|
33
26
|
if (reverse) {
|
|
34
27
|
nextAnimation.toValue = animation.startValue;
|
|
35
28
|
animation.startValue = startValue;
|
|
36
29
|
}
|
|
37
|
-
|
|
38
30
|
nextAnimation.onStart(nextAnimation, startValue, now, nextAnimation.previousAnimation);
|
|
39
31
|
return false;
|
|
40
32
|
}
|
|
41
|
-
|
|
42
33
|
return false;
|
|
43
34
|
}
|
|
44
|
-
|
|
45
35
|
const repCallback = finished => {
|
|
46
36
|
if (callback) {
|
|
47
37
|
callback(finished);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
38
|
+
}
|
|
39
|
+
// when cancelled call inner animation's callback
|
|
51
40
|
if (!finished && nextAnimation.callback) {
|
|
52
|
-
nextAnimation.callback(false
|
|
53
|
-
/* finished */
|
|
54
|
-
);
|
|
41
|
+
nextAnimation.callback(false /* finished */);
|
|
55
42
|
}
|
|
56
43
|
};
|
|
57
44
|
|
|
@@ -60,7 +47,6 @@ export function withRepeat(_nextAnimation) {
|
|
|
60
47
|
animation.reps = 0;
|
|
61
48
|
nextAnimation.onStart(nextAnimation, value, now, previousAnimation);
|
|
62
49
|
}
|
|
63
|
-
|
|
64
50
|
return {
|
|
65
51
|
isHigherOrder: true,
|
|
66
52
|
onFrame: repeat,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["defineAnimation","withRepeat","_nextAnimation","numberOfReps","reverse","callback","nextAnimation","repeat","animation","now","finished","onFrame","current","reps","startValue","toValue","onStart","previousAnimation","repCallback","value","isHigherOrder"],"sources":["repeat.ts"],"sourcesContent":["import { defineAnimation } from './util';\nimport {\n Animation,\n AnimationCallback,\n AnimatableValue,\n Timestamp,\n} from '../commonTypes';\nimport { NextAnimation, RepeatAnimation } from './commonTypes';\n\nexport interface InnerRepeatAnimation\n extends Omit<RepeatAnimation, 'toValue' | 'startValue'> {\n toValue: number;\n startValue: number;\n}\n\nexport function withRepeat(\n _nextAnimation: NextAnimation<RepeatAnimation>,\n numberOfReps = 2,\n reverse = false,\n callback?: AnimationCallback\n): Animation<RepeatAnimation> {\n 'worklet';\n\n return defineAnimation<RepeatAnimation>(_nextAnimation, () => {\n 'worklet';\n\n const nextAnimation: RepeatAnimation =\n typeof _nextAnimation === 'function' ? _nextAnimation() : _nextAnimation;\n\n function repeat(animation: InnerRepeatAnimation, now: Timestamp): boolean {\n const finished = nextAnimation.onFrame(nextAnimation, now);\n animation.current = nextAnimation.current;\n if (finished) {\n animation.reps += 1;\n // call inner animation's callback on every repetition\n // as the second argument the animation's current value is passed\n if (nextAnimation.callback) {\n nextAnimation.callback(true /* finished */, animation.current);\n }\n if (numberOfReps > 0 && animation.reps >= numberOfReps) {\n return true;\n }\n\n const startValue = reverse\n ? (nextAnimation.current as number)\n : animation.startValue;\n if (reverse) {\n nextAnimation.toValue = animation.startValue;\n animation.startValue = startValue;\n }\n nextAnimation.onStart(\n nextAnimation,\n startValue,\n now,\n nextAnimation.previousAnimation as RepeatAnimation\n );\n return false;\n }\n return false;\n }\n\n const repCallback = (finished: boolean): void => {\n if (callback) {\n callback(finished);\n }\n // when cancelled call inner animation's callback\n if (!finished && nextAnimation.callback) {\n nextAnimation.callback(false /* finished */);\n }\n };\n\n function onStart(\n animation: RepeatAnimation,\n value: AnimatableValue,\n now: Timestamp,\n previousAnimation: RepeatAnimation\n ): void {\n animation.startValue = value;\n animation.reps = 0;\n nextAnimation.onStart(nextAnimation, value, now, previousAnimation);\n }\n\n return {\n isHigherOrder: true,\n onFrame: repeat,\n onStart,\n reps: 0,\n current: nextAnimation.current,\n callback: repCallback,\n startValue: 0,\n } as RepeatAnimation;\n });\n}\n"],"mappings":"AAAA,SAASA,
|
|
1
|
+
{"version":3,"names":["defineAnimation","withRepeat","_nextAnimation","numberOfReps","arguments","length","undefined","reverse","callback","nextAnimation","repeat","animation","now","finished","onFrame","current","reps","startValue","toValue","onStart","previousAnimation","repCallback","value","isHigherOrder"],"sources":["repeat.ts"],"sourcesContent":["import { defineAnimation } from './util';\nimport {\n Animation,\n AnimationCallback,\n AnimatableValue,\n Timestamp,\n} from '../commonTypes';\nimport { NextAnimation, RepeatAnimation } from './commonTypes';\n\nexport interface InnerRepeatAnimation\n extends Omit<RepeatAnimation, 'toValue' | 'startValue'> {\n toValue: number;\n startValue: number;\n}\n\nexport function withRepeat(\n _nextAnimation: NextAnimation<RepeatAnimation>,\n numberOfReps = 2,\n reverse = false,\n callback?: AnimationCallback\n): Animation<RepeatAnimation> {\n 'worklet';\n\n return defineAnimation<RepeatAnimation>(_nextAnimation, () => {\n 'worklet';\n\n const nextAnimation: RepeatAnimation =\n typeof _nextAnimation === 'function' ? _nextAnimation() : _nextAnimation;\n\n function repeat(animation: InnerRepeatAnimation, now: Timestamp): boolean {\n const finished = nextAnimation.onFrame(nextAnimation, now);\n animation.current = nextAnimation.current;\n if (finished) {\n animation.reps += 1;\n // call inner animation's callback on every repetition\n // as the second argument the animation's current value is passed\n if (nextAnimation.callback) {\n nextAnimation.callback(true /* finished */, animation.current);\n }\n if (numberOfReps > 0 && animation.reps >= numberOfReps) {\n return true;\n }\n\n const startValue = reverse\n ? (nextAnimation.current as number)\n : animation.startValue;\n if (reverse) {\n nextAnimation.toValue = animation.startValue;\n animation.startValue = startValue;\n }\n nextAnimation.onStart(\n nextAnimation,\n startValue,\n now,\n nextAnimation.previousAnimation as RepeatAnimation\n );\n return false;\n }\n return false;\n }\n\n const repCallback = (finished: boolean): void => {\n if (callback) {\n callback(finished);\n }\n // when cancelled call inner animation's callback\n if (!finished && nextAnimation.callback) {\n nextAnimation.callback(false /* finished */);\n }\n };\n\n function onStart(\n animation: RepeatAnimation,\n value: AnimatableValue,\n now: Timestamp,\n previousAnimation: RepeatAnimation\n ): void {\n animation.startValue = value;\n animation.reps = 0;\n nextAnimation.onStart(nextAnimation, value, now, previousAnimation);\n }\n\n return {\n isHigherOrder: true,\n onFrame: repeat,\n onStart,\n reps: 0,\n current: nextAnimation.current,\n callback: repCallback,\n startValue: 0,\n } as RepeatAnimation;\n });\n}\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,QAAQ;AAexC,OAAO,SAASC,UAAUA,CACxBC,cAA8C,EAIlB;EAC5B,SAAS;;EAAC,IAJVC,YAAY,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC;EAAA,IAChBG,OAAO,GAAAH,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,KAAK;EAAA,IACfI,QAA4B,GAAAJ,SAAA,CAAAC,MAAA,OAAAD,SAAA,MAAAE,SAAA;EAI5B,OAAON,eAAe,CAAkBE,cAAc,EAAE,MAAM;IAC5D,SAAS;;IAET,MAAMO,aAA8B,GAClC,OAAOP,cAAc,KAAK,U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,CAACK,IAAI,GAAG,CAAC;MAClBP,aAAa,CAACU,OAAO,CAACV,aAAa,EAAEa,KAAK,EAAEV,GAAG,EAAEQ,iBAAiB,CAAC;IACrE;IAEA,OAAO;MACLG,aAAa,EAAE,IAAI;MACnBT,OAAO,EAAEJ,MAAM;MACfS,OAAO;MACPH,IAAI,EAAE,CAAC;MACPD,OAAO,EAAEN,aAAa,CAACM,OAAO;MAC9BP,QAAQ,EAAEa,WAAW;MACrBJ,UAAU,EAAE;IACd,CAAC;EACH,CAAC,CAAC;AACJ"}
|
|
@@ -5,7 +5,6 @@ export function withSequence() {
|
|
|
5
5
|
for (var _len = arguments.length, _animations = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
6
6
|
_animations[_key] = arguments[_key];
|
|
7
7
|
}
|
|
8
|
-
|
|
9
8
|
return defineAnimation(_animations[0], () => {
|
|
10
9
|
'worklet';
|
|
11
10
|
|
|
@@ -14,62 +13,48 @@ export function withSequence() {
|
|
|
14
13
|
result.finished = false;
|
|
15
14
|
return result;
|
|
16
15
|
});
|
|
17
|
-
|
|
18
16
|
const firstAnimation = animations[0];
|
|
19
|
-
|
|
20
17
|
const callback = finished => {
|
|
21
18
|
if (finished) {
|
|
22
19
|
// we want to call the callback after every single animation
|
|
23
20
|
// not after all of them
|
|
24
21
|
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
}
|
|
23
|
+
// this is going to be called only if sequence has been cancelled
|
|
28
24
|
animations.forEach(animation => {
|
|
29
25
|
if (typeof animation.callback === 'function' && !animation.finished) {
|
|
30
26
|
animation.callback(finished);
|
|
31
27
|
}
|
|
32
28
|
});
|
|
33
29
|
};
|
|
34
|
-
|
|
35
30
|
function sequence(animation, now) {
|
|
36
31
|
const currentAnim = animations[animation.animationIndex];
|
|
37
32
|
const finished = currentAnim.onFrame(currentAnim, now);
|
|
38
33
|
animation.current = currentAnim.current;
|
|
39
|
-
|
|
40
34
|
if (finished) {
|
|
41
35
|
// we want to call the callback after every single animation
|
|
42
36
|
if (currentAnim.callback) {
|
|
43
|
-
currentAnim.callback(true
|
|
44
|
-
/* finished */
|
|
45
|
-
);
|
|
37
|
+
currentAnim.callback(true /* finished */);
|
|
46
38
|
}
|
|
47
39
|
|
|
48
40
|
currentAnim.finished = true;
|
|
49
41
|
animation.animationIndex += 1;
|
|
50
|
-
|
|
51
42
|
if (animation.animationIndex < animations.length) {
|
|
52
43
|
const nextAnim = animations[animation.animationIndex];
|
|
53
44
|
nextAnim.onStart(nextAnim, currentAnim.current, now, currentAnim);
|
|
54
45
|
return false;
|
|
55
46
|
}
|
|
56
|
-
|
|
57
47
|
return true;
|
|
58
48
|
}
|
|
59
|
-
|
|
60
49
|
return false;
|
|
61
50
|
}
|
|
62
|
-
|
|
63
51
|
function onStart(animation, value, now, previousAnimation) {
|
|
64
52
|
animation.animationIndex = 0;
|
|
65
|
-
|
|
66
53
|
if (previousAnimation === undefined) {
|
|
67
54
|
previousAnimation = animations[animations.length - 1];
|
|
68
55
|
}
|
|
69
|
-
|
|
70
56
|
firstAnimation.onStart(firstAnimation, value, now, previousAnimation);
|
|
71
57
|
}
|
|
72
|
-
|
|
73
58
|
return {
|
|
74
59
|
isHigherOrder: true,
|
|
75
60
|
onFrame: sequence,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["defineAnimation","withSequence","_animations","animations","map","a","result","finished","firstAnimation","callback","forEach","animation","sequence","now","currentAnim","animationIndex","onFrame","current","
|
|
1
|
+
{"version":3,"names":["defineAnimation","withSequence","_len","arguments","length","_animations","Array","_key","animations","map","a","result","finished","firstAnimation","callback","forEach","animation","sequence","now","currentAnim","animationIndex","onFrame","current","nextAnim","onStart","value","previousAnimation","undefined","isHigherOrder"],"sources":["sequence.ts"],"sourcesContent":["import { defineAnimation } from './util';\nimport { NextAnimation, SequenceAnimation } from './commonTypes';\nimport {\n Animation,\n AnimatableValue,\n AnimationObject,\n Timestamp,\n} from '../commonTypes';\n\nexport function withSequence(\n ..._animations: NextAnimation<AnimationObject>[]\n): Animation<SequenceAnimation> {\n 'worklet';\n return defineAnimation<SequenceAnimation>(\n _animations[0] as SequenceAnimation,\n () => {\n 'worklet';\n const animations = _animations.map((a) => {\n const result = typeof a === 'function' ? a() : a;\n result.finished = false;\n return result;\n });\n const firstAnimation = animations[0];\n\n const callback = (finished: boolean): void => {\n if (finished) {\n // we want to call the callback after every single animation\n // not after all of them\n return;\n }\n // this is going to be called only if sequence has been cancelled\n animations.forEach((animation) => {\n if (typeof animation.callback === 'function' && !animation.finished) {\n animation.callback(finished);\n }\n });\n };\n\n function sequence(animation: SequenceAnimation, now: Timestamp): boolean {\n const currentAnim = animations[animation.animationIndex];\n const finished = currentAnim.onFrame(currentAnim, now);\n animation.current = currentAnim.current;\n if (finished) {\n // we want to call the callback after every single animation\n if (currentAnim.callback) {\n currentAnim.callback(true /* finished */);\n }\n currentAnim.finished = true;\n animation.animationIndex += 1;\n if (animation.animationIndex < animations.length) {\n const nextAnim = animations[animation.animationIndex];\n nextAnim.onStart(nextAnim, currentAnim.current, now, currentAnim);\n return false;\n }\n return true;\n }\n return false;\n }\n\n function onStart(\n animation: SequenceAnimation,\n value: AnimatableValue,\n now: Timestamp,\n previousAnimation: SequenceAnimation\n ): void {\n animation.animationIndex = 0;\n if (previousAnimation === undefined) {\n previousAnimation = animations[\n animations.length - 1\n ] as SequenceAnimation;\n }\n firstAnimation.onStart(firstAnimation, value, now, previousAnimation);\n }\n\n return {\n isHigherOrder: true,\n onFrame: sequence,\n onStart,\n animationIndex: 0,\n current: firstAnimation.current,\n callback,\n } as SequenceAnimation;\n }\n );\n}\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,QAAQ;AASxC,OAAO,SAASC,YAAYA,CAAA,EAEI;EAC9B,SAAS;;EAAC,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAFPC,WAAW,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EA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AAE;UAChD,MAAMmB,QAAQ,GAAGf,UAAU,CAACQ,SAAS,CAACI,cAAc,CAAC;UACrDG,QAAQ,CAACC,OAAO,CAACD,QAAQ,EAAEJ,WAAW,CAACG,OAAO,EAAEJ,GAAG,EAAEC,WAAW,CAAC;UACjE,OAAO,KAAK;QACd;QACA,OAAO,IAAI;MACb;MACA,OAAO,KAAK;IACd;IAEA,SAASK,OAAOA,CACdR,SAA4B,EAC5BS,KAAsB,EACtBP,GAAc,EACdQ,iBAAoC,EAC9B;MACNV,SAAS,CAACI,cAAc,GAAG,CAAC;MAC5B,IAAIM,iBAAiB,KAAKC,SAAS,EAAE;QACnCD,iBAAiB,GAAGlB,UAAU,CAC5BA,UAAU,CAACJ,MAAM,GAAG,CAAC,CACD;MACxB;MACAS,cAAc,CAACW,OAAO,CAACX,cAAc,EAAEY,KAAK,EAAEP,GAAG,EAAEQ,iBAAiB,CAAC;IACvE;IAEA,OAAO;MACLE,aAAa,EAAE,IAAI;MACnBP,OAAO,EAAEJ,QAAQ;MACjBO,OAAO;MACPJ,cAAc,EAAE,CAAC;MACjBE,OAAO,EAAET,cAAc,CAACS,OAAO;MAC/BR;IACF,CAAC;EACH,CAAC,CACF;AACH"}
|
|
@@ -3,10 +3,11 @@ export function withSpring(toValue, userConfig, callback) {
|
|
|
3
3
|
'worklet';
|
|
4
4
|
|
|
5
5
|
return defineAnimation(toValue, () => {
|
|
6
|
-
'worklet';
|
|
6
|
+
'worklet';
|
|
7
|
+
|
|
8
|
+
// TODO: figure out why we can't use spread or Object.assign here
|
|
7
9
|
// when user config is "frozen object" we can't enumerate it (perhaps
|
|
8
10
|
// something is wrong with the object prototype).
|
|
9
|
-
|
|
10
11
|
const config = {
|
|
11
12
|
damping: 10,
|
|
12
13
|
mass: 1,
|
|
@@ -16,11 +17,9 @@ export function withSpring(toValue, userConfig, callback) {
|
|
|
16
17
|
restSpeedThreshold: 2,
|
|
17
18
|
velocity: 0
|
|
18
19
|
};
|
|
19
|
-
|
|
20
20
|
if (userConfig) {
|
|
21
21
|
Object.keys(userConfig).forEach(key => config[key] = userConfig[key]);
|
|
22
22
|
}
|
|
23
|
-
|
|
24
23
|
function spring(animation, now) {
|
|
25
24
|
const {
|
|
26
25
|
toValue,
|
|
@@ -36,25 +35,24 @@ export function withSpring(toValue, userConfig, callback) {
|
|
|
36
35
|
const v0 = -velocity;
|
|
37
36
|
const x0 = toValue - current;
|
|
38
37
|
const zeta = c / (2 * Math.sqrt(k * m)); // damping ratio
|
|
39
|
-
|
|
40
38
|
const omega0 = Math.sqrt(k / m); // undamped angular frequency of the oscillator (rad/ms)
|
|
41
|
-
|
|
42
39
|
const omega1 = omega0 * Math.sqrt(1 - zeta ** 2); // exponential decay
|
|
43
40
|
|
|
44
41
|
const t = deltaTime / 1000;
|
|
45
42
|
const sin1 = Math.sin(omega1 * t);
|
|
46
|
-
const cos1 = Math.cos(omega1 * t);
|
|
43
|
+
const cos1 = Math.cos(omega1 * t);
|
|
47
44
|
|
|
45
|
+
// under damped
|
|
48
46
|
const underDampedEnvelope = Math.exp(-zeta * omega0 * t);
|
|
49
47
|
const underDampedFrag1 = underDampedEnvelope * (sin1 * ((v0 + zeta * omega0 * x0) / omega1) + x0 * cos1);
|
|
50
|
-
const underDampedPosition = toValue - underDampedFrag1;
|
|
51
|
-
|
|
52
|
-
const underDampedVelocity = zeta * omega0 * underDampedFrag1 - underDampedEnvelope * (cos1 * (v0 + zeta * omega0 * x0) - omega1 * x0 * sin1);
|
|
48
|
+
const underDampedPosition = toValue - underDampedFrag1;
|
|
49
|
+
// This looks crazy -- it's actually just the derivative of the oscillation function
|
|
50
|
+
const underDampedVelocity = zeta * omega0 * underDampedFrag1 - underDampedEnvelope * (cos1 * (v0 + zeta * omega0 * x0) - omega1 * x0 * sin1);
|
|
53
51
|
|
|
52
|
+
// critically damped
|
|
54
53
|
const criticallyDampedEnvelope = Math.exp(-omega0 * t);
|
|
55
54
|
const criticallyDampedPosition = toValue - criticallyDampedEnvelope * (x0 + (v0 + omega0 * x0) * t);
|
|
56
55
|
const criticallyDampedVelocity = criticallyDampedEnvelope * (v0 * (t * omega0 - 1) + t * x0 * omega0 * omega0);
|
|
57
|
-
|
|
58
56
|
const isOvershooting = () => {
|
|
59
57
|
if (config.overshootClamping && config.stiffness !== 0) {
|
|
60
58
|
return current < toValue ? animation.current > toValue : animation.current < toValue;
|
|
@@ -62,10 +60,8 @@ export function withSpring(toValue, userConfig, callback) {
|
|
|
62
60
|
return false;
|
|
63
61
|
}
|
|
64
62
|
};
|
|
65
|
-
|
|
66
63
|
const isVelocity = Math.abs(velocity) < config.restSpeedThreshold;
|
|
67
64
|
const isDisplacement = config.stiffness === 0 || Math.abs(toValue - current) < config.restDisplacementThreshold;
|
|
68
|
-
|
|
69
65
|
if (zeta < 1) {
|
|
70
66
|
animation.current = underDampedPosition;
|
|
71
67
|
animation.velocity = underDampedVelocity;
|
|
@@ -73,24 +69,19 @@ export function withSpring(toValue, userConfig, callback) {
|
|
|
73
69
|
animation.current = criticallyDampedPosition;
|
|
74
70
|
animation.velocity = criticallyDampedVelocity;
|
|
75
71
|
}
|
|
76
|
-
|
|
77
72
|
if (isOvershooting() || isVelocity && isDisplacement) {
|
|
78
73
|
if (config.stiffness !== 0) {
|
|
79
74
|
animation.velocity = 0;
|
|
80
75
|
animation.current = toValue;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
}
|
|
77
|
+
// clear lastTimestamp to avoid using stale value by the next spring animation that starts after this one
|
|
84
78
|
animation.lastTimestamp = 0;
|
|
85
79
|
return true;
|
|
86
80
|
}
|
|
87
|
-
|
|
88
81
|
return false;
|
|
89
82
|
}
|
|
90
|
-
|
|
91
83
|
function onStart(animation, value, now, previousAnimation) {
|
|
92
84
|
animation.current = value;
|
|
93
|
-
|
|
94
85
|
if (previousAnimation) {
|
|
95
86
|
animation.velocity = previousAnimation.velocity || animation.velocity || 0;
|
|
96
87
|
animation.lastTimestamp = previousAnimation.lastTimestamp || now;
|
|
@@ -98,7 +89,6 @@ export function withSpring(toValue, userConfig, callback) {
|
|
|
98
89
|
animation.lastTimestamp = now;
|
|
99
90
|
}
|
|
100
91
|
}
|
|
101
|
-
|
|
102
92
|
return {
|
|
103
93
|
onFrame: spring,
|
|
104
94
|
onStart,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["defineAnimation","withSpring","toValue","userConfig","callback","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,SAASA,
|
|
1
|
+
{"version":3,"names":["defineAnimation","withSpring","toValue","userConfig","callback","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,SAASA,eAAe,QAAQ,QAAQ;AA+BxC,OAAO,SAASC,UAAUA,CACxBC,OAAwB,EACxBC,UAAyB,EACzBC,QAA4B,EACA;EAC5B,SAAS;;EAET,OAAOJ,eAAe,CAAkBE,OAAO,EAAE,MAAM;IACrD,SAAS;;IAET;IACA;IACA;IACA,MAAMG,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