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,175 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { processColor } from '../Colors';
|
|
3
|
+
import { makeRemote } from '../core';
|
|
4
|
+
import { isWeb } from '../PlatformChecker';
|
|
5
|
+
import { colorProps } from '../UpdateProps';
|
|
6
|
+
import WorkletEventHandler from '../WorkletEventHandler';
|
|
7
|
+
export function useEvent(handler, eventNames = [], rebuild = false) {
|
|
8
|
+
const initRef = useRef(null);
|
|
9
|
+
if (initRef.current === null) {
|
|
10
|
+
initRef.current = new WorkletEventHandler(handler, eventNames);
|
|
11
|
+
}
|
|
12
|
+
else if (rebuild) {
|
|
13
|
+
initRef.current.updateWorklet(handler);
|
|
14
|
+
}
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
return () => {
|
|
17
|
+
initRef.current = null;
|
|
18
|
+
};
|
|
19
|
+
}, []);
|
|
20
|
+
return initRef;
|
|
21
|
+
}
|
|
22
|
+
export function useHandler(handlers, dependencies) {
|
|
23
|
+
const initRef = useRef(null);
|
|
24
|
+
if (initRef.current === null) {
|
|
25
|
+
initRef.current = {
|
|
26
|
+
context: makeRemote({}),
|
|
27
|
+
savedDependencies: [],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
return () => {
|
|
32
|
+
initRef.current = null;
|
|
33
|
+
};
|
|
34
|
+
}, []);
|
|
35
|
+
const { context, savedDependencies } = initRef.current;
|
|
36
|
+
dependencies = buildDependencies(dependencies, handlers);
|
|
37
|
+
const doDependenciesDiffer = !areDependenciesEqual(dependencies, savedDependencies);
|
|
38
|
+
initRef.current.savedDependencies = dependencies;
|
|
39
|
+
const useWeb = isWeb();
|
|
40
|
+
return { context, doDependenciesDiffer, useWeb };
|
|
41
|
+
}
|
|
42
|
+
// builds one big hash from multiple worklets' hashes
|
|
43
|
+
export function buildWorkletsHash(handlers) {
|
|
44
|
+
return Object.values(handlers).reduce((acc, worklet) =>
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
46
|
+
acc + worklet.__workletHash.toString(), '');
|
|
47
|
+
}
|
|
48
|
+
// builds dependencies array for gesture handlers
|
|
49
|
+
export function buildDependencies(dependencies, handlers) {
|
|
50
|
+
const handlersList = Object.values(handlers).filter((handler) => handler !== undefined);
|
|
51
|
+
if (!dependencies) {
|
|
52
|
+
dependencies = handlersList.map((handler) => {
|
|
53
|
+
return {
|
|
54
|
+
workletHash: handler.__workletHash,
|
|
55
|
+
closure: handler._closure,
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
dependencies.push(buildWorkletsHash(handlersList));
|
|
61
|
+
}
|
|
62
|
+
return dependencies;
|
|
63
|
+
}
|
|
64
|
+
// this is supposed to work as useEffect comparison
|
|
65
|
+
export function areDependenciesEqual(nextDeps, prevDeps) {
|
|
66
|
+
function is(x, y) {
|
|
67
|
+
/* eslint-disable no-self-compare */
|
|
68
|
+
return (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y);
|
|
69
|
+
/* eslint-enable no-self-compare */
|
|
70
|
+
}
|
|
71
|
+
const objectIs = typeof Object.is === 'function' ? Object.is : is;
|
|
72
|
+
function areHookInputsEqual(nextDeps, prevDeps) {
|
|
73
|
+
if (!nextDeps || !prevDeps || prevDeps.length !== nextDeps.length) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
for (let i = 0; i < prevDeps.length; ++i) {
|
|
77
|
+
if (!objectIs(nextDeps[i], prevDeps[i])) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
return areHookInputsEqual(nextDeps, prevDeps);
|
|
84
|
+
}
|
|
85
|
+
export function hasColorProps(updates) {
|
|
86
|
+
const colorPropsSet = new Set(colorProps);
|
|
87
|
+
for (const key in updates) {
|
|
88
|
+
if (colorPropsSet.has(key)) {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
export function parseColors(updates) {
|
|
95
|
+
'worklet';
|
|
96
|
+
for (const key in updates) {
|
|
97
|
+
if (colorProps.indexOf(key) !== -1) {
|
|
98
|
+
updates[key] = processColor(updates[key]);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export function canApplyOptimalisation(upadterFn) {
|
|
103
|
+
const FUNCTIONLESS_FLAG = 0b00000001;
|
|
104
|
+
const STATEMENTLESS_FLAG = 0b00000010;
|
|
105
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
106
|
+
const optimalization = upadterFn.__optimalization;
|
|
107
|
+
return (optimalization & FUNCTIONLESS_FLAG && optimalization & STATEMENTLESS_FLAG);
|
|
108
|
+
}
|
|
109
|
+
export function isAnimated(prop) {
|
|
110
|
+
'worklet';
|
|
111
|
+
const propsToCheck = [prop];
|
|
112
|
+
while (propsToCheck.length > 0) {
|
|
113
|
+
const currentProp = propsToCheck.pop();
|
|
114
|
+
if (Array.isArray(currentProp)) {
|
|
115
|
+
for (const item of currentProp) {
|
|
116
|
+
propsToCheck.push(item);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else if ((currentProp === null || currentProp === void 0 ? void 0 : currentProp.onFrame) !== undefined) {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
else if (typeof currentProp === 'object') {
|
|
123
|
+
for (const item of Object.values(currentProp)) {
|
|
124
|
+
propsToCheck.push(item);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// if none of the above, it's not the animated prop, check next one
|
|
128
|
+
}
|
|
129
|
+
// when none of the props were animated return false
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
export function styleDiff(oldStyle, newStyle) {
|
|
133
|
+
'worklet';
|
|
134
|
+
const diff = {};
|
|
135
|
+
Object.keys(oldStyle).forEach((key) => {
|
|
136
|
+
if (newStyle[key] === undefined) {
|
|
137
|
+
diff[key] = null;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
Object.keys(newStyle).forEach((key) => {
|
|
141
|
+
const value = newStyle[key];
|
|
142
|
+
const oldValue = oldStyle[key];
|
|
143
|
+
if (isAnimated(value)) {
|
|
144
|
+
// do nothing
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (oldValue !== value &&
|
|
148
|
+
JSON.stringify(oldValue) !== JSON.stringify(value)) {
|
|
149
|
+
// I'd use deep equal here but that'd take additional work and this was easier
|
|
150
|
+
diff[key] = value;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
return diff;
|
|
154
|
+
}
|
|
155
|
+
export function getStyleWithoutAnimations(newStyle) {
|
|
156
|
+
'worklet';
|
|
157
|
+
const diff = {};
|
|
158
|
+
for (const key in newStyle) {
|
|
159
|
+
const value = newStyle[key];
|
|
160
|
+
if (isAnimated(value)) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
diff[key] = value;
|
|
164
|
+
}
|
|
165
|
+
return diff;
|
|
166
|
+
}
|
|
167
|
+
export const validateAnimatedStyles = (styles) => {
|
|
168
|
+
'worklet';
|
|
169
|
+
if (typeof styles !== 'object') {
|
|
170
|
+
throw new Error(`useAnimatedStyle has to return an object, found ${typeof styles} instead`);
|
|
171
|
+
}
|
|
172
|
+
else if (Array.isArray(styles)) {
|
|
173
|
+
throw new Error('useAnimatedStyle has to return an object and cannot return static styles combined with dynamic ones. Please do merging where a component receives props.');
|
|
174
|
+
}
|
|
175
|
+
};
|
package/lib/reanimated2/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export * from './core';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
2
|
+
export * from './hook';
|
|
3
|
+
export * from './animation';
|
|
4
4
|
export * from './interpolation';
|
|
5
5
|
export * from './Easing';
|
|
6
6
|
export * from './NativeMethods';
|
|
7
7
|
export * from './Colors';
|
|
8
8
|
export * from './PropAdapters';
|
|
9
9
|
export * from './layoutReanimation';
|
|
10
|
+
export * from './utils';
|
|
@@ -1,118 +1,127 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function
|
|
1
|
+
// @ts-ignore JS file
|
|
2
|
+
import interpolateNode from '../reanimated1/derived/interpolate';
|
|
3
|
+
export var Extrapolation;
|
|
4
|
+
(function (Extrapolation) {
|
|
5
|
+
Extrapolation["IDENTITY"] = "identity";
|
|
6
|
+
Extrapolation["CLAMP"] = "clamp";
|
|
7
|
+
Extrapolation["EXTEND"] = "extend";
|
|
8
|
+
})(Extrapolation || (Extrapolation = {}));
|
|
9
|
+
function isNode(x) {
|
|
10
|
+
'worklet';
|
|
11
|
+
return x.__nodeId !== undefined;
|
|
12
|
+
}
|
|
13
|
+
function getVal(type, coef, val, leftEdgeOutput, rightEdgeOutput, x) {
|
|
5
14
|
'worklet';
|
|
6
|
-
const { type, coef, val, ll, rr, x } = config;
|
|
7
15
|
switch (type) {
|
|
8
|
-
case
|
|
16
|
+
case Extrapolation.IDENTITY:
|
|
9
17
|
return x;
|
|
10
|
-
case
|
|
11
|
-
if (coef * val < coef *
|
|
12
|
-
return
|
|
18
|
+
case Extrapolation.CLAMP:
|
|
19
|
+
if (coef * val < coef * leftEdgeOutput) {
|
|
20
|
+
return leftEdgeOutput;
|
|
13
21
|
}
|
|
14
|
-
return
|
|
15
|
-
case
|
|
22
|
+
return rightEdgeOutput;
|
|
23
|
+
case Extrapolation.EXTEND:
|
|
16
24
|
default:
|
|
17
25
|
return val;
|
|
18
26
|
}
|
|
19
27
|
}
|
|
20
28
|
function isExtrapolate(value) {
|
|
21
29
|
'worklet';
|
|
22
|
-
return (value ===
|
|
23
|
-
value ===
|
|
24
|
-
value ===
|
|
30
|
+
return (value === Extrapolation.EXTEND ||
|
|
31
|
+
value === Extrapolation.CLAMP ||
|
|
32
|
+
value === Extrapolation.IDENTITY);
|
|
25
33
|
}
|
|
34
|
+
// validates extrapolations type
|
|
35
|
+
// if type is correct, converts it to ExtrapolationConfig
|
|
26
36
|
function validateType(type) {
|
|
27
37
|
'worklet';
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
${extrapolate}: 'clamp',
|
|
36
|
-
})`;
|
|
37
|
-
type = type !== null && type !== void 0 ? type : 'extend';
|
|
38
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
39
|
-
const hasExtrapolateLeft = type.hasOwnProperty('extrapolateLeft');
|
|
40
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
41
|
-
const hasExtrapolateRight = type.hasOwnProperty('extrapolateRight');
|
|
42
|
-
if (typeof type === 'object' &&
|
|
43
|
-
((Object.keys(type).length === 2 &&
|
|
44
|
-
!(hasExtrapolateLeft && hasExtrapolateRight)) ||
|
|
45
|
-
(Object.keys(type).length === 1 &&
|
|
46
|
-
!(hasExtrapolateLeft || hasExtrapolateRight)) ||
|
|
47
|
-
Object.keys(type).length > 2)) {
|
|
48
|
-
throw new Error(EXTRAPOLATE_ERROR_MSG);
|
|
38
|
+
// initialize extrapolationConfig with default extrapolation
|
|
39
|
+
const extrapolationConfig = {
|
|
40
|
+
extrapolateLeft: Extrapolation.EXTEND,
|
|
41
|
+
extrapolateRight: Extrapolation.EXTEND,
|
|
42
|
+
};
|
|
43
|
+
if (!type) {
|
|
44
|
+
return extrapolationConfig;
|
|
49
45
|
}
|
|
50
|
-
if (typeof type === '
|
|
51
|
-
if (
|
|
52
|
-
throw new Error(
|
|
53
|
-
|
|
54
|
-
if (hasExtrapolateRight && !isExtrapolate(type.extrapolateRight)) {
|
|
55
|
-
throw new Error(EXTRAPOLATE_ERROR('extrapolateRight'));
|
|
46
|
+
if (typeof type === 'string') {
|
|
47
|
+
if (!isExtrapolate(type)) {
|
|
48
|
+
throw new Error(`Reanimated: not supported value for "interpolate" \nSupported values: ["extend", "clamp", "identity", Extrapolatation.CLAMP, Extrapolatation.EXTEND, Extrapolatation.IDENTITY]\n Valid example:
|
|
49
|
+
interpolate(value, [inputRange], [outputRange], "clamp")`);
|
|
56
50
|
}
|
|
51
|
+
extrapolationConfig.extrapolateLeft = type;
|
|
52
|
+
extrapolationConfig.extrapolateRight = type;
|
|
53
|
+
return extrapolationConfig;
|
|
57
54
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
// otherwise type is extrapolation config object
|
|
56
|
+
if ((type.extrapolateLeft && !isExtrapolate(type.extrapolateLeft)) ||
|
|
57
|
+
(type.extrapolateRight && !isExtrapolate(type.extrapolateRight))) {
|
|
58
|
+
throw new Error(`Reanimated: not supported value for "interpolate" \nSupported values: ["extend", "clamp", "identity", Extrapolatation.CLAMP, Extrapolatation.EXTEND, Extrapolatation.IDENTITY]\n Valid example:
|
|
59
|
+
interpolate(value, [inputRange], [outputRange], {
|
|
60
|
+
extrapolateLeft: Extrapolation.CLAMP,
|
|
61
|
+
extrapolateRight: Extrapolation.IDENTITY
|
|
62
|
+
}})`);
|
|
61
63
|
}
|
|
64
|
+
Object.assign(extrapolationConfig, type);
|
|
65
|
+
return extrapolationConfig;
|
|
62
66
|
}
|
|
63
|
-
|
|
64
|
-
// e.g. function interpolate(x, input, output, type = Extrapolate.CLAMP)
|
|
65
|
-
function internalInterpolate(x, l, r, ll, rr, type) {
|
|
67
|
+
function internalInterpolate(x, narrowedInput, extrapolationConfig) {
|
|
66
68
|
'worklet';
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
if (typeof type === 'object') {
|
|
76
|
-
if (coef * val < coef * ll) {
|
|
77
|
-
return getVal(Object.assign(config, { type: type.extrapolateLeft }));
|
|
78
|
-
}
|
|
79
|
-
else if (coef * val > coef * ll) {
|
|
80
|
-
return getVal(Object.assign(config, { type: type.extrapolateRight }));
|
|
81
|
-
}
|
|
69
|
+
const { leftEdgeInput, rightEdgeInput, leftEdgeOutput, rightEdgeOutput, } = narrowedInput;
|
|
70
|
+
if (rightEdgeInput - leftEdgeInput === 0)
|
|
71
|
+
return leftEdgeOutput;
|
|
72
|
+
const progress = (x - leftEdgeInput) / (rightEdgeInput - leftEdgeInput);
|
|
73
|
+
const val = leftEdgeOutput + progress * (rightEdgeOutput - leftEdgeOutput);
|
|
74
|
+
const coef = rightEdgeOutput >= leftEdgeOutput ? 1 : -1;
|
|
75
|
+
if (coef * val < coef * leftEdgeOutput) {
|
|
76
|
+
return getVal(extrapolationConfig.extrapolateLeft, coef, val, leftEdgeOutput, rightEdgeOutput, x);
|
|
82
77
|
}
|
|
83
|
-
if (coef * val
|
|
84
|
-
return getVal(
|
|
78
|
+
else if (coef * val > coef * rightEdgeOutput) {
|
|
79
|
+
return getVal(extrapolationConfig.extrapolateRight, coef, val, leftEdgeOutput, rightEdgeOutput, x);
|
|
85
80
|
}
|
|
86
81
|
return val;
|
|
87
82
|
}
|
|
83
|
+
// TODO: support default values in worklets:
|
|
84
|
+
// e.g. function interpolate(x, input, output, type = Extrapolatation.CLAMP)
|
|
88
85
|
export function interpolate(x, input, output, type) {
|
|
89
86
|
'worklet';
|
|
90
|
-
if (
|
|
87
|
+
if (input.length < 2 || output.length < 2) {
|
|
88
|
+
throw Error('Interpolation input and output should contain at least two values.');
|
|
89
|
+
}
|
|
90
|
+
const extrapolationConfig = validateType(type);
|
|
91
|
+
if (isNode(x)) {
|
|
91
92
|
console.warn(`interpolate() was renamed to interpolateNode() in Reanimated 2. Please use interpolateNode() instead`);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
return interpolateNode(x, {
|
|
94
|
+
inputRange: input,
|
|
95
|
+
outputRange: output,
|
|
96
|
+
extrapolateLeft: extrapolationConfig.extrapolateLeft,
|
|
97
|
+
extrapolateRight: extrapolationConfig.extrapolateRight,
|
|
98
|
+
});
|
|
95
99
|
}
|
|
96
100
|
const length = input.length;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
101
|
+
const narrowedInput = {
|
|
102
|
+
leftEdgeInput: input[0],
|
|
103
|
+
rightEdgeInput: input[1],
|
|
104
|
+
leftEdgeOutput: output[0],
|
|
105
|
+
rightEdgeOutput: output[1],
|
|
106
|
+
};
|
|
107
|
+
if (length > 2) {
|
|
108
|
+
if (x > input[length - 1]) {
|
|
109
|
+
narrowedInput.leftEdgeInput = input[length - 2];
|
|
110
|
+
narrowedInput.rightEdgeInput = input[length - 1];
|
|
111
|
+
narrowedInput.leftEdgeOutput = output[length - 2];
|
|
112
|
+
narrowedInput.rightEdgeOutput = output[length - 1];
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
for (let i = 1; i < length; ++i) {
|
|
116
|
+
if (x <= input[i]) {
|
|
117
|
+
narrowedInput.leftEdgeInput = input[i - 1];
|
|
118
|
+
narrowedInput.rightEdgeInput = input[i];
|
|
119
|
+
narrowedInput.leftEdgeOutput = output[i - 1];
|
|
120
|
+
narrowedInput.rightEdgeOutput = output[i];
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
114
123
|
}
|
|
115
124
|
}
|
|
116
125
|
}
|
|
117
|
-
return internalInterpolate
|
|
126
|
+
return internalInterpolate(x, narrowedInput, extrapolationConfig);
|
|
118
127
|
}
|
|
@@ -149,18 +149,6 @@ export const setUpTests = (userConfig = {}) => {
|
|
|
149
149
|
return compareStyle(received, expectedStyle, config);
|
|
150
150
|
},
|
|
151
151
|
});
|
|
152
|
-
jest.mock('./js-reanimated', () => require('./js-reanimated/index.web'));
|
|
153
|
-
jest.mock('../ReanimatedModule', () => require('../ReanimatedModuleCompat'));
|
|
154
|
-
jest.mock('./NativeReanimated', () => {
|
|
155
|
-
let module;
|
|
156
|
-
try {
|
|
157
|
-
module = require('./NativeReanimated.js');
|
|
158
|
-
}
|
|
159
|
-
catch (_a) {
|
|
160
|
-
module = require('./NativeReanimated.ts');
|
|
161
|
-
}
|
|
162
|
-
return module.default;
|
|
163
|
-
});
|
|
164
152
|
};
|
|
165
153
|
export const getAnimatedStyle = (received) => {
|
|
166
154
|
return getCurrentStyle(received);
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
-
// @ts-nocheck
|
|
3
1
|
import MapperRegistry from './MapperRegistry';
|
|
4
2
|
import MutableValue from './MutableValue';
|
|
5
3
|
import Mapper from './Mapper';
|
|
6
|
-
|
|
4
|
+
import { NativeReanimated } from '../NativeReanimated/NativeReanimated';
|
|
5
|
+
export default class JSReanimated extends NativeReanimated {
|
|
7
6
|
constructor() {
|
|
8
|
-
|
|
7
|
+
super(false);
|
|
9
8
|
this._valueSetter = undefined;
|
|
10
9
|
this._renderRequested = false;
|
|
11
10
|
this._mapperRegistry = new MapperRegistry(this);
|
|
12
11
|
this._frames = [];
|
|
13
|
-
this.timeProvider = {};
|
|
14
12
|
if (process.env.JEST_WORKER_ID) {
|
|
15
|
-
this.timeProvider
|
|
13
|
+
this.timeProvider = { now: () => Date.now() };
|
|
16
14
|
}
|
|
17
15
|
else {
|
|
18
|
-
this.timeProvider
|
|
16
|
+
this.timeProvider = { now: () => window.performance.now() };
|
|
19
17
|
}
|
|
20
18
|
}
|
|
21
19
|
pushFrame(frame) {
|
|
@@ -54,7 +52,7 @@ export default class JSReanimated {
|
|
|
54
52
|
makeMutable(value) {
|
|
55
53
|
return new MutableValue(value, this._valueSetter);
|
|
56
54
|
}
|
|
57
|
-
makeRemote(object) {
|
|
55
|
+
makeRemote(object = {}) {
|
|
58
56
|
return object;
|
|
59
57
|
}
|
|
60
58
|
startMapper(mapper, inputs = [], outputs = []) {
|
|
@@ -66,10 +64,11 @@ export default class JSReanimated {
|
|
|
66
64
|
stopMapper(mapperId) {
|
|
67
65
|
this._mapperRegistry.stopMapper(mapperId);
|
|
68
66
|
}
|
|
69
|
-
registerEventHandler(
|
|
67
|
+
registerEventHandler(_, __) {
|
|
70
68
|
// noop
|
|
69
|
+
return '';
|
|
71
70
|
}
|
|
72
|
-
unregisterEventHandler(
|
|
71
|
+
unregisterEventHandler(_) {
|
|
73
72
|
// noop
|
|
74
73
|
}
|
|
75
74
|
}
|
|
@@ -1 +1,57 @@
|
|
|
1
|
-
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
import JSReanimated from './JSReanimated';
|
|
4
|
+
import { shouldBeUseWeb } from '../PlatformChecker';
|
|
5
|
+
const reanimatedJS = new JSReanimated();
|
|
6
|
+
if (shouldBeUseWeb()) {
|
|
7
|
+
global._frameTimestamp = null;
|
|
8
|
+
global._setGlobalConsole = (_val) => {
|
|
9
|
+
// noop
|
|
10
|
+
};
|
|
11
|
+
global._measure = () => {
|
|
12
|
+
console.warn("[Reanimated] You can't use 'measue' method with Chrome Debugger or with web version");
|
|
13
|
+
return {
|
|
14
|
+
x: 0,
|
|
15
|
+
y: 0,
|
|
16
|
+
width: 0,
|
|
17
|
+
height: 0,
|
|
18
|
+
pageX: 0,
|
|
19
|
+
pageY: 0,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
global._scrollTo = () => {
|
|
23
|
+
console.warn("[Reanimated] You can't use 'scrollTo' method with Chrome Debugger or with web version");
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export const _updatePropsJS = (updates, viewRef) => {
|
|
27
|
+
if (viewRef === null || viewRef === void 0 ? void 0 : viewRef._component) {
|
|
28
|
+
const [rawStyles] = Object.keys(updates).reduce((acc, key) => {
|
|
29
|
+
const value = updates[key];
|
|
30
|
+
const index = typeof value === 'function' ? 1 : 0;
|
|
31
|
+
acc[index][key] = value;
|
|
32
|
+
return acc;
|
|
33
|
+
}, [{}, {}]);
|
|
34
|
+
if (typeof viewRef._component.setNativeProps === 'function') {
|
|
35
|
+
setNativeProps(viewRef._component, rawStyles);
|
|
36
|
+
}
|
|
37
|
+
else if (Object.keys(viewRef._component.props).length > 0) {
|
|
38
|
+
Object.keys(viewRef._component.props).forEach((key) => {
|
|
39
|
+
if (!rawStyles[key]) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const dashedKey = key.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());
|
|
43
|
+
viewRef._component._touchableNode.setAttribute(dashedKey, rawStyles[key]);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
console.warn('It is not possible to manipulate component');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const setNativeProps = (component, style) => {
|
|
52
|
+
const previousStyle = component.previousStyle ? component.previousStyle : {};
|
|
53
|
+
const currentStyle = Object.assign(Object.assign({}, previousStyle), style);
|
|
54
|
+
component.previousStyle = currentStyle;
|
|
55
|
+
component.setNativeProps({ style: currentStyle });
|
|
56
|
+
};
|
|
57
|
+
export default reanimatedJS;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/* global _stopObservingProgress, _startObservingProgress */
|
|
2
|
+
import { runOnUI } from '../core';
|
|
3
|
+
import { withStyleAnimation } from '../animation/styleAnimation';
|
|
4
|
+
runOnUI(() => {
|
|
5
|
+
'worklet';
|
|
6
|
+
const configs = {};
|
|
7
|
+
const enteringAnimationForTag = {};
|
|
8
|
+
global.LayoutAnimationRepository = {
|
|
9
|
+
configs,
|
|
10
|
+
registerConfig(tag, config) {
|
|
11
|
+
configs[tag] = config;
|
|
12
|
+
enteringAnimationForTag[tag] = null;
|
|
13
|
+
},
|
|
14
|
+
removeConfig(tag) {
|
|
15
|
+
delete configs[tag];
|
|
16
|
+
delete enteringAnimationForTag[tag];
|
|
17
|
+
},
|
|
18
|
+
startAnimationForTag(tag, type, yogaValues) {
|
|
19
|
+
if (configs[tag] == null) {
|
|
20
|
+
return; // :(
|
|
21
|
+
}
|
|
22
|
+
const style = configs[tag][type](yogaValues);
|
|
23
|
+
let currentAnimation = style.animations;
|
|
24
|
+
if (type === 'entering') {
|
|
25
|
+
enteringAnimationForTag[tag] = style;
|
|
26
|
+
}
|
|
27
|
+
else if (type === 'layout' && enteringAnimationForTag[tag] !== null) {
|
|
28
|
+
const entryAniamtion = enteringAnimationForTag[tag].animations;
|
|
29
|
+
const layoutAnimation = style.animations;
|
|
30
|
+
currentAnimation = {};
|
|
31
|
+
for (const key in entryAniamtion) {
|
|
32
|
+
currentAnimation[key] = entryAniamtion[key];
|
|
33
|
+
}
|
|
34
|
+
for (const key in layoutAnimation) {
|
|
35
|
+
currentAnimation[key] = layoutAnimation[key];
|
|
36
|
+
}
|
|
37
|
+
enteringAnimationForTag[tag] = null;
|
|
38
|
+
}
|
|
39
|
+
const sv = configs[tag].sv;
|
|
40
|
+
_stopObservingProgress(tag, false);
|
|
41
|
+
_startObservingProgress(tag, sv);
|
|
42
|
+
sv._value = Object.assign({}, sv._value, style.initialValues);
|
|
43
|
+
_stopObservingProgress(tag, false);
|
|
44
|
+
const animation = withStyleAnimation(currentAnimation);
|
|
45
|
+
animation.callback = (finished) => {
|
|
46
|
+
if (finished) {
|
|
47
|
+
_stopObservingProgress(tag, finished);
|
|
48
|
+
}
|
|
49
|
+
style.callback && style.callback(finished);
|
|
50
|
+
if (type === 'entering') {
|
|
51
|
+
enteringAnimationForTag[tag] = null;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
configs[tag].sv.value = animation;
|
|
55
|
+
_startObservingProgress(tag, sv);
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
})();
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { withDelay } from '../../animation';
|
|
2
|
+
export class BaseAnimationBuilder {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.randomizeDelay = false;
|
|
5
|
+
this.build = () => {
|
|
6
|
+
throw Error('Unimplemented method in child class.');
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
static duration(durationMs) {
|
|
10
|
+
const instance = this.createInstance();
|
|
11
|
+
return instance.duration(durationMs);
|
|
12
|
+
}
|
|
13
|
+
duration(durationMs) {
|
|
14
|
+
this.durationV = durationMs;
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
static delay(delayMs) {
|
|
18
|
+
const instance = this.createInstance();
|
|
19
|
+
return instance.delay(delayMs);
|
|
20
|
+
}
|
|
21
|
+
delay(delayMs) {
|
|
22
|
+
this.delayV = delayMs;
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
static withCallback(callback) {
|
|
26
|
+
const instance = this.createInstance();
|
|
27
|
+
return instance.withCallback(callback);
|
|
28
|
+
}
|
|
29
|
+
withCallback(callback) {
|
|
30
|
+
this.callbackV = callback;
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
// 300ms is the default animation duration. If any animation has different default has to override this method.
|
|
34
|
+
static getDuration() {
|
|
35
|
+
return 300;
|
|
36
|
+
}
|
|
37
|
+
getDuration() {
|
|
38
|
+
var _a;
|
|
39
|
+
return (_a = this.durationV) !== null && _a !== void 0 ? _a : 300;
|
|
40
|
+
}
|
|
41
|
+
static randomDelay() {
|
|
42
|
+
const instance = this.createInstance();
|
|
43
|
+
return instance.randomDelay();
|
|
44
|
+
}
|
|
45
|
+
randomDelay() {
|
|
46
|
+
this.randomizeDelay = true;
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
// when randomizeDelay is set to true, randomize delay between 0 and provided value (or 1000ms if delay is not provided)
|
|
50
|
+
getDelay() {
|
|
51
|
+
var _a, _b;
|
|
52
|
+
return this.randomizeDelay
|
|
53
|
+
? Math.random() * ((_a = this.delayV) !== null && _a !== void 0 ? _a : 1000)
|
|
54
|
+
: (_b = this.delayV) !== null && _b !== void 0 ? _b : 0;
|
|
55
|
+
}
|
|
56
|
+
getDelayFunction() {
|
|
57
|
+
const isDelayProvided = this.randomizeDelay || this.delayV;
|
|
58
|
+
return isDelayProvided
|
|
59
|
+
? withDelay
|
|
60
|
+
: (_, animation) => {
|
|
61
|
+
'worklet';
|
|
62
|
+
return animation;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
static build() {
|
|
66
|
+
const instance = this.createInstance();
|
|
67
|
+
return instance.build();
|
|
68
|
+
}
|
|
69
|
+
}
|