react-native-reanimated 2.15.0 → 2.16.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/Tools/SingleInstanceChecker.h +10 -2
- package/package.json +1 -1
- package/src/reanimated1/core/Core.test.js +30 -0
- package/android/.gradle/7.5.1/checksums/checksums.lock +0 -0
- package/android/.gradle/7.5.1/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/7.5.1/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/7.5.1/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.5.1/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.5.1/executionHistory/executionHistory.bin +0 -0
- package/android/.gradle/7.5.1/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/7.5.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.5.1/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/7.5.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.5.1/fileHashes/resourceHashesCache.bin +0 -0
- package/android/.gradle/7.5.1/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.gradle/file-system.probe +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/react-native-reanimated-67-hermes.aar +0 -0
- package/android/react-native-reanimated-67-jsc.aar +0 -0
- package/android/react-native-reanimated-68-hermes.aar +0 -0
- package/android/react-native-reanimated-68-jsc.aar +0 -0
- package/android/react-native-reanimated-69-hermes.aar +0 -0
- package/android/react-native-reanimated-69-jsc.aar +0 -0
- package/android/react-native-reanimated-70-hermes.aar +0 -0
- package/android/react-native-reanimated-70-jsc.aar +0 -0
- package/android/react-native-reanimated-71-hermes.aar +0 -0
- package/android/react-native-reanimated-71-jsc.aar +0 -0
- package/lib/Animated.js +0 -9
- package/lib/ConfigHelper.js +0 -145
- package/lib/ReanimatedEventEmitter.js +0 -3
- package/lib/ReanimatedModule.js +0 -2
- package/lib/ReanimatedModule.macos.js +0 -2
- package/lib/ReanimatedModule.native.js +0 -12
- package/lib/ReanimatedModule.windows.js +0 -2
- package/lib/ReanimatedModuleCompat.js +0 -66
- package/lib/__mocks__/ReanimatedEventEmitter.js +0 -8
- package/lib/__mocks__/ReanimatedModule.native.js +0 -11
- package/lib/createAnimatedComponent.js +0 -518
- package/lib/index.js +0 -14
- package/lib/index.web.js +0 -6
- package/lib/reanimated1/Easing.js +0 -231
- package/lib/reanimated1/SpringConfig.js +0 -79
- package/lib/reanimated1/Transitioning.js +0 -158
- package/lib/reanimated1/animations/Animation.js +0 -32
- package/lib/reanimated1/animations/SpringUtils.js +0 -199
- package/lib/reanimated1/animations/backwardCompatibleAnimWrapper.js +0 -117
- package/lib/reanimated1/animations/decay.js +0 -54
- package/lib/reanimated1/animations/spring.js +0 -198
- package/lib/reanimated1/animations/timing.js +0 -74
- package/lib/reanimated1/base.js +0 -13
- package/lib/reanimated1/core/AnimatedAlways.js +0 -33
- package/lib/reanimated1/core/AnimatedBezier.js +0 -150
- package/lib/reanimated1/core/AnimatedBlock.js +0 -52
- package/lib/reanimated1/core/AnimatedCall.js +0 -55
- package/lib/reanimated1/core/AnimatedCallFunc.js +0 -72
- package/lib/reanimated1/core/AnimatedClock.js +0 -90
- package/lib/reanimated1/core/AnimatedClockTest.js +0 -22
- package/lib/reanimated1/core/AnimatedCode.js +0 -32
- package/lib/reanimated1/core/AnimatedConcat.js +0 -32
- package/lib/reanimated1/core/AnimatedCond.js +0 -57
- package/lib/reanimated1/core/AnimatedDebug.js +0 -62
- package/lib/reanimated1/core/AnimatedEvent.js +0 -126
- package/lib/reanimated1/core/AnimatedFunction.js +0 -55
- package/lib/reanimated1/core/AnimatedNode.js +0 -223
- package/lib/reanimated1/core/AnimatedOperator.js +0 -103
- package/lib/reanimated1/core/AnimatedParam.js +0 -88
- package/lib/reanimated1/core/AnimatedProps.js +0 -108
- package/lib/reanimated1/core/AnimatedSet.js +0 -38
- package/lib/reanimated1/core/AnimatedStartClock.js +0 -30
- package/lib/reanimated1/core/AnimatedStopClock.js +0 -30
- package/lib/reanimated1/core/AnimatedStyle.js +0 -78
- package/lib/reanimated1/core/AnimatedTransform.js +0 -78
- package/lib/reanimated1/core/AnimatedValue.js +0 -38
- package/lib/reanimated1/core/InternalAnimatedValue.js +0 -87
- package/lib/reanimated1/core/__mocks__/AnimatedProps.js +0 -86
- package/lib/reanimated1/core/createEventObjectProxyPolyfill.js +0 -44
- package/lib/reanimated1/derived/__mocks__/evaluateOnce.js +0 -14
- package/lib/reanimated1/derived/acc.js +0 -11
- package/lib/reanimated1/derived/color.js +0 -47
- package/lib/reanimated1/derived/diff.js +0 -16
- package/lib/reanimated1/derived/diffClamp.js +0 -11
- package/lib/reanimated1/derived/evaluateOnce.js +0 -35
- package/lib/reanimated1/derived/index.js +0 -8
- package/lib/reanimated1/derived/interpolate.js +0 -152
- package/lib/reanimated1/derived/interpolateColors.js +0 -62
- package/lib/reanimated1/derived/onChange.js +0 -14
- package/lib/reanimated1/derived/useCode.js +0 -41
- package/lib/reanimated1/index.js +0 -53
- package/lib/reanimated1/operators.js +0 -35
- package/lib/reanimated1/useValue.js +0 -10
- package/lib/reanimated1/val.js +0 -3
- package/lib/reanimated2/Bezier.js +0 -126
- package/lib/reanimated2/Colors.js +0 -538
- package/lib/reanimated2/Easing.js +0 -248
- package/lib/reanimated2/NativeMethods.js +0 -94
- package/lib/reanimated2/NativeReanimated/NativeReanimated.js +0 -60
- package/lib/reanimated2/NativeReanimated/index.js +0 -11
- package/lib/reanimated2/PlatformChecker.js +0 -16
- package/lib/reanimated2/PropAdapters.js +0 -55
- package/lib/reanimated2/UpdateProps.js +0 -55
- package/lib/reanimated2/ViewDescriptorsSet.js +0 -75
- package/lib/reanimated2/WorkletEventHandler.js +0 -37
- package/lib/reanimated2/__mocks__/MutableValue.js +0 -13
- package/lib/reanimated2/__mocks__/NativeReanimated.js +0 -20
- package/lib/reanimated2/animation/commonTypes.js +0 -1
- package/lib/reanimated2/animation/decay.js +0 -71
- package/lib/reanimated2/animation/delay.js +0 -64
- package/lib/reanimated2/animation/index.js +0 -8
- package/lib/reanimated2/animation/repeat.js +0 -69
- package/lib/reanimated2/animation/sequence.js +0 -69
- package/lib/reanimated2/animation/spring.js +0 -103
- package/lib/reanimated2/animation/styleAnimation.js +0 -174
- package/lib/reanimated2/animation/timing.js +0 -64
- package/lib/reanimated2/animation/util.js +0 -183
- package/lib/reanimated2/commonTypes.js +0 -8
- package/lib/reanimated2/component/FlatList.js +0 -30
- package/lib/reanimated2/component/Image.js +0 -4
- package/lib/reanimated2/component/ScrollView.js +0 -4
- package/lib/reanimated2/component/Text.js +0 -4
- package/lib/reanimated2/component/View.js +0 -4
- package/lib/reanimated2/core.js +0 -269
- package/lib/reanimated2/frameCallback/FrameCallbackRegistryJS.js +0 -32
- package/lib/reanimated2/frameCallback/FrameCallbackRegistryUI.js +0 -76
- package/lib/reanimated2/globals.d.ts +0 -91
- package/lib/reanimated2/hook/Hooks.js +0 -9
- package/lib/reanimated2/hook/commonTypes.js +0 -1
- package/lib/reanimated2/hook/index.js +0 -12
- package/lib/reanimated2/hook/useAnimatedGestureHandler.js +0 -49
- package/lib/reanimated2/hook/useAnimatedKeyboard.js +0 -31
- package/lib/reanimated2/hook/useAnimatedReaction.js +0 -44
- package/lib/reanimated2/hook/useAnimatedRef.js +0 -25
- package/lib/reanimated2/hook/useAnimatedScrollHandler.js +0 -41
- package/lib/reanimated2/hook/useAnimatedSensor.js +0 -66
- package/lib/reanimated2/hook/useAnimatedStyle.js +0 -402
- package/lib/reanimated2/hook/useDerivedValue.js +0 -43
- package/lib/reanimated2/hook/useFrameCallback.js +0 -23
- package/lib/reanimated2/hook/useScrollViewOffset.js +0 -27
- package/lib/reanimated2/hook/useSharedValue.js +0 -17
- package/lib/reanimated2/hook/utils.js +0 -165
- package/lib/reanimated2/index.js +0 -12
- package/lib/reanimated2/interpolateColor.js +0 -157
- package/lib/reanimated2/interpolation.js +0 -127
- package/lib/reanimated2/jestUtils.js +0 -175
- package/lib/reanimated2/js-reanimated/JSReanimated.js +0 -106
- package/lib/reanimated2/js-reanimated/Mapper.js +0 -43
- package/lib/reanimated2/js-reanimated/MapperRegistry.js +0 -101
- package/lib/reanimated2/js-reanimated/MutableValue.js +0 -29
- package/lib/reanimated2/js-reanimated/commonTypes.js +0 -1
- package/lib/reanimated2/js-reanimated/global.js +0 -36
- package/lib/reanimated2/js-reanimated/index.js +0 -35
- package/lib/reanimated2/layoutReanimation/LayoutAnimationRepository.js +0 -67
- package/lib/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js +0 -69
- package/lib/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +0 -133
- package/lib/reanimated2/layoutReanimation/animationBuilder/Keyframe.js +0 -194
- package/lib/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +0 -1
- package/lib/reanimated2/layoutReanimation/animationBuilder/index.js +0 -3
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +0 -374
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Default.js +0 -36
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Fade.js +0 -275
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +0 -385
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +0 -136
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +0 -81
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Roll.js +0 -120
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +0 -273
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +0 -201
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +0 -101
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +0 -457
- package/lib/reanimated2/layoutReanimation/defaultAnimations/index.js +0 -10
- package/lib/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +0 -90
- package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +0 -132
- package/lib/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +0 -37
- package/lib/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +0 -41
- package/lib/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +0 -34
- package/lib/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +0 -46
- package/lib/reanimated2/layoutReanimation/defaultTransitions/index.js +0 -6
- package/lib/reanimated2/layoutReanimation/index.js +0 -4
- package/lib/reanimated2/mock.js +0 -75
- package/lib/reanimated2/platform-specific/RNRenderer.js +0 -3
- package/lib/reanimated2/platform-specific/RNRenderer.web.js +0 -3
- package/lib/reanimated2/platform-specific/checkVersion.js +0 -28
- package/lib/reanimated2/platform-specific/checkVersion.web.js +0 -6
- package/lib/reanimated2/utils.js +0 -16
- package/lib/setAndForwardRef.js +0 -19
- package/lib/types/lib/Animated.d.ts +0 -8
- package/lib/types/lib/ConfigHelper.d.ts +0 -12
- package/lib/types/lib/ReanimatedEventEmitter.d.ts +0 -3
- package/lib/types/lib/ReanimatedModule.d.ts +0 -2
- package/lib/types/lib/ReanimatedModule.macos.d.ts +0 -2
- package/lib/types/lib/ReanimatedModule.native.d.ts +0 -2
- package/lib/types/lib/ReanimatedModule.windows.d.ts +0 -2
- package/lib/types/lib/ReanimatedModuleCompat.d.ts +0 -14
- package/lib/types/lib/createAnimatedComponent.d.ts +0 -33
- package/lib/types/lib/index.d.ts +0 -4
- package/lib/types/lib/index.web.d.ts +0 -4
- package/lib/types/lib/reanimated2/Bezier.d.ts +0 -6
- package/lib/types/lib/reanimated2/Colors.d.ts +0 -33
- package/lib/types/lib/reanimated2/Easing.d.ts +0 -172
- package/lib/types/lib/reanimated2/NativeMethods.d.ts +0 -7
- package/lib/types/lib/reanimated2/NativeReanimated/NativeReanimated.d.ts +0 -22
- package/lib/types/lib/reanimated2/NativeReanimated/index.d.ts +0 -3
- package/lib/types/lib/reanimated2/PlatformChecker.d.ts +0 -5
- package/lib/types/lib/reanimated2/PropAdapters.d.ts +0 -4
- package/lib/types/lib/reanimated2/UpdateProps.d.ts +0 -9
- package/lib/types/lib/reanimated2/ViewDescriptorsSet.d.ts +0 -20
- package/lib/types/lib/reanimated2/WorkletEventHandler.d.ts +0 -13
- package/lib/types/lib/reanimated2/__mocks__/MutableValue.d.ts +0 -5
- package/lib/types/lib/reanimated2/__mocks__/NativeReanimated.d.ts +0 -13
- package/lib/types/lib/reanimated2/animation/commonTypes.d.ts +0 -27
- package/lib/types/lib/reanimated2/animation/decay.d.ts +0 -19
- package/lib/types/lib/reanimated2/animation/delay.d.ts +0 -7
- package/lib/types/lib/reanimated2/animation/index.d.ts +0 -9
- package/lib/types/lib/reanimated2/animation/repeat.d.ts +0 -12
- package/lib/types/lib/reanimated2/animation/sequence.d.ts +0 -7
- package/lib/types/lib/reanimated2/animation/spring.d.ts +0 -22
- package/lib/types/lib/reanimated2/animation/styleAnimation.d.ts +0 -7
- package/lib/types/lib/reanimated2/animation/timing.d.ts +0 -21
- package/lib/types/lib/reanimated2/animation/util.d.ts +0 -9
- package/lib/types/lib/reanimated2/commonTypes.d.ts +0 -99
- package/lib/types/lib/reanimated2/component/FlatList.d.ts +0 -9
- package/lib/types/lib/reanimated2/component/Image.d.ts +0 -3
- package/lib/types/lib/reanimated2/component/ScrollView.d.ts +0 -3
- package/lib/types/lib/reanimated2/component/Text.d.ts +0 -3
- package/lib/types/lib/reanimated2/component/View.d.ts +0 -3
- package/lib/types/lib/reanimated2/core.d.ts +0 -24
- package/lib/types/lib/reanimated2/frameCallback/FrameCallbackRegistryJS.d.ts +0 -8
- package/lib/types/lib/reanimated2/frameCallback/FrameCallbackRegistryUI.d.ts +0 -20
- package/lib/types/lib/reanimated2/hook/Hooks.d.ts +0 -5
- package/lib/types/lib/reanimated2/hook/commonTypes.d.ts +0 -14
- package/lib/types/lib/reanimated2/hook/index.d.ts +0 -14
- package/lib/types/lib/reanimated2/hook/useAnimatedGestureHandler.d.ts +0 -35
- package/lib/types/lib/reanimated2/hook/useAnimatedKeyboard.d.ts +0 -2
- package/lib/types/lib/reanimated2/hook/useAnimatedReaction.d.ts +0 -12
- package/lib/types/lib/reanimated2/hook/useAnimatedRef.d.ts +0 -3
- package/lib/types/lib/reanimated2/hook/useAnimatedScrollHandler.d.ts +0 -20
- package/lib/types/lib/reanimated2/hook/useAnimatedSensor.d.ts +0 -18
- package/lib/types/lib/reanimated2/hook/useAnimatedStyle.d.ts +0 -11
- package/lib/types/lib/reanimated2/hook/useDerivedValue.d.ts +0 -4
- package/lib/types/lib/reanimated2/hook/useFrameCallback.d.ts +0 -7
- package/lib/types/lib/reanimated2/hook/useScrollViewOffset.d.ts +0 -4
- package/lib/types/lib/reanimated2/hook/useSharedValue.d.ts +0 -2
- package/lib/types/lib/reanimated2/hook/utils.d.ts +0 -28
- package/lib/types/lib/reanimated2/index.d.ts +0 -12
- package/lib/types/lib/reanimated2/interpolateColor.d.ts +0 -32
- package/lib/types/lib/reanimated2/interpolation.d.ts +0 -14
- package/lib/types/lib/reanimated2/jestUtils.d.ts +0 -12
- package/lib/types/lib/reanimated2/js-reanimated/JSReanimated.d.ts +0 -32
- package/lib/types/lib/reanimated2/js-reanimated/Mapper.d.ts +0 -14
- package/lib/types/lib/reanimated2/js-reanimated/MapperRegistry.d.ts +0 -14
- package/lib/types/lib/reanimated2/js-reanimated/MutableValue.d.ts +0 -14
- package/lib/types/lib/reanimated2/js-reanimated/commonTypes.d.ts +0 -44
- package/lib/types/lib/reanimated2/js-reanimated/global.d.ts +0 -2
- package/lib/types/lib/reanimated2/js-reanimated/index.d.ts +0 -15
- package/lib/types/lib/reanimated2/layoutReanimation/LayoutAnimationRepository.d.ts +0 -1
- package/lib/types/lib/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.d.ts +0 -22
- package/lib/types/lib/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.d.ts +0 -38
- package/lib/types/lib/reanimated2/layoutReanimation/animationBuilder/Keyframe.d.ts +0 -25
- package/lib/types/lib/reanimated2/layoutReanimation/animationBuilder/commonTypes.d.ts +0 -81
- package/lib/types/lib/reanimated2/layoutReanimation/animationBuilder/index.d.ts +0 -4
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Bounce.d.ts +0 -62
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Default.d.ts +0 -4
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Fade.d.ts +0 -42
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.d.ts +0 -50
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.d.ts +0 -18
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.d.ts +0 -10
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Roll.d.ts +0 -18
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.d.ts +0 -34
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.d.ts +0 -34
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Stretch.d.ts +0 -18
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.d.ts +0 -66
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/index.d.ts +0 -10
- package/lib/types/lib/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.d.ts +0 -19
- package/lib/types/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.d.ts +0 -13
- package/lib/types/lib/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.d.ts +0 -6
- package/lib/types/lib/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.d.ts +0 -6
- package/lib/types/lib/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.d.ts +0 -7
- package/lib/types/lib/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.d.ts +0 -9
- package/lib/types/lib/reanimated2/layoutReanimation/defaultTransitions/index.d.ts +0 -6
- package/lib/types/lib/reanimated2/layoutReanimation/index.d.ts +0 -4
- package/lib/types/lib/reanimated2/mock.d.ts +0 -61
- package/lib/types/lib/reanimated2/platform-specific/RNRenderer.d.ts +0 -1
- package/lib/types/lib/reanimated2/platform-specific/RNRenderer.web.d.ts +0 -0
- package/lib/types/lib/reanimated2/platform-specific/checkVersion.d.ts +0 -4
- package/lib/types/lib/reanimated2/platform-specific/checkVersion.web.d.ts +0 -5
- package/lib/types/lib/reanimated2/utils.d.ts +0 -11
- package/lib/types/lib/setAndForwardRef.d.ts +0 -40
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { defineAnimation } from './util';
|
|
2
|
-
import { Platform } from 'react-native';
|
|
3
|
-
export function withDecay(userConfig, callback) {
|
|
4
|
-
'worklet';
|
|
5
|
-
return defineAnimation(0, () => {
|
|
6
|
-
'worklet';
|
|
7
|
-
var _a;
|
|
8
|
-
const config = {
|
|
9
|
-
deceleration: 0.998,
|
|
10
|
-
velocityFactor: Platform.OS !== 'web' ? 1 : 1000,
|
|
11
|
-
velocity: 0,
|
|
12
|
-
};
|
|
13
|
-
if (userConfig) {
|
|
14
|
-
Object.keys(userConfig).forEach((key) => (config[key] = userConfig[key]));
|
|
15
|
-
}
|
|
16
|
-
const VELOCITY_EPS = Platform.OS !== 'web' ? 1 : 1 / 20;
|
|
17
|
-
const SLOPE_FACTOR = 0.1;
|
|
18
|
-
function decay(animation, now) {
|
|
19
|
-
const { lastTimestamp, startTimestamp, initialVelocity, current, velocity, } = animation;
|
|
20
|
-
const deltaTime = Math.min(now - lastTimestamp, 64);
|
|
21
|
-
const v = velocity *
|
|
22
|
-
Math.exp(-(1 - config.deceleration) * (now - startTimestamp) * SLOPE_FACTOR);
|
|
23
|
-
animation.current =
|
|
24
|
-
current + (v * config.velocityFactor * deltaTime) / 1000; // /1000 because time is in ms not in s
|
|
25
|
-
animation.velocity = v;
|
|
26
|
-
animation.lastTimestamp = now;
|
|
27
|
-
if (config.clamp) {
|
|
28
|
-
if (initialVelocity < 0 && animation.current <= config.clamp[0]) {
|
|
29
|
-
animation.current = config.clamp[0];
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
else if (initialVelocity > 0 &&
|
|
33
|
-
animation.current >= config.clamp[1]) {
|
|
34
|
-
animation.current = config.clamp[1];
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return Math.abs(v) < VELOCITY_EPS;
|
|
39
|
-
}
|
|
40
|
-
function validateConfig() {
|
|
41
|
-
if (config.clamp) {
|
|
42
|
-
if (!Array.isArray(config.clamp)) {
|
|
43
|
-
throw Error(`config.clamp must be an array but is ${typeof config.clamp}`);
|
|
44
|
-
}
|
|
45
|
-
if (config.clamp.length !== 2) {
|
|
46
|
-
throw Error(`clamp array must contain 2 items but is given ${config.clamp.length}`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (config.velocityFactor <= 0) {
|
|
50
|
-
throw Error(`config.velocityFactor must be greather then 0 but is ${config.velocityFactor}`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
function onStart(animation, value, now) {
|
|
54
|
-
animation.current = value;
|
|
55
|
-
animation.lastTimestamp = now;
|
|
56
|
-
animation.startTimestamp = now;
|
|
57
|
-
animation.initialVelocity = config.velocity;
|
|
58
|
-
validateConfig();
|
|
59
|
-
}
|
|
60
|
-
return {
|
|
61
|
-
onFrame: decay,
|
|
62
|
-
onStart,
|
|
63
|
-
callback,
|
|
64
|
-
velocity: (_a = config.velocity) !== null && _a !== void 0 ? _a : 0,
|
|
65
|
-
initialVelocity: 0,
|
|
66
|
-
current: 0,
|
|
67
|
-
lastTimestamp: 0,
|
|
68
|
-
startTimestamp: 0,
|
|
69
|
-
};
|
|
70
|
-
});
|
|
71
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { defineAnimation } from './util';
|
|
2
|
-
export function withDelay(delayMs, _nextAnimation) {
|
|
3
|
-
'worklet';
|
|
4
|
-
return defineAnimation(_nextAnimation, () => {
|
|
5
|
-
'worklet';
|
|
6
|
-
const nextAnimation = typeof _nextAnimation === 'function' ? _nextAnimation() : _nextAnimation;
|
|
7
|
-
function delay(animation, now) {
|
|
8
|
-
const { startTime, started, previousAnimation } = animation;
|
|
9
|
-
if (now - startTime > delayMs) {
|
|
10
|
-
if (!started) {
|
|
11
|
-
nextAnimation.onStart(nextAnimation, animation.current, now, previousAnimation);
|
|
12
|
-
animation.previousAnimation = null;
|
|
13
|
-
animation.started = true;
|
|
14
|
-
}
|
|
15
|
-
const finished = nextAnimation.onFrame(nextAnimation, now);
|
|
16
|
-
animation.current = nextAnimation.current;
|
|
17
|
-
return finished;
|
|
18
|
-
}
|
|
19
|
-
else if (previousAnimation) {
|
|
20
|
-
const finished = previousAnimation.finished ||
|
|
21
|
-
previousAnimation.onFrame(previousAnimation, now);
|
|
22
|
-
animation.current = previousAnimation.current;
|
|
23
|
-
if (finished) {
|
|
24
|
-
animation.previousAnimation = null;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
function onStart(animation, value, now, previousAnimation) {
|
|
30
|
-
animation.startTime = now;
|
|
31
|
-
animation.started = false;
|
|
32
|
-
animation.current = value;
|
|
33
|
-
if (previousAnimation === animation) {
|
|
34
|
-
animation.previousAnimation = previousAnimation.previousAnimation;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
animation.previousAnimation = previousAnimation;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const callback = (finished) => {
|
|
41
|
-
if (nextAnimation.callback) {
|
|
42
|
-
nextAnimation.callback(finished);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
return {
|
|
46
|
-
isHigherOrder: true,
|
|
47
|
-
onFrame: delay,
|
|
48
|
-
onStart,
|
|
49
|
-
current: nextAnimation.current,
|
|
50
|
-
callback,
|
|
51
|
-
previousAnimation: null,
|
|
52
|
-
startTime: 0,
|
|
53
|
-
started: false,
|
|
54
|
-
};
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* @deprecated Kept for backward compatibility. Will be removed soon.
|
|
59
|
-
*/
|
|
60
|
-
export function delay(delayMs, _nextAnimation) {
|
|
61
|
-
'worklet';
|
|
62
|
-
console.warn('Method `delay` is deprecated. Please use `withDelay` instead');
|
|
63
|
-
return withDelay(delayMs, _nextAnimation);
|
|
64
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { cancelAnimation, defineAnimation, initialUpdaterRun } from './util';
|
|
2
|
-
export { withTiming } from './timing';
|
|
3
|
-
export { withSpring } from './spring';
|
|
4
|
-
export { withDecay } from './decay';
|
|
5
|
-
export { withDelay } from './delay';
|
|
6
|
-
export { withRepeat } from './repeat';
|
|
7
|
-
export { withSequence } from './sequence';
|
|
8
|
-
export { withStyleAnimation } from './styleAnimation';
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { defineAnimation } from './util';
|
|
2
|
-
export function withRepeat(_nextAnimation, numberOfReps = 2, reverse = false, callback) {
|
|
3
|
-
'worklet';
|
|
4
|
-
return defineAnimation(_nextAnimation, () => {
|
|
5
|
-
'worklet';
|
|
6
|
-
const nextAnimation = typeof _nextAnimation === 'function' ? _nextAnimation() : _nextAnimation;
|
|
7
|
-
function repeat(animation, now) {
|
|
8
|
-
const finished = nextAnimation.onFrame(nextAnimation, now);
|
|
9
|
-
animation.current = nextAnimation.current;
|
|
10
|
-
if (finished) {
|
|
11
|
-
animation.reps += 1;
|
|
12
|
-
// call inner animation's callback on every repetition
|
|
13
|
-
// as the second argument the animation's current value is passed
|
|
14
|
-
if (nextAnimation.callback) {
|
|
15
|
-
nextAnimation.callback(true /* finished */, animation.current);
|
|
16
|
-
}
|
|
17
|
-
if (numberOfReps > 0 && animation.reps >= numberOfReps) {
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
const startValue = reverse
|
|
21
|
-
? nextAnimation.current
|
|
22
|
-
: animation.startValue;
|
|
23
|
-
if (reverse) {
|
|
24
|
-
nextAnimation.toValue = animation.startValue;
|
|
25
|
-
animation.startValue = startValue;
|
|
26
|
-
}
|
|
27
|
-
nextAnimation.onStart(nextAnimation, startValue, now, nextAnimation.previousAnimation);
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
const repCallback = (finished) => {
|
|
33
|
-
if (callback) {
|
|
34
|
-
callback(finished);
|
|
35
|
-
}
|
|
36
|
-
// when cancelled call inner animation's callback
|
|
37
|
-
if (!finished && nextAnimation.callback) {
|
|
38
|
-
nextAnimation.callback(false /* finished */);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
function onStart(animation, value, now, previousAnimation) {
|
|
42
|
-
animation.startValue = value;
|
|
43
|
-
animation.reps = 0;
|
|
44
|
-
nextAnimation.onStart(nextAnimation, value, now, previousAnimation);
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
isHigherOrder: true,
|
|
48
|
-
onFrame: repeat,
|
|
49
|
-
onStart,
|
|
50
|
-
reps: 0,
|
|
51
|
-
current: nextAnimation.current,
|
|
52
|
-
callback: repCallback,
|
|
53
|
-
startValue: 0,
|
|
54
|
-
};
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* @deprecated Kept for backward compatibility. Will be removed soon.
|
|
59
|
-
*/
|
|
60
|
-
export function repeat(_nextAnimation, numberOfReps = 2, reverse = false, callback) {
|
|
61
|
-
'worklet';
|
|
62
|
-
console.warn('Method `repeat` is deprecated. Please use `withRepeat` instead');
|
|
63
|
-
return withRepeat(_nextAnimation, numberOfReps, reverse, callback);
|
|
64
|
-
}
|
|
65
|
-
export function loop(nextAnimation, numberOfLoops = 1) {
|
|
66
|
-
'worklet';
|
|
67
|
-
console.warn('Method `loop` is deprecated. Please use `withRepeat` instead');
|
|
68
|
-
return repeat(nextAnimation, Math.round(numberOfLoops * 2), true);
|
|
69
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { defineAnimation } from './util';
|
|
2
|
-
export function withSequence(..._animations) {
|
|
3
|
-
'worklet';
|
|
4
|
-
return defineAnimation(_animations[0], () => {
|
|
5
|
-
'worklet';
|
|
6
|
-
const animations = _animations.map((a) => {
|
|
7
|
-
const result = typeof a === 'function' ? a() : a;
|
|
8
|
-
result.finished = false;
|
|
9
|
-
return result;
|
|
10
|
-
});
|
|
11
|
-
const firstAnimation = animations[0];
|
|
12
|
-
const callback = (finished) => {
|
|
13
|
-
if (finished) {
|
|
14
|
-
// we want to call the callback after every single animation
|
|
15
|
-
// not after all of them
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
// this is going to be called only if sequence has been cancelled
|
|
19
|
-
animations.forEach((animation) => {
|
|
20
|
-
if (typeof animation.callback === 'function' && !animation.finished) {
|
|
21
|
-
animation.callback(finished);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
function sequence(animation, now) {
|
|
26
|
-
const currentAnim = animations[animation.animationIndex];
|
|
27
|
-
const finished = currentAnim.onFrame(currentAnim, now);
|
|
28
|
-
animation.current = currentAnim.current;
|
|
29
|
-
if (finished) {
|
|
30
|
-
// we want to call the callback after every single animation
|
|
31
|
-
if (currentAnim.callback) {
|
|
32
|
-
currentAnim.callback(true /* finished */);
|
|
33
|
-
}
|
|
34
|
-
currentAnim.finished = true;
|
|
35
|
-
animation.animationIndex += 1;
|
|
36
|
-
if (animation.animationIndex < animations.length) {
|
|
37
|
-
const nextAnim = animations[animation.animationIndex];
|
|
38
|
-
nextAnim.onStart(nextAnim, currentAnim.current, now, currentAnim);
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
function onStart(animation, value, now, previousAnimation) {
|
|
46
|
-
animation.animationIndex = 0;
|
|
47
|
-
if (previousAnimation === undefined) {
|
|
48
|
-
previousAnimation = animations[animations.length - 1];
|
|
49
|
-
}
|
|
50
|
-
firstAnimation.onStart(firstAnimation, value, now, previousAnimation);
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
isHigherOrder: true,
|
|
54
|
-
onFrame: sequence,
|
|
55
|
-
onStart,
|
|
56
|
-
animationIndex: 0,
|
|
57
|
-
current: firstAnimation.current,
|
|
58
|
-
callback,
|
|
59
|
-
};
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* @deprecated Kept for backward compatibility. Will be removed soon.
|
|
64
|
-
*/
|
|
65
|
-
export function sequence(..._animations) {
|
|
66
|
-
'worklet';
|
|
67
|
-
console.warn('Method `sequence` is deprecated. Please use `withSequence` instead');
|
|
68
|
-
return withSequence(..._animations);
|
|
69
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { defineAnimation } from './util';
|
|
2
|
-
export function withSpring(toValue, userConfig, callback) {
|
|
3
|
-
'worklet';
|
|
4
|
-
return defineAnimation(toValue, () => {
|
|
5
|
-
'worklet';
|
|
6
|
-
// TODO: figure out why we can't use spread or Object.assign here
|
|
7
|
-
// when user config is "frozen object" we can't enumerate it (perhaps
|
|
8
|
-
// something is wrong with the object prototype).
|
|
9
|
-
const config = {
|
|
10
|
-
damping: 10,
|
|
11
|
-
mass: 1,
|
|
12
|
-
stiffness: 100,
|
|
13
|
-
overshootClamping: false,
|
|
14
|
-
restDisplacementThreshold: 0.01,
|
|
15
|
-
restSpeedThreshold: 2,
|
|
16
|
-
velocity: 0,
|
|
17
|
-
};
|
|
18
|
-
if (userConfig) {
|
|
19
|
-
Object.keys(userConfig).forEach((key) => (config[key] = userConfig[key]));
|
|
20
|
-
}
|
|
21
|
-
function spring(animation, now) {
|
|
22
|
-
const { toValue, lastTimestamp, current, velocity } = animation;
|
|
23
|
-
const deltaTime = Math.min(now - lastTimestamp, 64);
|
|
24
|
-
animation.lastTimestamp = now;
|
|
25
|
-
const c = config.damping;
|
|
26
|
-
const m = config.mass;
|
|
27
|
-
const k = config.stiffness;
|
|
28
|
-
const v0 = -velocity;
|
|
29
|
-
const x0 = toValue - current;
|
|
30
|
-
const zeta = c / (2 * Math.sqrt(k * m)); // damping ratio
|
|
31
|
-
const omega0 = Math.sqrt(k / m); // undamped angular frequency of the oscillator (rad/ms)
|
|
32
|
-
const omega1 = omega0 * Math.sqrt(1 - Math.pow(zeta, 2)); // exponential decay
|
|
33
|
-
const t = deltaTime / 1000;
|
|
34
|
-
const sin1 = Math.sin(omega1 * t);
|
|
35
|
-
const cos1 = Math.cos(omega1 * t);
|
|
36
|
-
// under damped
|
|
37
|
-
const underDampedEnvelope = Math.exp(-zeta * omega0 * t);
|
|
38
|
-
const underDampedFrag1 = underDampedEnvelope *
|
|
39
|
-
(sin1 * ((v0 + zeta * omega0 * x0) / omega1) + x0 * cos1);
|
|
40
|
-
const underDampedPosition = toValue - underDampedFrag1;
|
|
41
|
-
// This looks crazy -- it's actually just the derivative of the oscillation function
|
|
42
|
-
const underDampedVelocity = zeta * omega0 * underDampedFrag1 -
|
|
43
|
-
underDampedEnvelope *
|
|
44
|
-
(cos1 * (v0 + zeta * omega0 * x0) - omega1 * x0 * sin1);
|
|
45
|
-
// critically damped
|
|
46
|
-
const criticallyDampedEnvelope = Math.exp(-omega0 * t);
|
|
47
|
-
const criticallyDampedPosition = toValue - criticallyDampedEnvelope * (x0 + (v0 + omega0 * x0) * t);
|
|
48
|
-
const criticallyDampedVelocity = criticallyDampedEnvelope *
|
|
49
|
-
(v0 * (t * omega0 - 1) + t * x0 * omega0 * omega0);
|
|
50
|
-
const isOvershooting = () => {
|
|
51
|
-
if (config.overshootClamping && config.stiffness !== 0) {
|
|
52
|
-
return current < toValue
|
|
53
|
-
? animation.current > toValue
|
|
54
|
-
: animation.current < toValue;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
const isVelocity = Math.abs(velocity) < config.restSpeedThreshold;
|
|
61
|
-
const isDisplacement = config.stiffness === 0 ||
|
|
62
|
-
Math.abs(toValue - current) < config.restDisplacementThreshold;
|
|
63
|
-
if (zeta < 1) {
|
|
64
|
-
animation.current = underDampedPosition;
|
|
65
|
-
animation.velocity = underDampedVelocity;
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
animation.current = criticallyDampedPosition;
|
|
69
|
-
animation.velocity = criticallyDampedVelocity;
|
|
70
|
-
}
|
|
71
|
-
if (isOvershooting() || (isVelocity && isDisplacement)) {
|
|
72
|
-
if (config.stiffness !== 0) {
|
|
73
|
-
animation.velocity = 0;
|
|
74
|
-
animation.current = toValue;
|
|
75
|
-
}
|
|
76
|
-
// clear lastTimestamp to avoid using stale value by the next spring animation that starts after this one
|
|
77
|
-
animation.lastTimestamp = 0;
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
function onStart(animation, value, now, previousAnimation) {
|
|
83
|
-
animation.current = value;
|
|
84
|
-
if (previousAnimation) {
|
|
85
|
-
animation.velocity =
|
|
86
|
-
previousAnimation.velocity || animation.velocity || 0;
|
|
87
|
-
animation.lastTimestamp = previousAnimation.lastTimestamp || now;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
animation.lastTimestamp = now;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
onFrame: spring,
|
|
95
|
-
onStart,
|
|
96
|
-
toValue,
|
|
97
|
-
velocity: config.velocity || 0,
|
|
98
|
-
current: toValue,
|
|
99
|
-
callback,
|
|
100
|
-
lastTimestamp: 0,
|
|
101
|
-
};
|
|
102
|
-
});
|
|
103
|
-
}
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { defineAnimation } from './util';
|
|
2
|
-
import { withTiming } from './timing';
|
|
3
|
-
import { ColorProperties } from '../UpdateProps';
|
|
4
|
-
import { processColor } from '../Colors';
|
|
5
|
-
// resolves path to value for nested objects
|
|
6
|
-
// if path cannot be resolved returns undefined
|
|
7
|
-
export function resolvePath(obj, path) {
|
|
8
|
-
'worklet';
|
|
9
|
-
const keys = Array.isArray(path) ? path : [path];
|
|
10
|
-
return keys.reduce((acc, current) => {
|
|
11
|
-
if (Array.isArray(acc) && typeof current === 'number') {
|
|
12
|
-
return acc[current];
|
|
13
|
-
}
|
|
14
|
-
else if (typeof acc === 'object' && current in acc) {
|
|
15
|
-
return acc[current];
|
|
16
|
-
}
|
|
17
|
-
return undefined;
|
|
18
|
-
}, obj);
|
|
19
|
-
}
|
|
20
|
-
export function setPath(obj, path, value) {
|
|
21
|
-
'worklet';
|
|
22
|
-
const keys = Array.isArray(path) ? path : [path];
|
|
23
|
-
let currObj = obj;
|
|
24
|
-
for (let i = 0; i < keys.length - 1; i++) {
|
|
25
|
-
// creates entry if there isn't one
|
|
26
|
-
currObj = currObj;
|
|
27
|
-
if (!(keys[i] in currObj)) {
|
|
28
|
-
// if next key is a number create an array
|
|
29
|
-
if (typeof keys[i + 1] === 'number') {
|
|
30
|
-
currObj[keys[i]] = [];
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
currObj[keys[i]] = {};
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
currObj = currObj[keys[i]];
|
|
37
|
-
}
|
|
38
|
-
currObj[keys[keys.length - 1]] =
|
|
39
|
-
value;
|
|
40
|
-
}
|
|
41
|
-
export function withStyleAnimation(styleAnimations) {
|
|
42
|
-
'worklet';
|
|
43
|
-
return defineAnimation({}, () => {
|
|
44
|
-
'worklet';
|
|
45
|
-
const onFrame = (animation, now) => {
|
|
46
|
-
let stillGoing = false;
|
|
47
|
-
const entriesToCheck = [
|
|
48
|
-
{ value: animation.styleAnimations, path: [] },
|
|
49
|
-
];
|
|
50
|
-
while (entriesToCheck.length > 0) {
|
|
51
|
-
const currentEntry = entriesToCheck.pop();
|
|
52
|
-
if (Array.isArray(currentEntry.value)) {
|
|
53
|
-
for (let index = 0; index < currentEntry.value.length; index++) {
|
|
54
|
-
entriesToCheck.push({
|
|
55
|
-
value: currentEntry.value[index],
|
|
56
|
-
path: currentEntry.path.concat(index),
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
else if (typeof currentEntry.value === 'object' &&
|
|
61
|
-
currentEntry.value.onFrame === undefined) {
|
|
62
|
-
// nested object
|
|
63
|
-
for (const key of Object.keys(currentEntry.value)) {
|
|
64
|
-
entriesToCheck.push({
|
|
65
|
-
value: currentEntry.value[key],
|
|
66
|
-
path: currentEntry.path.concat(key),
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
const currentStyleAnimation = currentEntry.value;
|
|
72
|
-
if (currentStyleAnimation.finished) {
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
const finished = currentStyleAnimation.onFrame(currentStyleAnimation, now);
|
|
76
|
-
if (finished) {
|
|
77
|
-
currentStyleAnimation.finished = true;
|
|
78
|
-
if (currentStyleAnimation.callback) {
|
|
79
|
-
currentStyleAnimation.callback(true);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
stillGoing = true;
|
|
84
|
-
}
|
|
85
|
-
if (ColorProperties.includes(currentEntry.path[0])) {
|
|
86
|
-
currentStyleAnimation.current = processColor(currentStyleAnimation.current);
|
|
87
|
-
}
|
|
88
|
-
setPath(animation.current, currentEntry.path, currentStyleAnimation.current);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return !stillGoing;
|
|
92
|
-
};
|
|
93
|
-
const onStart = (animation, value, now, previousAnimation) => {
|
|
94
|
-
const entriesToCheck = [{ value: styleAnimations, path: [] }];
|
|
95
|
-
while (entriesToCheck.length > 0) {
|
|
96
|
-
const currentEntry = entriesToCheck.pop();
|
|
97
|
-
if (Array.isArray(currentEntry.value)) {
|
|
98
|
-
for (let index = 0; index < currentEntry.value.length; index++) {
|
|
99
|
-
entriesToCheck.push({
|
|
100
|
-
value: currentEntry.value[index],
|
|
101
|
-
path: currentEntry.path.concat(index),
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
else if (typeof currentEntry.value === 'object' &&
|
|
106
|
-
currentEntry.value.onStart === undefined) {
|
|
107
|
-
for (const key of Object.keys(currentEntry.value)) {
|
|
108
|
-
entriesToCheck.push({
|
|
109
|
-
value: currentEntry.value[key],
|
|
110
|
-
path: currentEntry.path.concat(key),
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
const prevAnimation = resolvePath(previousAnimation === null || previousAnimation === void 0 ? void 0 : previousAnimation.styleAnimations, currentEntry.path);
|
|
116
|
-
let prevVal = resolvePath(value, currentEntry.path);
|
|
117
|
-
if (prevAnimation && !prevVal) {
|
|
118
|
-
prevVal = prevAnimation.current;
|
|
119
|
-
}
|
|
120
|
-
if (prevVal === undefined) {
|
|
121
|
-
console.warn(`Initial values for animation are missing for property ${currentEntry.path.join('.')}`);
|
|
122
|
-
}
|
|
123
|
-
setPath(animation.current, currentEntry.path, prevVal);
|
|
124
|
-
let currentAnimation;
|
|
125
|
-
if (typeof currentEntry.value !== 'object' ||
|
|
126
|
-
!currentEntry.value.onStart) {
|
|
127
|
-
currentAnimation = withTiming(currentEntry.value, { duration: 0 });
|
|
128
|
-
setPath(animation.styleAnimations, currentEntry.path, currentAnimation);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
currentAnimation = currentEntry.value;
|
|
132
|
-
}
|
|
133
|
-
currentAnimation.onStart(currentAnimation, prevVal, now, prevAnimation);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
const callback = (finished) => {
|
|
138
|
-
if (!finished) {
|
|
139
|
-
const animationsToCheck = [
|
|
140
|
-
styleAnimations,
|
|
141
|
-
];
|
|
142
|
-
while (animationsToCheck.length > 0) {
|
|
143
|
-
const currentAnimation = animationsToCheck.pop();
|
|
144
|
-
if (Array.isArray(currentAnimation)) {
|
|
145
|
-
for (const element of currentAnimation) {
|
|
146
|
-
animationsToCheck.push(element);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
else if (typeof currentAnimation === 'object' &&
|
|
150
|
-
currentAnimation.onStart === undefined) {
|
|
151
|
-
for (const value of Object.values(currentAnimation)) {
|
|
152
|
-
animationsToCheck.push(value);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
const currentStyleAnimation = currentAnimation;
|
|
157
|
-
if (!currentStyleAnimation.finished &&
|
|
158
|
-
currentStyleAnimation.callback) {
|
|
159
|
-
currentStyleAnimation.callback(false);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
return {
|
|
166
|
-
isHigherOrder: true,
|
|
167
|
-
onFrame,
|
|
168
|
-
onStart,
|
|
169
|
-
current: {},
|
|
170
|
-
styleAnimations,
|
|
171
|
-
callback,
|
|
172
|
-
};
|
|
173
|
-
});
|
|
174
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Easing } from '../Easing';
|
|
2
|
-
import { defineAnimation } from './util';
|
|
3
|
-
export function withTiming(toValue, userConfig, callback) {
|
|
4
|
-
'worklet';
|
|
5
|
-
return defineAnimation(toValue, () => {
|
|
6
|
-
'worklet';
|
|
7
|
-
const config = {
|
|
8
|
-
duration: 300,
|
|
9
|
-
easing: Easing.inOut(Easing.quad),
|
|
10
|
-
};
|
|
11
|
-
if (userConfig) {
|
|
12
|
-
Object.keys(userConfig).forEach((key) => (config[key] = userConfig[key]));
|
|
13
|
-
}
|
|
14
|
-
function timing(animation, now) {
|
|
15
|
-
const { toValue, startTime, startValue } = animation;
|
|
16
|
-
const runtime = now - startTime;
|
|
17
|
-
if (runtime >= config.duration) {
|
|
18
|
-
// reset startTime to avoid reusing finished animation config in `start` method
|
|
19
|
-
animation.startTime = 0;
|
|
20
|
-
animation.current = toValue;
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
const progress = animation.easing(runtime / config.duration);
|
|
24
|
-
animation.current =
|
|
25
|
-
startValue + (toValue - startValue) * progress;
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
function onStart(animation, value, now, previousAnimation) {
|
|
29
|
-
if (previousAnimation &&
|
|
30
|
-
previousAnimation.type === 'timing' &&
|
|
31
|
-
previousAnimation.toValue === toValue &&
|
|
32
|
-
previousAnimation.startTime) {
|
|
33
|
-
// to maintain continuity of timing animations we check if we are starting
|
|
34
|
-
// new timing over the old one with the same parameters. If so, we want
|
|
35
|
-
// to copy animation timeline properties
|
|
36
|
-
animation.startTime = previousAnimation.startTime;
|
|
37
|
-
animation.startValue = previousAnimation.startValue;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
animation.startTime = now;
|
|
41
|
-
animation.startValue = value;
|
|
42
|
-
}
|
|
43
|
-
animation.current = value;
|
|
44
|
-
if (typeof config.easing === 'object') {
|
|
45
|
-
animation.easing = config.easing.factory();
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
animation.easing = config.easing;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
type: 'timing',
|
|
53
|
-
onFrame: timing,
|
|
54
|
-
onStart: onStart,
|
|
55
|
-
progress: 0,
|
|
56
|
-
toValue,
|
|
57
|
-
startValue: 0,
|
|
58
|
-
startTime: 0,
|
|
59
|
-
easing: () => 0,
|
|
60
|
-
current: toValue,
|
|
61
|
-
callback,
|
|
62
|
-
};
|
|
63
|
-
});
|
|
64
|
-
}
|