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,83 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { NativeScrollEvent } from 'react-native';
|
|
3
|
+
import { NativeEvent, WorkletFunction } from '../commonTypes';
|
|
4
|
+
import WorkletEventHandler from '../WorkletEventHandler';
|
|
5
|
+
import { Context, DependencyList } from './commonTypes';
|
|
6
|
+
import { useEvent, useHandler } from './Hooks';
|
|
7
|
+
|
|
8
|
+
export interface ScrollHandler<TContext extends Context>
|
|
9
|
+
extends WorkletFunction {
|
|
10
|
+
(event: NativeScrollEvent, context?: TContext): void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface ScrollEvent extends NativeScrollEvent, NativeEvent<ScrollEvent> {
|
|
14
|
+
eventName: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ScrollHandlers<TContext extends Context> {
|
|
17
|
+
[key: string]: ScrollHandler<TContext> | undefined;
|
|
18
|
+
onScroll?: ScrollHandler<TContext>;
|
|
19
|
+
onBeginDrag?: ScrollHandler<TContext>;
|
|
20
|
+
onEndDrag?: ScrollHandler<TContext>;
|
|
21
|
+
onMomentumBegin?: ScrollHandler<TContext>;
|
|
22
|
+
onMomentumEnd?: ScrollHandler<TContext>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function useAnimatedScrollHandler<TContext extends Context>(
|
|
26
|
+
handlers: ScrollHandlers<TContext> | ScrollHandler<TContext>,
|
|
27
|
+
dependencies?: DependencyList
|
|
28
|
+
): RefObject<WorkletEventHandler<ScrollEvent>> {
|
|
29
|
+
// case when handlers is a function
|
|
30
|
+
const scrollHandlers: ScrollHandlers<TContext> =
|
|
31
|
+
typeof handlers === 'function' ? { onScroll: handlers } : handlers;
|
|
32
|
+
const { context, doDependenciesDiffer } = useHandler<ScrollEvent, TContext>(
|
|
33
|
+
scrollHandlers,
|
|
34
|
+
dependencies
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
// build event subscription array
|
|
38
|
+
const subscribeForEvents = ['onScroll'];
|
|
39
|
+
if (scrollHandlers.onBeginDrag !== undefined) {
|
|
40
|
+
subscribeForEvents.push('onScrollBeginDrag');
|
|
41
|
+
}
|
|
42
|
+
if (scrollHandlers.onEndDrag !== undefined) {
|
|
43
|
+
subscribeForEvents.push('onScrollEndDrag');
|
|
44
|
+
}
|
|
45
|
+
if (scrollHandlers.onMomentumBegin !== undefined) {
|
|
46
|
+
subscribeForEvents.push('onMomentumScrollBegin');
|
|
47
|
+
}
|
|
48
|
+
if (scrollHandlers.onMomentumEnd !== undefined) {
|
|
49
|
+
subscribeForEvents.push('onMomentumScrollEnd');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return useEvent<ScrollEvent>(
|
|
53
|
+
(event: ScrollEvent) => {
|
|
54
|
+
'worklet';
|
|
55
|
+
const {
|
|
56
|
+
onScroll,
|
|
57
|
+
onBeginDrag,
|
|
58
|
+
onEndDrag,
|
|
59
|
+
onMomentumBegin,
|
|
60
|
+
onMomentumEnd,
|
|
61
|
+
} = scrollHandlers;
|
|
62
|
+
if (onScroll && event.eventName.endsWith('onScroll')) {
|
|
63
|
+
onScroll(event, context);
|
|
64
|
+
} else if (onBeginDrag && event.eventName.endsWith('onScrollBeginDrag')) {
|
|
65
|
+
onBeginDrag(event, context);
|
|
66
|
+
} else if (onEndDrag && event.eventName.endsWith('onScrollEndDrag')) {
|
|
67
|
+
onEndDrag(event, context);
|
|
68
|
+
} else if (
|
|
69
|
+
onMomentumBegin &&
|
|
70
|
+
event.eventName.endsWith('onMomentumScrollBegin')
|
|
71
|
+
) {
|
|
72
|
+
onMomentumBegin(event, context);
|
|
73
|
+
} else if (
|
|
74
|
+
onMomentumEnd &&
|
|
75
|
+
event.eventName.endsWith('onMomentumScrollEnd')
|
|
76
|
+
) {
|
|
77
|
+
onMomentumEnd(event, context);
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
subscribeForEvents,
|
|
81
|
+
doDependenciesDiffer
|
|
82
|
+
);
|
|
83
|
+
}
|
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
/* global _frameTimestamp */
|
|
2
|
+
import { MutableRefObject, useEffect, useRef } from 'react';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
startMapper,
|
|
6
|
+
stopMapper,
|
|
7
|
+
makeRemote,
|
|
8
|
+
requestFrame,
|
|
9
|
+
getTimestamp,
|
|
10
|
+
makeMutable,
|
|
11
|
+
} from '../core';
|
|
12
|
+
import updateProps, { updatePropsJestWrapper } from '../UpdateProps';
|
|
13
|
+
import { initialUpdaterRun, Timestamp } from '../animation';
|
|
14
|
+
import NativeReanimatedModule from '../NativeReanimated';
|
|
15
|
+
import { useSharedValue } from './useSharedValue';
|
|
16
|
+
import {
|
|
17
|
+
buildWorkletsHash,
|
|
18
|
+
canApplyOptimalisation,
|
|
19
|
+
getStyleWithoutAnimations,
|
|
20
|
+
hasColorProps,
|
|
21
|
+
isAnimated,
|
|
22
|
+
parseColors,
|
|
23
|
+
styleDiff,
|
|
24
|
+
validateAnimatedStyles,
|
|
25
|
+
} from './utils';
|
|
26
|
+
import { DependencyList, Descriptor } from './commonTypes';
|
|
27
|
+
import {
|
|
28
|
+
makeViewDescriptorsSet,
|
|
29
|
+
makeViewsRefSet,
|
|
30
|
+
ViewDescriptorsSet,
|
|
31
|
+
ViewRefSet,
|
|
32
|
+
} from '../ViewDescriptorsSet';
|
|
33
|
+
import { isJest, shouldBeUseWeb } from '../PlatformChecker';
|
|
34
|
+
import { AnimationObject, PrimitiveValue } from '../animation/commonTypes';
|
|
35
|
+
import {
|
|
36
|
+
AdapterWorkletFunction,
|
|
37
|
+
AnimatedStyle,
|
|
38
|
+
BasicWorkletFunction,
|
|
39
|
+
NestedObjectValues,
|
|
40
|
+
SharedValue,
|
|
41
|
+
} from '../commonTypes';
|
|
42
|
+
export interface AnimatedStyleResult {
|
|
43
|
+
viewDescriptors: ViewDescriptorsSet;
|
|
44
|
+
initial: AnimatedStyle;
|
|
45
|
+
viewsRef: ViewRefSet<any>;
|
|
46
|
+
animatedStyle?: MutableRefObject<AnimatedStyle>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface AnimatedState {
|
|
50
|
+
last: AnimatedStyle;
|
|
51
|
+
animations: AnimatedStyle;
|
|
52
|
+
isAnimationRunning: boolean;
|
|
53
|
+
isAnimationCancelled: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface AnimationRef {
|
|
57
|
+
initial: {
|
|
58
|
+
value: AnimatedStyle;
|
|
59
|
+
updater: () => AnimatedStyle;
|
|
60
|
+
};
|
|
61
|
+
remoteState: AnimatedState;
|
|
62
|
+
sharableViewDescriptors: SharedValue<Descriptor[]>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function prepareAnimation(
|
|
66
|
+
animatedProp: AnimatedStyle,
|
|
67
|
+
lastAnimation: AnimatedStyle,
|
|
68
|
+
lastValue: AnimatedStyle
|
|
69
|
+
): void {
|
|
70
|
+
'worklet';
|
|
71
|
+
if (Array.isArray(animatedProp)) {
|
|
72
|
+
animatedProp.forEach((prop, index) =>
|
|
73
|
+
prepareAnimation(
|
|
74
|
+
prop,
|
|
75
|
+
lastAnimation && lastAnimation[index],
|
|
76
|
+
lastValue && lastValue[index]
|
|
77
|
+
)
|
|
78
|
+
);
|
|
79
|
+
// return animatedProp;
|
|
80
|
+
}
|
|
81
|
+
if (typeof animatedProp === 'object' && animatedProp.onFrame) {
|
|
82
|
+
const animation = animatedProp;
|
|
83
|
+
|
|
84
|
+
let value = animation.current;
|
|
85
|
+
if (lastValue !== undefined) {
|
|
86
|
+
if (typeof lastValue === 'object') {
|
|
87
|
+
if (lastValue.value !== undefined) {
|
|
88
|
+
// previously it was a shared value
|
|
89
|
+
value = lastValue.value;
|
|
90
|
+
} else if (lastValue.onFrame !== undefined) {
|
|
91
|
+
if (lastAnimation?.current !== undefined) {
|
|
92
|
+
// it was an animation before, copy its state
|
|
93
|
+
value = lastAnimation.current;
|
|
94
|
+
} else if (lastValue?.current !== undefined) {
|
|
95
|
+
// it was initialized
|
|
96
|
+
value = lastValue.current;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
// previously it was a plain value, just set it as starting point
|
|
101
|
+
value = lastValue;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
animation.callStart = (timestamp: Timestamp) => {
|
|
106
|
+
animation.onStart(animation, value, timestamp, lastAnimation);
|
|
107
|
+
};
|
|
108
|
+
animation.callStart(getTimestamp());
|
|
109
|
+
animation.callStart = null;
|
|
110
|
+
} else if (typeof animatedProp === 'object') {
|
|
111
|
+
// it is an object
|
|
112
|
+
Object.keys(animatedProp).forEach((key) =>
|
|
113
|
+
prepareAnimation(
|
|
114
|
+
animatedProp[key],
|
|
115
|
+
lastAnimation && lastAnimation[key],
|
|
116
|
+
lastValue && lastValue[key]
|
|
117
|
+
)
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function runAnimations(
|
|
123
|
+
animation: AnimatedStyle,
|
|
124
|
+
timestamp: Timestamp,
|
|
125
|
+
key: PrimitiveValue,
|
|
126
|
+
result: AnimatedStyle,
|
|
127
|
+
animationsActive: SharedValue<boolean>
|
|
128
|
+
): boolean {
|
|
129
|
+
'worklet';
|
|
130
|
+
if (!animationsActive.value) {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
if (Array.isArray(animation)) {
|
|
134
|
+
result[key] = [];
|
|
135
|
+
let allFinished = true;
|
|
136
|
+
animation.forEach((entry, index) => {
|
|
137
|
+
if (
|
|
138
|
+
!runAnimations(entry, timestamp, index, result[key], animationsActive)
|
|
139
|
+
) {
|
|
140
|
+
allFinished = false;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return allFinished;
|
|
144
|
+
} else if (typeof animation === 'object' && animation.onFrame) {
|
|
145
|
+
let finished = true;
|
|
146
|
+
if (!animation.finished) {
|
|
147
|
+
if (animation.callStart) {
|
|
148
|
+
animation.callStart(timestamp);
|
|
149
|
+
animation.callStart = null;
|
|
150
|
+
}
|
|
151
|
+
finished = animation.onFrame(animation, timestamp);
|
|
152
|
+
animation.timestamp = timestamp;
|
|
153
|
+
if (finished) {
|
|
154
|
+
animation.finished = true;
|
|
155
|
+
animation.callback && animation.callback(true /* finished */);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
result[key] = animation.current;
|
|
159
|
+
return finished;
|
|
160
|
+
} else if (typeof animation === 'object') {
|
|
161
|
+
result[key] = {};
|
|
162
|
+
let allFinished = true;
|
|
163
|
+
Object.keys(animation).forEach((k) => {
|
|
164
|
+
if (
|
|
165
|
+
!runAnimations(
|
|
166
|
+
animation[k],
|
|
167
|
+
timestamp,
|
|
168
|
+
k,
|
|
169
|
+
result[key],
|
|
170
|
+
animationsActive
|
|
171
|
+
)
|
|
172
|
+
) {
|
|
173
|
+
allFinished = false;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
return allFinished;
|
|
177
|
+
} else {
|
|
178
|
+
result[key] = animation;
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function styleUpdater(
|
|
184
|
+
viewDescriptors: SharedValue<Descriptor[]>,
|
|
185
|
+
updater: BasicWorkletFunction<AnimatedStyle>,
|
|
186
|
+
state: AnimatedState,
|
|
187
|
+
maybeViewRef: ViewRefSet<any> | undefined,
|
|
188
|
+
animationsActive: SharedValue<boolean>
|
|
189
|
+
): void {
|
|
190
|
+
'worklet';
|
|
191
|
+
const animations = state.animations ?? {};
|
|
192
|
+
const newValues = updater() ?? {};
|
|
193
|
+
const oldValues = state.last;
|
|
194
|
+
|
|
195
|
+
let hasAnimations = false;
|
|
196
|
+
for (const key in newValues) {
|
|
197
|
+
const value = newValues[key];
|
|
198
|
+
if (isAnimated(value)) {
|
|
199
|
+
prepareAnimation(value, animations[key], oldValues[key]);
|
|
200
|
+
animations[key] = value;
|
|
201
|
+
hasAnimations = true;
|
|
202
|
+
} else {
|
|
203
|
+
delete animations[key];
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (hasAnimations) {
|
|
208
|
+
const frame = (timestamp: Timestamp) => {
|
|
209
|
+
const { animations, last, isAnimationCancelled } = state;
|
|
210
|
+
if (isAnimationCancelled) {
|
|
211
|
+
state.isAnimationRunning = false;
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const updates: AnimatedStyle = {};
|
|
216
|
+
let allFinished = true;
|
|
217
|
+
for (const propName in animations) {
|
|
218
|
+
const finished = runAnimations(
|
|
219
|
+
animations[propName],
|
|
220
|
+
timestamp,
|
|
221
|
+
propName,
|
|
222
|
+
updates,
|
|
223
|
+
animationsActive
|
|
224
|
+
);
|
|
225
|
+
if (finished) {
|
|
226
|
+
last[propName] = updates[propName];
|
|
227
|
+
delete animations[propName];
|
|
228
|
+
} else {
|
|
229
|
+
allFinished = false;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (updates) {
|
|
234
|
+
updateProps(viewDescriptors, updates, maybeViewRef);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (!allFinished) {
|
|
238
|
+
requestFrame(frame);
|
|
239
|
+
} else {
|
|
240
|
+
state.isAnimationRunning = false;
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
state.animations = animations;
|
|
245
|
+
if (!state.isAnimationRunning) {
|
|
246
|
+
state.isAnimationCancelled = false;
|
|
247
|
+
state.isAnimationRunning = true;
|
|
248
|
+
if (_frameTimestamp) {
|
|
249
|
+
frame(_frameTimestamp);
|
|
250
|
+
} else {
|
|
251
|
+
requestFrame(frame);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
state.last = Object.assign({}, oldValues, newValues);
|
|
255
|
+
const style = getStyleWithoutAnimations(state.last);
|
|
256
|
+
if (style) {
|
|
257
|
+
updateProps(viewDescriptors, style, maybeViewRef);
|
|
258
|
+
}
|
|
259
|
+
} else {
|
|
260
|
+
state.isAnimationCancelled = true;
|
|
261
|
+
state.animations = [];
|
|
262
|
+
updateProps(viewDescriptors, newValues, maybeViewRef);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function jestStyleUpdater(
|
|
267
|
+
viewDescriptors: SharedValue<Descriptor[]>,
|
|
268
|
+
updater: BasicWorkletFunction<AnimatedStyle>,
|
|
269
|
+
state: AnimatedState,
|
|
270
|
+
maybeViewRef: ViewRefSet<any> | undefined,
|
|
271
|
+
animationsActive: SharedValue<boolean>,
|
|
272
|
+
animatedStyle: MutableRefObject<AnimatedStyle>,
|
|
273
|
+
adapters: AdapterWorkletFunction[] = []
|
|
274
|
+
): void {
|
|
275
|
+
'worklet';
|
|
276
|
+
const animations: AnimatedStyle = state.animations ?? {};
|
|
277
|
+
const newValues = updater() ?? {};
|
|
278
|
+
const oldValues = state.last;
|
|
279
|
+
|
|
280
|
+
// extract animated props
|
|
281
|
+
let hasAnimations = false;
|
|
282
|
+
Object.keys(animations).forEach((key) => {
|
|
283
|
+
const value = newValues[key];
|
|
284
|
+
if (!isAnimated(value)) {
|
|
285
|
+
delete animations[key];
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
Object.keys(newValues).forEach((key) => {
|
|
289
|
+
const value = newValues[key];
|
|
290
|
+
if (isAnimated(value)) {
|
|
291
|
+
prepareAnimation(value, animations[key], oldValues[key]);
|
|
292
|
+
animations[key] = value;
|
|
293
|
+
hasAnimations = true;
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
function frame(timestamp: Timestamp) {
|
|
298
|
+
const { animations, last, isAnimationCancelled } = state;
|
|
299
|
+
if (isAnimationCancelled) {
|
|
300
|
+
state.isAnimationRunning = false;
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const updates: AnimatedStyle = {};
|
|
305
|
+
let allFinished = true;
|
|
306
|
+
Object.keys(animations).forEach((propName) => {
|
|
307
|
+
const finished = runAnimations(
|
|
308
|
+
animations[propName],
|
|
309
|
+
timestamp,
|
|
310
|
+
propName,
|
|
311
|
+
updates,
|
|
312
|
+
animationsActive
|
|
313
|
+
);
|
|
314
|
+
if (finished) {
|
|
315
|
+
last[propName] = updates[propName];
|
|
316
|
+
delete animations[propName];
|
|
317
|
+
} else {
|
|
318
|
+
allFinished = false;
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
if (Object.keys(updates).length) {
|
|
323
|
+
updatePropsJestWrapper(
|
|
324
|
+
viewDescriptors,
|
|
325
|
+
updates,
|
|
326
|
+
maybeViewRef,
|
|
327
|
+
animatedStyle,
|
|
328
|
+
adapters
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (!allFinished) {
|
|
333
|
+
requestFrame(frame);
|
|
334
|
+
} else {
|
|
335
|
+
state.isAnimationRunning = false;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (hasAnimations) {
|
|
340
|
+
state.animations = animations;
|
|
341
|
+
if (!state.isAnimationRunning) {
|
|
342
|
+
state.isAnimationCancelled = false;
|
|
343
|
+
state.isAnimationRunning = true;
|
|
344
|
+
if (_frameTimestamp) {
|
|
345
|
+
frame(_frameTimestamp);
|
|
346
|
+
} else {
|
|
347
|
+
requestFrame(frame);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
} else {
|
|
351
|
+
state.isAnimationCancelled = true;
|
|
352
|
+
state.animations = [];
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// calculate diff
|
|
356
|
+
const diff = styleDiff(oldValues, newValues);
|
|
357
|
+
state.last = Object.assign({}, oldValues, newValues);
|
|
358
|
+
|
|
359
|
+
if (Object.keys(diff).length !== 0) {
|
|
360
|
+
updatePropsJestWrapper(
|
|
361
|
+
viewDescriptors,
|
|
362
|
+
diff,
|
|
363
|
+
maybeViewRef,
|
|
364
|
+
animatedStyle,
|
|
365
|
+
adapters
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// check for invalid usage of shared values in returned object
|
|
371
|
+
function checkSharedValueUsage(
|
|
372
|
+
prop: NestedObjectValues<AnimationObject>,
|
|
373
|
+
currentKey?: string
|
|
374
|
+
): void {
|
|
375
|
+
if (Array.isArray(prop)) {
|
|
376
|
+
// if it's an array (i.ex. transform) validate all its elements
|
|
377
|
+
for (const element of prop) {
|
|
378
|
+
checkSharedValueUsage(element, currentKey);
|
|
379
|
+
}
|
|
380
|
+
} else if (typeof prop === 'object' && prop.value === undefined) {
|
|
381
|
+
// if it's a nested object, run validation for all its props
|
|
382
|
+
for (const key of Object.keys(prop)) {
|
|
383
|
+
checkSharedValueUsage(prop[key], key);
|
|
384
|
+
}
|
|
385
|
+
} else if (
|
|
386
|
+
currentKey !== undefined &&
|
|
387
|
+
typeof prop === 'object' &&
|
|
388
|
+
prop.value !== undefined
|
|
389
|
+
) {
|
|
390
|
+
// if shared value is passed insted of its value, throw an error
|
|
391
|
+
throw new Error(
|
|
392
|
+
`invalid value passed to \`${currentKey}\`, maybe you forgot to use \`.value\`?`
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export function useAnimatedStyle<T extends AnimatedStyle>(
|
|
398
|
+
updater: BasicWorkletFunction<T>,
|
|
399
|
+
dependencies?: DependencyList,
|
|
400
|
+
adapters?: AdapterWorkletFunction | AdapterWorkletFunction[]
|
|
401
|
+
): AnimatedStyleResult {
|
|
402
|
+
const viewsRef: ViewRefSet<any> = makeViewsRefSet();
|
|
403
|
+
const viewDescriptors: ViewDescriptorsSet = makeViewDescriptorsSet();
|
|
404
|
+
const initRef = useRef<AnimationRef>();
|
|
405
|
+
const inputs = Object.values(updater._closure ?? {});
|
|
406
|
+
const adaptersArray: AdapterWorkletFunction[] = adapters
|
|
407
|
+
? Array.isArray(adapters)
|
|
408
|
+
? adapters
|
|
409
|
+
: [adapters]
|
|
410
|
+
: [];
|
|
411
|
+
const adaptersHash = adapters ? buildWorkletsHash(adaptersArray) : null;
|
|
412
|
+
const animationsActive = useSharedValue<boolean>(true);
|
|
413
|
+
const animatedStyle: MutableRefObject<AnimatedStyle> = useRef<AnimatedStyle>(
|
|
414
|
+
{}
|
|
415
|
+
);
|
|
416
|
+
|
|
417
|
+
// build dependencies
|
|
418
|
+
if (!dependencies) {
|
|
419
|
+
dependencies = [...inputs, updater.__workletHash];
|
|
420
|
+
} else {
|
|
421
|
+
dependencies.push(updater.__workletHash);
|
|
422
|
+
}
|
|
423
|
+
adaptersHash && dependencies.push(adaptersHash);
|
|
424
|
+
|
|
425
|
+
if (!initRef.current) {
|
|
426
|
+
const initialStyle: AnimatedStyle = initialUpdaterRun(updater);
|
|
427
|
+
validateAnimatedStyles(initialStyle);
|
|
428
|
+
initRef.current = {
|
|
429
|
+
initial: {
|
|
430
|
+
value: initialStyle,
|
|
431
|
+
updater: updater,
|
|
432
|
+
},
|
|
433
|
+
remoteState: makeRemote({ last: initialStyle }),
|
|
434
|
+
sharableViewDescriptors: makeMutable([]),
|
|
435
|
+
};
|
|
436
|
+
viewDescriptors.rebuildsharableViewDescriptors(
|
|
437
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
438
|
+
initRef.current!.sharableViewDescriptors
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
dependencies.push(initRef.current?.sharableViewDescriptors.value);
|
|
442
|
+
|
|
443
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
444
|
+
const { initial, remoteState, sharableViewDescriptors } = initRef.current!;
|
|
445
|
+
const maybeViewRef = NativeReanimatedModule.native ? undefined : viewsRef;
|
|
446
|
+
|
|
447
|
+
useEffect(() => {
|
|
448
|
+
let fun;
|
|
449
|
+
let upadterFn = updater;
|
|
450
|
+
let optimalization = updater.__optimalization;
|
|
451
|
+
if (adapters) {
|
|
452
|
+
upadterFn = () => {
|
|
453
|
+
'worklet';
|
|
454
|
+
const newValues = updater();
|
|
455
|
+
adaptersArray.forEach((adapter) => {
|
|
456
|
+
adapter(newValues);
|
|
457
|
+
});
|
|
458
|
+
return newValues;
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
if (canApplyOptimalisation(upadterFn) && !shouldBeUseWeb()) {
|
|
463
|
+
if (hasColorProps(upadterFn())) {
|
|
464
|
+
upadterFn = () => {
|
|
465
|
+
'worklet';
|
|
466
|
+
const style = upadterFn();
|
|
467
|
+
parseColors(style);
|
|
468
|
+
return style;
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
} else if (!shouldBeUseWeb()) {
|
|
472
|
+
optimalization = 0;
|
|
473
|
+
upadterFn = () => {
|
|
474
|
+
'worklet';
|
|
475
|
+
const style = upadterFn();
|
|
476
|
+
parseColors(style);
|
|
477
|
+
return style;
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
if (typeof updater.__optimalization !== undefined) {
|
|
481
|
+
upadterFn.__optimalization = optimalization;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
if (isJest()) {
|
|
485
|
+
fun = () => {
|
|
486
|
+
'worklet';
|
|
487
|
+
jestStyleUpdater(
|
|
488
|
+
sharableViewDescriptors,
|
|
489
|
+
updater,
|
|
490
|
+
remoteState,
|
|
491
|
+
maybeViewRef,
|
|
492
|
+
animationsActive,
|
|
493
|
+
animatedStyle,
|
|
494
|
+
adaptersArray
|
|
495
|
+
);
|
|
496
|
+
};
|
|
497
|
+
} else {
|
|
498
|
+
fun = () => {
|
|
499
|
+
'worklet';
|
|
500
|
+
styleUpdater(
|
|
501
|
+
sharableViewDescriptors,
|
|
502
|
+
upadterFn,
|
|
503
|
+
remoteState,
|
|
504
|
+
maybeViewRef,
|
|
505
|
+
animationsActive
|
|
506
|
+
);
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
const mapperId = startMapper(
|
|
510
|
+
fun,
|
|
511
|
+
inputs,
|
|
512
|
+
[],
|
|
513
|
+
upadterFn,
|
|
514
|
+
// TODO fix this
|
|
515
|
+
sharableViewDescriptors
|
|
516
|
+
);
|
|
517
|
+
return () => {
|
|
518
|
+
stopMapper(mapperId);
|
|
519
|
+
};
|
|
520
|
+
}, dependencies);
|
|
521
|
+
|
|
522
|
+
useEffect(() => {
|
|
523
|
+
animationsActive.value = true;
|
|
524
|
+
return () => {
|
|
525
|
+
// initRef.current = null;
|
|
526
|
+
// viewsRef = null;
|
|
527
|
+
animationsActive.value = false;
|
|
528
|
+
};
|
|
529
|
+
}, []);
|
|
530
|
+
|
|
531
|
+
checkSharedValueUsage(initial.value);
|
|
532
|
+
|
|
533
|
+
if (process.env.JEST_WORKER_ID) {
|
|
534
|
+
return { viewDescriptors, initial: initial, viewsRef, animatedStyle };
|
|
535
|
+
} else {
|
|
536
|
+
return { viewDescriptors, initial: initial, viewsRef };
|
|
537
|
+
}
|
|
538
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { initialUpdaterRun } from '../animation';
|
|
3
|
+
import { BasicWorkletFunction, SharedValue } from '../commonTypes';
|
|
4
|
+
import { makeMutable, startMapper, stopMapper } from '../core';
|
|
5
|
+
import { DependencyList } from './commonTypes';
|
|
6
|
+
|
|
7
|
+
export type DerivedValue<T> = Readonly<SharedValue<T>>;
|
|
8
|
+
|
|
9
|
+
export function useDerivedValue<T>(
|
|
10
|
+
processor: BasicWorkletFunction<T>,
|
|
11
|
+
dependencies: DependencyList
|
|
12
|
+
): DerivedValue<T> {
|
|
13
|
+
const initRef = useRef<SharedValue<T> | null>(null);
|
|
14
|
+
const inputs = Object.values(processor._closure ?? {});
|
|
15
|
+
|
|
16
|
+
// build dependencies
|
|
17
|
+
if (dependencies === undefined) {
|
|
18
|
+
dependencies = [...inputs, processor.__workletHash];
|
|
19
|
+
} else {
|
|
20
|
+
dependencies.push(processor.__workletHash);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (initRef.current === null) {
|
|
24
|
+
initRef.current = makeMutable(initialUpdaterRun(processor));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
28
|
+
const sharedValue: SharedValue<T> = initRef.current!;
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const fun = () => {
|
|
32
|
+
'worklet';
|
|
33
|
+
sharedValue.value = processor();
|
|
34
|
+
};
|
|
35
|
+
const mapperId = startMapper(fun, inputs, [sharedValue]);
|
|
36
|
+
return () => {
|
|
37
|
+
stopMapper(mapperId);
|
|
38
|
+
};
|
|
39
|
+
}, dependencies);
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
return () => {
|
|
43
|
+
initRef.current = null;
|
|
44
|
+
};
|
|
45
|
+
}, []);
|
|
46
|
+
|
|
47
|
+
return sharedValue;
|
|
48
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { cancelAnimation } from '../animation';
|
|
3
|
+
import { SharedValue } from '../commonTypes';
|
|
4
|
+
import { makeMutable } from '../core';
|
|
5
|
+
|
|
6
|
+
export function useSharedValue<T>(init: T): SharedValue<T> {
|
|
7
|
+
const ref = useRef<SharedValue<T>>(makeMutable(init));
|
|
8
|
+
|
|
9
|
+
if (ref.current === null) {
|
|
10
|
+
ref.current = makeMutable(init);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
return () => {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
16
|
+
cancelAnimation(ref.current!);
|
|
17
|
+
};
|
|
18
|
+
}, []);
|
|
19
|
+
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
21
|
+
return ref.current!;
|
|
22
|
+
}
|