react-native-reanimated 2.3.0-alpha.1 → 2.3.0-beta.2
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/LayoutAnimations/LayoutAnimationsProxy.cpp +15 -8
- package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +170 -166
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +36 -34
- package/Common/cpp/Registries/EventHandlerRegistry.cpp +13 -6
- package/Common/cpp/Registries/MapperRegistry.cpp +19 -15
- package/Common/cpp/Registries/WorkletsCache.cpp +19 -9
- package/Common/cpp/SharedItems/FrozenObject.cpp +19 -8
- package/Common/cpp/SharedItems/MutableValue.cpp +38 -25
- package/Common/cpp/SharedItems/MutableValueSetterProxy.cpp +11 -7
- package/Common/cpp/SharedItems/RemoteObject.cpp +9 -5
- package/Common/cpp/SharedItems/ShareableValue.cpp +216 -143
- package/Common/cpp/Tools/JSIStoreValueUser.cpp +36 -24
- package/Common/cpp/Tools/Mapper.cpp +41 -29
- package/Common/cpp/Tools/RuntimeDecorator.cpp +103 -84
- package/Common/cpp/Tools/Scheduler.cpp +14 -6
- package/Common/cpp/Tools/WorkletEventHandler.cpp +1 -1
- package/Common/cpp/headers/LayoutAnimations/LayoutAnimationsProxy.h +12 -11
- package/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +45 -34
- package/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +28 -16
- package/Common/cpp/headers/Registries/EventHandlerRegistry.h +14 -8
- package/Common/cpp/headers/Registries/MapperRegistry.h +4 -4
- package/Common/cpp/headers/Registries/WorkletsCache.h +9 -7
- package/Common/cpp/headers/SharedItems/FrozenObject.h +15 -11
- package/Common/cpp/headers/SharedItems/HostFunctionHandler.h +6 -4
- package/Common/cpp/headers/SharedItems/MutableValue.h +21 -12
- package/Common/cpp/headers/SharedItems/MutableValueSetterProxy.h +10 -7
- package/Common/cpp/headers/SharedItems/RemoteObject.h +16 -8
- package/Common/cpp/headers/SharedItems/RuntimeManager.h +39 -21
- package/Common/cpp/headers/SharedItems/ShareableValue.h +31 -27
- package/Common/cpp/headers/SharedItems/SharedParent.h +7 -4
- package/Common/cpp/headers/SharedItems/ValueWrapper.h +80 -61
- package/Common/cpp/headers/SpecTools/ErrorHandler.h +17 -19
- package/Common/cpp/headers/Tools/JSIStoreValueUser.h +18 -13
- package/Common/cpp/headers/Tools/Mapper.h +24 -18
- package/Common/cpp/headers/Tools/PlatformDepMethodsHolder.h +12 -7
- package/Common/cpp/headers/Tools/ReanimatedHiddenHeaders.h +7 -7
- package/Common/cpp/headers/Tools/RuntimeDecorator.h +29 -23
- package/Common/cpp/headers/Tools/Scheduler.h +28 -33
- package/Common/cpp/headers/Tools/WorkletEventHandler.h +9 -7
- package/Common/cpp/hidden_headers/Logger.h +14 -14
- package/Common/cpp/hidden_headers/LoggerInterface.h +8 -9
- package/Common/cpp/hidden_headers/SpeedChecker.h +7 -8
- package/README.md +1 -1
- package/RNReanimated.podspec +4 -4
- package/android/build.gradle +80 -3
- package/android/react-native-reanimated-63-hermes.aar +0 -0
- package/android/react-native-reanimated-63-jsc.aar +0 -0
- package/android/react-native-reanimated-64-hermes.aar +0 -0
- package/android/react-native-reanimated-64-jsc.aar +0 -0
- package/android/react-native-reanimated-65-hermes.aar +0 -0
- package/android/react-native-reanimated-65-jsc.aar +0 -0
- package/android/react-native-reanimated-66-hermes.aar +0 -0
- package/android/react-native-reanimated-66-jsc.aar +0 -0
- package/ios/LayoutReanimation/REAAnimationsManager.h +19 -10
- package/ios/LayoutReanimation/REAAnimationsManager.m +195 -200
- package/ios/LayoutReanimation/REASnapshot.h +13 -0
- package/ios/LayoutReanimation/REASnapshot.m +29 -0
- package/ios/LayoutReanimation/REAUIManager.h +16 -0
- package/ios/LayoutReanimation/REAUIManager.mm +348 -0
- package/ios/Nodes/REAAlwaysNode.m +14 -15
- package/ios/Nodes/REABezierNode.m +8 -7
- package/ios/Nodes/REABlockNode.m +1 -1
- package/ios/Nodes/REACallFuncNode.h +0 -1
- package/ios/Nodes/REACallFuncNode.m +10 -8
- package/ios/Nodes/REAClockNodes.m +22 -20
- package/ios/Nodes/REAConcatNode.h +0 -1
- package/ios/Nodes/REAConcatNode.m +2 -2
- package/ios/Nodes/REACondNode.m +7 -5
- package/ios/Nodes/READebugNode.m +5 -4
- package/ios/Nodes/REAEventNode.m +1 -1
- package/ios/Nodes/REAFunctionNode.h +0 -1
- package/ios/Nodes/REAFunctionNode.m +2 -2
- package/ios/Nodes/REAJSCallNode.m +4 -5
- package/ios/Nodes/REANode.h +3 -4
- package/ios/Nodes/REANode.m +9 -11
- package/ios/Nodes/REAOperatorNode.m +68 -67
- package/ios/Nodes/REAParamNode.h +1 -3
- package/ios/Nodes/REAParamNode.m +15 -17
- package/ios/Nodes/REAPropsNode.h +1 -3
- package/ios/Nodes/REAPropsNode.m +19 -22
- package/ios/Nodes/REASetNode.h +0 -1
- package/ios/Nodes/REASetNode.m +7 -5
- package/ios/Nodes/REAStyleNode.h +0 -1
- package/ios/Nodes/REAStyleNode.m +2 -4
- package/ios/Nodes/REATransformNode.h +0 -1
- package/ios/Nodes/REATransformNode.m +3 -5
- package/ios/Nodes/REAValueNode.m +5 -7
- package/ios/REAEventDispatcher.m +3 -3
- package/ios/REAModule.h +0 -2
- package/ios/REAModule.m +29 -40
- package/ios/REANodesManager.h +11 -19
- package/ios/REANodesManager.m +105 -130
- package/ios/REAUtils.h +5 -3
- package/ios/Transitioning/RCTConvert+REATransition.m +45 -29
- package/ios/Transitioning/REAAllTransitions.h +2 -2
- package/ios/Transitioning/REAAllTransitions.m +14 -25
- package/ios/Transitioning/REATransition.h +8 -7
- package/ios/Transitioning/REATransition.m +19 -16
- package/ios/Transitioning/REATransitionAnimation.h +1 -1
- package/ios/Transitioning/REATransitionAnimation.m +2 -3
- package/ios/Transitioning/REATransitionManager.m +3 -3
- package/ios/native/NativeMethods.h +15 -5
- package/ios/native/NativeProxy.h +4 -3
- package/ios/native/NativeProxy.mm +19 -5
- package/ios/native/REAIOSErrorHandler.h +13 -10
- package/ios/native/REAIOSLogger.h +8 -8
- package/ios/native/REAIOSScheduler.h +5 -5
- package/ios/native/REAIOSScheduler.mm +7 -5
- package/ios/native/REAInitializer.h +37 -0
- package/ios/native/REAInitializer.mm +63 -0
- package/ios/native/UIResponder+Reanimated.mm +9 -48
- package/lib/ConfigHelper.js +1 -0
- package/lib/ReanimatedModule.native.js +10 -2
- package/lib/createAnimatedComponent.js +64 -30
- package/lib/reanimated1/core/AnimatedAlways.js +1 -1
- package/lib/reanimated1/core/AnimatedBezier.js +1 -1
- package/lib/reanimated1/core/AnimatedBlock.js +1 -1
- package/lib/reanimated1/core/AnimatedCall.js +1 -1
- package/lib/reanimated1/core/AnimatedCallFunc.js +1 -1
- package/lib/reanimated1/core/AnimatedConcat.js +1 -1
- package/lib/reanimated1/core/AnimatedCond.js +1 -1
- package/lib/reanimated1/core/AnimatedDebug.js +1 -1
- package/lib/reanimated1/core/AnimatedEvent.js +1 -1
- package/lib/reanimated1/core/AnimatedFunction.js +1 -1
- package/lib/reanimated1/core/AnimatedOperator.js +1 -1
- package/lib/reanimated1/core/AnimatedParam.js +1 -1
- package/lib/reanimated1/core/AnimatedProps.js +2 -2
- package/lib/reanimated1/core/AnimatedSet.js +1 -1
- package/lib/reanimated1/core/AnimatedStartClock.js +1 -1
- package/lib/reanimated1/core/AnimatedStopClock.js +1 -1
- package/lib/reanimated1/core/AnimatedStyle.js +1 -1
- package/lib/reanimated1/core/AnimatedTransform.js +1 -1
- package/lib/reanimated1/core/Core.test.js +30 -0
- package/lib/reanimated1/core/InternalAnimatedValue.js +1 -1
- package/lib/reanimated1/core/__mocks__/AnimatedProps.js +1 -1
- package/lib/reanimated1/derived/interpolate.js +1 -1
- package/lib/reanimated2/Colors.js +16 -12
- package/lib/reanimated2/NativeMethods.js +3 -14
- package/lib/reanimated2/{NativeReanimated.native.js → NativeReanimated/NativeReanimated.js} +19 -24
- package/lib/reanimated2/NativeReanimated/index.js +15 -0
- package/lib/reanimated2/PlatformChecker.js +16 -0
- package/lib/reanimated2/PropAdapters.js +14 -4
- package/lib/reanimated2/UpdateProps.js +14 -11
- package/lib/reanimated2/ViewDescriptorsSet.js +73 -0
- package/lib/reanimated2/WorkletEventHandler.js +15 -13
- package/lib/reanimated2/animation/commonTypes.js +1 -0
- package/lib/reanimated2/animation/decay.js +71 -0
- package/lib/reanimated2/animation/delay.js +64 -0
- package/lib/reanimated2/animation/index.js +8 -0
- package/lib/reanimated2/animation/repeat.js +69 -0
- package/lib/reanimated2/animation/sequence.js +72 -0
- package/lib/reanimated2/animation/spring.js +101 -0
- package/lib/reanimated2/animation/styleAnimation.js +166 -0
- package/lib/reanimated2/animation/timing.js +64 -0
- package/lib/reanimated2/animation/util.js +157 -0
- package/lib/reanimated2/commonTypes.js +1 -0
- package/lib/reanimated2/core.js +35 -39
- package/lib/reanimated2/globals.d.ts +47 -1
- package/lib/reanimated2/hook/Hooks.js +9 -0
- package/lib/reanimated2/hook/commonTypes.js +1 -0
- package/lib/reanimated2/hook/index.js +8 -0
- package/lib/reanimated2/hook/useAnimatedGestureHandler.js +50 -0
- package/lib/reanimated2/hook/useAnimatedReaction.js +37 -0
- package/lib/reanimated2/hook/useAnimatedRef.js +25 -0
- package/lib/reanimated2/hook/useAnimatedScrollHandler.js +41 -0
- package/lib/reanimated2/hook/useAnimatedStyle.js +376 -0
- package/lib/reanimated2/hook/useDerivedValue.js +36 -0
- package/lib/reanimated2/hook/useSharedValue.js +17 -0
- package/lib/reanimated2/hook/utils.js +175 -0
- package/lib/reanimated2/index.js +3 -2
- package/lib/reanimated2/interpolation.js +95 -86
- package/lib/reanimated2/jestUtils.js +0 -12
- package/lib/reanimated2/js-reanimated/JSReanimated.js +9 -10
- package/lib/reanimated2/js-reanimated/index.js +57 -1
- package/lib/reanimated2/layoutReanimation/LayoutAnimationRepository.js +58 -0
- package/lib/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js +69 -0
- package/lib/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +125 -0
- package/lib/reanimated2/layoutReanimation/animationBuilder/Keyframe.js +193 -0
- package/lib/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +1 -0
- package/lib/reanimated2/layoutReanimation/animationBuilder/index.js +3 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +325 -207
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Default.js +36 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Fade.js +235 -187
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +327 -269
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +146 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +85 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Roll.js +119 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +289 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +159 -121
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +83 -65
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +371 -277
- package/lib/reanimated2/layoutReanimation/defaultAnimations/index.js +4 -0
- package/lib/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +78 -0
- package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +128 -0
- package/lib/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +37 -0
- package/lib/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +41 -0
- package/lib/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +34 -0
- package/lib/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +46 -0
- package/lib/reanimated2/layoutReanimation/defaultTransitions/index.js +6 -0
- package/lib/reanimated2/layoutReanimation/index.js +3 -2
- package/lib/reanimated2/platform-specific/RNRenderer.web.js +2 -0
- package/lib/reanimated2/utils.js +9 -0
- package/libSo/fbjni/jni/arm64-v8a/libfbjni.so +0 -0
- package/libSo/fbjni/jni/armeabi-v7a/libfbjni.so +0 -0
- package/libSo/fbjni/jni/x86/libfbjni.so +0 -0
- package/libSo/fbjni/jni/x86_64/libfbjni.so +0 -0
- package/package.json +21 -10
- package/plugin.js +244 -85
- package/react-native-reanimated.d.ts +531 -453
- package/src/ConfigHelper.js +1 -0
- package/src/ReanimatedModule.native.js +10 -2
- package/src/createAnimatedComponent.js +64 -30
- package/src/reanimated1/core/AnimatedAlways.js +1 -1
- package/src/reanimated1/core/AnimatedBezier.js +1 -1
- package/src/reanimated1/core/AnimatedBlock.js +1 -1
- package/src/reanimated1/core/AnimatedCall.js +1 -1
- package/src/reanimated1/core/AnimatedCallFunc.js +1 -1
- package/src/reanimated1/core/AnimatedConcat.js +1 -1
- package/src/reanimated1/core/AnimatedCond.js +1 -1
- package/src/reanimated1/core/AnimatedDebug.js +1 -1
- package/src/reanimated1/core/AnimatedEvent.js +1 -1
- package/src/reanimated1/core/AnimatedFunction.js +1 -1
- package/src/reanimated1/core/AnimatedOperator.js +1 -1
- package/src/reanimated1/core/AnimatedParam.js +1 -1
- package/src/reanimated1/core/AnimatedProps.js +2 -2
- package/src/reanimated1/core/AnimatedSet.js +1 -1
- package/src/reanimated1/core/AnimatedStartClock.js +1 -1
- package/src/reanimated1/core/AnimatedStopClock.js +1 -1
- package/src/reanimated1/core/AnimatedStyle.js +1 -1
- package/src/reanimated1/core/AnimatedTransform.js +1 -1
- package/src/reanimated1/core/Core.test.js +30 -0
- package/src/reanimated1/core/InternalAnimatedValue.js +1 -1
- package/src/reanimated1/core/__mocks__/AnimatedProps.js +1 -1
- package/src/reanimated1/derived/interpolate.js +1 -1
- package/src/reanimated2/Colors.ts +30 -27
- package/src/reanimated2/Easing.ts +3 -1
- package/src/reanimated2/NativeMethods.ts +26 -16
- package/src/reanimated2/NativeReanimated/NativeReanimated.ts +78 -0
- package/src/reanimated2/NativeReanimated/index.ts +18 -0
- package/src/reanimated2/PlatformChecker.ts +21 -0
- package/src/reanimated2/PropAdapters.ts +52 -34
- package/src/reanimated2/UpdateProps.ts +40 -20
- package/src/reanimated2/ViewDescriptorsSet.ts +108 -0
- package/src/reanimated2/WorkletEventHandler.ts +41 -23
- package/src/reanimated2/animation/commonTypes.ts +48 -0
- package/src/reanimated2/animation/decay.ts +141 -0
- package/src/reanimated2/animation/delay.ts +103 -0
- package/src/reanimated2/animation/index.ts +16 -0
- package/src/reanimated2/animation/repeat.ts +128 -0
- package/src/reanimated2/animation/sequence.ts +110 -0
- package/src/reanimated2/animation/spring.ts +165 -0
- package/src/reanimated2/animation/styleAnimation.ts +253 -0
- package/src/reanimated2/animation/timing.ts +109 -0
- package/src/reanimated2/animation/util.ts +242 -0
- package/src/reanimated2/commonTypes.ts +81 -0
- package/src/reanimated2/core.ts +128 -82
- package/src/reanimated2/globals.d.ts +47 -1
- package/src/reanimated2/hook/Hooks.ts +16 -0
- package/src/reanimated2/hook/commonTypes.ts +12 -0
- package/src/reanimated2/hook/index.ts +25 -0
- package/src/reanimated2/hook/useAnimatedGestureHandler.ts +110 -0
- package/src/reanimated2/hook/useAnimatedReaction.ts +49 -0
- package/src/reanimated2/hook/useAnimatedRef.ts +34 -0
- package/src/reanimated2/hook/useAnimatedScrollHandler.ts +83 -0
- package/src/reanimated2/hook/useAnimatedStyle.ts +538 -0
- package/src/reanimated2/hook/useDerivedValue.ts +48 -0
- package/src/reanimated2/hook/useSharedValue.ts +22 -0
- package/src/reanimated2/hook/utils.ts +259 -0
- package/src/reanimated2/index.ts +3 -2
- package/src/reanimated2/interpolation.ts +170 -101
- package/src/reanimated2/jestUtils.ts +0 -12
- package/src/reanimated2/js-reanimated/JSReanimated.ts +47 -22
- package/src/reanimated2/js-reanimated/Mapper.ts +1 -1
- package/src/reanimated2/js-reanimated/index.ts +71 -0
- package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.tsx +62 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.ts +91 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.ts +169 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/Keyframe.ts +263 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +78 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +16 -0
- package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +243 -121
- package/src/reanimated2/layoutReanimation/defaultAnimations/Default.ts +43 -0
- package/src/reanimated2/layoutReanimation/defaultAnimations/Fade.ts +95 -53
- package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +114 -64
- package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +179 -0
- package/src/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.ts +93 -0
- package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +132 -0
- package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +333 -0
- package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +84 -50
- package/src/reanimated2/layoutReanimation/defaultAnimations/Stretch.ts +41 -23
- package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +234 -154
- package/src/reanimated2/layoutReanimation/defaultAnimations/index.ts +4 -0
- package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +104 -0
- package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +213 -0
- package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +60 -0
- package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +58 -0
- package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +41 -0
- package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +78 -0
- package/src/reanimated2/layoutReanimation/defaultTransitions/index.ts +6 -0
- package/src/reanimated2/layoutReanimation/index.ts +3 -2
- package/src/reanimated2/platform-specific/RNRenderer.web.ts +2 -0
- package/src/reanimated2/utils.ts +21 -0
- package/android/react-native-reanimated-62-hermes.aar +0 -0
- package/android/react-native-reanimated-62-jsc.aar +0 -0
- package/ios/LayoutReanimation/REAAnimationRootView.h +0 -12
- package/ios/LayoutReanimation/REAAnimationRootView.m +0 -16
- package/ios/LayoutReanimation/REAAnimationRootViewManager.h +0 -9
- package/ios/LayoutReanimation/REAAnimationRootViewManager.m +0 -49
- package/ios/LayoutReanimation/REAReactBatchObserver.h +0 -20
- package/ios/LayoutReanimation/REAReactBatchObserver.m +0 -125
- package/ios/LayoutReanimation/REASnapshooter.h +0 -19
- package/ios/LayoutReanimation/REASnapshooter.m +0 -64
- package/ios/LayoutReanimation/REAViewTraverser.h +0 -13
- package/ios/LayoutReanimation/REAViewTraverser.m +0 -40
- package/lib/reanimated2/Hooks.js +0 -732
- package/lib/reanimated2/NativeReanimated.js +0 -4
- package/lib/reanimated2/animations.js +0 -713
- package/lib/reanimated2/js-reanimated/index.web.js +0 -20
- package/lib/reanimated2/layoutReanimation/AnimatedRoot.js +0 -55
- package/lib/reanimated2/layoutReanimation/defaultAnimationsBuilder.js +0 -374
- package/src/reanimated2/Hooks.ts +0 -918
- package/src/reanimated2/NativeReanimated.native.ts +0 -61
- package/src/reanimated2/NativeReanimated.ts +0 -5
- package/src/reanimated2/animations.ts +0 -868
- package/src/reanimated2/js-reanimated/index.js +0 -0
- package/src/reanimated2/js-reanimated/index.web.ts +0 -29
- package/src/reanimated2/layoutReanimation/AnimatedRoot.tsx +0 -68
- package/src/reanimated2/layoutReanimation/defaultAnimationsBuilder.ts +0 -440
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { defineAnimation } from './util';
|
|
2
|
+
import { withTiming } from './timing';
|
|
3
|
+
// resolves path to value for nested objects
|
|
4
|
+
// if path cannot be resolved returns undefined
|
|
5
|
+
export function resolvePath(obj, path) {
|
|
6
|
+
'worklet';
|
|
7
|
+
const keys = Array.isArray(path) ? path : [path];
|
|
8
|
+
return keys.reduce((acc, current) => {
|
|
9
|
+
if (Array.isArray(acc) && typeof current === 'number') {
|
|
10
|
+
return acc[current];
|
|
11
|
+
}
|
|
12
|
+
else if (typeof acc === 'object' && current in acc) {
|
|
13
|
+
return acc[current];
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}, obj);
|
|
17
|
+
}
|
|
18
|
+
// set value at given path
|
|
19
|
+
export function setPath(obj, path, value) {
|
|
20
|
+
'worklet';
|
|
21
|
+
const keys = Array.isArray(path) ? path : [path];
|
|
22
|
+
let currObj = obj;
|
|
23
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
24
|
+
// creates entry if there isn't one
|
|
25
|
+
currObj = currObj;
|
|
26
|
+
if (!currObj[keys[i]]) {
|
|
27
|
+
// if next key is a number create an array
|
|
28
|
+
if (typeof keys[i + 1] === 'number') {
|
|
29
|
+
currObj[keys[i]] = [];
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
currObj[keys[i]] = {};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
currObj = currObj[keys[i]];
|
|
36
|
+
}
|
|
37
|
+
currObj[keys[keys.length - 1]] = value;
|
|
38
|
+
}
|
|
39
|
+
export function withStyleAnimation(styleAnimations) {
|
|
40
|
+
'worklet';
|
|
41
|
+
return defineAnimation({}, () => {
|
|
42
|
+
'worklet';
|
|
43
|
+
const onFrame = (animation, now) => {
|
|
44
|
+
let stillGoing = false;
|
|
45
|
+
const entriesToCheck = [
|
|
46
|
+
{ value: animation.styleAnimations, path: [] },
|
|
47
|
+
];
|
|
48
|
+
while (entriesToCheck.length > 0) {
|
|
49
|
+
const currentEntry = entriesToCheck.pop();
|
|
50
|
+
if (Array.isArray(currentEntry.value)) {
|
|
51
|
+
for (let index = 0; index < currentEntry.value.length; index++) {
|
|
52
|
+
entriesToCheck.push({
|
|
53
|
+
value: currentEntry.value[index],
|
|
54
|
+
path: currentEntry.path.concat(index),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else if (typeof currentEntry.value === 'object' &&
|
|
59
|
+
currentEntry.value.onFrame === undefined) {
|
|
60
|
+
// nested object
|
|
61
|
+
for (const key of Object.keys(currentEntry.value)) {
|
|
62
|
+
entriesToCheck.push({
|
|
63
|
+
value: currentEntry.value[key],
|
|
64
|
+
path: currentEntry.path.concat(key),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const currentStyleAnimation = currentEntry.value;
|
|
70
|
+
if (currentStyleAnimation.finished) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const finished = currentStyleAnimation.onFrame(currentStyleAnimation, now);
|
|
74
|
+
if (finished) {
|
|
75
|
+
currentStyleAnimation.finished = true;
|
|
76
|
+
if (currentStyleAnimation.callback) {
|
|
77
|
+
currentStyleAnimation.callback(true);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
stillGoing = true;
|
|
82
|
+
}
|
|
83
|
+
setPath(animation.current, currentEntry.path, currentStyleAnimation.current);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return !stillGoing;
|
|
87
|
+
};
|
|
88
|
+
const onStart = (animation, value, now, previousAnimation) => {
|
|
89
|
+
const entriesToCheck = [{ value: styleAnimations, path: [] }];
|
|
90
|
+
while (entriesToCheck.length > 0) {
|
|
91
|
+
const currentEntry = entriesToCheck.pop();
|
|
92
|
+
if (Array.isArray(currentEntry.value)) {
|
|
93
|
+
for (let index = 0; index < currentEntry.value.length; index++) {
|
|
94
|
+
entriesToCheck.push({
|
|
95
|
+
value: currentEntry.value[index],
|
|
96
|
+
path: currentEntry.path.concat(index),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else if (typeof currentEntry.value === 'object' &&
|
|
101
|
+
currentEntry.value.onStart === undefined) {
|
|
102
|
+
for (const key of Object.keys(currentEntry.value)) {
|
|
103
|
+
entriesToCheck.push({
|
|
104
|
+
value: currentEntry.value[key],
|
|
105
|
+
path: currentEntry.path.concat(key),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
const prevAnimation = resolvePath(previousAnimation === null || previousAnimation === void 0 ? void 0 : previousAnimation.styleAnimations, currentEntry.path);
|
|
111
|
+
let prevVal = resolvePath(value, currentEntry.path);
|
|
112
|
+
if (prevAnimation && !prevVal) {
|
|
113
|
+
prevVal = prevAnimation.current;
|
|
114
|
+
}
|
|
115
|
+
setPath(animation.current, currentEntry.path, prevVal);
|
|
116
|
+
let currentAnimation;
|
|
117
|
+
if (typeof currentEntry.value !== 'object' ||
|
|
118
|
+
!currentEntry.value.onStart) {
|
|
119
|
+
currentAnimation = withTiming(currentEntry.value, { duration: 0 });
|
|
120
|
+
setPath(animation.styleAnimations, currentEntry.path, currentAnimation);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
currentAnimation = currentEntry.value;
|
|
124
|
+
}
|
|
125
|
+
currentAnimation.onStart(currentAnimation, prevVal, now, prevAnimation);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
const callback = (finished) => {
|
|
130
|
+
if (!finished) {
|
|
131
|
+
const animationsToCheck = [
|
|
132
|
+
styleAnimations,
|
|
133
|
+
];
|
|
134
|
+
while (animationsToCheck.length > 0) {
|
|
135
|
+
const currentAnimation = animationsToCheck.pop();
|
|
136
|
+
if (Array.isArray(currentAnimation)) {
|
|
137
|
+
for (const element of currentAnimation) {
|
|
138
|
+
animationsToCheck.push(element);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else if (typeof currentAnimation === 'object' &&
|
|
142
|
+
currentAnimation.onStart === undefined) {
|
|
143
|
+
for (const value of Object.values(currentAnimation)) {
|
|
144
|
+
animationsToCheck.push(value);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
const currentStyleAnimation = currentAnimation;
|
|
149
|
+
if (!currentStyleAnimation.finished &&
|
|
150
|
+
currentStyleAnimation.callback) {
|
|
151
|
+
currentStyleAnimation.callback(false);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
return {
|
|
158
|
+
isHigherOrder: true,
|
|
159
|
+
onFrame,
|
|
160
|
+
onStart,
|
|
161
|
+
current: {},
|
|
162
|
+
styleAnimations,
|
|
163
|
+
callback,
|
|
164
|
+
};
|
|
165
|
+
});
|
|
166
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/* global _WORKLET */
|
|
2
|
+
import { convertToHSVA, isColor, toRGBA } from '../Colors';
|
|
3
|
+
import NativeReanimatedModule from '../NativeReanimated';
|
|
4
|
+
let IN_STYLE_UPDATER = false;
|
|
5
|
+
export function initialUpdaterRun(updater) {
|
|
6
|
+
IN_STYLE_UPDATER = true;
|
|
7
|
+
const result = updater();
|
|
8
|
+
IN_STYLE_UPDATER = false;
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
function recognizePrefixSuffix(value) {
|
|
12
|
+
'worklet';
|
|
13
|
+
var _a;
|
|
14
|
+
if (typeof value === 'string') {
|
|
15
|
+
const match = value.match(/([A-Za-z]*)(-?\d*\.?\d*)([eE][-+]?[0-9]+)?([A-Za-z%]*)/);
|
|
16
|
+
if (!match) {
|
|
17
|
+
throw Error("Couldn't parse animation value. Check if there isn't any typo.");
|
|
18
|
+
}
|
|
19
|
+
const prefix = match[1];
|
|
20
|
+
const suffix = match[4];
|
|
21
|
+
// number with scientific notation
|
|
22
|
+
const number = match[2] + ((_a = match[3]) !== null && _a !== void 0 ? _a : '');
|
|
23
|
+
return { prefix, suffix, strippedValue: parseFloat(number) };
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return { strippedValue: value };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function decorateAnimation(animation) {
|
|
30
|
+
'worklet';
|
|
31
|
+
if (animation.isHigherOrder) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const baseOnStart = animation.onStart;
|
|
35
|
+
const baseOnFrame = animation.onFrame;
|
|
36
|
+
const animationCopy = Object.assign({}, animation);
|
|
37
|
+
delete animationCopy.callback;
|
|
38
|
+
const prefNumberSuffOnStart = (animation, value, timestamp, previousAnimation) => {
|
|
39
|
+
var _a, _b, _c, _d;
|
|
40
|
+
// recognize prefix, suffix, and updates stripped value on animation start
|
|
41
|
+
const { prefix, suffix, strippedValue } = recognizePrefixSuffix(value);
|
|
42
|
+
animation.__prefix = prefix;
|
|
43
|
+
animation.__suffix = suffix;
|
|
44
|
+
animation.strippedCurrent = strippedValue;
|
|
45
|
+
const { strippedValue: strippedToValue } = recognizePrefixSuffix(animation.toValue);
|
|
46
|
+
animation.current = strippedValue;
|
|
47
|
+
animation.startValue = strippedValue;
|
|
48
|
+
animation.toValue = strippedToValue;
|
|
49
|
+
if (previousAnimation && previousAnimation !== animation) {
|
|
50
|
+
previousAnimation.current = previousAnimation.strippedCurrent;
|
|
51
|
+
}
|
|
52
|
+
baseOnStart(animation, strippedValue, timestamp, previousAnimation);
|
|
53
|
+
animation.current =
|
|
54
|
+
((_a = animation.__prefix) !== null && _a !== void 0 ? _a : '') +
|
|
55
|
+
animation.current +
|
|
56
|
+
((_b = animation.__suffix) !== null && _b !== void 0 ? _b : '');
|
|
57
|
+
if (previousAnimation && previousAnimation !== animation) {
|
|
58
|
+
previousAnimation.current =
|
|
59
|
+
((_c = previousAnimation.__prefix) !== null && _c !== void 0 ? _c : '') +
|
|
60
|
+
previousAnimation.current +
|
|
61
|
+
((_d = previousAnimation.__suffix) !== null && _d !== void 0 ? _d : '');
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const prefNumberSuffOnFrame = (animation, timestamp) => {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
animation.current = animation.strippedCurrent;
|
|
67
|
+
const res = baseOnFrame(animation, timestamp);
|
|
68
|
+
animation.strippedCurrent = animation.current;
|
|
69
|
+
animation.current =
|
|
70
|
+
((_a = animation.__prefix) !== null && _a !== void 0 ? _a : '') +
|
|
71
|
+
animation.current +
|
|
72
|
+
((_b = animation.__suffix) !== null && _b !== void 0 ? _b : '');
|
|
73
|
+
return res;
|
|
74
|
+
};
|
|
75
|
+
const tab = ['H', 'S', 'V', 'A'];
|
|
76
|
+
const colorOnStart = (animation, value, timestamp, previousAnimation) => {
|
|
77
|
+
let HSVAValue;
|
|
78
|
+
let HSVACurrent;
|
|
79
|
+
let HSVAToValue;
|
|
80
|
+
const res = [];
|
|
81
|
+
if (isColor(value)) {
|
|
82
|
+
HSVACurrent = convertToHSVA(animation.current);
|
|
83
|
+
HSVAValue = convertToHSVA(value);
|
|
84
|
+
if (animation.toValue) {
|
|
85
|
+
HSVAToValue = convertToHSVA(animation.toValue);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
tab.forEach((i, index) => {
|
|
89
|
+
animation[i] = Object.assign({}, animationCopy);
|
|
90
|
+
animation[i].current = HSVACurrent[index];
|
|
91
|
+
animation[i].toValue = HSVAToValue ? HSVAToValue[index] : undefined;
|
|
92
|
+
animation[i].onStart(animation[i], HSVAValue[index], timestamp, previousAnimation ? previousAnimation[i] : undefined);
|
|
93
|
+
res.push(animation[i].current);
|
|
94
|
+
});
|
|
95
|
+
animation.current = toRGBA(res);
|
|
96
|
+
};
|
|
97
|
+
const colorOnFrame = (animation, timestamp) => {
|
|
98
|
+
const HSVACurrent = convertToHSVA(animation.current);
|
|
99
|
+
const res = [];
|
|
100
|
+
let finished = true;
|
|
101
|
+
tab.forEach((i, index) => {
|
|
102
|
+
animation[i].current = HSVACurrent[index];
|
|
103
|
+
// @ts-ignore: disable-next-line
|
|
104
|
+
finished &= animation[i].onFrame(animation[i], timestamp);
|
|
105
|
+
res.push(animation[i].current);
|
|
106
|
+
});
|
|
107
|
+
animation.current = toRGBA(res);
|
|
108
|
+
return finished;
|
|
109
|
+
};
|
|
110
|
+
animation.onStart = (animation, value, timestamp, previousAnimation) => {
|
|
111
|
+
if (isColor(value)) {
|
|
112
|
+
colorOnStart(animation, value, timestamp, previousAnimation);
|
|
113
|
+
animation.onFrame = colorOnFrame;
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
else if (typeof value === 'string') {
|
|
117
|
+
prefNumberSuffOnStart(animation, value, timestamp, previousAnimation);
|
|
118
|
+
animation.onFrame = prefNumberSuffOnFrame;
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
baseOnStart(animation, value, timestamp, previousAnimation);
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export function defineAnimation(starting, factory) {
|
|
125
|
+
'worklet';
|
|
126
|
+
if (IN_STYLE_UPDATER) {
|
|
127
|
+
return starting;
|
|
128
|
+
}
|
|
129
|
+
const create = () => {
|
|
130
|
+
'worklet';
|
|
131
|
+
const animation = factory();
|
|
132
|
+
decorateAnimation(animation);
|
|
133
|
+
return animation;
|
|
134
|
+
};
|
|
135
|
+
if (_WORKLET || !NativeReanimatedModule.native) {
|
|
136
|
+
return create();
|
|
137
|
+
}
|
|
138
|
+
// @ts-ignore: eslint-disable-line
|
|
139
|
+
return create;
|
|
140
|
+
}
|
|
141
|
+
export function cancelAnimation(sharedValue) {
|
|
142
|
+
'worklet';
|
|
143
|
+
// setting the current value cancels the animation if one is currently running
|
|
144
|
+
sharedValue.value = sharedValue.value; // eslint-disable-line no-self-assign
|
|
145
|
+
}
|
|
146
|
+
// TODO it should work only if there was no animation before.
|
|
147
|
+
export function withStartValue(startValue, animation) {
|
|
148
|
+
'worklet';
|
|
149
|
+
return defineAnimation(startValue, () => {
|
|
150
|
+
'worklet';
|
|
151
|
+
if (!_WORKLET && typeof animation === 'function') {
|
|
152
|
+
animation = animation();
|
|
153
|
+
}
|
|
154
|
+
animation.current = startValue;
|
|
155
|
+
return animation;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/reanimated2/core.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/* global _WORKLET _getCurrentTime _frameTimestamp _eventTimestamp, _setGlobalConsole */
|
|
2
|
-
|
|
3
|
-
// @ts-nocheck
|
|
4
|
-
import NativeReanimated from './NativeReanimated';
|
|
2
|
+
import NativeReanimatedModule from './NativeReanimated';
|
|
5
3
|
import { Platform } from 'react-native';
|
|
6
|
-
import {
|
|
4
|
+
import { nativeShouldBeMock, shouldBeUseWeb } from './PlatformChecker';
|
|
7
5
|
global.__reanimatedWorkletInit = function (worklet) {
|
|
8
6
|
worklet.__worklet = true;
|
|
9
7
|
};
|
|
@@ -17,7 +15,7 @@ const testWorklet = () => {
|
|
|
17
15
|
'worklet';
|
|
18
16
|
};
|
|
19
17
|
export const checkPluginState = (throwError = true) => {
|
|
20
|
-
if (!testWorklet.__workletHash && !
|
|
18
|
+
if (!testWorklet.__workletHash && !shouldBeUseWeb()) {
|
|
21
19
|
if (throwError) {
|
|
22
20
|
throw new Error("Reanimated 2 failed to create a worklet, maybe you forgot to add Reanimated's babel plugin?");
|
|
23
21
|
}
|
|
@@ -26,11 +24,11 @@ export const checkPluginState = (throwError = true) => {
|
|
|
26
24
|
return true;
|
|
27
25
|
};
|
|
28
26
|
export const isConfigured = (throwError = false) => {
|
|
29
|
-
return checkPluginState(throwError) && !
|
|
27
|
+
return checkPluginState(throwError) && !NativeReanimatedModule.useOnlyV1;
|
|
30
28
|
};
|
|
31
29
|
export const isConfiguredCheck = () => {
|
|
32
30
|
if (!isConfigured(true)) {
|
|
33
|
-
throw new Error('If you want to use Reanimated 2 then go through our installation steps https://docs.swmansion.com/react-native-reanimated/docs/installation');
|
|
31
|
+
throw new Error('If you want to use Reanimated 2 then go through our installation steps https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation');
|
|
34
32
|
}
|
|
35
33
|
};
|
|
36
34
|
function _toArrayReanimated(object) {
|
|
@@ -40,15 +38,17 @@ function _toArrayReanimated(object) {
|
|
|
40
38
|
}
|
|
41
39
|
if (typeof Symbol !== 'undefined' &&
|
|
42
40
|
(typeof Symbol === 'function' ? Symbol.iterator : '@@iterator') in
|
|
43
|
-
Object(object))
|
|
41
|
+
Object(object)) {
|
|
44
42
|
return Array.from(object);
|
|
45
|
-
|
|
43
|
+
}
|
|
44
|
+
throw new Error('Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.');
|
|
46
45
|
}
|
|
47
46
|
function _mergeObjectsReanimated() {
|
|
48
47
|
'worklet';
|
|
49
48
|
// we can't use rest parameters in worklets at the moment
|
|
50
49
|
// eslint-disable-next-line prefer-rest-params
|
|
51
|
-
|
|
50
|
+
const arr = Array.from(arguments);
|
|
51
|
+
return Object.assign.apply(null, [arr[0], ...arr.slice(1)]);
|
|
52
52
|
}
|
|
53
53
|
global.__reanimatedWorkletInit = function (worklet) {
|
|
54
54
|
worklet.__worklet = true;
|
|
@@ -65,11 +65,11 @@ global.__reanimatedWorkletInit = function (worklet) {
|
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
67
|
function pushFrame(frame) {
|
|
68
|
-
|
|
68
|
+
NativeReanimatedModule.pushFrame(frame);
|
|
69
69
|
}
|
|
70
70
|
export function requestFrame(frame) {
|
|
71
71
|
'worklet';
|
|
72
|
-
if (
|
|
72
|
+
if (NativeReanimatedModule.native) {
|
|
73
73
|
requestAnimationFrame(frame);
|
|
74
74
|
}
|
|
75
75
|
else {
|
|
@@ -85,12 +85,12 @@ export function runOnUI(worklet) {
|
|
|
85
85
|
}
|
|
86
86
|
export function makeShareable(value) {
|
|
87
87
|
isConfiguredCheck();
|
|
88
|
-
return
|
|
88
|
+
return NativeReanimatedModule.makeShareable(value);
|
|
89
89
|
}
|
|
90
90
|
export function getViewProp(viewTag, propName) {
|
|
91
91
|
return new Promise((resolve, reject) => {
|
|
92
|
-
return
|
|
93
|
-
if (result.substr(0, 6) === 'error:') {
|
|
92
|
+
return NativeReanimatedModule.getViewProp(viewTag, propName, (result) => {
|
|
93
|
+
if (typeof result === 'string' && result.substr(0, 6) === 'error:') {
|
|
94
94
|
reject(result);
|
|
95
95
|
}
|
|
96
96
|
else {
|
|
@@ -100,9 +100,9 @@ export function getViewProp(viewTag, propName) {
|
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
102
|
let _getTimestamp;
|
|
103
|
-
if (
|
|
103
|
+
if (nativeShouldBeMock()) {
|
|
104
104
|
_getTimestamp = () => {
|
|
105
|
-
return
|
|
105
|
+
return NativeReanimatedModule.getTimestamp();
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
108
|
else {
|
|
@@ -120,7 +120,7 @@ else {
|
|
|
120
120
|
export function getTimestamp() {
|
|
121
121
|
'worklet';
|
|
122
122
|
if (Platform.OS === 'web') {
|
|
123
|
-
return
|
|
123
|
+
return NativeReanimatedModule.getTimestamp();
|
|
124
124
|
}
|
|
125
125
|
return _getTimestamp();
|
|
126
126
|
}
|
|
@@ -132,13 +132,16 @@ function workletValueSetter(value) {
|
|
|
132
132
|
this._animation = null;
|
|
133
133
|
}
|
|
134
134
|
if (typeof value === 'function' ||
|
|
135
|
-
(value !== null &&
|
|
135
|
+
(value !== null &&
|
|
136
|
+
typeof value === 'object' &&
|
|
137
|
+
value.onFrame !== undefined)) {
|
|
136
138
|
const animation = typeof value === 'function' ? value() : value;
|
|
137
139
|
// prevent setting again to the same value
|
|
138
140
|
// and triggering the mappers that treat this value as an input
|
|
139
141
|
// this happens when the animation's target value(stored in animation.current until animation.onStart is called) is set to the same value as a current one(this._value)
|
|
140
142
|
// built in animations that are not higher order(withTiming, withSpring) hold target value in .current
|
|
141
143
|
if (this._value === animation.current && !animation.isHigherOrder) {
|
|
144
|
+
animation.callback && animation.callback(true);
|
|
142
145
|
return;
|
|
143
146
|
}
|
|
144
147
|
// animated set
|
|
@@ -189,7 +192,9 @@ function workletValueSetterJS(value) {
|
|
|
189
192
|
this._animation = null;
|
|
190
193
|
}
|
|
191
194
|
if (typeof value === 'function' ||
|
|
192
|
-
(value !== null &&
|
|
195
|
+
(value !== null &&
|
|
196
|
+
typeof value === 'object' &&
|
|
197
|
+
value.onFrame)) {
|
|
193
198
|
// animated set
|
|
194
199
|
const animation = typeof value === 'function' ? value() : value;
|
|
195
200
|
let initializeAnimation = (timestamp) => {
|
|
@@ -206,7 +211,7 @@ function workletValueSetterJS(value) {
|
|
|
206
211
|
}
|
|
207
212
|
const finished = animation.onFrame(animation, timestamp);
|
|
208
213
|
animation.timestamp = timestamp;
|
|
209
|
-
this._setValue(animation.current);
|
|
214
|
+
this._setValue && this._setValue(animation.current);
|
|
210
215
|
if (finished) {
|
|
211
216
|
animation.callback && animation.callback(true /* finished */);
|
|
212
217
|
}
|
|
@@ -218,27 +223,27 @@ function workletValueSetterJS(value) {
|
|
|
218
223
|
requestFrame(step);
|
|
219
224
|
}
|
|
220
225
|
else {
|
|
221
|
-
this._setValue(value);
|
|
226
|
+
this._setValue && this._setValue(value);
|
|
222
227
|
}
|
|
223
228
|
}
|
|
224
229
|
export function makeMutable(value) {
|
|
225
230
|
isConfiguredCheck();
|
|
226
|
-
return
|
|
231
|
+
return NativeReanimatedModule.makeMutable(value);
|
|
227
232
|
}
|
|
228
233
|
export function makeRemote(object = {}) {
|
|
229
234
|
isConfiguredCheck();
|
|
230
|
-
return
|
|
235
|
+
return NativeReanimatedModule.makeRemote(object);
|
|
231
236
|
}
|
|
232
237
|
export function startMapper(mapper, inputs = [], outputs = [], updater = () => {
|
|
233
238
|
// noop
|
|
234
|
-
},
|
|
239
|
+
}, viewDescriptors = []) {
|
|
235
240
|
isConfiguredCheck();
|
|
236
|
-
return
|
|
241
|
+
return NativeReanimatedModule.startMapper(mapper, inputs, outputs, updater, viewDescriptors);
|
|
237
242
|
}
|
|
238
243
|
export function stopMapper(mapperId) {
|
|
239
|
-
|
|
244
|
+
NativeReanimatedModule.stopMapper(mapperId);
|
|
240
245
|
}
|
|
241
|
-
export
|
|
246
|
+
export function runOnJS(fun) {
|
|
242
247
|
'worklet';
|
|
243
248
|
if (!_WORKLET) {
|
|
244
249
|
return fun;
|
|
@@ -249,18 +254,9 @@ export const runOnJS = (fun) => {
|
|
|
249
254
|
else {
|
|
250
255
|
return fun.__callAsync;
|
|
251
256
|
}
|
|
252
|
-
};
|
|
253
|
-
export function createAnimatedPropAdapter(adapter, nativeProps) {
|
|
254
|
-
const nativePropsToAdd = {};
|
|
255
|
-
// eslint-disable-next-line no-unused-expressions
|
|
256
|
-
nativeProps === null || nativeProps === void 0 ? void 0 : nativeProps.forEach((prop) => {
|
|
257
|
-
nativePropsToAdd[prop] = true;
|
|
258
|
-
});
|
|
259
|
-
addWhitelistedNativeProps(nativePropsToAdd);
|
|
260
|
-
return adapter;
|
|
261
257
|
}
|
|
262
|
-
if (!
|
|
263
|
-
|
|
258
|
+
if (!NativeReanimatedModule.useOnlyV1) {
|
|
259
|
+
NativeReanimatedModule.installCoreFunctions(NativeReanimatedModule.native ? workletValueSetter : workletValueSetterJS);
|
|
264
260
|
const capturableConsole = console;
|
|
265
261
|
isConfigured() &&
|
|
266
262
|
runOnUI(() => {
|
|
@@ -1 +1,47 @@
|
|
|
1
|
-
|
|
1
|
+
import { AnimatedStyle, StyleProps, WorkletFunction } from './commonTypes';
|
|
2
|
+
import { ReanimatedConsole } from './core';
|
|
3
|
+
import { MeasuredDimensions } from './NativeMethods';
|
|
4
|
+
import { NativeReanimated } from './NativeReanimated/NativeReanimated';
|
|
5
|
+
declare global {
|
|
6
|
+
const _WORKLET: boolean;
|
|
7
|
+
const _frameTimestamp: number;
|
|
8
|
+
const _eventTimestamp: number;
|
|
9
|
+
const _setGlobalConsole: (console?: ReanimatedConsole) => void;
|
|
10
|
+
const _getCurrentTime: () => number;
|
|
11
|
+
const _stopObservingProgress: (tag: number, flag: boolean) => void;
|
|
12
|
+
const _startObservingProgress: (
|
|
13
|
+
tag: number,
|
|
14
|
+
flag: { value: boolean; _value: boolean }
|
|
15
|
+
) => void;
|
|
16
|
+
const _updateProps: (
|
|
17
|
+
tag: number,
|
|
18
|
+
name: string,
|
|
19
|
+
updates: StyleProps | AnimatedStyle
|
|
20
|
+
) => void;
|
|
21
|
+
const _measure: (viewTag: number) => MeasuredDimensions;
|
|
22
|
+
const _scrollTo: (
|
|
23
|
+
viewTag: number,
|
|
24
|
+
x: number,
|
|
25
|
+
y: number,
|
|
26
|
+
animated: boolean
|
|
27
|
+
) => void;
|
|
28
|
+
namespace NodeJS {
|
|
29
|
+
interface Global {
|
|
30
|
+
__reanimatedWorkletInit: (worklet: WorkletFunction) => void;
|
|
31
|
+
_setGlobalConsole: (console?: ReanimatedConsole) => void;
|
|
32
|
+
_log: (s: string) => void;
|
|
33
|
+
_WORKLET: boolean;
|
|
34
|
+
__reanimatedModuleProxy: NativeReanimated;
|
|
35
|
+
LayoutAnimationRepository: {
|
|
36
|
+
configs: Record<string, unknown>;
|
|
37
|
+
registerConfig(tag: number, config: Record<string, unknown>): void;
|
|
38
|
+
removeConfig(tag: number): void;
|
|
39
|
+
startAnimationForTag(
|
|
40
|
+
tag: number,
|
|
41
|
+
type: string,
|
|
42
|
+
yogaValues: unknown
|
|
43
|
+
): void;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useAnimatedStyle } from './useAnimatedStyle';
|
|
3
|
+
// TODO: we should make sure that when useAP is used we are not assigning styles
|
|
4
|
+
// when you need styles to animated you should always use useAS
|
|
5
|
+
export const useAnimatedProps = useAnimatedStyle;
|
|
6
|
+
export function useWorkletCallback(fun, deps) {
|
|
7
|
+
return useCallback(fun, deps !== null && deps !== void 0 ? deps : []);
|
|
8
|
+
}
|
|
9
|
+
export { useEvent, useHandler } from './utils';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { useAnimatedProps, useEvent, useHandler, useWorkletCallback, } from './Hooks';
|
|
2
|
+
export { useSharedValue } from './useSharedValue';
|
|
3
|
+
export { useAnimatedStyle } from './useAnimatedStyle';
|
|
4
|
+
export { useAnimatedGestureHandler, } from './useAnimatedGestureHandler';
|
|
5
|
+
export { useAnimatedReaction, } from './useAnimatedReaction';
|
|
6
|
+
export { useAnimatedRef } from './useAnimatedRef';
|
|
7
|
+
export { useAnimatedScrollHandler, } from './useAnimatedScrollHandler';
|
|
8
|
+
export { useDerivedValue } from './useDerivedValue';
|