react-native-reanimated 2.3.0-alpha.3 → 2.3.0-beta.4
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 +176 -154
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +49 -33
- package/Common/cpp/Registries/EventHandlerRegistry.cpp +14 -7
- package/Common/cpp/Registries/MapperRegistry.cpp +24 -20
- package/Common/cpp/Registries/WorkletsCache.cpp +19 -9
- package/Common/cpp/SharedItems/FrozenObject.cpp +17 -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 +211 -160
- package/Common/cpp/Tools/FeaturesConfig.cpp +5 -0
- package/Common/cpp/Tools/JSIStoreValueUser.cpp +25 -6
- package/Common/cpp/Tools/Mapper.cpp +30 -30
- package/Common/cpp/Tools/RuntimeDecorator.cpp +124 -86
- package/Common/cpp/Tools/Scheduler.cpp +6 -5
- package/Common/cpp/Tools/WorkletEventHandler.cpp +4 -2
- package/Common/cpp/headers/LayoutAnimations/LayoutAnimationsProxy.h +12 -11
- package/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +50 -31
- package/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +34 -16
- package/Common/cpp/headers/Registries/EventHandlerRegistry.h +15 -8
- package/Common/cpp/headers/Registries/MapperRegistry.h +5 -4
- package/Common/cpp/headers/Registries/WorkletsCache.h +9 -7
- package/Common/cpp/headers/SharedItems/FrozenObject.h +19 -11
- package/Common/cpp/headers/SharedItems/HostFunctionHandler.h +8 -4
- package/Common/cpp/headers/SharedItems/MutableValue.h +23 -12
- package/Common/cpp/headers/SharedItems/MutableValueSetterProxy.h +12 -7
- package/Common/cpp/headers/SharedItems/RemoteObject.h +19 -8
- package/Common/cpp/headers/SharedItems/RuntimeManager.h +26 -25
- package/Common/cpp/headers/SharedItems/ShareableValue.h +32 -27
- package/Common/cpp/headers/SharedItems/SharedParent.h +10 -7
- package/Common/cpp/headers/SharedItems/ValueWrapper.h +95 -72
- package/Common/cpp/headers/SpecTools/ErrorHandler.h +18 -19
- package/Common/cpp/headers/Tools/FeaturesConfig.h +19 -0
- package/Common/cpp/headers/Tools/JSIStoreValueUser.h +13 -16
- package/Common/cpp/headers/Tools/Mapper.h +19 -16
- package/Common/cpp/headers/Tools/PlatformDepMethodsHolder.h +17 -7
- package/Common/cpp/headers/Tools/ReanimatedHiddenHeaders.h +7 -11
- package/Common/cpp/headers/Tools/RuntimeDecorator.h +36 -27
- package/Common/cpp/headers/Tools/Scheduler.h +30 -35
- package/Common/cpp/headers/Tools/WorkletEventHandler.h +11 -8
- 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 +24 -6
- package/android/build.gradle +38 -29
- 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/android/react-native-reanimated-67-hermes.aar +0 -0
- package/android/react-native-reanimated-67-jsc.aar +0 -0
- package/ios/LayoutReanimation/REAAnimationsManager.h +10 -8
- package/ios/LayoutReanimation/REAAnimationsManager.m +91 -87
- package/ios/LayoutReanimation/REASnapshot.h +2 -2
- package/ios/LayoutReanimation/REASnapshot.m +8 -7
- package/ios/LayoutReanimation/REAUIManager.h +4 -4
- package/ios/LayoutReanimation/REAUIManager.mm +116 -70
- 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 +4 -4
- package/ios/REAModule.h +0 -2
- package/ios/REAModule.m +29 -38
- package/ios/REANodesManager.h +11 -19
- package/ios/REANodesManager.m +106 -130
- package/ios/REAUtils.h +5 -3
- package/ios/RNGestureHandlerStateManager.h +5 -0
- 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 +20 -5
- package/ios/native/NativeMethods.mm +14 -6
- package/ios/native/NativeProxy.h +4 -2
- package/ios/native/NativeProxy.mm +84 -63
- package/ios/native/REAIOSErrorHandler.h +13 -10
- package/ios/native/REAIOSErrorHandler.mm +19 -15
- package/ios/native/REAIOSLogger.h +8 -8
- package/ios/native/REAIOSLogger.mm +10 -6
- package/ios/native/REAIOSScheduler.h +5 -5
- package/ios/native/REAIOSScheduler.mm +17 -10
- package/ios/native/REAInitializer.h +5 -7
- package/ios/native/REAInitializer.mm +43 -31
- package/ios/native/UIResponder+Reanimated.mm +2 -2
- package/lib/Animated.js +9 -1
- package/lib/ConfigHelper.js +121 -138
- package/lib/ReanimatedEventEmitter.js +0 -1
- package/lib/ReanimatedModule.js +0 -1
- package/lib/ReanimatedModule.macos.js +0 -1
- package/lib/ReanimatedModule.native.js +5 -6
- package/lib/ReanimatedModule.windows.js +0 -1
- package/lib/ReanimatedModuleCompat.js +64 -35
- package/lib/createAnimatedComponent.js +468 -487
- package/lib/index.js +9 -1
- package/lib/reanimated2/NativeMethods.js +7 -12
- package/lib/reanimated2/NativeReanimated/NativeReanimated.js +37 -0
- package/lib/reanimated2/NativeReanimated/index.js +15 -0
- package/lib/reanimated2/PropAdapters.js +0 -1
- package/lib/reanimated2/UpdateProps.js +6 -7
- package/lib/reanimated2/ViewDescriptorsSet.js +4 -4
- package/lib/reanimated2/WorkletEventHandler.js +15 -13
- package/lib/reanimated2/animation/delay.js +8 -2
- package/lib/reanimated2/animation/spring.js +2 -0
- package/lib/reanimated2/animation/styleAnimation.js +7 -3
- package/lib/reanimated2/animation/util.js +25 -2
- package/lib/reanimated2/core.js +41 -17
- package/lib/reanimated2/globals.d.ts +21 -1
- package/lib/reanimated2/hook/useAnimatedRef.js +1 -1
- package/lib/reanimated2/hook/useAnimatedStyle.js +3 -3
- package/lib/reanimated2/index.js +1 -0
- package/lib/reanimated2/interpolation.js +95 -87
- package/lib/reanimated2/js-reanimated/JSReanimated.js +13 -10
- package/lib/reanimated2/js-reanimated/Mapper.js +4 -3
- package/lib/reanimated2/js-reanimated/MapperRegistry.js +3 -6
- package/lib/reanimated2/js-reanimated/MutableValue.js +0 -2
- package/lib/reanimated2/js-reanimated/index.js +10 -8
- package/lib/reanimated2/layoutReanimation/LayoutAnimationRepository.js +33 -2
- package/lib/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js +27 -124
- package/lib/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +125 -0
- package/lib/reanimated2/layoutReanimation/animationBuilder/index.js +1 -2
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +115 -45
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Default.js +7 -2
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Fade.js +21 -21
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +25 -25
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +19 -17
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +5 -5
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Roll.js +9 -9
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +17 -17
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +19 -19
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +9 -9
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +33 -33
- 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 +1 -0
- package/lib/reanimated2/mock.js +3 -1
- package/lib/reanimated2/utils.js +9 -0
- package/lib/setAndForwardRef.js +14 -48
- 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/mock.js +1 -1
- package/package.json +28 -17
- package/plugin.js +220 -39
- package/react-native-reanimated.d.ts +542 -547
- package/src/Animated.js +9 -1
- package/src/{ConfigHelper.js → ConfigHelper.ts} +15 -7
- package/src/{ReanimatedEventEmitter.js → ReanimatedEventEmitter.ts} +0 -0
- package/src/{ReanimatedModule.js → ReanimatedModule.macos.ts} +0 -0
- package/src/{ReanimatedModule.native.js → ReanimatedModule.native.ts} +0 -0
- package/src/{ReanimatedModule.macos.js → ReanimatedModule.ts} +0 -0
- package/src/{ReanimatedModule.windows.js → ReanimatedModule.windows.ts} +0 -0
- package/src/ReanimatedModuleCompat.ts +51 -0
- package/src/{createAnimatedComponent.js → createAnimatedComponent.tsx} +285 -126
- package/src/reanimated2/NativeMethods.ts +34 -13
- package/src/reanimated2/NativeReanimated/NativeReanimated.ts +72 -0
- package/src/reanimated2/NativeReanimated/index.ts +18 -0
- package/src/reanimated2/PropAdapters.ts +0 -1
- package/src/reanimated2/UpdateProps.ts +31 -15
- package/src/reanimated2/ViewDescriptorsSet.ts +15 -12
- package/src/reanimated2/WorkletEventHandler.ts +41 -23
- package/src/reanimated2/animation/commonTypes.ts +4 -4
- package/src/reanimated2/animation/decay.ts +2 -2
- package/src/reanimated2/animation/delay.ts +11 -5
- package/src/reanimated2/animation/index.ts +7 -7
- package/src/reanimated2/animation/repeat.ts +4 -4
- package/src/reanimated2/animation/sequence.ts +2 -2
- package/src/reanimated2/animation/spring.ts +6 -5
- package/src/reanimated2/animation/styleAnimation.ts +27 -15
- package/src/reanimated2/animation/timing.ts +5 -5
- package/src/reanimated2/animation/util.ts +47 -8
- package/src/reanimated2/commonTypes.ts +3 -0
- package/src/reanimated2/core.ts +80 -34
- package/src/reanimated2/globals.d.ts +21 -1
- package/src/reanimated2/hook/useAnimatedGestureHandler.ts +1 -1
- package/src/reanimated2/hook/useAnimatedRef.ts +13 -15
- package/src/reanimated2/hook/useAnimatedScrollHandler.ts +3 -3
- package/src/reanimated2/hook/useAnimatedStyle.ts +7 -7
- package/src/reanimated2/hook/utils.ts +4 -3
- package/src/reanimated2/index.ts +1 -0
- package/src/reanimated2/interpolation.ts +170 -103
- package/src/reanimated2/js-reanimated/JSReanimated.ts +37 -23
- package/src/reanimated2/js-reanimated/Mapper.ts +22 -9
- package/src/reanimated2/js-reanimated/MapperRegistry.ts +22 -19
- package/src/reanimated2/js-reanimated/MutableValue.ts +11 -11
- package/src/reanimated2/js-reanimated/index.ts +31 -14
- package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.ts +75 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.ts +29 -159
- package/src/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.ts +169 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/Keyframe.ts +2 -2
- package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +3 -9
- package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +1 -5
- package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +162 -82
- package/src/reanimated2/layoutReanimation/defaultAnimations/Default.ts +7 -2
- package/src/reanimated2/layoutReanimation/defaultAnimations/Fade.ts +32 -32
- package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +38 -38
- package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +34 -32
- package/src/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.ts +8 -8
- package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +14 -14
- package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +26 -26
- package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +28 -28
- package/src/reanimated2/layoutReanimation/defaultAnimations/Stretch.ts +14 -14
- package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +50 -50
- 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 +1 -0
- package/src/reanimated2/mock.ts +3 -1
- package/src/reanimated2/utils.ts +21 -0
- package/src/{setAndForwardRef.js → setAndForwardRef.ts} +12 -2
- package/android/react-native-reanimated-62-hermes.aar +0 -0
- package/android/react-native-reanimated-62-jsc.aar +0 -0
- package/lib/reanimated2/NativeReanimated.js +0 -48
- package/lib/reanimated2/layoutReanimation/animationBuilder/BaseBounceAnimationBuilder.js +0 -55
- package/lib/reanimated2/layoutReanimation/animationBuilder/LayoutAnimationBuilder.js +0 -165
- package/src/ReanimatedModuleCompat.js +0 -37
- package/src/reanimated2/NativeReanimated.ts +0 -70
- package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.tsx +0 -41
- package/src/reanimated2/layoutReanimation/animationBuilder/BaseBounceAnimationBuilder.ts +0 -82
- package/src/reanimated2/layoutReanimation/animationBuilder/LayoutAnimationBuilder.ts +0 -217
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from '../core';
|
|
12
12
|
import updateProps, { updatePropsJestWrapper } from '../UpdateProps';
|
|
13
13
|
import { initialUpdaterRun, Timestamp } from '../animation';
|
|
14
|
-
import
|
|
14
|
+
import NativeReanimatedModule from '../NativeReanimated';
|
|
15
15
|
import { useSharedValue } from './useSharedValue';
|
|
16
16
|
import {
|
|
17
17
|
buildWorkletsHash,
|
|
@@ -31,14 +31,13 @@ import {
|
|
|
31
31
|
ViewRefSet,
|
|
32
32
|
} from '../ViewDescriptorsSet';
|
|
33
33
|
import { isJest, shouldBeUseWeb } from '../PlatformChecker';
|
|
34
|
-
import { AnimationObject
|
|
34
|
+
import { AnimationObject } from '../animation/commonTypes';
|
|
35
35
|
import {
|
|
36
36
|
AdapterWorkletFunction,
|
|
37
37
|
AnimatedStyle,
|
|
38
38
|
BasicWorkletFunction,
|
|
39
39
|
NestedObjectValues,
|
|
40
40
|
SharedValue,
|
|
41
|
-
WorkletFunction,
|
|
42
41
|
} from '../commonTypes';
|
|
43
42
|
export interface AnimatedStyleResult {
|
|
44
43
|
viewDescriptors: ViewDescriptorsSet;
|
|
@@ -57,6 +56,7 @@ interface AnimatedState {
|
|
|
57
56
|
interface AnimationRef {
|
|
58
57
|
initial: {
|
|
59
58
|
value: AnimatedStyle;
|
|
59
|
+
updater: () => AnimatedStyle;
|
|
60
60
|
};
|
|
61
61
|
remoteState: AnimatedState;
|
|
62
62
|
sharableViewDescriptors: SharedValue<Descriptor[]>;
|
|
@@ -122,7 +122,7 @@ function prepareAnimation(
|
|
|
122
122
|
function runAnimations(
|
|
123
123
|
animation: AnimatedStyle,
|
|
124
124
|
timestamp: Timestamp,
|
|
125
|
-
key:
|
|
125
|
+
key: number | string,
|
|
126
126
|
result: AnimatedStyle,
|
|
127
127
|
animationsActive: SharedValue<boolean>
|
|
128
128
|
): boolean {
|
|
@@ -270,7 +270,7 @@ function jestStyleUpdater(
|
|
|
270
270
|
maybeViewRef: ViewRefSet<any> | undefined,
|
|
271
271
|
animationsActive: SharedValue<boolean>,
|
|
272
272
|
animatedStyle: MutableRefObject<AnimatedStyle>,
|
|
273
|
-
adapters:
|
|
273
|
+
adapters: AdapterWorkletFunction[] = []
|
|
274
274
|
): void {
|
|
275
275
|
'worklet';
|
|
276
276
|
const animations: AnimatedStyle = state.animations ?? {};
|
|
@@ -428,6 +428,7 @@ export function useAnimatedStyle<T extends AnimatedStyle>(
|
|
|
428
428
|
initRef.current = {
|
|
429
429
|
initial: {
|
|
430
430
|
value: initialStyle,
|
|
431
|
+
updater: updater,
|
|
431
432
|
},
|
|
432
433
|
remoteState: makeRemote({ last: initialStyle }),
|
|
433
434
|
sharableViewDescriptors: makeMutable([]),
|
|
@@ -441,9 +442,8 @@ export function useAnimatedStyle<T extends AnimatedStyle>(
|
|
|
441
442
|
|
|
442
443
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
443
444
|
const { initial, remoteState, sharableViewDescriptors } = initRef.current!;
|
|
444
|
-
const maybeViewRef =
|
|
445
|
+
const maybeViewRef = NativeReanimatedModule.native ? undefined : viewsRef;
|
|
445
446
|
|
|
446
|
-
initial.value = initialUpdaterRun(updater);
|
|
447
447
|
useEffect(() => {
|
|
448
448
|
let fun;
|
|
449
449
|
let upadterFn = updater;
|
|
@@ -3,6 +3,7 @@ import { AnimationObject } from '../animation';
|
|
|
3
3
|
import { processColor } from '../Colors';
|
|
4
4
|
import {
|
|
5
5
|
AnimatedStyle,
|
|
6
|
+
NativeEvent,
|
|
6
7
|
NestedObjectValues,
|
|
7
8
|
StyleProps,
|
|
8
9
|
WorkletFunction,
|
|
@@ -31,12 +32,12 @@ export interface UseHandlerContext<TContext extends Context> {
|
|
|
31
32
|
useWeb: boolean;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
export function useEvent<T
|
|
35
|
+
export function useEvent<T extends NativeEvent<T>>(
|
|
35
36
|
handler: (event: T) => void,
|
|
36
37
|
eventNames: string[] = [],
|
|
37
38
|
rebuild = false
|
|
38
|
-
): MutableRefObject<WorkletEventHandler | null> {
|
|
39
|
-
const initRef = useRef<WorkletEventHandler | null>(null);
|
|
39
|
+
): MutableRefObject<WorkletEventHandler<T> | null> {
|
|
40
|
+
const initRef = useRef<WorkletEventHandler<T> | null>(null);
|
|
40
41
|
if (initRef.current === null) {
|
|
41
42
|
initRef.current = new WorkletEventHandler(handler, eventNames);
|
|
42
43
|
} else if (rebuild) {
|
package/src/reanimated2/index.ts
CHANGED
|
@@ -1,149 +1,216 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import interpolateNode, {
|
|
4
|
-
Extrapolate,
|
|
5
|
-
} from '../reanimated1/derived/interpolate';
|
|
1
|
+
// @ts-ignore JS file
|
|
2
|
+
import interpolateNode from '../reanimated1/derived/interpolate';
|
|
6
3
|
|
|
7
|
-
|
|
4
|
+
export enum Extrapolation {
|
|
5
|
+
IDENTITY = 'identity',
|
|
6
|
+
CLAMP = 'clamp',
|
|
7
|
+
EXTEND = 'extend',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface InterpolatedNode {
|
|
11
|
+
__nodeId: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface InterpolationNarrowedInput {
|
|
15
|
+
leftEdgeInput: number;
|
|
16
|
+
rightEdgeInput: number;
|
|
17
|
+
leftEdgeOutput: number;
|
|
18
|
+
rightEdgeOutput: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ExtrapolationConfig {
|
|
22
|
+
extrapolateLeft?: Extrapolation | string;
|
|
23
|
+
extrapolateRight?: Extrapolation | string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface RequiredExtrapolationConfig {
|
|
27
|
+
extrapolateLeft: Extrapolation;
|
|
28
|
+
extrapolateRight: Extrapolation;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type ExtrapolationType =
|
|
32
|
+
| ExtrapolationConfig
|
|
33
|
+
| Extrapolation
|
|
34
|
+
| string
|
|
35
|
+
| undefined;
|
|
36
|
+
|
|
37
|
+
function isNode(x: number | InterpolatedNode): x is InterpolatedNode {
|
|
8
38
|
'worklet';
|
|
39
|
+
return (x as InterpolatedNode).__nodeId !== undefined;
|
|
40
|
+
}
|
|
9
41
|
|
|
10
|
-
|
|
42
|
+
function getVal(
|
|
43
|
+
type: Extrapolation,
|
|
44
|
+
coef: number,
|
|
45
|
+
val: number,
|
|
46
|
+
leftEdgeOutput: number,
|
|
47
|
+
rightEdgeOutput: number,
|
|
48
|
+
x: number
|
|
49
|
+
): number {
|
|
50
|
+
'worklet';
|
|
11
51
|
|
|
12
52
|
switch (type) {
|
|
13
|
-
case
|
|
53
|
+
case Extrapolation.IDENTITY:
|
|
14
54
|
return x;
|
|
15
|
-
case
|
|
16
|
-
if (coef * val < coef *
|
|
17
|
-
return
|
|
55
|
+
case Extrapolation.CLAMP:
|
|
56
|
+
if (coef * val < coef * leftEdgeOutput) {
|
|
57
|
+
return leftEdgeOutput;
|
|
18
58
|
}
|
|
19
|
-
return
|
|
20
|
-
case
|
|
59
|
+
return rightEdgeOutput;
|
|
60
|
+
case Extrapolation.EXTEND:
|
|
21
61
|
default:
|
|
22
62
|
return val;
|
|
23
63
|
}
|
|
24
64
|
}
|
|
25
65
|
|
|
26
|
-
function isExtrapolate(value) {
|
|
66
|
+
function isExtrapolate(value: string): value is Extrapolation {
|
|
27
67
|
'worklet';
|
|
28
68
|
|
|
29
69
|
return (
|
|
30
|
-
value ===
|
|
31
|
-
value ===
|
|
32
|
-
value ===
|
|
70
|
+
value === Extrapolation.EXTEND ||
|
|
71
|
+
value === Extrapolation.CLAMP ||
|
|
72
|
+
value === Extrapolation.IDENTITY
|
|
33
73
|
);
|
|
34
74
|
}
|
|
35
75
|
|
|
36
|
-
|
|
76
|
+
// validates extrapolations type
|
|
77
|
+
// if type is correct, converts it to ExtrapolationConfig
|
|
78
|
+
function validateType(type: ExtrapolationType): RequiredExtrapolationConfig {
|
|
37
79
|
'worklet';
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
extrapolate
|
|
47
|
-
) => `Reanimated: not supported value for "${extrapolate}" \nSupported values: ["extend", "clamp", "identity"]\n Valid example:
|
|
48
|
-
interpolate(value, [inputRange], [outputRange], {
|
|
49
|
-
${extrapolate}: 'clamp',
|
|
50
|
-
})`;
|
|
51
|
-
|
|
52
|
-
type = type ?? 'extend';
|
|
53
|
-
|
|
54
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
55
|
-
const hasExtrapolateLeft = type.hasOwnProperty('extrapolateLeft');
|
|
56
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
57
|
-
const hasExtrapolateRight = type.hasOwnProperty('extrapolateRight');
|
|
58
|
-
|
|
59
|
-
if (
|
|
60
|
-
typeof type === 'object' &&
|
|
61
|
-
((Object.keys(type).length === 2 &&
|
|
62
|
-
!(hasExtrapolateLeft && hasExtrapolateRight)) ||
|
|
63
|
-
(Object.keys(type).length === 1 &&
|
|
64
|
-
!(hasExtrapolateLeft || hasExtrapolateRight)) ||
|
|
65
|
-
Object.keys(type).length > 2)
|
|
66
|
-
) {
|
|
67
|
-
throw new Error(EXTRAPOLATE_ERROR_MSG);
|
|
80
|
+
// initialize extrapolationConfig with default extrapolation
|
|
81
|
+
const extrapolationConfig: RequiredExtrapolationConfig = {
|
|
82
|
+
extrapolateLeft: Extrapolation.EXTEND,
|
|
83
|
+
extrapolateRight: Extrapolation.EXTEND,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
if (!type) {
|
|
87
|
+
return extrapolationConfig;
|
|
68
88
|
}
|
|
69
89
|
|
|
70
|
-
if (typeof type === '
|
|
71
|
-
if (
|
|
72
|
-
throw new Error(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
throw new Error(EXTRAPOLATE_ERROR('extrapolateRight'));
|
|
90
|
+
if (typeof type === 'string') {
|
|
91
|
+
if (!isExtrapolate(type)) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
`Reanimated: not supported value for "interpolate" \nSupported values: ["extend", "clamp", "identity", Extrapolatation.CLAMP, Extrapolatation.EXTEND, Extrapolatation.IDENTITY]\n Valid example:
|
|
94
|
+
interpolate(value, [inputRange], [outputRange], "clamp")`
|
|
95
|
+
);
|
|
77
96
|
}
|
|
97
|
+
extrapolationConfig.extrapolateLeft = type;
|
|
98
|
+
extrapolationConfig.extrapolateRight = type;
|
|
99
|
+
return extrapolationConfig;
|
|
78
100
|
}
|
|
79
101
|
|
|
80
|
-
|
|
102
|
+
// otherwise type is extrapolation config object
|
|
103
|
+
if (
|
|
104
|
+
(type.extrapolateLeft && !isExtrapolate(type.extrapolateLeft)) ||
|
|
105
|
+
(type.extrapolateRight && !isExtrapolate(type.extrapolateRight))
|
|
106
|
+
) {
|
|
81
107
|
throw new Error(
|
|
82
|
-
`Reanimated: not supported value for "interpolate" \nSupported values: ["extend", "clamp", "identity"]\n Valid example:
|
|
83
|
-
|
|
108
|
+
`Reanimated: not supported value for "interpolate" \nSupported values: ["extend", "clamp", "identity", Extrapolatation.CLAMP, Extrapolatation.EXTEND, Extrapolatation.IDENTITY]\n Valid example:
|
|
109
|
+
interpolate(value, [inputRange], [outputRange], {
|
|
110
|
+
extrapolateLeft: Extrapolation.CLAMP,
|
|
111
|
+
extrapolateRight: Extrapolation.IDENTITY
|
|
112
|
+
}})`
|
|
84
113
|
);
|
|
85
114
|
}
|
|
115
|
+
|
|
116
|
+
Object.assign(extrapolationConfig, type);
|
|
117
|
+
return extrapolationConfig;
|
|
86
118
|
}
|
|
87
119
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
120
|
+
function internalInterpolate(
|
|
121
|
+
x: number,
|
|
122
|
+
narrowedInput: InterpolationNarrowedInput,
|
|
123
|
+
extrapolationConfig: RequiredExtrapolationConfig
|
|
124
|
+
) {
|
|
91
125
|
'worklet';
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
126
|
+
const {
|
|
127
|
+
leftEdgeInput,
|
|
128
|
+
rightEdgeInput,
|
|
129
|
+
leftEdgeOutput,
|
|
130
|
+
rightEdgeOutput,
|
|
131
|
+
} = narrowedInput;
|
|
132
|
+
if (rightEdgeInput - leftEdgeInput === 0) return leftEdgeOutput;
|
|
133
|
+
const progress = (x - leftEdgeInput) / (rightEdgeInput - leftEdgeInput);
|
|
134
|
+
const val = leftEdgeOutput + progress * (rightEdgeOutput - leftEdgeOutput);
|
|
135
|
+
const coef = rightEdgeOutput >= leftEdgeOutput ? 1 : -1;
|
|
136
|
+
|
|
137
|
+
if (coef * val < coef * leftEdgeOutput) {
|
|
138
|
+
return getVal(
|
|
139
|
+
extrapolationConfig.extrapolateLeft,
|
|
140
|
+
coef,
|
|
141
|
+
val,
|
|
142
|
+
leftEdgeOutput,
|
|
143
|
+
rightEdgeOutput,
|
|
144
|
+
x
|
|
145
|
+
);
|
|
146
|
+
} else if (coef * val > coef * rightEdgeOutput) {
|
|
147
|
+
return getVal(
|
|
148
|
+
extrapolationConfig.extrapolateRight,
|
|
149
|
+
coef,
|
|
150
|
+
val,
|
|
151
|
+
leftEdgeOutput,
|
|
152
|
+
rightEdgeOutput,
|
|
153
|
+
x
|
|
154
|
+
);
|
|
113
155
|
}
|
|
114
156
|
|
|
115
157
|
return val;
|
|
116
158
|
}
|
|
117
159
|
|
|
118
|
-
|
|
160
|
+
// TODO: support default values in worklets:
|
|
161
|
+
// e.g. function interpolate(x, input, output, type = Extrapolatation.CLAMP)
|
|
162
|
+
export function interpolate(
|
|
163
|
+
x: number | InterpolatedNode,
|
|
164
|
+
input: readonly number[],
|
|
165
|
+
output: readonly number[],
|
|
166
|
+
type?: ExtrapolationType
|
|
167
|
+
): number {
|
|
119
168
|
'worklet';
|
|
120
|
-
if (
|
|
169
|
+
if (input.length < 2 || output.length < 2) {
|
|
170
|
+
throw Error(
|
|
171
|
+
'Interpolation input and output should contain at least two values.'
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const extrapolationConfig = validateType(type);
|
|
176
|
+
|
|
177
|
+
if (isNode(x)) {
|
|
121
178
|
console.warn(
|
|
122
179
|
`interpolate() was renamed to interpolateNode() in Reanimated 2. Please use interpolateNode() instead`
|
|
123
180
|
);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
181
|
+
return interpolateNode(x, {
|
|
182
|
+
inputRange: input,
|
|
183
|
+
outputRange: output,
|
|
184
|
+
extrapolateLeft: extrapolationConfig.extrapolateLeft,
|
|
185
|
+
extrapolateRight: extrapolationConfig.extrapolateRight,
|
|
186
|
+
});
|
|
127
187
|
}
|
|
128
188
|
|
|
129
189
|
const length = input.length;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
190
|
+
const narrowedInput: InterpolationNarrowedInput = {
|
|
191
|
+
leftEdgeInput: input[0],
|
|
192
|
+
rightEdgeInput: input[1],
|
|
193
|
+
leftEdgeOutput: output[0],
|
|
194
|
+
rightEdgeOutput: output[1],
|
|
195
|
+
};
|
|
196
|
+
if (length > 2) {
|
|
197
|
+
if (x > input[length - 1]) {
|
|
198
|
+
narrowedInput.leftEdgeInput = input[length - 2];
|
|
199
|
+
narrowedInput.rightEdgeInput = input[length - 1];
|
|
200
|
+
narrowedInput.leftEdgeOutput = output[length - 2];
|
|
201
|
+
narrowedInput.rightEdgeOutput = output[length - 1];
|
|
202
|
+
} else {
|
|
203
|
+
for (let i = 1; i < length; ++i) {
|
|
204
|
+
if (x <= input[i]) {
|
|
205
|
+
narrowedInput.leftEdgeInput = input[i - 1];
|
|
206
|
+
narrowedInput.rightEdgeInput = input[i];
|
|
207
|
+
narrowedInput.leftEdgeOutput = output[i - 1];
|
|
208
|
+
narrowedInput.rightEdgeOutput = output[i];
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
145
211
|
}
|
|
146
212
|
}
|
|
147
213
|
}
|
|
148
|
-
|
|
214
|
+
|
|
215
|
+
return internalInterpolate(x, narrowedInput, extrapolationConfig);
|
|
149
216
|
}
|
|
@@ -1,35 +1,37 @@
|
|
|
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';
|
|
4
|
+
import { NativeReanimated } from '../NativeReanimated/NativeReanimated';
|
|
5
|
+
import { Timestamp } from '../animation/commonTypes';
|
|
6
|
+
import { NestedObjectValues } from '../commonTypes';
|
|
7
|
+
|
|
8
|
+
export default class JSReanimated extends NativeReanimated {
|
|
9
|
+
_valueSetter?: <T>(value: T) => void = undefined;
|
|
6
10
|
|
|
7
|
-
export default class JSReanimated {
|
|
8
|
-
native = false;
|
|
9
|
-
_valueSetter = undefined;
|
|
10
11
|
_renderRequested = false;
|
|
11
12
|
_mapperRegistry = new MapperRegistry(this);
|
|
12
|
-
_frames = [];
|
|
13
|
-
timeProvider
|
|
13
|
+
_frames: ((timestamp: Timestamp) => void)[] = [];
|
|
14
|
+
timeProvider: { now: () => number };
|
|
14
15
|
|
|
15
16
|
constructor() {
|
|
17
|
+
super(false);
|
|
16
18
|
if (process.env.JEST_WORKER_ID) {
|
|
17
|
-
this.timeProvider
|
|
19
|
+
this.timeProvider = { now: () => Date.now() };
|
|
18
20
|
} else {
|
|
19
|
-
this.timeProvider
|
|
21
|
+
this.timeProvider = { now: () => window.performance.now() };
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
pushFrame(frame) {
|
|
25
|
+
pushFrame(frame: (timestamp: Timestamp) => void): void {
|
|
24
26
|
this._frames.push(frame);
|
|
25
27
|
this.maybeRequestRender();
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
getTimestamp() {
|
|
30
|
+
getTimestamp(): number {
|
|
29
31
|
return this.timeProvider.now();
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
maybeRequestRender() {
|
|
34
|
+
maybeRequestRender(): void {
|
|
33
35
|
if (!this._renderRequested) {
|
|
34
36
|
this._renderRequested = true;
|
|
35
37
|
|
|
@@ -41,7 +43,7 @@ export default class JSReanimated {
|
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
_onRender(timestampMs) {
|
|
46
|
+
_onRender(timestampMs: number): void {
|
|
45
47
|
this._mapperRegistry.execute();
|
|
46
48
|
|
|
47
49
|
const frames = [...this._frames];
|
|
@@ -56,38 +58,50 @@ export default class JSReanimated {
|
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
installCoreFunctions(valueSetter) {
|
|
61
|
+
installCoreFunctions(valueSetter: <T>(value: T) => void): void {
|
|
60
62
|
this._valueSetter = valueSetter;
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
makeShareable(value) {
|
|
65
|
+
makeShareable<T>(value: T): T {
|
|
64
66
|
return value;
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
makeMutable(value) {
|
|
68
|
-
|
|
69
|
+
makeMutable<T>(value: T): MutableValue<T> {
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
71
|
+
return new MutableValue(value, this._valueSetter!);
|
|
69
72
|
}
|
|
70
73
|
|
|
71
|
-
makeRemote(object) {
|
|
72
|
-
return object;
|
|
74
|
+
makeRemote<T>(object = {}): T {
|
|
75
|
+
return object as T;
|
|
73
76
|
}
|
|
74
77
|
|
|
75
|
-
startMapper(
|
|
78
|
+
startMapper(
|
|
79
|
+
mapper: () => void,
|
|
80
|
+
inputs: NestedObjectValues<MutableValue<unknown>>[] = [],
|
|
81
|
+
outputs: NestedObjectValues<MutableValue<unknown>>[] = []
|
|
82
|
+
): number {
|
|
76
83
|
const instance = new Mapper(this, mapper, inputs, outputs);
|
|
77
84
|
const mapperId = this._mapperRegistry.startMapper(instance);
|
|
78
85
|
this.maybeRequestRender();
|
|
79
86
|
return mapperId;
|
|
80
87
|
}
|
|
81
88
|
|
|
82
|
-
stopMapper(mapperId) {
|
|
89
|
+
stopMapper(mapperId: number): void {
|
|
83
90
|
this._mapperRegistry.stopMapper(mapperId);
|
|
84
91
|
}
|
|
85
92
|
|
|
86
|
-
registerEventHandler(
|
|
93
|
+
registerEventHandler<T>(_: string, __: (event: T) => void): string {
|
|
87
94
|
// noop
|
|
95
|
+
return '';
|
|
88
96
|
}
|
|
89
97
|
|
|
90
|
-
unregisterEventHandler(
|
|
98
|
+
unregisterEventHandler(_: string): void {
|
|
91
99
|
// noop
|
|
92
100
|
}
|
|
101
|
+
|
|
102
|
+
enableLayoutAnimations() {
|
|
103
|
+
console.warn(
|
|
104
|
+
'[Reanimated] enableLayoutAnimations is not available for WEB yet'
|
|
105
|
+
);
|
|
106
|
+
}
|
|
93
107
|
}
|
|
@@ -1,13 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { NestedObjectValues } from '../commonTypes';
|
|
2
|
+
import JSReanimated from './JSReanimated';
|
|
3
3
|
import MutableValue from './MutableValue';
|
|
4
4
|
|
|
5
|
-
export default class Mapper {
|
|
5
|
+
export default class Mapper<T> {
|
|
6
6
|
static MAPPER_ID = 1;
|
|
7
|
+
id: number;
|
|
8
|
+
inputs: MutableValue<T>[];
|
|
9
|
+
outputs: MutableValue<T>[];
|
|
10
|
+
mapper: () => void;
|
|
7
11
|
|
|
8
12
|
dirty = true;
|
|
9
13
|
|
|
10
|
-
constructor(
|
|
14
|
+
constructor(
|
|
15
|
+
module: JSReanimated,
|
|
16
|
+
mapper: () => void,
|
|
17
|
+
inputs: NestedObjectValues<MutableValue<T>>[] = [],
|
|
18
|
+
outputs: NestedObjectValues<MutableValue<T>>[] = []
|
|
19
|
+
) {
|
|
11
20
|
this.id = Mapper.MAPPER_ID++;
|
|
12
21
|
this.inputs = this.extractMutablesFromArray(inputs);
|
|
13
22
|
this.outputs = this.extractMutablesFromArray(outputs);
|
|
@@ -23,16 +32,20 @@ export default class Mapper {
|
|
|
23
32
|
});
|
|
24
33
|
}
|
|
25
34
|
|
|
26
|
-
execute() {
|
|
35
|
+
execute(): void {
|
|
27
36
|
this.dirty = false;
|
|
28
37
|
this.mapper();
|
|
29
38
|
}
|
|
30
39
|
|
|
31
|
-
extractMutablesFromArray(
|
|
32
|
-
|
|
40
|
+
extractMutablesFromArray<T>(
|
|
41
|
+
array: NestedObjectValues<MutableValue<T>>
|
|
42
|
+
): MutableValue<T>[] {
|
|
43
|
+
const res: MutableValue<T>[] = [];
|
|
33
44
|
|
|
34
|
-
function extractMutables(value) {
|
|
35
|
-
if (value
|
|
45
|
+
function extractMutables(value: NestedObjectValues<MutableValue<T>>) {
|
|
46
|
+
if (value == null) {
|
|
47
|
+
// return;
|
|
48
|
+
} else if (value instanceof MutableValue) {
|
|
36
49
|
res.push(value);
|
|
37
50
|
} else if (Array.isArray(value)) {
|
|
38
51
|
value.forEach((v) => extractMutables(v));
|