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
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { withSequence, withTiming } from '../../animation';
|
|
2
|
+
import { BaseAnimationBuilder } from '../animationBuilder';
|
|
3
|
+
export class SequencedTransition extends BaseAnimationBuilder {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.reversed = false;
|
|
7
|
+
this.build = () => {
|
|
8
|
+
var _a;
|
|
9
|
+
const delayFunction = this.getDelayFunction();
|
|
10
|
+
const callback = this.callbackV;
|
|
11
|
+
const delay = this.getDelay();
|
|
12
|
+
const sequenceDuration = ((_a = this.durationV) !== null && _a !== void 0 ? _a : 500) / 2;
|
|
13
|
+
const config = { duration: sequenceDuration };
|
|
14
|
+
const reverse = this.reversed;
|
|
15
|
+
return (values) => {
|
|
16
|
+
'worklet';
|
|
17
|
+
return {
|
|
18
|
+
initialValues: {
|
|
19
|
+
originX: values.boriginX,
|
|
20
|
+
originY: values.boriginY,
|
|
21
|
+
width: values.bwidth,
|
|
22
|
+
height: values.bheight,
|
|
23
|
+
},
|
|
24
|
+
animations: {
|
|
25
|
+
originX: delayFunction(delay, withSequence(withTiming(reverse ? values.boriginX : values.originX, config), withTiming(values.originX, config))),
|
|
26
|
+
originY: delayFunction(delay, withSequence(withTiming(reverse ? values.originY : values.boriginY, config), withTiming(values.originY, config))),
|
|
27
|
+
width: delayFunction(delay, withSequence(withTiming(reverse ? values.bwidth : values.width, config), withTiming(values.width, config))),
|
|
28
|
+
height: delayFunction(delay, withSequence(withTiming(reverse ? values.height : values.bheight, config), withTiming(values.height, config))),
|
|
29
|
+
},
|
|
30
|
+
callback: callback,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
static createInstance() {
|
|
36
|
+
return new SequencedTransition();
|
|
37
|
+
}
|
|
38
|
+
static reverse() {
|
|
39
|
+
const instance = SequencedTransition.createInstance();
|
|
40
|
+
return instance.reverse();
|
|
41
|
+
}
|
|
42
|
+
reverse() {
|
|
43
|
+
this.reversed = !this.reversed;
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
}
|
package/lib/reanimated2/mock.js
CHANGED
|
@@ -6,14 +6,16 @@ const NOOP = () => {
|
|
|
6
6
|
// noop
|
|
7
7
|
};
|
|
8
8
|
const ID = (t) => t;
|
|
9
|
+
const IMMEDIATE_CB_INVOCATION = (cb) => cb();
|
|
9
10
|
const ReanimatedV2 = {
|
|
10
11
|
useSharedValue: (v) => ({ value: v }),
|
|
11
12
|
useDerivedValue: (a) => ({ value: a() }),
|
|
12
13
|
useAnimatedScrollHandler: () => NOOP,
|
|
13
14
|
useAnimatedGestureHandler: () => NOOP,
|
|
14
|
-
useAnimatedStyle:
|
|
15
|
+
useAnimatedStyle: IMMEDIATE_CB_INVOCATION,
|
|
15
16
|
useAnimatedRef: () => ({ current: null }),
|
|
16
17
|
useAnimatedReaction: NOOP,
|
|
18
|
+
useAnimatedProps: IMMEDIATE_CB_INVOCATION,
|
|
17
19
|
withTiming: (toValue, _, cb) => {
|
|
18
20
|
cb && cb(true);
|
|
19
21
|
return toValue;
|
package/lib/setAndForwardRef.js
CHANGED
|
@@ -1,53 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* imported from react-native
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* getForwardedRef: () => this.props.forwardedRef,
|
|
19
|
-
* setLocalRef: ref => {
|
|
20
|
-
* this._nativeRef = ref;
|
|
21
|
-
* },
|
|
22
|
-
* });
|
|
23
|
-
*
|
|
24
|
-
* render() {
|
|
25
|
-
* return <View ref={this._setNativeRef} />;
|
|
26
|
-
* }
|
|
27
|
-
* }
|
|
28
|
-
*
|
|
29
|
-
* const MyViewWithRef = React.forwardRef((props, ref) => (
|
|
30
|
-
* <MyView {...props} forwardedRef={ref} />
|
|
31
|
-
* ));
|
|
32
|
-
*
|
|
33
|
-
* module.exports = MyViewWithRef;
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
function setAndForwardRef({ getForwardedRef, setLocalRef }) {
|
|
37
|
-
return function forwardRef(ref) {
|
|
38
|
-
const forwardedRef = getForwardedRef();
|
|
39
|
-
|
|
40
|
-
setLocalRef(ref);
|
|
41
|
-
|
|
42
|
-
// Forward to user ref prop (if one has been specified)
|
|
43
|
-
if (typeof forwardedRef === 'function') {
|
|
44
|
-
// Handle function-based refs. String-based refs are handled as functions.
|
|
45
|
-
forwardedRef(ref);
|
|
46
|
-
} else if (typeof forwardedRef === 'object' && forwardedRef != null) {
|
|
47
|
-
// Handle createRef-based refs
|
|
48
|
-
forwardedRef.current = ref;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
4
|
+
function setAndForwardRef({ getForwardedRef, setLocalRef, }) {
|
|
5
|
+
return function forwardRef(ref) {
|
|
6
|
+
const forwardedRef = getForwardedRef();
|
|
7
|
+
setLocalRef(ref);
|
|
8
|
+
// Forward to user ref prop (if one has been specified)
|
|
9
|
+
if (typeof forwardedRef === 'function') {
|
|
10
|
+
// Handle function-based refs. String-based refs are handled as functions.
|
|
11
|
+
forwardedRef(ref);
|
|
12
|
+
}
|
|
13
|
+
else if (typeof forwardedRef === 'object' && forwardedRef != null) {
|
|
14
|
+
// Handle createRef-based refs
|
|
15
|
+
forwardedRef.current = ref;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
51
18
|
}
|
|
52
|
-
|
|
53
19
|
export default setAndForwardRef;
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/mock.js
CHANGED
package/package.json
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-reanimated",
|
|
3
|
-
"version": "2.3.0-
|
|
3
|
+
"version": "2.3.0-beta.4",
|
|
4
4
|
"description": "More powerful alternative to Animated library for React Native.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"start": "node node_modules/react-native/local-cli/cli.js start",
|
|
7
|
-
"test": "yarn run format && yarn run lint
|
|
7
|
+
"test": "yarn run format:js && yarn run lint:js && yarn run test:unit",
|
|
8
8
|
"test:unit": "jest",
|
|
9
|
-
"
|
|
10
|
-
"lint
|
|
11
|
-
"lint
|
|
9
|
+
"lint": "yarn lint:js && yarn lint:cpp && yarn lint:java",
|
|
10
|
+
"lint:js": "eslint --ext '.js,.ts,.tsx' src/ && yarn prettier --check src/",
|
|
11
|
+
"lint:java": "./android/gradlew -p android spotlessCheck -q",
|
|
12
|
+
"lint:cpp": "./scripts/cpplint.sh",
|
|
13
|
+
"format": "yarn format:js && yarn format:java && yarn format:ios && yarn format:android && yarn format:common",
|
|
14
|
+
"format:js": "prettier --write --list-different './src/'",
|
|
15
|
+
"format:java": "node ./scripts/format-java.js",
|
|
16
|
+
"format:ios": "find ios/ -iname *.h -o -iname *.m -o -iname *.mm -o -iname *.cpp | xargs clang-format -i",
|
|
17
|
+
"format:android": "find android/src/ -iname *.h -o -iname *.cpp | xargs clang-format -i",
|
|
18
|
+
"format:common": "find Common/ -iname *.h -o -iname *.cpp | xargs clang-format -i",
|
|
12
19
|
"release": "npm login && release-it",
|
|
13
20
|
"type:check": "yarn tsc --noEmit",
|
|
14
21
|
"type:generate": "yarn type:generate:clean && yarn type:generate:cp-js-src && yarn type:generate:tsc && yarn type:generate:remove.ts && yarn type:generate:remove.tsx",
|
|
@@ -16,7 +23,8 @@
|
|
|
16
23
|
"type:generate:cp-js-src": "cp -RL src/ lib/",
|
|
17
24
|
"type:generate:tsc": "yarn tsc",
|
|
18
25
|
"type:generate:remove.ts": "find ./lib -type f -name \"*.ts\" -and -not -name \"*.d.ts\" -delete",
|
|
19
|
-
"type:generate:remove.tsx": "find ./lib -type f -name \"*.tsx\" -and -not -name \"*.d.ts\" -delete"
|
|
26
|
+
"type:generate:remove.tsx": "find ./lib -type f -name \"*.tsx\" -and -not -name \"*.d.ts\" -delete",
|
|
27
|
+
"prepare": "husky install"
|
|
20
28
|
},
|
|
21
29
|
"main": "lib/Animated.js",
|
|
22
30
|
"module": "lib/Animated",
|
|
@@ -27,6 +35,7 @@
|
|
|
27
35
|
"Common/",
|
|
28
36
|
"src/",
|
|
29
37
|
"lib/",
|
|
38
|
+
"libSo/",
|
|
30
39
|
"android/src/main/AndroidManifest.xml",
|
|
31
40
|
"android/src/main/java/",
|
|
32
41
|
"android/build.gradle",
|
|
@@ -59,6 +68,7 @@
|
|
|
59
68
|
"homepage": "https://github.com/software-mansion/react-native-reanimated#readme",
|
|
60
69
|
"dependencies": {
|
|
61
70
|
"@babel/plugin-transform-object-assign": "^7.10.4",
|
|
71
|
+
"@types/invariant": "^2.2.35",
|
|
62
72
|
"invariant": "^2.2.4",
|
|
63
73
|
"lodash.isequal": "^4.5.0",
|
|
64
74
|
"mockdate": "^3.0.2",
|
|
@@ -85,12 +95,13 @@
|
|
|
85
95
|
"@types/babel__generator": "^7.6.2",
|
|
86
96
|
"@types/babel__traverse": "^7.0.15",
|
|
87
97
|
"@types/jest": "^26.0.15",
|
|
88
|
-
"@types/react-native": "^0.
|
|
98
|
+
"@types/react-native": "^0.65.1",
|
|
89
99
|
"@typescript-eslint/eslint-plugin": "^4.15.1",
|
|
90
100
|
"@typescript-eslint/parser": "^4.15.1",
|
|
91
101
|
"babel-eslint": "^10.0.3",
|
|
92
102
|
"babel-jest": "^26.6.3",
|
|
93
103
|
"babel-plugin-module-resolver": "^4.1.0",
|
|
104
|
+
"clang-format": "^1.5.0",
|
|
94
105
|
"eslint": "^7.31.0",
|
|
95
106
|
"eslint-config-prettier": "^6.4.0",
|
|
96
107
|
"eslint-config-standard": "^14.1.0",
|
|
@@ -99,28 +110,28 @@
|
|
|
99
110
|
"eslint-plugin-node": "^10.0.0",
|
|
100
111
|
"eslint-plugin-promise": "^4.2.1",
|
|
101
112
|
"eslint-plugin-standard": "^4.0.1",
|
|
102
|
-
"husky": "^
|
|
113
|
+
"husky": "^7.0.0",
|
|
103
114
|
"jest": "^26.6.3",
|
|
104
|
-
"lint-staged": "^
|
|
115
|
+
"lint-staged": "^11.2.0",
|
|
105
116
|
"prettier": "^2.2.1",
|
|
106
117
|
"react": "17.0.2",
|
|
107
|
-
"react-native": "0.
|
|
118
|
+
"react-native": "0.67.0-rc.3",
|
|
108
119
|
"react-native-codegen": "^0.0.7",
|
|
109
120
|
"react-native-gesture-handler": "^1.6.1",
|
|
110
121
|
"react-test-renderer": "17.0.2",
|
|
111
|
-
"release-it": "^13.
|
|
122
|
+
"release-it": "^13.7.2",
|
|
112
123
|
"typescript": "^4.1.3"
|
|
113
124
|
},
|
|
114
125
|
"lint-staged": {
|
|
115
126
|
"*.(js|ts|tsx)": [
|
|
116
127
|
"eslint --ext '.js,.ts,.tsx' src/ --ignore-pattern src/reanimated1 --ignore-pattern react-native-reanimated.d.ts",
|
|
117
128
|
"prettier --write"
|
|
118
|
-
]
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
"
|
|
122
|
-
|
|
123
|
-
}
|
|
129
|
+
],
|
|
130
|
+
"**/*.{h,cpp}": "yarn lint:cpp",
|
|
131
|
+
"android/src/**/*.java": "yarn format:java",
|
|
132
|
+
"android/src/**/*.{h,cpp}": "yarn format:android",
|
|
133
|
+
"ios/**/*.{h,m,mm,cpp}": "yarn format:ios",
|
|
134
|
+
"Common/**/*.{h,cpp}": "yarn format:common"
|
|
124
135
|
},
|
|
125
136
|
"release-it": {
|
|
126
137
|
"hooks": {
|
package/plugin.js
CHANGED
|
@@ -69,6 +69,7 @@ const globals = new Set([
|
|
|
69
69
|
'global',
|
|
70
70
|
'_measure',
|
|
71
71
|
'_scrollTo',
|
|
72
|
+
'_setGestureState',
|
|
72
73
|
'_getCurrentTime',
|
|
73
74
|
'_eventTimestamp',
|
|
74
75
|
'_frameTimestamp',
|
|
@@ -135,6 +136,33 @@ const blacklistedFunctions = new Set([
|
|
|
135
136
|
|
|
136
137
|
const possibleOptFunction = new Set(['interpolate']);
|
|
137
138
|
|
|
139
|
+
const gestureHandlerGestureObjects = new Set([
|
|
140
|
+
// from https://github.com/software-mansion/react-native-gesture-handler/blob/new-api/src/handlers/gestures/gestureObjects.ts
|
|
141
|
+
'Tap',
|
|
142
|
+
'Pan',
|
|
143
|
+
'Pinch',
|
|
144
|
+
'Rotation',
|
|
145
|
+
'Fling',
|
|
146
|
+
'LongPress',
|
|
147
|
+
'ForceTouch',
|
|
148
|
+
'Native',
|
|
149
|
+
'Custom',
|
|
150
|
+
'Race',
|
|
151
|
+
'Simultaneous',
|
|
152
|
+
'Exclusive',
|
|
153
|
+
]);
|
|
154
|
+
|
|
155
|
+
const gestureHandlerBuilderMethods = new Set([
|
|
156
|
+
'onBegin',
|
|
157
|
+
'onStart',
|
|
158
|
+
'onEnd',
|
|
159
|
+
'onUpdate',
|
|
160
|
+
'onTouchesDown',
|
|
161
|
+
'onTouchesMove',
|
|
162
|
+
'onTouchesUp',
|
|
163
|
+
'onTouchesCancelled',
|
|
164
|
+
]);
|
|
165
|
+
|
|
138
166
|
class ClosureGenerator {
|
|
139
167
|
constructor() {
|
|
140
168
|
this.trie = [{}, false];
|
|
@@ -285,20 +313,45 @@ function buildWorkletString(t, fun, closureVariables, name) {
|
|
|
285
313
|
return generate(workletFunction, { compact: true }).code;
|
|
286
314
|
}
|
|
287
315
|
|
|
288
|
-
function
|
|
289
|
-
if (
|
|
290
|
-
return;
|
|
316
|
+
function makeWorkletName(t, fun) {
|
|
317
|
+
if (t.isObjectMethod(fun)) {
|
|
318
|
+
return fun.node.key.name;
|
|
319
|
+
}
|
|
320
|
+
if (t.isFunctionDeclaration(fun)) {
|
|
321
|
+
return fun.node.id.name;
|
|
322
|
+
}
|
|
323
|
+
if (t.isFunctionExpression(fun) && t.isIdentifier(fun.node.id)) {
|
|
324
|
+
return fun.node.id.name;
|
|
291
325
|
}
|
|
292
|
-
|
|
326
|
+
return '_f'; // fallback for ArrowFunctionExpression and unnamed FunctionExpression
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function makeWorklet(t, fun, fileName) {
|
|
330
|
+
// Returns a new FunctionExpression which is a workletized version of provided
|
|
331
|
+
// FunctionDeclaration, FunctionExpression, ArrowFunctionExpression or ObjectMethod.
|
|
332
|
+
|
|
333
|
+
const functionName = makeWorkletName(t, fun);
|
|
293
334
|
|
|
294
335
|
const closure = new Map();
|
|
295
336
|
const outputs = new Set();
|
|
296
337
|
const closureGenerator = new ClosureGenerator();
|
|
297
338
|
const options = {};
|
|
298
339
|
|
|
340
|
+
// remove 'worklet'; directive before calling .toString()
|
|
341
|
+
fun.traverse({
|
|
342
|
+
DirectiveLiteral(path) {
|
|
343
|
+
if (path.node.value === 'worklet' && path.getFunctionParent() === fun) {
|
|
344
|
+
path.parentPath.remove();
|
|
345
|
+
}
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
|
|
299
349
|
// We use copy because some of the plugins don't update bindings and
|
|
300
350
|
// some even break them
|
|
301
|
-
|
|
351
|
+
|
|
352
|
+
const code =
|
|
353
|
+
'\n(' + (t.isObjectMethod(fun) ? 'function ' : '') + fun.toString() + '\n)';
|
|
354
|
+
|
|
302
355
|
const transformed = transformSync(code, {
|
|
303
356
|
filename: fileName,
|
|
304
357
|
presets: ['@babel/preset-typescript'],
|
|
@@ -357,7 +410,7 @@ function processWorkletFunction(t, fun, fileName) {
|
|
|
357
410
|
closureGenerator.addPath(name, path);
|
|
358
411
|
},
|
|
359
412
|
AssignmentExpression(path) {
|
|
360
|
-
// test for <
|
|
413
|
+
// test for <something>.value = <something> expressions
|
|
361
414
|
const left = path.node.left;
|
|
362
415
|
if (
|
|
363
416
|
t.isMemberExpression(left) &&
|
|
@@ -369,13 +422,6 @@ function processWorkletFunction(t, fun, fileName) {
|
|
|
369
422
|
},
|
|
370
423
|
});
|
|
371
424
|
|
|
372
|
-
fun.traverse({
|
|
373
|
-
DirectiveLiteral(path) {
|
|
374
|
-
if (path.node.value === 'worklet' && path.getFunctionParent() === fun) {
|
|
375
|
-
path.parentPath.remove();
|
|
376
|
-
}
|
|
377
|
-
},
|
|
378
|
-
});
|
|
379
425
|
const variables = Array.from(closure.values());
|
|
380
426
|
|
|
381
427
|
const privateFunctionId = t.identifier('_f');
|
|
@@ -391,7 +437,7 @@ function processWorkletFunction(t, fun, fileName) {
|
|
|
391
437
|
transformed.ast,
|
|
392
438
|
variables,
|
|
393
439
|
functionName
|
|
394
|
-
)
|
|
440
|
+
);
|
|
395
441
|
const workletHash = hash(funString);
|
|
396
442
|
|
|
397
443
|
const loc = fun && fun.node && fun.node.loc && fun.node.loc.start;
|
|
@@ -402,7 +448,7 @@ function processWorkletFunction(t, fun, fileName) {
|
|
|
402
448
|
}
|
|
403
449
|
}
|
|
404
450
|
|
|
405
|
-
const
|
|
451
|
+
const statements = [
|
|
406
452
|
t.variableDeclaration('const', [
|
|
407
453
|
t.variableDeclarator(privateFunctionId, funExpression),
|
|
408
454
|
]),
|
|
@@ -445,7 +491,7 @@ function processWorkletFunction(t, fun, fileName) {
|
|
|
445
491
|
];
|
|
446
492
|
|
|
447
493
|
if (options && options.optFlags) {
|
|
448
|
-
|
|
494
|
+
statements.push(
|
|
449
495
|
t.expressionStatement(
|
|
450
496
|
t.assignmentExpression(
|
|
451
497
|
'=',
|
|
@@ -460,7 +506,7 @@ function processWorkletFunction(t, fun, fileName) {
|
|
|
460
506
|
);
|
|
461
507
|
}
|
|
462
508
|
|
|
463
|
-
|
|
509
|
+
statements.push(
|
|
464
510
|
t.expressionStatement(
|
|
465
511
|
t.callExpression(
|
|
466
512
|
t.memberExpression(
|
|
@@ -472,20 +518,30 @@ function processWorkletFunction(t, fun, fileName) {
|
|
|
472
518
|
)
|
|
473
519
|
)
|
|
474
520
|
);
|
|
475
|
-
|
|
521
|
+
statements.push(t.returnStatement(privateFunctionId));
|
|
476
522
|
|
|
477
|
-
const newFun = t.functionExpression(
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
523
|
+
const newFun = t.functionExpression(fun.id, [], t.blockStatement(statements));
|
|
524
|
+
|
|
525
|
+
return newFun;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
function processWorkletFunction(t, fun, fileName) {
|
|
529
|
+
// Replaces FunctionDeclaration, FunctionExpression or ArrowFunctionExpression
|
|
530
|
+
// with a workletized version of itself.
|
|
531
|
+
|
|
532
|
+
if (!t.isFunctionParent(fun)) {
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
const newFun = makeWorklet(t, fun, fileName);
|
|
482
537
|
|
|
483
538
|
const replacement = t.callExpression(newFun, []);
|
|
539
|
+
|
|
484
540
|
// we check if function needs to be assigned to variable declaration.
|
|
485
541
|
// This is needed if function definition directly in a scope. Some other ways
|
|
486
542
|
// where function definition can be used is for example with variable declaration:
|
|
487
543
|
// const ggg = function foo() { }
|
|
488
|
-
// ^ in such a case we don't need to
|
|
544
|
+
// ^ in such a case we don't need to define variable for the function
|
|
489
545
|
const needDeclaration =
|
|
490
546
|
t.isScopable(fun.parent) || t.isExportNamedDeclaration(fun.parent);
|
|
491
547
|
fun.replaceWith(
|
|
@@ -497,6 +553,23 @@ function processWorkletFunction(t, fun, fileName) {
|
|
|
497
553
|
);
|
|
498
554
|
}
|
|
499
555
|
|
|
556
|
+
function processWorkletObjectMethod(t, path, fileName) {
|
|
557
|
+
// Replaces ObjectMethod with a workletized version of itself.
|
|
558
|
+
|
|
559
|
+
if (!t.isFunctionParent(path)) {
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
const newFun = makeWorklet(t, path, fileName);
|
|
564
|
+
|
|
565
|
+
const replacement = t.objectProperty(
|
|
566
|
+
t.identifier(path.node.key.name),
|
|
567
|
+
t.callExpression(newFun, [])
|
|
568
|
+
);
|
|
569
|
+
|
|
570
|
+
path.replaceWith(replacement);
|
|
571
|
+
}
|
|
572
|
+
|
|
500
573
|
function processIfWorkletNode(t, fun, fileName) {
|
|
501
574
|
fun.traverse({
|
|
502
575
|
DirectiveLiteral(path) {
|
|
@@ -522,6 +595,115 @@ function processIfWorkletNode(t, fun, fileName) {
|
|
|
522
595
|
});
|
|
523
596
|
}
|
|
524
597
|
|
|
598
|
+
function processIfGestureHandlerEventCallbackFunctionNode(t, fun, fileName) {
|
|
599
|
+
// Auto-workletizes React Native Gesture Handler callback functions.
|
|
600
|
+
// Detects `Gesture.Tap().onEnd(<fun>)` or similar, but skips `something.onEnd(<fun>)`.
|
|
601
|
+
// Supports method chaining as well, e.g. `Gesture.Tap().onStart(<fun1>).onUpdate(<fun2>).onEnd(<fun3>)`.
|
|
602
|
+
|
|
603
|
+
// Example #1: `Gesture.Tap().onEnd(<fun>)`
|
|
604
|
+
/*
|
|
605
|
+
CallExpression(
|
|
606
|
+
callee: MemberExpression(
|
|
607
|
+
object: CallExpression(
|
|
608
|
+
callee: MemberExpression(
|
|
609
|
+
object: Identifier('Gesture')
|
|
610
|
+
property: Identifier('Tap')
|
|
611
|
+
)
|
|
612
|
+
)
|
|
613
|
+
property: Identifier('onEnd')
|
|
614
|
+
)
|
|
615
|
+
arguments: [fun]
|
|
616
|
+
)
|
|
617
|
+
*/
|
|
618
|
+
|
|
619
|
+
// Example #2: `Gesture.Tap().onStart(<fun1>).onUpdate(<fun2>).onEnd(<fun3>)`
|
|
620
|
+
/*
|
|
621
|
+
CallExpression(
|
|
622
|
+
callee: MemberExpression(
|
|
623
|
+
object: CallExpression(
|
|
624
|
+
callee: MemberExpression(
|
|
625
|
+
object: CallExpression(
|
|
626
|
+
callee: MemberExpression(
|
|
627
|
+
object: CallExpression(
|
|
628
|
+
callee: MemberExpression(
|
|
629
|
+
object: Identifier('Gesture')
|
|
630
|
+
property: Identifier('Tap')
|
|
631
|
+
)
|
|
632
|
+
)
|
|
633
|
+
property: Identifier('onStart')
|
|
634
|
+
)
|
|
635
|
+
arguments: [fun1]
|
|
636
|
+
)
|
|
637
|
+
property: Identifier('onUpdate')
|
|
638
|
+
)
|
|
639
|
+
arguments: [fun2]
|
|
640
|
+
)
|
|
641
|
+
property: Identifier('onEnd')
|
|
642
|
+
)
|
|
643
|
+
arguments: [fun3]
|
|
644
|
+
)
|
|
645
|
+
*/
|
|
646
|
+
|
|
647
|
+
if (
|
|
648
|
+
t.isCallExpression(fun.parent) &&
|
|
649
|
+
isGestureObjectEventCallbackMethod(t, fun.parent.callee)
|
|
650
|
+
) {
|
|
651
|
+
processWorkletFunction(t, fun, fileName);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
function isGestureObjectEventCallbackMethod(t, node) {
|
|
656
|
+
// Checks if node matches the pattern `Gesture.Foo()[*].onBar`
|
|
657
|
+
// where `[*]` represents any number of method calls.
|
|
658
|
+
return (
|
|
659
|
+
t.isMemberExpression(node) &&
|
|
660
|
+
t.isIdentifier(node.property) &&
|
|
661
|
+
gestureHandlerBuilderMethods.has(node.property.name) &&
|
|
662
|
+
containsGestureObject(t, node.object)
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
function containsGestureObject(t, node) {
|
|
667
|
+
// Checks if node matches the pattern `Gesture.Foo()[*]`
|
|
668
|
+
// where `[*]` represents any number of chained method calls, like `.something(42)`.
|
|
669
|
+
|
|
670
|
+
// direct call
|
|
671
|
+
if (isGestureObject(t, node)) {
|
|
672
|
+
return true;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// method chaining
|
|
676
|
+
if (
|
|
677
|
+
t.isCallExpression(node) &&
|
|
678
|
+
t.isMemberExpression(node.callee) &&
|
|
679
|
+
containsGestureObject(t, node.callee.object)
|
|
680
|
+
) {
|
|
681
|
+
return true;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
return false;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
function isGestureObject(t, node) {
|
|
688
|
+
// Checks if node matches `Gesture.Tap()` or similar.
|
|
689
|
+
/*
|
|
690
|
+
node: CallExpression(
|
|
691
|
+
callee: MemberExpression(
|
|
692
|
+
object: Identifier('Gesture')
|
|
693
|
+
property: Identifier('Tap')
|
|
694
|
+
)
|
|
695
|
+
)
|
|
696
|
+
*/
|
|
697
|
+
return (
|
|
698
|
+
t.isCallExpression(node) &&
|
|
699
|
+
t.isMemberExpression(node.callee) &&
|
|
700
|
+
t.isIdentifier(node.callee.object) &&
|
|
701
|
+
node.callee.object.name === 'Gesture' &&
|
|
702
|
+
t.isIdentifier(node.callee.property) &&
|
|
703
|
+
gestureHandlerGestureObjects.has(node.callee.property.name)
|
|
704
|
+
);
|
|
705
|
+
}
|
|
706
|
+
|
|
525
707
|
function processWorklets(t, path, fileName) {
|
|
526
708
|
const name =
|
|
527
709
|
path.node.callee.type === 'MemberExpression'
|
|
@@ -531,17 +713,14 @@ function processWorklets(t, path, fileName) {
|
|
|
531
713
|
objectHooks.has(name) &&
|
|
532
714
|
path.get('arguments.0').type === 'ObjectExpression'
|
|
533
715
|
) {
|
|
534
|
-
const
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
objectPath.getSibling(i).get('value'),
|
|
543
|
-
fileName
|
|
544
|
-
);
|
|
716
|
+
const properties = path.get('arguments.0.properties');
|
|
717
|
+
for (const property of properties) {
|
|
718
|
+
if (t.isObjectMethod(property)) {
|
|
719
|
+
processWorkletObjectMethod(t, property, fileName);
|
|
720
|
+
} else {
|
|
721
|
+
const value = property.get('value');
|
|
722
|
+
processWorkletFunction(t, value, fileName);
|
|
723
|
+
}
|
|
545
724
|
}
|
|
546
725
|
} else {
|
|
547
726
|
const indexes = functionArgsToWorkletize.get(name);
|
|
@@ -558,7 +737,7 @@ const STATEMENTLESS_FLAG = 0b00000010;
|
|
|
558
737
|
|
|
559
738
|
function isPossibleOptimization(fun) {
|
|
560
739
|
let isFunctionCall = false;
|
|
561
|
-
let
|
|
740
|
+
let isStatement = false;
|
|
562
741
|
traverse(fun, {
|
|
563
742
|
CallExpression(path) {
|
|
564
743
|
if (!possibleOptFunction.has(path.node.callee.name)) {
|
|
@@ -566,14 +745,14 @@ function isPossibleOptimization(fun) {
|
|
|
566
745
|
}
|
|
567
746
|
},
|
|
568
747
|
IfStatement() {
|
|
569
|
-
|
|
748
|
+
isStatement = true;
|
|
570
749
|
},
|
|
571
750
|
});
|
|
572
751
|
let flags = 0;
|
|
573
752
|
if (!isFunctionCall) {
|
|
574
753
|
flags = flags | FUNCTIONLESS_FLAG;
|
|
575
754
|
}
|
|
576
|
-
if (!
|
|
755
|
+
if (!isStatement) {
|
|
577
756
|
flags = flags | STATEMENTLESS_FLAG;
|
|
578
757
|
}
|
|
579
758
|
return flags;
|
|
@@ -597,7 +776,9 @@ module.exports = function ({ types: t }) {
|
|
|
597
776
|
},
|
|
598
777
|
'FunctionDeclaration|FunctionExpression|ArrowFunctionExpression': {
|
|
599
778
|
enter(path, state) {
|
|
600
|
-
|
|
779
|
+
const fileName = state.file.opts.filename;
|
|
780
|
+
processIfWorkletNode(t, path, fileName);
|
|
781
|
+
processIfGestureHandlerEventCallbackFunctionNode(t, path, fileName);
|
|
601
782
|
},
|
|
602
783
|
},
|
|
603
784
|
},
|