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
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
/* global _WORKLET _measure _scrollTo */
|
|
2
|
-
|
|
3
|
-
// @ts-nocheck
|
|
2
|
+
import { Component } from 'react';
|
|
4
3
|
import { findNodeHandle } from 'react-native';
|
|
4
|
+
import { RefObjectFunction } from './hook/useAnimatedRef';
|
|
5
|
+
import { isChromeDebugger } from './PlatformChecker';
|
|
5
6
|
|
|
6
|
-
export function getTag(
|
|
7
|
+
export function getTag(
|
|
8
|
+
view: null | number | React.Component<any, any> | React.ComponentClass<any>
|
|
9
|
+
): null | number {
|
|
7
10
|
return findNodeHandle(view);
|
|
8
11
|
}
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export function measure(
|
|
13
|
+
export interface MeasuredDimensions {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
pageX: number;
|
|
19
|
+
pageY: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function measure(
|
|
23
|
+
animatedRef: RefObjectFunction<Component>
|
|
24
|
+
): MeasuredDimensions {
|
|
20
25
|
'worklet';
|
|
21
|
-
if (!_WORKLET) {
|
|
26
|
+
if (!_WORKLET && !isChromeDebugger()) {
|
|
22
27
|
throw new Error('(measure) method cannot be used on RN side!');
|
|
23
28
|
}
|
|
24
29
|
const viewTag = animatedRef();
|
|
@@ -29,9 +34,14 @@ export function measure(animatedRef) {
|
|
|
29
34
|
return result;
|
|
30
35
|
}
|
|
31
36
|
|
|
32
|
-
export function scrollTo(
|
|
37
|
+
export function scrollTo(
|
|
38
|
+
animatedRef: RefObjectFunction<Component>,
|
|
39
|
+
x: number,
|
|
40
|
+
y: number,
|
|
41
|
+
animated: boolean
|
|
42
|
+
): void {
|
|
33
43
|
'worklet';
|
|
34
|
-
if (!_WORKLET) {
|
|
44
|
+
if (!_WORKLET && !isChromeDebugger()) {
|
|
35
45
|
return;
|
|
36
46
|
}
|
|
37
47
|
const viewTag = animatedRef();
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { AnimationObject } from '../animation';
|
|
2
|
+
import { PrimitiveValue } from '../animation/commonTypes';
|
|
3
|
+
import { SharedValue } from '../commonTypes';
|
|
4
|
+
import { Descriptor } from '../hook/commonTypes';
|
|
5
|
+
|
|
6
|
+
const InnerNativeModule = global.__reanimatedModuleProxy;
|
|
7
|
+
export class NativeReanimated {
|
|
8
|
+
native: boolean;
|
|
9
|
+
useOnlyV1: boolean;
|
|
10
|
+
|
|
11
|
+
constructor(native = true) {
|
|
12
|
+
this.native = native;
|
|
13
|
+
this.useOnlyV1 = InnerNativeModule === null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
installCoreFunctions(
|
|
17
|
+
valueSetter: (
|
|
18
|
+
value:
|
|
19
|
+
| (() => AnimationObject)
|
|
20
|
+
| AnimationObject
|
|
21
|
+
| PrimitiveValue
|
|
22
|
+
| Descriptor
|
|
23
|
+
) => void
|
|
24
|
+
): void {
|
|
25
|
+
return InnerNativeModule.installCoreFunctions(valueSetter);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
makeShareable<T>(value: T): T {
|
|
29
|
+
return InnerNativeModule.makeShareable(value);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
makeMutable<T>(value: T): SharedValue<T> {
|
|
33
|
+
return InnerNativeModule.makeMutable(value);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
makeRemote<T>(object = {}): T {
|
|
37
|
+
return InnerNativeModule.makeRemote(object);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
startMapper(
|
|
41
|
+
mapper: () => void,
|
|
42
|
+
inputs: any[] = [],
|
|
43
|
+
outputs: any[] = [],
|
|
44
|
+
updater: () => void,
|
|
45
|
+
viewDescriptors: Descriptor[] | SharedValue<Descriptor[]>
|
|
46
|
+
): number {
|
|
47
|
+
return InnerNativeModule.startMapper(
|
|
48
|
+
mapper,
|
|
49
|
+
inputs,
|
|
50
|
+
outputs,
|
|
51
|
+
updater,
|
|
52
|
+
viewDescriptors
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
stopMapper(mapperId: number): void {
|
|
57
|
+
return InnerNativeModule.stopMapper(mapperId);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
registerEventHandler<T>(
|
|
61
|
+
eventHash: string,
|
|
62
|
+
eventHandler: (event: T) => void
|
|
63
|
+
): string {
|
|
64
|
+
return InnerNativeModule.registerEventHandler(eventHash, eventHandler);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
unregisterEventHandler(id: string): void {
|
|
68
|
+
return InnerNativeModule.unregisterEventHandler(id);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
getViewProp<T>(
|
|
72
|
+
viewTag: string,
|
|
73
|
+
propName: string,
|
|
74
|
+
callback?: (result: T) => void
|
|
75
|
+
): Promise<T> {
|
|
76
|
+
return InnerNativeModule.getViewProp(viewTag, propName, callback);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import reanimatedJS from '../js-reanimated';
|
|
2
|
+
import { nativeShouldBeMock } from '../PlatformChecker';
|
|
3
|
+
import { Platform } from 'react-native';
|
|
4
|
+
import { NativeReanimated } from './NativeReanimated';
|
|
5
|
+
|
|
6
|
+
let exportedModule;
|
|
7
|
+
if (nativeShouldBeMock()) {
|
|
8
|
+
exportedModule = reanimatedJS;
|
|
9
|
+
} else {
|
|
10
|
+
exportedModule = new NativeReanimated();
|
|
11
|
+
if (exportedModule.useOnlyV1 && Platform.OS === 'android') {
|
|
12
|
+
console.warn(
|
|
13
|
+
`If you want to use Reanimated 2 then go through our installation steps https://docs.swmansion.com/react-native-reanimated/docs/installation`
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default exportedModule as NativeReanimated;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export function isJest(): boolean {
|
|
4
|
+
return !!process.env.JEST_WORKER_ID;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function isChromeDebugger(): boolean {
|
|
8
|
+
return !(global as any).nativeCallSyncHook || (global as any).__REMOTEDEV__;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isWeb(): boolean {
|
|
12
|
+
return Platform.OS === 'web';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function shouldBeUseWeb() {
|
|
16
|
+
return isJest() || isChromeDebugger() || isWeb();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function nativeShouldBeMock() {
|
|
20
|
+
return isJest() || isChromeDebugger();
|
|
21
|
+
}
|
|
@@ -1,41 +1,59 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import {
|
|
1
|
+
// @ts-ignore JS file
|
|
2
|
+
import { addWhitelistedNativeProps } from '../ConfigHelper';
|
|
3
|
+
import { AdapterWorkletFunction } from './commonTypes';
|
|
4
4
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
export function createAnimatedPropAdapter(
|
|
6
|
+
adapter: AdapterWorkletFunction,
|
|
7
|
+
nativeProps?: string[]
|
|
8
|
+
): AdapterWorkletFunction {
|
|
9
|
+
const nativePropsToAdd: { [key: string]: boolean } = {};
|
|
10
|
+
// eslint-disable-next-line no-unused-expressions
|
|
11
|
+
nativeProps?.forEach((prop) => {
|
|
12
|
+
nativePropsToAdd[prop] = true;
|
|
13
|
+
});
|
|
14
|
+
addWhitelistedNativeProps(nativePropsToAdd);
|
|
15
|
+
return adapter;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// ADAPTERS
|
|
19
|
+
|
|
20
|
+
export const SVGAdapter: AdapterWorkletFunction = createAnimatedPropAdapter(
|
|
21
|
+
(props) => {
|
|
22
|
+
'worklet';
|
|
23
|
+
const keys = Object.keys(props);
|
|
24
|
+
// transform
|
|
25
|
+
if (keys.includes('transform')) {
|
|
26
|
+
if (Array.isArray(props.transform)) {
|
|
27
|
+
// case of array with 6 values => https://github.com/react-native-svg/react-native-svg/blob/b2e2c355204ff4b10973d3afce1495f7e4167ff7/src/elements/Shape.tsx#L200
|
|
28
|
+
if (props.transform.length !== 6) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
`invalid transform length of ${props.transform.length}, should be 6`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
const transform: number[] = props.transform as number[];
|
|
34
|
+
const x: number = (props.x as number) ?? 0;
|
|
35
|
+
const y: number = (props.y as number) ?? 0;
|
|
36
|
+
props.transform = [
|
|
37
|
+
{ translateX: transform[0] * x + transform[2] * y + transform[4] },
|
|
38
|
+
{ translateY: transform[1] * x + transform[3] * y + transform[5] },
|
|
39
|
+
];
|
|
40
|
+
} else if (typeof props.transform === 'string') {
|
|
41
|
+
// case of string 'translate(translateX translateY)'
|
|
42
|
+
// todo: handle other cases of transform string like here https://github.com/react-native-svg/react-native-svg/blob/b2e2c355204ff4b10973d3afce1495f7e4167ff7/src/lib/extract/extractTransform.ts#L184
|
|
43
|
+
const transform: string = props.transform as string;
|
|
44
|
+
const arr = transform
|
|
45
|
+
.replace('translate(', '')
|
|
46
|
+
.replace(')', '')
|
|
47
|
+
.split(' ');
|
|
48
|
+
props.transform = [
|
|
49
|
+
{ translateX: parseFloat(arr[0]) },
|
|
50
|
+
{ translateY: parseFloat(arr[1]) },
|
|
51
|
+
];
|
|
16
52
|
}
|
|
17
|
-
const transform = props.transform;
|
|
18
|
-
const x = props.x ?? 0;
|
|
19
|
-
const y = props.y ?? 0;
|
|
20
|
-
props.transform = [
|
|
21
|
-
{ translateX: transform[0] * x + transform[2] * y + transform[4] },
|
|
22
|
-
{ translateY: transform[1] * x + transform[3] * y + transform[5] },
|
|
23
|
-
];
|
|
24
|
-
} else if (typeof props.transform === 'string') {
|
|
25
|
-
// case of string 'translate(translateX translateY)'
|
|
26
|
-
// todo: handle other cases of transform string like here https://github.com/react-native-svg/react-native-svg/blob/b2e2c355204ff4b10973d3afce1495f7e4167ff7/src/lib/extract/extractTransform.ts#L184
|
|
27
|
-
const arr = props.transform
|
|
28
|
-
.replace('translate(', '')
|
|
29
|
-
.replace(')', '')
|
|
30
|
-
.split(' ');
|
|
31
|
-
props.transform = [
|
|
32
|
-
{ translateX: parseFloat(arr[0]) },
|
|
33
|
-
{ translateY: parseFloat(arr[1]) },
|
|
34
|
-
];
|
|
35
53
|
}
|
|
54
|
+
// todo: other props
|
|
36
55
|
}
|
|
37
|
-
|
|
38
|
-
});
|
|
56
|
+
);
|
|
39
57
|
|
|
40
58
|
export const TextInputAdapter = createAnimatedPropAdapter(
|
|
41
59
|
(props) => {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/* global _updateProps */
|
|
2
|
-
|
|
3
|
-
// @ts-nocheck
|
|
2
|
+
import { MutableRefObject } from 'react';
|
|
4
3
|
import { processColor } from './Colors';
|
|
4
|
+
import { AnimatedStyle, SharedValue, StyleProps } from './commonTypes';
|
|
5
5
|
import { makeShareable, isConfigured } from './core';
|
|
6
|
-
import {
|
|
6
|
+
import { Descriptor } from './hook/commonTypes';
|
|
7
7
|
import { _updatePropsJS } from './js-reanimated';
|
|
8
|
+
import { shouldBeUseWeb } from './PlatformChecker';
|
|
9
|
+
import { ViewRefSet } from './ViewDescriptorsSet';
|
|
8
10
|
|
|
9
11
|
// copied from react-native/Libraries/Components/View/ReactNativeStyleAttributes
|
|
10
12
|
export const colorProps = [
|
|
@@ -27,13 +29,25 @@ export const colorProps = [
|
|
|
27
29
|
const ColorProperties = !isConfigured() ? [] : makeShareable(colorProps);
|
|
28
30
|
|
|
29
31
|
let updatePropsByPlatform;
|
|
30
|
-
if (
|
|
31
|
-
updatePropsByPlatform = (
|
|
32
|
+
if (shouldBeUseWeb()) {
|
|
33
|
+
updatePropsByPlatform = (
|
|
34
|
+
_: SharedValue<Descriptor[]>,
|
|
35
|
+
updates: StyleProps | AnimatedStyle,
|
|
36
|
+
maybeViewRef: ViewRefSet<any> | undefined
|
|
37
|
+
): void => {
|
|
32
38
|
'worklet';
|
|
33
|
-
|
|
39
|
+
if (maybeViewRef) {
|
|
40
|
+
maybeViewRef.items.forEach((item, _) => {
|
|
41
|
+
_updatePropsJS(updates, item);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
34
44
|
};
|
|
35
45
|
} else {
|
|
36
|
-
updatePropsByPlatform = (
|
|
46
|
+
updatePropsByPlatform = (
|
|
47
|
+
viewDescriptors: SharedValue<Descriptor[]>,
|
|
48
|
+
updates: StyleProps | AnimatedStyle,
|
|
49
|
+
_: ViewRefSet<any> | undefined
|
|
50
|
+
): void => {
|
|
37
51
|
'worklet';
|
|
38
52
|
|
|
39
53
|
for (const key in updates) {
|
|
@@ -42,23 +56,29 @@ if (Platform.OS === 'web' || process.env.JEST_WORKER_ID) {
|
|
|
42
56
|
}
|
|
43
57
|
}
|
|
44
58
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
59
|
+
viewDescriptors.value.forEach((viewDescriptor) => {
|
|
60
|
+
_updateProps(
|
|
61
|
+
viewDescriptor.tag,
|
|
62
|
+
viewDescriptor.name || 'RCTView',
|
|
63
|
+
updates
|
|
64
|
+
);
|
|
65
|
+
});
|
|
50
66
|
};
|
|
51
67
|
}
|
|
52
68
|
|
|
53
|
-
export const updateProps
|
|
69
|
+
export const updateProps: (
|
|
70
|
+
viewDescriptor: SharedValue<Descriptor[]>,
|
|
71
|
+
updates: StyleProps | AnimatedStyle,
|
|
72
|
+
maybeViewRef: ViewRefSet<any> | undefined
|
|
73
|
+
) => void = updatePropsByPlatform;
|
|
54
74
|
|
|
55
75
|
export const updatePropsJestWrapper = (
|
|
56
|
-
|
|
57
|
-
updates,
|
|
58
|
-
maybeViewRef,
|
|
59
|
-
animatedStyle
|
|
60
|
-
adapters
|
|
61
|
-
) => {
|
|
76
|
+
viewDescriptors: SharedValue<Descriptor[]>,
|
|
77
|
+
updates: AnimatedStyle,
|
|
78
|
+
maybeViewRef: ViewRefSet<any> | undefined,
|
|
79
|
+
animatedStyle: MutableRefObject<AnimatedStyle>,
|
|
80
|
+
adapters: ((updates: AnimatedStyle) => void)[]
|
|
81
|
+
): void => {
|
|
62
82
|
adapters.forEach((adapter) => {
|
|
63
83
|
adapter(updates);
|
|
64
84
|
});
|
|
@@ -67,7 +87,7 @@ export const updatePropsJestWrapper = (
|
|
|
67
87
|
...updates,
|
|
68
88
|
};
|
|
69
89
|
|
|
70
|
-
updateProps(
|
|
90
|
+
updateProps(viewDescriptors, updates, maybeViewRef);
|
|
71
91
|
};
|
|
72
92
|
|
|
73
93
|
export default updateProps;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
import { makeMutable } from './core';
|
|
3
|
+
import { SharedValue } from './commonTypes';
|
|
4
|
+
import { Descriptor } from './hook/commonTypes';
|
|
5
|
+
|
|
6
|
+
export interface ViewRefSet<T> {
|
|
7
|
+
items: Set<T>;
|
|
8
|
+
add: (item: T) => void;
|
|
9
|
+
remove: (item: T) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ViewDescriptorsSet {
|
|
13
|
+
batchToRemove: Set<number>;
|
|
14
|
+
tags: Set<number>;
|
|
15
|
+
waitForInsertSync: boolean;
|
|
16
|
+
waitForRemoveSync: boolean;
|
|
17
|
+
sharableViewDescriptors: SharedValue<Descriptor[]>;
|
|
18
|
+
items: Descriptor[];
|
|
19
|
+
add: (item: Descriptor) => void;
|
|
20
|
+
remove: (viewTag: number) => void;
|
|
21
|
+
rebuildsharableViewDescriptors: (
|
|
22
|
+
sharableViewDescriptor: SharedValue<Descriptor[]>
|
|
23
|
+
) => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function makeViewDescriptorsSet(): ViewDescriptorsSet {
|
|
27
|
+
const ref = useRef<ViewDescriptorsSet | null>(null);
|
|
28
|
+
if (ref.current === null) {
|
|
29
|
+
const data: ViewDescriptorsSet = {
|
|
30
|
+
batchToRemove: new Set(),
|
|
31
|
+
tags: new Set(),
|
|
32
|
+
waitForInsertSync: false,
|
|
33
|
+
waitForRemoveSync: false,
|
|
34
|
+
sharableViewDescriptors: makeMutable([]),
|
|
35
|
+
items: [],
|
|
36
|
+
|
|
37
|
+
add: (item: Descriptor) => {
|
|
38
|
+
if (data.tags.has(item.tag)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
data.tags.add(item.tag);
|
|
42
|
+
data.items.push(item);
|
|
43
|
+
|
|
44
|
+
if (!data.waitForInsertSync) {
|
|
45
|
+
data.waitForInsertSync = true;
|
|
46
|
+
|
|
47
|
+
setImmediate(() => {
|
|
48
|
+
data.sharableViewDescriptors.value = data.items;
|
|
49
|
+
data.waitForInsertSync = false;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
remove: (viewTag: number) => {
|
|
55
|
+
data.batchToRemove.add(viewTag);
|
|
56
|
+
|
|
57
|
+
if (!data.waitForRemoveSync) {
|
|
58
|
+
data.waitForRemoveSync = true;
|
|
59
|
+
|
|
60
|
+
setImmediate(() => {
|
|
61
|
+
const items = [];
|
|
62
|
+
for (const item of data.items) {
|
|
63
|
+
if (data.batchToRemove.has(item.tag)) {
|
|
64
|
+
data.tags.delete(item.tag);
|
|
65
|
+
} else {
|
|
66
|
+
items.push(item);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
data.items = items;
|
|
70
|
+
data.sharableViewDescriptors.value = items;
|
|
71
|
+
data.batchToRemove = new Set();
|
|
72
|
+
data.waitForRemoveSync = false;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
rebuildsharableViewDescriptors: (
|
|
78
|
+
sharableViewDescriptors: SharedValue<Descriptor[]>
|
|
79
|
+
) => {
|
|
80
|
+
data.sharableViewDescriptors = sharableViewDescriptors;
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
ref.current = data;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return ref.current;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function makeViewsRefSet<T>(): ViewRefSet<T> {
|
|
90
|
+
const ref = useRef<ViewRefSet<T> | null>(null);
|
|
91
|
+
if (ref.current === null) {
|
|
92
|
+
const data: ViewRefSet<T> = {
|
|
93
|
+
items: new Set(),
|
|
94
|
+
|
|
95
|
+
add: (item: T) => {
|
|
96
|
+
if (data.items.has(item)) return;
|
|
97
|
+
data.items.add(item);
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
remove: (item: T) => {
|
|
101
|
+
data.items.delete(item);
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
ref.current = data;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return ref.current;
|
|
108
|
+
}
|
|
@@ -1,38 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import NativeModule from './NativeReanimated';
|
|
1
|
+
import { NativeEvent } from './commonTypes';
|
|
2
|
+
import NativeReanimatedModule from './NativeReanimated';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
function jsListener<T extends NativeEvent<T>>(
|
|
5
|
+
eventName: string,
|
|
6
|
+
handler: (event: T) => void
|
|
7
|
+
) {
|
|
8
|
+
return (evt: T) => {
|
|
9
|
+
handler({ ...evt.nativeEvent, eventName });
|
|
10
|
+
};
|
|
11
|
+
}
|
|
8
12
|
|
|
9
|
-
export default class WorkletEventHandler {
|
|
10
|
-
|
|
13
|
+
export default class WorkletEventHandler<T extends NativeEvent<T>> {
|
|
14
|
+
worklet: (event: T) => void;
|
|
15
|
+
eventNames: string[];
|
|
16
|
+
reattachNeeded: boolean;
|
|
17
|
+
listeners: Record<string, (event: T) => void>;
|
|
18
|
+
viewTag: number | undefined;
|
|
19
|
+
registrations: string[];
|
|
20
|
+
constructor(worklet: (event: T) => void, eventNames: string[] = []) {
|
|
11
21
|
this.worklet = worklet;
|
|
12
22
|
this.eventNames = eventNames;
|
|
13
23
|
this.reattachNeeded = false;
|
|
24
|
+
this.listeners = {};
|
|
25
|
+
this.viewTag = undefined;
|
|
26
|
+
this.registrations = [];
|
|
14
27
|
|
|
15
|
-
if (!
|
|
16
|
-
this.listeners = eventNames.reduce(
|
|
17
|
-
acc
|
|
18
|
-
|
|
19
|
-
|
|
28
|
+
if (!NativeReanimatedModule.native) {
|
|
29
|
+
this.listeners = eventNames.reduce(
|
|
30
|
+
(acc: Record<string, (event: T) => void>, eventName: string) => {
|
|
31
|
+
acc[eventName] = jsListener(eventName, worklet);
|
|
32
|
+
return acc;
|
|
33
|
+
},
|
|
34
|
+
{}
|
|
35
|
+
);
|
|
20
36
|
}
|
|
21
37
|
}
|
|
22
38
|
|
|
23
|
-
updateWorklet(newWorklet) {
|
|
39
|
+
updateWorklet(newWorklet: (event: T) => void): void {
|
|
24
40
|
this.worklet = newWorklet;
|
|
25
41
|
this.reattachNeeded = true;
|
|
26
42
|
}
|
|
27
43
|
|
|
28
|
-
registerForEvents(viewTag, fallbackEventName
|
|
44
|
+
registerForEvents(viewTag: number, fallbackEventName?: string): void {
|
|
29
45
|
this.viewTag = viewTag;
|
|
30
46
|
this.registrations = this.eventNames.map((eventName) =>
|
|
31
|
-
|
|
47
|
+
NativeReanimatedModule.registerEventHandler(
|
|
48
|
+
viewTag + eventName,
|
|
49
|
+
this.worklet
|
|
50
|
+
)
|
|
32
51
|
);
|
|
33
52
|
if (this.registrations.length === 0 && fallbackEventName) {
|
|
34
53
|
this.registrations.push(
|
|
35
|
-
|
|
54
|
+
NativeReanimatedModule.registerEventHandler(
|
|
36
55
|
viewTag + fallbackEventName,
|
|
37
56
|
this.worklet
|
|
38
57
|
)
|
|
@@ -40,11 +59,10 @@ export default class WorkletEventHandler {
|
|
|
40
59
|
}
|
|
41
60
|
}
|
|
42
61
|
|
|
43
|
-
unregisterFromEvents() {
|
|
44
|
-
this.registrations
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
this.registrations = undefined;
|
|
62
|
+
unregisterFromEvents(): void {
|
|
63
|
+
this.registrations.forEach((id) =>
|
|
64
|
+
NativeReanimatedModule.unregisterEventHandler(id)
|
|
65
|
+
);
|
|
66
|
+
this.registrations = [];
|
|
49
67
|
}
|
|
50
68
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export type PrimitiveValue = number | string;
|
|
2
|
+
|
|
3
|
+
export interface AnimationObject {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
callback: AnimationCallback;
|
|
6
|
+
current?: PrimitiveValue;
|
|
7
|
+
toValue?: AnimationObject['current'];
|
|
8
|
+
startValue?: AnimationObject['current'];
|
|
9
|
+
finished?: boolean;
|
|
10
|
+
strippedCurrent?: number;
|
|
11
|
+
cancelled?: boolean;
|
|
12
|
+
|
|
13
|
+
__prefix?: string;
|
|
14
|
+
__suffix?: string;
|
|
15
|
+
onFrame: (animation: any, timestamp: Timestamp) => boolean;
|
|
16
|
+
onStart: (
|
|
17
|
+
nextAnimation: any,
|
|
18
|
+
current: any,
|
|
19
|
+
timestamp: Timestamp,
|
|
20
|
+
previousAnimation: any
|
|
21
|
+
) => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface Animation<T extends AnimationObject> extends AnimationObject {
|
|
25
|
+
onFrame: (animation: T, timestamp: Timestamp) => boolean;
|
|
26
|
+
onStart: (
|
|
27
|
+
nextAnimation: T,
|
|
28
|
+
current: T extends NumericAnimation ? number : PrimitiveValue,
|
|
29
|
+
timestamp: Timestamp,
|
|
30
|
+
previousAnimation: T
|
|
31
|
+
) => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface NumericAnimation {
|
|
35
|
+
current?: number;
|
|
36
|
+
}
|
|
37
|
+
export interface HigherOrderAnimation {
|
|
38
|
+
isHigherOrder?: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type AnimationCallback = (
|
|
42
|
+
finished?: boolean,
|
|
43
|
+
current?: PrimitiveValue
|
|
44
|
+
) => void;
|
|
45
|
+
|
|
46
|
+
export type NextAnimation<T extends AnimationObject> = T | (() => T);
|
|
47
|
+
|
|
48
|
+
export type Timestamp = number;
|