react-native-reanimated 2.3.0-beta.2 → 2.3.1
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/NativeModules/NativeReanimatedModule.cpp +12 -3
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +13 -0
- package/Common/cpp/Registries/EventHandlerRegistry.cpp +2 -2
- package/Common/cpp/Registries/MapperRegistry.cpp +5 -5
- package/Common/cpp/SharedItems/FrozenObject.cpp +1 -3
- package/Common/cpp/SharedItems/ShareableValue.cpp +8 -10
- package/Common/cpp/Tools/FeaturesConfig.cpp +5 -0
- package/Common/cpp/Tools/JSIStoreValueUser.cpp +8 -8
- package/Common/cpp/Tools/Mapper.cpp +1 -1
- package/Common/cpp/Tools/RuntimeDecorator.cpp +40 -4
- package/Common/cpp/Tools/WorkletEventHandler.cpp +3 -1
- package/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +5 -0
- package/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +6 -1
- package/Common/cpp/headers/Registries/EventHandlerRegistry.h +1 -0
- package/Common/cpp/headers/Registries/MapperRegistry.h +1 -0
- package/Common/cpp/headers/SharedItems/FrozenObject.h +4 -0
- package/Common/cpp/headers/SharedItems/HostFunctionHandler.h +2 -0
- package/Common/cpp/headers/SharedItems/MutableValue.h +2 -0
- package/Common/cpp/headers/SharedItems/MutableValueSetterProxy.h +3 -1
- package/Common/cpp/headers/SharedItems/RemoteObject.h +4 -1
- package/Common/cpp/headers/SharedItems/ShareableValue.h +2 -0
- package/Common/cpp/headers/SharedItems/SharedParent.h +9 -9
- package/Common/cpp/headers/SharedItems/ValueWrapper.h +32 -28
- package/Common/cpp/headers/SpecTools/ErrorHandler.h +1 -0
- package/Common/cpp/headers/Tools/FeaturesConfig.h +19 -0
- package/Common/cpp/headers/Tools/JSIStoreValueUser.h +2 -5
- package/Common/cpp/headers/Tools/Mapper.h +2 -0
- package/Common/cpp/headers/Tools/PlatformDepMethodsHolder.h +5 -0
- package/Common/cpp/headers/Tools/ReanimatedHiddenHeaders.h +1 -5
- package/Common/cpp/headers/Tools/RuntimeDecorator.h +10 -7
- package/Common/cpp/headers/Tools/Scheduler.h +2 -0
- package/Common/cpp/headers/Tools/WorkletEventHandler.h +2 -1
- package/Common/cpp/hidden_headers/Logger.h +2 -2
- package/Common/cpp/hidden_headers/LoggerInterface.h +1 -1
- package/README.md +1 -1
- package/RNReanimated.podspec +21 -3
- package/android/build.gradle +33 -13
- package/android/expo/linking.gradle +46 -0
- package/android/expo/src/main/java/com/swmansion/reanimated/EXReanimatedAdapter.java +12 -0
- package/android/expo/src/main/java/expo/modules/adapters/reanimated/EXReanimatedPackage.java +26 -0
- 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/expo-module.config.json +3 -0
- package/ios/LayoutReanimation/REAAnimationsManager.m +65 -19
- package/ios/LayoutReanimation/REAUIManager.mm +101 -61
- package/ios/Nodes/REAPropsNode.m +1 -1
- package/ios/REAEventDispatcher.m +1 -1
- package/ios/REAModule.h +0 -2
- package/ios/REAModule.m +0 -3
- package/ios/REANodesManager.m +1 -0
- package/ios/RNGestureHandlerStateManager.h +5 -0
- package/ios/native/NativeMethods.h +5 -0
- package/ios/native/NativeMethods.mm +14 -6
- package/ios/native/NativeProxy.h +1 -0
- package/ios/native/NativeProxy.mm +84 -63
- package/ios/native/REAIOSErrorHandler.mm +19 -15
- package/ios/native/REAIOSLogger.mm +10 -6
- package/ios/native/REAIOSScheduler.mm +17 -10
- package/ios/native/REAInitializer.mm +39 -37
- package/ios/native/UIResponder+Reanimated.mm +2 -2
- package/lib/Animated.js +11 -5
- 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 +469 -499
- package/lib/index.js +11 -5
- package/lib/reanimated1/core/Core.test.js +1 -1
- package/lib/reanimated2/NativeMethods.js +7 -0
- package/lib/reanimated2/NativeReanimated/NativeReanimated.js +3 -0
- package/lib/reanimated2/PropAdapters.js +0 -1
- package/lib/reanimated2/UpdateProps.js +1 -1
- package/lib/reanimated2/ViewDescriptorsSet.js +4 -2
- package/lib/reanimated2/animation/spring.js +2 -0
- package/lib/reanimated2/animation/styleAnimation.js +5 -1
- package/lib/reanimated2/animation/util.js +23 -0
- package/lib/reanimated2/component/FlatList.js +30 -0
- package/lib/reanimated2/component/WrappedComponents.js +9 -0
- package/lib/reanimated2/component/index.js +4 -0
- package/lib/reanimated2/core.js +34 -6
- package/lib/reanimated2/globals.d.ts +8 -0
- package/lib/reanimated2/js-reanimated/JSReanimated.js +4 -0
- 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 +14 -5
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Default.js +14 -14
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +8 -8
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +16 -16
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +16 -16
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +4 -4
- package/lib/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +20 -8
- package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +3 -3
- package/lib/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +8 -8
- package/lib/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +10 -10
- package/lib/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +8 -8
- package/lib/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +8 -8
- package/lib/reanimated2/mock.js +3 -1
- package/lib/setAndForwardRef.js +14 -48
- package/mock.js +1 -1
- package/package.json +27 -23
- package/plugin.js +111 -110
- package/react-native-reanimated.d.ts +56 -27
- package/src/Animated.js +11 -5
- 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} +278 -124
- package/src/reanimated1/core/Core.test.js +1 -1
- package/src/reanimated2/NativeMethods.ts +13 -1
- package/src/reanimated2/NativeReanimated/NativeReanimated.ts +5 -11
- package/src/reanimated2/PropAdapters.ts +0 -1
- package/src/reanimated2/UpdateProps.ts +1 -1
- package/src/reanimated2/ViewDescriptorsSet.ts +6 -2
- package/src/reanimated2/animation/commonTypes.ts +4 -4
- package/src/reanimated2/animation/decay.ts +2 -2
- package/src/reanimated2/animation/delay.ts +3 -3
- 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 +24 -12
- package/src/reanimated2/animation/timing.ts +5 -5
- package/src/reanimated2/animation/util.ts +45 -6
- package/src/reanimated2/component/FlatList.tsx +44 -0
- package/src/reanimated2/component/WrappedComponents.ts +11 -0
- package/src/reanimated2/component/index.ts +9 -0
- package/src/reanimated2/core.ts +62 -17
- package/src/reanimated2/globals.d.ts +8 -0
- package/src/reanimated2/hook/useAnimatedStyle.ts +2 -2
- package/src/reanimated2/js-reanimated/JSReanimated.ts +15 -26
- 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.tsx → LayoutAnimationRepository.ts} +18 -5
- package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +39 -20
- package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +5 -1
- package/src/reanimated2/layoutReanimation/defaultAnimations/Default.ts +21 -15
- package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +29 -24
- package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +61 -34
- package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +49 -34
- package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +17 -12
- package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +20 -8
- package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +9 -9
- package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +8 -8
- package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +20 -14
- package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +14 -8
- package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +24 -12
- package/src/reanimated2/mock.ts +3 -1
- package/src/{setAndForwardRef.js → setAndForwardRef.ts} +12 -2
- package/src/ReanimatedModuleCompat.js +0 -37
package/lib/index.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LogBox } from 'react-native';
|
|
2
2
|
import createAnimatedComponent from './createAnimatedComponent';
|
|
3
3
|
import {
|
|
4
4
|
addWhitelistedNativeProps,
|
|
5
5
|
addWhitelistedUIProps,
|
|
6
6
|
} from './ConfigHelper';
|
|
7
7
|
import * as reanimated1 from './reanimated1';
|
|
8
|
+
import ReanimatedComponents from './reanimated2/component';
|
|
8
9
|
|
|
9
10
|
const Animated = {
|
|
10
11
|
// components
|
|
11
|
-
|
|
12
|
-
Text: createAnimatedComponent(Text),
|
|
13
|
-
Image: createAnimatedComponent(Image),
|
|
14
|
-
ScrollView: createAnimatedComponent(ScrollView),
|
|
12
|
+
...ReanimatedComponents,
|
|
15
13
|
createAnimatedComponent,
|
|
16
14
|
// configuration
|
|
17
15
|
addWhitelistedNativeProps,
|
|
@@ -23,3 +21,11 @@ const Animated = {
|
|
|
23
21
|
export * from './reanimated2';
|
|
24
22
|
export * from './reanimated1';
|
|
25
23
|
export default Animated;
|
|
24
|
+
|
|
25
|
+
// I think we can ignore this message as long as Gesture Handler doesn't
|
|
26
|
+
// try to load the Reanimated module. I figured it should be here instead of
|
|
27
|
+
// RNGH because this prevents the message from being displayed for all
|
|
28
|
+
// versions of RNGH.
|
|
29
|
+
LogBox.ignoreLogs([
|
|
30
|
+
'RCTBridge required dispatch_sync to load RNGestureHandlerModule. This may lead to deadlocks',
|
|
31
|
+
]);
|
|
@@ -5,7 +5,7 @@ import renderer from 'react-test-renderer';
|
|
|
5
5
|
|
|
6
6
|
jest.mock('../../ReanimatedEventEmitter');
|
|
7
7
|
jest.mock('../../ReanimatedModule');
|
|
8
|
-
jest.mock('../../reanimated2/NativeReanimated');
|
|
8
|
+
jest.mock('../../reanimated2/NativeReanimated/NativeReanimated');
|
|
9
9
|
|
|
10
10
|
describe('Core Animated components', () => {
|
|
11
11
|
xit('fails if something other then a node or function that returns a node is passed to Animated.Code exec prop', () => {
|
|
@@ -23,3 +23,10 @@ export function scrollTo(animatedRef, x, y, animated) {
|
|
|
23
23
|
const viewTag = animatedRef();
|
|
24
24
|
_scrollTo(viewTag, x, y, animated);
|
|
25
25
|
}
|
|
26
|
+
export function setGestureState(handlerTag, newState) {
|
|
27
|
+
'worklet';
|
|
28
|
+
if (!_WORKLET && !isChromeDebugger()) {
|
|
29
|
+
console.warn('[Reanimated] You can not use setGestureState in non-worklet function.');
|
|
30
|
+
}
|
|
31
|
+
_setGestureState(handlerTag, newState);
|
|
32
|
+
}
|
|
@@ -19,7 +19,7 @@ export const colorProps = [
|
|
|
19
19
|
'textShadowColor',
|
|
20
20
|
'overlayColor',
|
|
21
21
|
];
|
|
22
|
-
const ColorProperties = !isConfigured() ? [] : makeShareable(colorProps);
|
|
22
|
+
export const ColorProperties = !isConfigured() ? [] : makeShareable(colorProps);
|
|
23
23
|
let updatePropsByPlatform;
|
|
24
24
|
if (shouldBeUseWeb()) {
|
|
25
25
|
updatePropsByPlatform = (_, updates, maybeViewRef) => {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { useRef } from 'react';
|
|
2
2
|
import { makeMutable } from './core';
|
|
3
|
+
import { Platform } from 'react-native';
|
|
4
|
+
const scheduleUpdates = Platform.OS === 'web' ? requestAnimationFrame : setImmediate;
|
|
3
5
|
export function makeViewDescriptorsSet() {
|
|
4
6
|
const ref = useRef(null);
|
|
5
7
|
if (ref.current === null) {
|
|
@@ -18,7 +20,7 @@ export function makeViewDescriptorsSet() {
|
|
|
18
20
|
data.items.push(item);
|
|
19
21
|
if (!data.waitForInsertSync) {
|
|
20
22
|
data.waitForInsertSync = true;
|
|
21
|
-
|
|
23
|
+
scheduleUpdates(() => {
|
|
22
24
|
data.sharableViewDescriptors.value = data.items;
|
|
23
25
|
data.waitForInsertSync = false;
|
|
24
26
|
});
|
|
@@ -28,7 +30,7 @@ export function makeViewDescriptorsSet() {
|
|
|
28
30
|
data.batchToRemove.add(viewTag);
|
|
29
31
|
if (!data.waitForRemoveSync) {
|
|
30
32
|
data.waitForRemoveSync = true;
|
|
31
|
-
|
|
33
|
+
scheduleUpdates(() => {
|
|
32
34
|
const items = [];
|
|
33
35
|
for (const item of data.items) {
|
|
34
36
|
if (data.batchToRemove.has(item.tag)) {
|
|
@@ -73,6 +73,8 @@ export function withSpring(toValue, userConfig, callback) {
|
|
|
73
73
|
animation.velocity = 0;
|
|
74
74
|
animation.current = toValue;
|
|
75
75
|
}
|
|
76
|
+
// clear lastTimestamp to avoid using stale value by the next spring animation that starts after this one
|
|
77
|
+
animation.lastTimestamp = 0;
|
|
76
78
|
return true;
|
|
77
79
|
}
|
|
78
80
|
return false;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { defineAnimation } from './util';
|
|
2
2
|
import { withTiming } from './timing';
|
|
3
|
+
import { ColorProperties } from '../UpdateProps';
|
|
4
|
+
import { processColor } from '../Colors';
|
|
3
5
|
// resolves path to value for nested objects
|
|
4
6
|
// if path cannot be resolved returns undefined
|
|
5
7
|
export function resolvePath(obj, path) {
|
|
@@ -15,7 +17,6 @@ export function resolvePath(obj, path) {
|
|
|
15
17
|
return undefined;
|
|
16
18
|
}, obj);
|
|
17
19
|
}
|
|
18
|
-
// set value at given path
|
|
19
20
|
export function setPath(obj, path, value) {
|
|
20
21
|
'worklet';
|
|
21
22
|
const keys = Array.isArray(path) ? path : [path];
|
|
@@ -80,6 +81,9 @@ export function withStyleAnimation(styleAnimations) {
|
|
|
80
81
|
else {
|
|
81
82
|
stillGoing = true;
|
|
82
83
|
}
|
|
84
|
+
if (ColorProperties.includes(currentEntry.path[0])) {
|
|
85
|
+
currentStyleAnimation.current = processColor(currentStyleAnimation.current);
|
|
86
|
+
}
|
|
83
87
|
setPath(animation.current, currentEntry.path, currentStyleAnimation.current);
|
|
84
88
|
}
|
|
85
89
|
}
|
|
@@ -107,12 +107,35 @@ function decorateAnimation(animation) {
|
|
|
107
107
|
animation.current = toRGBA(res);
|
|
108
108
|
return finished;
|
|
109
109
|
};
|
|
110
|
+
const arrayOnStart = (animation, value, timestamp, previousAnimation) => {
|
|
111
|
+
value.forEach((v, i) => {
|
|
112
|
+
animation[i] = Object.assign({}, animationCopy);
|
|
113
|
+
animation[i].current = v;
|
|
114
|
+
animation[i].toValue = animation.toValue[i];
|
|
115
|
+
animation[i].onStart(animation[i], v, timestamp, previousAnimation ? previousAnimation[i] : undefined);
|
|
116
|
+
});
|
|
117
|
+
animation.current = value;
|
|
118
|
+
};
|
|
119
|
+
const arrayOnFrame = (animation, timestamp) => {
|
|
120
|
+
let finished = true;
|
|
121
|
+
animation.current.forEach((v, i) => {
|
|
122
|
+
// @ts-ignore: disable-next-line
|
|
123
|
+
finished &= animation[i].onFrame(animation[i], timestamp);
|
|
124
|
+
animation.current[i] = animation[i].current;
|
|
125
|
+
});
|
|
126
|
+
return finished;
|
|
127
|
+
};
|
|
110
128
|
animation.onStart = (animation, value, timestamp, previousAnimation) => {
|
|
111
129
|
if (isColor(value)) {
|
|
112
130
|
colorOnStart(animation, value, timestamp, previousAnimation);
|
|
113
131
|
animation.onFrame = colorOnFrame;
|
|
114
132
|
return;
|
|
115
133
|
}
|
|
134
|
+
else if (Array.isArray(value)) {
|
|
135
|
+
arrayOnStart(animation, value, timestamp, previousAnimation);
|
|
136
|
+
animation.onFrame = arrayOnFrame;
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
116
139
|
else if (typeof value === 'string') {
|
|
117
140
|
prefNumberSuffOnStart(animation, value, timestamp, previousAnimation);
|
|
118
141
|
animation.onFrame = prefNumberSuffOnFrame;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import { FlatList } from 'react-native';
|
|
14
|
+
import WrappedComponents from './WrappedComponents';
|
|
15
|
+
import createAnimatedComponent from '../../createAnimatedComponent';
|
|
16
|
+
const AnimatedFlatList = createAnimatedComponent(FlatList);
|
|
17
|
+
const createCellRenderer = (itemLayoutAnimation) => {
|
|
18
|
+
const cellRenderer = (props) => {
|
|
19
|
+
return (<WrappedComponents.View layout={itemLayoutAnimation} onLayout={props.onLayout}>
|
|
20
|
+
{props.children}
|
|
21
|
+
</WrappedComponents.View>);
|
|
22
|
+
};
|
|
23
|
+
return cellRenderer;
|
|
24
|
+
};
|
|
25
|
+
const ReanimatedFlatlist = (_a) => {
|
|
26
|
+
var { itemLayoutAnimation } = _a, restProps = __rest(_a, ["itemLayoutAnimation"]);
|
|
27
|
+
const cellRenderer = React.useMemo(() => createCellRenderer(itemLayoutAnimation), []);
|
|
28
|
+
return (<AnimatedFlatList {...restProps} CellRendererComponent={cellRenderer}/>);
|
|
29
|
+
};
|
|
30
|
+
export default ReanimatedFlatlist;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Image, ScrollView, Text, View } from 'react-native';
|
|
2
|
+
import createAnimatedComponent from '../../createAnimatedComponent';
|
|
3
|
+
const WrappedComponents = {
|
|
4
|
+
View: createAnimatedComponent(View),
|
|
5
|
+
Text: createAnimatedComponent(Text),
|
|
6
|
+
Image: createAnimatedComponent(Image),
|
|
7
|
+
ScrollView: createAnimatedComponent(ScrollView),
|
|
8
|
+
};
|
|
9
|
+
export default WrappedComponents;
|
package/lib/reanimated2/core.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* global _WORKLET _getCurrentTime _frameTimestamp _eventTimestamp, _setGlobalConsole */
|
|
2
2
|
import NativeReanimatedModule from './NativeReanimated';
|
|
3
3
|
import { Platform } from 'react-native';
|
|
4
|
-
import { nativeShouldBeMock, shouldBeUseWeb } from './PlatformChecker';
|
|
4
|
+
import { nativeShouldBeMock, shouldBeUseWeb, isWeb } from './PlatformChecker';
|
|
5
5
|
global.__reanimatedWorkletInit = function (worklet) {
|
|
6
6
|
worklet.__worklet = true;
|
|
7
7
|
};
|
|
@@ -135,7 +135,9 @@ function workletValueSetter(value) {
|
|
|
135
135
|
(value !== null &&
|
|
136
136
|
typeof value === 'object' &&
|
|
137
137
|
value.onFrame !== undefined)) {
|
|
138
|
-
const animation = typeof value === 'function'
|
|
138
|
+
const animation = typeof value === 'function'
|
|
139
|
+
? value()
|
|
140
|
+
: value;
|
|
139
141
|
// prevent setting again to the same value
|
|
140
142
|
// and triggering the mappers that treat this value as an input
|
|
141
143
|
// this happens when the animation's target value(stored in animation.current until animation.onStart is called) is set to the same value as a current one(this._value)
|
|
@@ -196,7 +198,9 @@ function workletValueSetterJS(value) {
|
|
|
196
198
|
typeof value === 'object' &&
|
|
197
199
|
value.onFrame)) {
|
|
198
200
|
// animated set
|
|
199
|
-
const animation = typeof value === 'function'
|
|
201
|
+
const animation = typeof value === 'function'
|
|
202
|
+
? value()
|
|
203
|
+
: value;
|
|
200
204
|
let initializeAnimation = (timestamp) => {
|
|
201
205
|
animation.onStart(animation, this.value, timestamp, previousAnimation);
|
|
202
206
|
};
|
|
@@ -256,9 +260,11 @@ export function runOnJS(fun) {
|
|
|
256
260
|
}
|
|
257
261
|
}
|
|
258
262
|
if (!NativeReanimatedModule.useOnlyV1) {
|
|
259
|
-
NativeReanimatedModule.installCoreFunctions(NativeReanimatedModule.native
|
|
260
|
-
|
|
261
|
-
|
|
263
|
+
NativeReanimatedModule.installCoreFunctions(NativeReanimatedModule.native
|
|
264
|
+
? workletValueSetter
|
|
265
|
+
: workletValueSetterJS);
|
|
266
|
+
if (!isWeb() && isConfigured()) {
|
|
267
|
+
const capturableConsole = console;
|
|
262
268
|
runOnUI(() => {
|
|
263
269
|
'worklet';
|
|
264
270
|
const console = {
|
|
@@ -269,5 +275,27 @@ if (!NativeReanimatedModule.useOnlyV1) {
|
|
|
269
275
|
info: runOnJS(capturableConsole.info),
|
|
270
276
|
};
|
|
271
277
|
_setGlobalConsole(console);
|
|
278
|
+
global.performance = {
|
|
279
|
+
now: global._chronoNow,
|
|
280
|
+
};
|
|
272
281
|
})();
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
let featuresConfig = {
|
|
285
|
+
enableLayoutAnimations: false,
|
|
286
|
+
setByUser: false,
|
|
287
|
+
};
|
|
288
|
+
export function enableLayoutAnimations(flag, isCallByUser = true) {
|
|
289
|
+
if (isCallByUser) {
|
|
290
|
+
featuresConfig = {
|
|
291
|
+
enableLayoutAnimations: flag,
|
|
292
|
+
setByUser: true,
|
|
293
|
+
};
|
|
294
|
+
NativeReanimatedModule.enableLayoutAnimations(flag);
|
|
295
|
+
}
|
|
296
|
+
else if (!featuresConfig.setByUser &&
|
|
297
|
+
featuresConfig.enableLayoutAnimations !== flag) {
|
|
298
|
+
featuresConfig.enableLayoutAnimations = flag;
|
|
299
|
+
NativeReanimatedModule.enableLayoutAnimations(flag);
|
|
300
|
+
}
|
|
273
301
|
}
|
|
@@ -13,6 +13,7 @@ declare global {
|
|
|
13
13
|
tag: number,
|
|
14
14
|
flag: { value: boolean; _value: boolean }
|
|
15
15
|
) => void;
|
|
16
|
+
const _setGestureState: (handlerTag: number, newState: number) => void;
|
|
16
17
|
const _updateProps: (
|
|
17
18
|
tag: number,
|
|
18
19
|
name: string,
|
|
@@ -25,13 +26,20 @@ declare global {
|
|
|
25
26
|
y: number,
|
|
26
27
|
animated: boolean
|
|
27
28
|
) => void;
|
|
29
|
+
const _chronoNow: () => number;
|
|
28
30
|
namespace NodeJS {
|
|
29
31
|
interface Global {
|
|
30
32
|
__reanimatedWorkletInit: (worklet: WorkletFunction) => void;
|
|
31
33
|
_setGlobalConsole: (console?: ReanimatedConsole) => void;
|
|
32
34
|
_log: (s: string) => void;
|
|
35
|
+
_setGestureState: () => void;
|
|
33
36
|
_WORKLET: boolean;
|
|
34
37
|
__reanimatedModuleProxy: NativeReanimated;
|
|
38
|
+
_frameTimestamp: number | null;
|
|
39
|
+
_measure: () => MeasuredDimensions;
|
|
40
|
+
_scrollTo: () => void;
|
|
41
|
+
_chronoNow: () => number;
|
|
42
|
+
performance: { now: () => number };
|
|
35
43
|
LayoutAnimationRepository: {
|
|
36
44
|
configs: Record<string, unknown>;
|
|
37
45
|
registerConfig(tag: number, config: Record<string, unknown>): void;
|
|
@@ -50,6 +50,7 @@ export default class JSReanimated extends NativeReanimated {
|
|
|
50
50
|
return value;
|
|
51
51
|
}
|
|
52
52
|
makeMutable(value) {
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
53
54
|
return new MutableValue(value, this._valueSetter);
|
|
54
55
|
}
|
|
55
56
|
makeRemote(object = {}) {
|
|
@@ -71,4 +72,7 @@ export default class JSReanimated extends NativeReanimated {
|
|
|
71
72
|
unregisterEventHandler(_) {
|
|
72
73
|
// noop
|
|
73
74
|
}
|
|
75
|
+
enableLayoutAnimations() {
|
|
76
|
+
console.warn('[Reanimated] enableLayoutAnimations is not available for WEB yet');
|
|
77
|
+
}
|
|
74
78
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
-
// @ts-nocheck
|
|
3
1
|
import MutableValue from './MutableValue';
|
|
4
2
|
export default class Mapper {
|
|
5
3
|
constructor(module, mapper, inputs = [], outputs = []) {
|
|
@@ -23,7 +21,10 @@ export default class Mapper {
|
|
|
23
21
|
extractMutablesFromArray(array) {
|
|
24
22
|
const res = [];
|
|
25
23
|
function extractMutables(value) {
|
|
26
|
-
if (value
|
|
24
|
+
if (value == null) {
|
|
25
|
+
// return;
|
|
26
|
+
}
|
|
27
|
+
else if (value instanceof MutableValue) {
|
|
27
28
|
res.push(value);
|
|
28
29
|
}
|
|
29
30
|
else if (Array.isArray(value)) {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
-
// @ts-nocheck
|
|
3
1
|
export default class MapperRegistry {
|
|
4
2
|
constructor(module) {
|
|
5
3
|
this.sortedMappers = [];
|
|
@@ -78,7 +76,8 @@ export default class MapperRegistry {
|
|
|
78
76
|
while (nodes.length)
|
|
79
77
|
dfs(nodes[0]);
|
|
80
78
|
const postArray = Object.keys(post).map((key) => {
|
|
81
|
-
|
|
79
|
+
const num = parseInt(key);
|
|
80
|
+
return [num, post[num]];
|
|
82
81
|
});
|
|
83
82
|
postArray.sort((a, b) => {
|
|
84
83
|
return b[1] - a[1];
|
|
@@ -95,9 +94,7 @@ export default class MapperRegistry {
|
|
|
95
94
|
}
|
|
96
95
|
}
|
|
97
96
|
class Node {
|
|
98
|
-
constructor(mapper,
|
|
99
|
-
this.mapper = null;
|
|
100
|
-
this.children = [];
|
|
97
|
+
constructor(mapper, children = []) {
|
|
101
98
|
this.mapper = mapper;
|
|
102
99
|
this.children = children;
|
|
103
100
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
-
// @ts-nocheck
|
|
3
1
|
import JSReanimated from './JSReanimated';
|
|
4
2
|
import { shouldBeUseWeb } from '../PlatformChecker';
|
|
5
3
|
const reanimatedJS = new JSReanimated();
|
|
@@ -22,25 +20,29 @@ if (shouldBeUseWeb()) {
|
|
|
22
20
|
global._scrollTo = () => {
|
|
23
21
|
console.warn("[Reanimated] You can't use 'scrollTo' method with Chrome Debugger or with web version");
|
|
24
22
|
};
|
|
23
|
+
global._setGestureState = () => {
|
|
24
|
+
console.warn("[Reanimated] You can't use 'setGestureState' method with Chrome Debugger or with web version");
|
|
25
|
+
};
|
|
25
26
|
}
|
|
26
27
|
export const _updatePropsJS = (updates, viewRef) => {
|
|
27
|
-
if (viewRef
|
|
28
|
+
if (viewRef._component) {
|
|
29
|
+
const component = viewRef._component;
|
|
28
30
|
const [rawStyles] = Object.keys(updates).reduce((acc, key) => {
|
|
29
31
|
const value = updates[key];
|
|
30
32
|
const index = typeof value === 'function' ? 1 : 0;
|
|
31
33
|
acc[index][key] = value;
|
|
32
34
|
return acc;
|
|
33
35
|
}, [{}, {}]);
|
|
34
|
-
if (typeof
|
|
35
|
-
setNativeProps(
|
|
36
|
+
if (typeof component.setNativeProps === 'function') {
|
|
37
|
+
setNativeProps(component, rawStyles);
|
|
36
38
|
}
|
|
37
|
-
else if (Object.keys(
|
|
38
|
-
Object.keys(
|
|
39
|
+
else if (Object.keys(component.props).length > 0) {
|
|
40
|
+
Object.keys(component.props).forEach((key) => {
|
|
39
41
|
if (!rawStyles[key]) {
|
|
40
42
|
return;
|
|
41
43
|
}
|
|
42
44
|
const dashedKey = key.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());
|
|
43
|
-
|
|
45
|
+
component._touchableNode.setAttribute(dashedKey, rawStyles[key]);
|
|
44
46
|
});
|
|
45
47
|
}
|
|
46
48
|
else {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* global _stopObservingProgress, _startObservingProgress */
|
|
2
2
|
import { runOnUI } from '../core';
|
|
3
3
|
import { withStyleAnimation } from '../animation/styleAnimation';
|
|
4
|
+
import { ColorProperties } from '../UpdateProps';
|
|
5
|
+
import { processColor } from '../Colors';
|
|
4
6
|
runOnUI(() => {
|
|
5
7
|
'worklet';
|
|
6
8
|
const configs = {};
|
|
@@ -34,12 +36,19 @@ runOnUI(() => {
|
|
|
34
36
|
for (const key in layoutAnimation) {
|
|
35
37
|
currentAnimation[key] = layoutAnimation[key];
|
|
36
38
|
}
|
|
37
|
-
enteringAnimationForTag[tag] = null;
|
|
38
39
|
}
|
|
39
40
|
const sv = configs[tag].sv;
|
|
40
41
|
_stopObservingProgress(tag, false);
|
|
41
42
|
_startObservingProgress(tag, sv);
|
|
42
|
-
|
|
43
|
+
const backupColor = {};
|
|
44
|
+
for (const key in style.initialValues) {
|
|
45
|
+
if (ColorProperties.includes(key)) {
|
|
46
|
+
const value = style.initialValues[key];
|
|
47
|
+
backupColor[key] = value;
|
|
48
|
+
style.initialValues[key] = processColor(value);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
sv.value = Object.assign({}, sv._value, style.initialValues);
|
|
43
52
|
_stopObservingProgress(tag, false);
|
|
44
53
|
const animation = withStyleAnimation(currentAnimation);
|
|
45
54
|
animation.callback = (finished) => {
|
|
@@ -47,10 +56,10 @@ runOnUI(() => {
|
|
|
47
56
|
_stopObservingProgress(tag, finished);
|
|
48
57
|
}
|
|
49
58
|
style.callback && style.callback(finished);
|
|
50
|
-
if (type === 'entering') {
|
|
51
|
-
enteringAnimationForTag[tag] = null;
|
|
52
|
-
}
|
|
53
59
|
};
|
|
60
|
+
if (backupColor) {
|
|
61
|
+
configs[tag].sv._value = Object.assign(Object.assign({}, configs[tag].sv.value), backupColor);
|
|
62
|
+
}
|
|
54
63
|
configs[tag].sv.value = animation;
|
|
55
64
|
_startObservingProgress(tag, sv);
|
|
56
65
|
},
|
|
@@ -2,34 +2,34 @@ export const DefaultLayout = (values) => {
|
|
|
2
2
|
'worklet';
|
|
3
3
|
return {
|
|
4
4
|
initialValues: {
|
|
5
|
-
originX: values.
|
|
6
|
-
originY: values.
|
|
7
|
-
width: values.
|
|
8
|
-
height: values.
|
|
5
|
+
originX: values.targetOriginX,
|
|
6
|
+
originY: values.targetOriginY,
|
|
7
|
+
width: values.targetWidth,
|
|
8
|
+
height: values.targetHeight,
|
|
9
9
|
},
|
|
10
10
|
animations: {},
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
|
-
export const DefaultEntering = (
|
|
13
|
+
export const DefaultEntering = (values) => {
|
|
14
14
|
'worklet';
|
|
15
15
|
return {
|
|
16
16
|
initialValues: {
|
|
17
|
-
originX:
|
|
18
|
-
originY:
|
|
19
|
-
width:
|
|
20
|
-
height:
|
|
17
|
+
originX: values.targetOriginX,
|
|
18
|
+
originY: values.targetOriginY,
|
|
19
|
+
width: values.targetWidth,
|
|
20
|
+
height: values.targetHeight,
|
|
21
21
|
},
|
|
22
22
|
animations: {},
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
|
-
export const DefaultExiting = (
|
|
25
|
+
export const DefaultExiting = (values) => {
|
|
26
26
|
'worklet';
|
|
27
27
|
return {
|
|
28
28
|
initialValues: {
|
|
29
|
-
originX:
|
|
30
|
-
originY:
|
|
31
|
-
width:
|
|
32
|
-
height:
|
|
29
|
+
originX: values.currentOriginX,
|
|
30
|
+
originY: values.currentOriginY,
|
|
31
|
+
width: values.currentWidth,
|
|
32
|
+
height: values.currentHeight,
|
|
33
33
|
},
|
|
34
34
|
animations: {},
|
|
35
35
|
};
|
|
@@ -14,7 +14,7 @@ export class FlipInXUp extends ComplexAnimationBuilder {
|
|
|
14
14
|
transform: [
|
|
15
15
|
{ perspective: 500 },
|
|
16
16
|
{ rotateX: '90deg' },
|
|
17
|
-
{ translateY: -targetValues.
|
|
17
|
+
{ translateY: -targetValues.targetHeight },
|
|
18
18
|
],
|
|
19
19
|
},
|
|
20
20
|
animations: {
|
|
@@ -48,7 +48,7 @@ export class FlipInYLeft extends ComplexAnimationBuilder {
|
|
|
48
48
|
transform: [
|
|
49
49
|
{ perspective: 500 },
|
|
50
50
|
{ rotateY: '-90deg' },
|
|
51
|
-
{ translateX: -targetValues.
|
|
51
|
+
{ translateX: -targetValues.targetWidth },
|
|
52
52
|
],
|
|
53
53
|
},
|
|
54
54
|
animations: {
|
|
@@ -82,7 +82,7 @@ export class FlipInXDown extends ComplexAnimationBuilder {
|
|
|
82
82
|
transform: [
|
|
83
83
|
{ perspective: 500 },
|
|
84
84
|
{ rotateX: '-90deg' },
|
|
85
|
-
{ translateY: targetValues.
|
|
85
|
+
{ translateY: targetValues.targetHeight },
|
|
86
86
|
],
|
|
87
87
|
},
|
|
88
88
|
animations: {
|
|
@@ -116,7 +116,7 @@ export class FlipInYRight extends ComplexAnimationBuilder {
|
|
|
116
116
|
transform: [
|
|
117
117
|
{ perspective: 500 },
|
|
118
118
|
{ rotateY: '90deg' },
|
|
119
|
-
{ translateX: targetValues.
|
|
119
|
+
{ translateX: targetValues.targetWidth },
|
|
120
120
|
],
|
|
121
121
|
},
|
|
122
122
|
animations: {
|
|
@@ -216,7 +216,7 @@ export class FlipOutXUp extends ComplexAnimationBuilder {
|
|
|
216
216
|
{ perspective: delayFunction(delay, animation(500, config)) },
|
|
217
217
|
{ rotateX: delayFunction(delay, animation('90deg', config)) },
|
|
218
218
|
{
|
|
219
|
-
translateY: delayFunction(delay, animation(-targetValues.
|
|
219
|
+
translateY: delayFunction(delay, animation(-targetValues.currentHeight, config)),
|
|
220
220
|
},
|
|
221
221
|
],
|
|
222
222
|
},
|
|
@@ -252,7 +252,7 @@ export class FlipOutYLeft extends ComplexAnimationBuilder {
|
|
|
252
252
|
{ perspective: delayFunction(delay, animation(500, config)) },
|
|
253
253
|
{ rotateY: delayFunction(delay, animation('-90deg', config)) },
|
|
254
254
|
{
|
|
255
|
-
translateX: delayFunction(delay, animation(-targetValues.
|
|
255
|
+
translateX: delayFunction(delay, animation(-targetValues.currentWidth, config)),
|
|
256
256
|
},
|
|
257
257
|
],
|
|
258
258
|
},
|
|
@@ -288,7 +288,7 @@ export class FlipOutXDown extends ComplexAnimationBuilder {
|
|
|
288
288
|
{ perspective: delayFunction(delay, animation(500, config)) },
|
|
289
289
|
{ rotateX: delayFunction(delay, animation('-90deg', config)) },
|
|
290
290
|
{
|
|
291
|
-
translateY: delayFunction(delay, animation(targetValues.
|
|
291
|
+
translateY: delayFunction(delay, animation(targetValues.currentHeight, config)),
|
|
292
292
|
},
|
|
293
293
|
],
|
|
294
294
|
},
|
|
@@ -324,7 +324,7 @@ export class FlipOutYRight extends ComplexAnimationBuilder {
|
|
|
324
324
|
{ perspective: delayFunction(delay, animation(500, config)) },
|
|
325
325
|
{ rotateY: delayFunction(delay, animation('90deg', config)) },
|
|
326
326
|
{
|
|
327
|
-
translateX: delayFunction(delay, animation(targetValues.
|
|
327
|
+
translateX: delayFunction(delay, animation(targetValues.currentWidth, config)),
|
|
328
328
|
},
|
|
329
329
|
],
|
|
330
330
|
},
|