react-native-reanimated 3.0.0-rc.7 → 3.0.0-rc.8
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/AnimatedSensor/AnimatedSensorModule.cpp +32 -37
- package/Common/cpp/AnimatedSensor/AnimatedSensorModule.h +4 -3
- package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.cpp +76 -0
- package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.h +41 -0
- package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +161 -165
- package/Common/cpp/NativeModules/NativeReanimatedModule.h +36 -34
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +22 -34
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.h +13 -14
- package/Common/cpp/SharedItems/RuntimeManager.h +1 -34
- package/Common/cpp/SharedItems/Shareables.cpp +142 -0
- package/Common/cpp/SharedItems/Shareables.h +455 -0
- package/Common/cpp/Tools/PlatformDepMethodsHolder.h +6 -0
- package/Common/cpp/Tools/RuntimeDecorator.cpp +54 -26
- package/Common/cpp/Tools/RuntimeDecorator.h +11 -2
- package/Common/cpp/Tools/Scheduler.cpp +10 -0
- package/Common/cpp/Tools/SingleInstanceChecker.h +1 -1
- package/android/src/main/cpp/LayoutAnimations.cpp +6 -16
- package/android/src/main/cpp/LayoutAnimations.h +4 -4
- package/android/src/main/cpp/NativeProxy.cpp +50 -63
- package/ios/native/NativeProxy.mm +26 -42
- package/lib/commonjs/createAnimatedComponent.js +7 -11
- package/lib/commonjs/createAnimatedComponent.js.map +1 -1
- package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js +24 -25
- package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
- package/lib/commonjs/reanimated2/ViewDescriptorsSet.js +27 -55
- package/lib/commonjs/reanimated2/ViewDescriptorsSet.js.map +1 -1
- package/lib/commonjs/reanimated2/WorkletEventHandler.js +5 -3
- package/lib/commonjs/reanimated2/WorkletEventHandler.js.map +1 -1
- package/lib/commonjs/reanimated2/animation/util.js.map +1 -1
- package/lib/commonjs/reanimated2/commonTypes.js +7 -0
- package/lib/commonjs/reanimated2/commonTypes.js.map +1 -1
- package/lib/commonjs/reanimated2/core.js +111 -209
- package/lib/commonjs/reanimated2/core.js.map +1 -1
- package/lib/commonjs/reanimated2/globals.d.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js +15 -9
- package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedRef.js +18 -8
- package/lib/commonjs/reanimated2/hook/useAnimatedRef.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js +27 -36
- package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js +24 -50
- package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useSharedValue.js +3 -2
- package/lib/commonjs/reanimated2/hook/useSharedValue.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/utils.js.map +1 -1
- package/lib/commonjs/reanimated2/interpolateColor.js.map +1 -1
- package/lib/commonjs/reanimated2/jestUtils.js +8 -33
- package/lib/commonjs/reanimated2/jestUtils.js.map +1 -1
- package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js +16 -100
- package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
- package/lib/commonjs/reanimated2/js-reanimated/index.js +5 -0
- package/lib/commonjs/reanimated2/js-reanimated/index.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js +91 -0
- package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js.map +1 -0
- package/lib/commonjs/reanimated2/layoutReanimation/index.js +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/index.js.map +1 -1
- package/lib/commonjs/reanimated2/mappers.js +186 -0
- package/lib/commonjs/reanimated2/mappers.js.map +1 -0
- package/lib/commonjs/reanimated2/mutables.js +173 -0
- package/lib/commonjs/reanimated2/mutables.js.map +1 -0
- package/lib/commonjs/reanimated2/shareables.js +153 -0
- package/lib/commonjs/reanimated2/shareables.js.map +1 -0
- package/lib/commonjs/reanimated2/threads.js +58 -0
- package/lib/commonjs/reanimated2/threads.js.map +1 -0
- package/lib/commonjs/reanimated2/time.js +55 -0
- package/lib/commonjs/reanimated2/time.js.map +1 -0
- package/lib/commonjs/reanimated2/valueSetter.js +81 -0
- package/lib/commonjs/reanimated2/valueSetter.js.map +1 -0
- package/lib/module/createAnimatedComponent.js +7 -12
- package/lib/module/createAnimatedComponent.js.map +1 -1
- package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js +24 -25
- package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
- package/lib/module/reanimated2/ViewDescriptorsSet.js +27 -53
- package/lib/module/reanimated2/ViewDescriptorsSet.js.map +1 -1
- package/lib/module/reanimated2/WorkletEventHandler.js +4 -3
- package/lib/module/reanimated2/WorkletEventHandler.js.map +1 -1
- package/lib/module/reanimated2/animation/util.js.map +1 -1
- package/lib/module/reanimated2/commonTypes.js +7 -0
- package/lib/module/reanimated2/commonTypes.js.map +1 -1
- package/lib/module/reanimated2/core.js +66 -188
- package/lib/module/reanimated2/core.js.map +1 -1
- package/lib/module/reanimated2/globals.d.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedKeyboard.js +16 -6
- package/lib/module/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedRef.js +17 -8
- package/lib/module/reanimated2/hook/useAnimatedRef.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedSensor.js +29 -34
- package/lib/module/reanimated2/hook/useAnimatedSensor.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedStyle.js +26 -52
- package/lib/module/reanimated2/hook/useAnimatedStyle.js.map +1 -1
- package/lib/module/reanimated2/hook/useSharedValue.js +3 -2
- package/lib/module/reanimated2/hook/useSharedValue.js.map +1 -1
- package/lib/module/reanimated2/hook/utils.js.map +1 -1
- package/lib/module/reanimated2/interpolateColor.js.map +1 -1
- package/lib/module/reanimated2/jestUtils.js +8 -31
- package/lib/module/reanimated2/jestUtils.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/JSReanimated.js +16 -95
- package/lib/module/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/index.js +5 -0
- package/lib/module/reanimated2/js-reanimated/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationsManager.js +84 -0
- package/lib/module/reanimated2/layoutReanimation/animationsManager.js.map +1 -0
- package/lib/module/reanimated2/layoutReanimation/index.js +1 -1
- package/lib/module/reanimated2/layoutReanimation/index.js.map +1 -1
- package/lib/module/reanimated2/mappers.js +173 -0
- package/lib/module/reanimated2/mappers.js.map +1 -0
- package/lib/module/reanimated2/mutables.js +149 -0
- package/lib/module/reanimated2/mutables.js.map +1 -0
- package/lib/module/reanimated2/shareables.js +133 -0
- package/lib/module/reanimated2/shareables.js.map +1 -0
- package/lib/module/reanimated2/threads.js +45 -0
- package/lib/module/reanimated2/threads.js.map +1 -0
- package/lib/module/reanimated2/time.js +37 -0
- package/lib/module/reanimated2/time.js.map +1 -0
- package/lib/module/reanimated2/valueSetter.js +66 -0
- package/lib/module/reanimated2/valueSetter.js.map +1 -0
- package/package.json +1 -1
- package/plugin.js +31 -15
- package/src/createAnimatedComponent.tsx +8 -24
- package/src/reanimated2/NativeReanimated/NativeReanimated.ts +34 -53
- package/src/reanimated2/ViewDescriptorsSet.ts +30 -69
- package/src/reanimated2/WorkletEventHandler.ts +4 -11
- package/src/reanimated2/animation/util.ts +1 -0
- package/src/reanimated2/commonTypes.ts +29 -4
- package/src/reanimated2/core.ts +103 -230
- package/src/reanimated2/globals.d.ts +26 -26
- package/src/reanimated2/hook/useAnimatedKeyboard.ts +18 -9
- package/src/reanimated2/hook/useAnimatedRef.ts +27 -9
- package/src/reanimated2/hook/useAnimatedSensor.ts +33 -31
- package/src/reanimated2/hook/useAnimatedStyle.ts +26 -64
- package/src/reanimated2/hook/useSharedValue.ts +6 -3
- package/src/reanimated2/hook/utils.ts +1 -1
- package/src/reanimated2/interpolateColor.ts +2 -2
- package/src/reanimated2/jestUtils.ts +14 -29
- package/src/reanimated2/js-reanimated/JSReanimated.ts +19 -93
- package/src/reanimated2/js-reanimated/index.ts +4 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +7 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +1 -0
- package/src/reanimated2/layoutReanimation/animationsManager.ts +94 -0
- package/src/reanimated2/layoutReanimation/index.ts +1 -1
- package/src/reanimated2/mappers.ts +179 -0
- package/src/reanimated2/mutables.ts +151 -0
- package/src/reanimated2/shareables.ts +121 -0
- package/src/reanimated2/threads.ts +46 -0
- package/src/reanimated2/time.ts +30 -0
- package/src/reanimated2/valueSetter.ts +64 -0
- package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +0 -127
- package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.h +0 -56
- package/Common/cpp/Registries/MapperRegistry.cpp +0 -147
- package/Common/cpp/Registries/MapperRegistry.h +0 -29
- package/Common/cpp/Registries/WorkletsCache.cpp +0 -45
- package/Common/cpp/Registries/WorkletsCache.h +0 -24
- package/Common/cpp/SharedItems/FrozenObject.cpp +0 -35
- package/Common/cpp/SharedItems/FrozenObject.h +0 -36
- package/Common/cpp/SharedItems/HostFunctionHandler.h +0 -28
- package/Common/cpp/SharedItems/MutableValue.cpp +0 -134
- package/Common/cpp/SharedItems/MutableValue.h +0 -54
- package/Common/cpp/SharedItems/MutableValueSetterProxy.cpp +0 -47
- package/Common/cpp/SharedItems/MutableValueSetterProxy.h +0 -25
- package/Common/cpp/SharedItems/RemoteObject.cpp +0 -45
- package/Common/cpp/SharedItems/RemoteObject.h +0 -35
- package/Common/cpp/SharedItems/ShareableValue.cpp +0 -529
- package/Common/cpp/SharedItems/ShareableValue.h +0 -63
- package/Common/cpp/SharedItems/ValueWrapper.h +0 -183
- package/Common/cpp/Tools/JSIStoreValueUser.cpp +0 -55
- package/Common/cpp/Tools/JSIStoreValueUser.h +0 -37
- package/Common/cpp/Tools/Mapper.cpp +0 -86
- package/Common/cpp/Tools/Mapper.h +0 -51
- package/lib/commonjs/reanimated2/layoutReanimation/LayoutAnimationRepository.js +0 -58
- package/lib/commonjs/reanimated2/layoutReanimation/LayoutAnimationRepository.js.map +0 -1
- package/lib/module/reanimated2/layoutReanimation/LayoutAnimationRepository.js +0 -52
- package/lib/module/reanimated2/layoutReanimation/LayoutAnimationRepository.js.map +0 -1
- package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.ts +0 -49
package/src/reanimated2/core.ts
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
/* global
|
|
1
|
+
/* global _setGlobalConsole */
|
|
2
2
|
import NativeReanimatedModule from './NativeReanimated';
|
|
3
|
-
import { Platform } from 'react-native';
|
|
4
3
|
import { nativeShouldBeMock, shouldBeUseWeb, isWeb } from './PlatformChecker';
|
|
4
|
+
import { BasicWorkletFunction, Value3D, ValueRotation } from './commonTypes';
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
makeShareableCloneRecursive,
|
|
7
|
+
makeShareable as makeShareableUnwrapped,
|
|
8
|
+
} from './shareables';
|
|
9
|
+
import { runOnUI, runOnJS } from './threads';
|
|
10
|
+
import { startMapper as startMapperUnwrapped } from './mappers';
|
|
11
|
+
import {
|
|
12
|
+
makeMutable as makeMutableUnwrapped,
|
|
13
|
+
makeRemote as makeRemoteUnwrapped,
|
|
14
|
+
} from './mutables';
|
|
15
15
|
import { LayoutAnimationFunction } from './layoutReanimation';
|
|
16
16
|
|
|
17
|
+
export { stopMapper } from './mappers';
|
|
18
|
+
export { runOnJS, runOnUI } from './threads';
|
|
19
|
+
export { getTimestamp } from './time';
|
|
20
|
+
|
|
17
21
|
if (global._setGlobalConsole === undefined) {
|
|
18
22
|
// it can happen when Reanimated plugin wasn't added, but the user uses the only API from version 1
|
|
19
23
|
global._setGlobalConsole = () => {
|
|
@@ -26,18 +30,6 @@ export type ReanimatedConsole = Pick<
|
|
|
26
30
|
'debug' | 'log' | 'warn' | 'info' | 'error'
|
|
27
31
|
>;
|
|
28
32
|
|
|
29
|
-
export type WorkletValue =
|
|
30
|
-
| (() => AnimationObject)
|
|
31
|
-
| AnimationObject
|
|
32
|
-
| AnimatableValue
|
|
33
|
-
| Descriptor;
|
|
34
|
-
interface WorkletValueSetterContext {
|
|
35
|
-
_animation?: AnimationObject | null;
|
|
36
|
-
_value?: AnimatableValue | Descriptor;
|
|
37
|
-
value?: AnimatableValue;
|
|
38
|
-
_setValue?: (val: AnimatableValue | Descriptor) => void;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
33
|
const testWorklet: BasicWorkletFunction<void> = () => {
|
|
42
34
|
'worklet';
|
|
43
35
|
};
|
|
@@ -70,35 +62,36 @@ export const isConfiguredCheck: () => void = () => {
|
|
|
70
62
|
checkPluginState(true);
|
|
71
63
|
};
|
|
72
64
|
|
|
73
|
-
|
|
74
|
-
(
|
|
75
|
-
|
|
65
|
+
const configurationCheckWrapper = __DEV__
|
|
66
|
+
? <T extends Array<any>, U>(fn: (...args: T) => U) => {
|
|
67
|
+
return (...args: T): U => {
|
|
68
|
+
isConfigured(true);
|
|
69
|
+
return fn(...args);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
: <T extends Array<any>, U>(fn: (...args: T) => U) => fn;
|
|
76
73
|
|
|
77
|
-
export
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
74
|
+
export const startMapper = __DEV__
|
|
75
|
+
? configurationCheckWrapper(startMapperUnwrapped)
|
|
76
|
+
: startMapperUnwrapped;
|
|
77
|
+
|
|
78
|
+
export const makeShareable = __DEV__
|
|
79
|
+
? configurationCheckWrapper(makeShareableUnwrapped)
|
|
80
|
+
: makeShareableUnwrapped;
|
|
81
|
+
|
|
82
|
+
export const makeMutable = __DEV__
|
|
83
|
+
? configurationCheckWrapper(makeMutableUnwrapped)
|
|
84
|
+
: makeMutableUnwrapped;
|
|
85
|
+
|
|
86
|
+
export const makeRemote = __DEV__
|
|
87
|
+
? configurationCheckWrapper(makeRemoteUnwrapped)
|
|
88
|
+
: makeRemoteUnwrapped;
|
|
85
89
|
|
|
86
90
|
global._WORKLET = false;
|
|
87
91
|
global._log = function (s: string) {
|
|
88
92
|
console.log(s);
|
|
89
93
|
};
|
|
90
94
|
|
|
91
|
-
export function runOnUI<A extends any[], R>(
|
|
92
|
-
worklet: ComplexWorkletFunction<A, R>
|
|
93
|
-
): (...args: A) => void {
|
|
94
|
-
return makeShareable(worklet);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function makeShareable<T>(value: T): T {
|
|
98
|
-
isConfiguredCheck();
|
|
99
|
-
return NativeReanimatedModule.makeShareable(value);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
95
|
export function getViewProp<T>(viewTag: string, propName: string): Promise<T> {
|
|
103
96
|
if (global._IS_FABRIC) {
|
|
104
97
|
throw new Error(
|
|
@@ -121,206 +114,92 @@ export function getViewProp<T>(viewTag: string, propName: string): Promise<T> {
|
|
|
121
114
|
});
|
|
122
115
|
}
|
|
123
116
|
|
|
124
|
-
|
|
125
|
-
if (nativeShouldBeMock()) {
|
|
126
|
-
_getTimestamp = () => {
|
|
127
|
-
return (NativeReanimatedModule as JSReanimated).getTimestamp();
|
|
128
|
-
};
|
|
129
|
-
} else {
|
|
130
|
-
_getTimestamp = () => {
|
|
131
|
-
'worklet';
|
|
132
|
-
if (_frameTimestamp) {
|
|
133
|
-
return _frameTimestamp;
|
|
134
|
-
}
|
|
135
|
-
if (_eventTimestamp) {
|
|
136
|
-
return _eventTimestamp;
|
|
137
|
-
}
|
|
138
|
-
return _getCurrentTime();
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export function getTimestamp(): number {
|
|
117
|
+
function valueUnpacker(objectToUnpack: any, category?: string): any {
|
|
143
118
|
'worklet';
|
|
144
|
-
|
|
145
|
-
|
|
119
|
+
let workletsCache = global.__workletsCache;
|
|
120
|
+
let handleCache = global.__handleCache;
|
|
121
|
+
if (workletsCache === undefined) {
|
|
122
|
+
// init
|
|
123
|
+
workletsCache = global.__workletsCache = new Map();
|
|
124
|
+
handleCache = global.__handleCache = new WeakMap();
|
|
146
125
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
)
|
|
154
|
-
|
|
155
|
-
const previousAnimation = this._animation;
|
|
156
|
-
if (previousAnimation) {
|
|
157
|
-
previousAnimation.cancelled = true;
|
|
158
|
-
this._animation = null;
|
|
159
|
-
}
|
|
160
|
-
if (
|
|
161
|
-
typeof value === 'function' ||
|
|
162
|
-
(value !== null &&
|
|
163
|
-
typeof value === 'object' &&
|
|
164
|
-
(value as AnimationObject).onFrame !== undefined)
|
|
165
|
-
) {
|
|
166
|
-
const animation: AnimationObject =
|
|
167
|
-
typeof value === 'function'
|
|
168
|
-
? (value as () => AnimationObject)()
|
|
169
|
-
: (value as AnimationObject);
|
|
170
|
-
// prevent setting again to the same value
|
|
171
|
-
// and triggering the mappers that treat this value as an input
|
|
172
|
-
// 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)
|
|
173
|
-
// built in animations that are not higher order(withTiming, withSpring) hold target value in .current
|
|
174
|
-
if (this._value === animation.current && !animation.isHigherOrder) {
|
|
175
|
-
animation.callback && animation.callback(true);
|
|
176
|
-
return;
|
|
126
|
+
if (objectToUnpack.__workletHash) {
|
|
127
|
+
let workletFun = workletsCache.get(objectToUnpack.__workletHash);
|
|
128
|
+
if (workletFun === undefined) {
|
|
129
|
+
// eslint-disable-next-line no-eval
|
|
130
|
+
workletFun = eval('(' + objectToUnpack.asString + '\n)') as (
|
|
131
|
+
...args: any[]
|
|
132
|
+
) => any;
|
|
133
|
+
workletsCache.set(objectToUnpack.__workletHash, workletFun);
|
|
177
134
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
animation.callback && animation.callback(false /* finished */);
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
const finished = animation.onFrame(animation, timestamp);
|
|
190
|
-
animation.finished = true;
|
|
191
|
-
animation.timestamp = timestamp;
|
|
192
|
-
this._value = animation.current;
|
|
193
|
-
if (finished) {
|
|
194
|
-
animation.callback && animation.callback(true /* finished */);
|
|
195
|
-
} else {
|
|
196
|
-
requestAnimationFrame(step);
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
this._animation = animation;
|
|
201
|
-
step(currentTimestamp);
|
|
202
|
-
} else {
|
|
203
|
-
// prevent setting again to the same value
|
|
204
|
-
// and triggering the mappers that treat this value as an input
|
|
205
|
-
if (this._value === value) {
|
|
206
|
-
return;
|
|
135
|
+
const functionInstance = workletFun.bind(objectToUnpack);
|
|
136
|
+
objectToUnpack._recur = functionInstance;
|
|
137
|
+
return functionInstance;
|
|
138
|
+
} else if (objectToUnpack.__init) {
|
|
139
|
+
let value = handleCache!.get(objectToUnpack);
|
|
140
|
+
if (value === undefined) {
|
|
141
|
+
value = objectToUnpack.__init();
|
|
142
|
+
handleCache!.set(objectToUnpack, value);
|
|
207
143
|
}
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
this
|
|
216
|
-
value: T
|
|
217
|
-
): void {
|
|
218
|
-
const previousAnimation = this._animation;
|
|
219
|
-
if (previousAnimation) {
|
|
220
|
-
previousAnimation.cancelled = true;
|
|
221
|
-
this._animation = null;
|
|
222
|
-
}
|
|
223
|
-
if (
|
|
224
|
-
typeof value === 'function' ||
|
|
225
|
-
(value !== null &&
|
|
226
|
-
typeof value === 'object' &&
|
|
227
|
-
(value as AnimationObject).onFrame)
|
|
228
|
-
) {
|
|
229
|
-
// animated set
|
|
230
|
-
const animation: AnimationObject =
|
|
231
|
-
typeof value === 'function'
|
|
232
|
-
? (value as () => AnimationObject)()
|
|
233
|
-
: (value as AnimationObject);
|
|
234
|
-
let initializeAnimation: ((timestamp: number) => void) | null = (
|
|
235
|
-
timestamp: number
|
|
236
|
-
) => {
|
|
237
|
-
animation.onStart(animation, this.value, timestamp, previousAnimation);
|
|
238
|
-
};
|
|
239
|
-
const step = (timestamp: number) => {
|
|
240
|
-
if (animation.cancelled) {
|
|
241
|
-
animation.callback && animation.callback(false /* finished */);
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
if (initializeAnimation) {
|
|
245
|
-
initializeAnimation(timestamp);
|
|
246
|
-
initializeAnimation = null; // prevent closure from keeping ref to previous animation
|
|
247
|
-
}
|
|
248
|
-
const finished = animation.onFrame(animation, timestamp);
|
|
249
|
-
animation.timestamp = timestamp;
|
|
250
|
-
this._setValue && this._setValue(animation.current as AnimatableValue);
|
|
251
|
-
if (finished) {
|
|
252
|
-
animation.callback && animation.callback(true /* finished */);
|
|
253
|
-
} else {
|
|
254
|
-
requestFrame(step);
|
|
255
|
-
}
|
|
144
|
+
return value;
|
|
145
|
+
} else if (category === 'RemoteFunction') {
|
|
146
|
+
const fun = () => {
|
|
147
|
+
throw new Error(`Tried to synchronously call a non-worklet function on the UI thread.
|
|
148
|
+
|
|
149
|
+
Possible solutions are:
|
|
150
|
+
a) If you want to synchronously execute this method, mark it as a worklet
|
|
151
|
+
b) If you want to execute this function on the JS thread, wrap it using \`runOnJS\``);
|
|
256
152
|
};
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
step(getTimestamp());
|
|
153
|
+
fun.__remoteFunction = objectToUnpack;
|
|
154
|
+
return fun;
|
|
260
155
|
} else {
|
|
261
|
-
|
|
156
|
+
throw new Error('data type not recognized by unpack method');
|
|
262
157
|
}
|
|
263
158
|
}
|
|
264
159
|
|
|
265
|
-
export function
|
|
266
|
-
|
|
267
|
-
|
|
160
|
+
export function registerEventHandler<T>(
|
|
161
|
+
eventHash: string,
|
|
162
|
+
eventHandler: (event: T) => void
|
|
163
|
+
): string {
|
|
164
|
+
return NativeReanimatedModule.registerEventHandler(
|
|
165
|
+
eventHash,
|
|
166
|
+
makeShareableCloneRecursive(eventHandler)
|
|
167
|
+
);
|
|
268
168
|
}
|
|
269
169
|
|
|
270
|
-
export function
|
|
271
|
-
|
|
272
|
-
return NativeReanimatedModule.makeRemote(object);
|
|
170
|
+
export function unregisterEventHandler(id: string): void {
|
|
171
|
+
return NativeReanimatedModule.unregisterEventHandler(id);
|
|
273
172
|
}
|
|
274
173
|
|
|
275
|
-
export function
|
|
276
|
-
|
|
277
|
-
inputs: any[] = [],
|
|
278
|
-
outputs: any[] = [],
|
|
279
|
-
updater: () => void = () => {
|
|
280
|
-
// noop
|
|
281
|
-
},
|
|
282
|
-
viewDescriptors: Descriptor[] | SharedValue<Descriptor[]> = []
|
|
174
|
+
export function subscribeForKeyboardEvents(
|
|
175
|
+
eventHandler: (state: number, height: number) => void
|
|
283
176
|
): number {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
mapper,
|
|
287
|
-
inputs,
|
|
288
|
-
outputs,
|
|
289
|
-
updater,
|
|
290
|
-
viewDescriptors
|
|
177
|
+
return NativeReanimatedModule.subscribeForKeyboardEvents(
|
|
178
|
+
makeShareableCloneRecursive(eventHandler)
|
|
291
179
|
);
|
|
292
180
|
}
|
|
293
181
|
|
|
294
|
-
export function
|
|
295
|
-
NativeReanimatedModule.
|
|
182
|
+
export function unsubscribeFromKeyboardEvents(listenerId: number): void {
|
|
183
|
+
return NativeReanimatedModule.unsubscribeFromKeyboardEvents(listenerId);
|
|
296
184
|
}
|
|
297
185
|
|
|
298
|
-
export
|
|
299
|
-
|
|
300
|
-
|
|
186
|
+
export function registerSensor(
|
|
187
|
+
sensorType: number,
|
|
188
|
+
interval: number,
|
|
189
|
+
eventHandler: (data: Value3D | ValueRotation) => void
|
|
190
|
+
): number {
|
|
191
|
+
return NativeReanimatedModule.registerSensor(
|
|
192
|
+
sensorType,
|
|
193
|
+
interval,
|
|
194
|
+
makeShareableCloneRecursive(eventHandler)
|
|
195
|
+
);
|
|
301
196
|
}
|
|
302
197
|
|
|
303
|
-
export function
|
|
304
|
-
|
|
305
|
-
): () => void {
|
|
306
|
-
'worklet';
|
|
307
|
-
if (!_WORKLET) {
|
|
308
|
-
return fun;
|
|
309
|
-
}
|
|
310
|
-
if (!fun.__callAsync) {
|
|
311
|
-
throw new Error(
|
|
312
|
-
"Attempting to call runOnJS with an object that is not a host function. Using runOnJS is only possible with methods that are defined on the main React-Native Javascript thread and that aren't marked as worklets"
|
|
313
|
-
);
|
|
314
|
-
} else {
|
|
315
|
-
return fun.__callAsync;
|
|
316
|
-
}
|
|
198
|
+
export function unregisterSensor(listenerId: number): void {
|
|
199
|
+
return NativeReanimatedModule.unregisterSensor(listenerId);
|
|
317
200
|
}
|
|
318
201
|
|
|
319
|
-
NativeReanimatedModule.installCoreFunctions(
|
|
320
|
-
NativeReanimatedModule.native
|
|
321
|
-
? (workletValueSetter as <T>(value: T) => void)
|
|
322
|
-
: (workletValueSetterJS as <T>(value: T) => void)
|
|
323
|
-
);
|
|
202
|
+
NativeReanimatedModule.installCoreFunctions(valueUnpacker);
|
|
324
203
|
|
|
325
204
|
if (!isWeb() && isConfigured()) {
|
|
326
205
|
const capturableConsole = console;
|
|
@@ -369,14 +248,12 @@ export function enableLayoutAnimations(
|
|
|
369
248
|
export function configureLayoutAnimations(
|
|
370
249
|
viewTag: number,
|
|
371
250
|
type: string,
|
|
372
|
-
config: LayoutAnimationFunction | Keyframe
|
|
373
|
-
viewSharedValue: SharedValue<null | Record<string, unknown>> | null
|
|
251
|
+
config: LayoutAnimationFunction | Keyframe
|
|
374
252
|
): void {
|
|
375
253
|
NativeReanimatedModule.configureLayoutAnimation(
|
|
376
254
|
viewTag,
|
|
377
255
|
type,
|
|
378
|
-
config
|
|
379
|
-
viewSharedValue
|
|
256
|
+
makeShareableCloneRecursive(config)
|
|
380
257
|
);
|
|
381
258
|
}
|
|
382
259
|
|
|
@@ -385,7 +262,3 @@ export function configureProps(uiProps: string[], nativeProps: string[]): void {
|
|
|
385
262
|
NativeReanimatedModule.configureProps(uiProps, nativeProps);
|
|
386
263
|
}
|
|
387
264
|
}
|
|
388
|
-
|
|
389
|
-
export function jestResetJsReanimatedModule() {
|
|
390
|
-
(NativeReanimatedModule as JSReanimated).jestResetModule();
|
|
391
|
-
}
|
|
@@ -2,10 +2,14 @@ import type {
|
|
|
2
2
|
AnimatedStyle,
|
|
3
3
|
StyleProps,
|
|
4
4
|
MeasuredDimensions,
|
|
5
|
+
MapperRegistry,
|
|
6
|
+
ShareableRef,
|
|
7
|
+
ShareableSyncDataHolderRef,
|
|
5
8
|
} from './commonTypes';
|
|
6
9
|
import type { ReanimatedConsole } from './core';
|
|
7
10
|
import type { FrameCallbackRegistryUI } from './frameCallback/FrameCallbackRegistryUI';
|
|
8
11
|
import type { ShadowNodeWrapper } from './hook/commonTypes';
|
|
12
|
+
import { LayoutAnimationStartFunction } from './layoutReanimation';
|
|
9
13
|
import type { NativeReanimated } from './NativeReanimated/NativeReanimated';
|
|
10
14
|
|
|
11
15
|
declare global {
|
|
@@ -18,17 +22,20 @@ declare global {
|
|
|
18
22
|
const _setGlobalConsole: (console?: ReanimatedConsole) => void;
|
|
19
23
|
const _log: (s: string) => void;
|
|
20
24
|
const _getCurrentTime: () => number;
|
|
21
|
-
const
|
|
25
|
+
const _getTimestamp: () => number;
|
|
26
|
+
const _notifyAboutProgress: (tag: number, value: number) => void;
|
|
27
|
+
const _notifyAboutEnd: (
|
|
22
28
|
tag: number,
|
|
23
|
-
|
|
29
|
+
finished: boolean,
|
|
24
30
|
removeView: boolean
|
|
25
31
|
) => void;
|
|
26
|
-
const _startObservingProgress: (
|
|
27
|
-
tag: number,
|
|
28
|
-
viewSharedValue: { value: unknown; _value: unknown },
|
|
29
|
-
type: string
|
|
30
|
-
) => void;
|
|
31
32
|
const _setGestureState: (handlerTag: number, newState: number) => void;
|
|
33
|
+
const _makeShareableClone: (value: any) => any;
|
|
34
|
+
const _updateDataSynchronously: (
|
|
35
|
+
dataHolder: ShareableSyncDataHolderRef,
|
|
36
|
+
data: ShareableRef
|
|
37
|
+
) => void;
|
|
38
|
+
const _scheduleOnJS: (fun: ShareableRef, args?: ShareableRef) => void;
|
|
32
39
|
const _updatePropsPaper: (
|
|
33
40
|
tag: number,
|
|
34
41
|
name: string,
|
|
@@ -55,12 +62,6 @@ declare global {
|
|
|
55
62
|
) => void;
|
|
56
63
|
const _chronoNow: () => number;
|
|
57
64
|
const performance: { now: () => number };
|
|
58
|
-
const LayoutAnimationRepository: {
|
|
59
|
-
configs: Record<string, unknown>;
|
|
60
|
-
registerConfig(tag: number, config: Record<string, unknown>): void;
|
|
61
|
-
removeConfig(tag: number): void;
|
|
62
|
-
startAnimationForTag(tag: number, type: string, yogaValues: unknown): void;
|
|
63
|
-
};
|
|
64
65
|
const ReanimatedDataMock: {
|
|
65
66
|
now: () => number;
|
|
66
67
|
};
|
|
@@ -77,12 +78,14 @@ declare global {
|
|
|
77
78
|
_setGlobalConsole: (console?: ReanimatedConsole) => void;
|
|
78
79
|
_log: (s: string) => void;
|
|
79
80
|
_getCurrentTime: () => number;
|
|
80
|
-
|
|
81
|
-
_startObservingProgress: (
|
|
82
|
-
tag: number,
|
|
83
|
-
flag: { value: boolean; _value: boolean }
|
|
84
|
-
) => void;
|
|
81
|
+
_getTimestamp: () => number;
|
|
85
82
|
_setGestureState: (handlerTag: number, newState: number) => void;
|
|
83
|
+
_makeShareableClone: (value: any) => any;
|
|
84
|
+
_updateDataSynchronously: (
|
|
85
|
+
ShareableSyncDataHolderRef,
|
|
86
|
+
ShareableRef
|
|
87
|
+
) => void;
|
|
88
|
+
_scheduleOnJS: (fun: ShareableRef, args?: ShareableRef) => void;
|
|
86
89
|
_updatePropsPaper: (
|
|
87
90
|
tag: number,
|
|
88
91
|
name: string,
|
|
@@ -109,19 +112,16 @@ declare global {
|
|
|
109
112
|
) => void;
|
|
110
113
|
_chronoNow: () => number;
|
|
111
114
|
performance: { now: () => number };
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
tag: number,
|
|
115
|
-
type: string,
|
|
116
|
-
yogaValues: Record<string, number>,
|
|
117
|
-
config: LayoutAnimationFunction | Keyframe,
|
|
118
|
-
viewSharedValue: { value: unknown; _value: unknown }
|
|
119
|
-
): void;
|
|
115
|
+
LayoutAnimationsManager: {
|
|
116
|
+
start: LayoutAnimationStartFunction;
|
|
120
117
|
};
|
|
121
118
|
ReanimatedDataMock: {
|
|
122
119
|
now: () => number;
|
|
123
120
|
};
|
|
124
121
|
_frameCallbackRegistry: FrameCallbackRegistryUI;
|
|
122
|
+
__workletsCache?: Map<string, (...args: any[]) => any>;
|
|
123
|
+
__handleCache?: WeakMap<any, any>;
|
|
124
|
+
__mapperRegistry?: MapperRegistry;
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
makeMutable,
|
|
4
|
+
subscribeForKeyboardEvents,
|
|
5
|
+
unsubscribeFromKeyboardEvents,
|
|
6
|
+
} from '../core';
|
|
4
7
|
import { AnimatedKeyboardInfo, KeyboardState } from '../commonTypes';
|
|
5
8
|
|
|
6
9
|
export function useAnimatedKeyboard(): AnimatedKeyboardInfo {
|
|
@@ -10,24 +13,30 @@ export function useAnimatedKeyboard(): AnimatedKeyboardInfo {
|
|
|
10
13
|
|
|
11
14
|
if (ref.current === null) {
|
|
12
15
|
const keyboardEventData: AnimatedKeyboardInfo = {
|
|
13
|
-
state: makeMutable(KeyboardState.UNKNOWN),
|
|
16
|
+
state: makeMutable<KeyboardState>(KeyboardState.UNKNOWN),
|
|
14
17
|
height: makeMutable(0),
|
|
15
18
|
};
|
|
16
|
-
listenerId.current =
|
|
17
|
-
|
|
19
|
+
listenerId.current = subscribeForKeyboardEvents((state, height) => {
|
|
20
|
+
'worklet';
|
|
21
|
+
keyboardEventData.state.value = state;
|
|
22
|
+
keyboardEventData.height.value = height;
|
|
23
|
+
});
|
|
18
24
|
ref.current = keyboardEventData;
|
|
19
25
|
isSubscribed.current = true;
|
|
20
26
|
}
|
|
21
27
|
useEffect(() => {
|
|
22
28
|
if (isSubscribed.current === false && ref.current !== null) {
|
|
29
|
+
const keyboardEventData = ref.current;
|
|
23
30
|
// subscribe again after Fast Refresh
|
|
24
|
-
listenerId.current =
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
listenerId.current = subscribeForKeyboardEvents((state, height) => {
|
|
32
|
+
'worklet';
|
|
33
|
+
keyboardEventData.state.value = state;
|
|
34
|
+
keyboardEventData.height.value = height;
|
|
35
|
+
});
|
|
27
36
|
isSubscribed.current = true;
|
|
28
37
|
}
|
|
29
38
|
return () => {
|
|
30
|
-
|
|
39
|
+
unsubscribeFromKeyboardEvents(listenerId.current);
|
|
31
40
|
isSubscribed.current = false;
|
|
32
41
|
};
|
|
33
42
|
}, []);
|
|
@@ -4,30 +4,48 @@ import { RefObjectFunction } from './commonTypes';
|
|
|
4
4
|
import { ShadowNodeWrapper } from '../commonTypes';
|
|
5
5
|
import { getTag } from '../NativeMethods';
|
|
6
6
|
import { getShadowNodeWrapperFromHostInstance } from '../fabricUtils';
|
|
7
|
+
import {
|
|
8
|
+
makeShareableCloneRecursive,
|
|
9
|
+
makeShareableShadowNodeWrapper,
|
|
10
|
+
registerShareableMapping,
|
|
11
|
+
} from '../shareables';
|
|
12
|
+
|
|
13
|
+
function getShareableShadowNodeFromComponent(
|
|
14
|
+
component: Component
|
|
15
|
+
): ShadowNodeWrapper {
|
|
16
|
+
return makeShareableShadowNodeWrapper(
|
|
17
|
+
getShadowNodeWrapperFromHostInstance(component)
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const getTagValueFunction = global._IS_FABRIC
|
|
22
|
+
? getShareableShadowNodeFromComponent
|
|
23
|
+
: getTag;
|
|
7
24
|
|
|
8
25
|
export function useAnimatedRef<T extends Component>(): RefObjectFunction<T> {
|
|
9
26
|
const tag = useSharedValue<number | ShadowNodeWrapper | null>(-1);
|
|
10
27
|
const ref = useRef<RefObjectFunction<T>>();
|
|
11
|
-
const isFabric = global._IS_FABRIC;
|
|
12
28
|
|
|
13
29
|
if (!ref.current) {
|
|
14
30
|
const fun: RefObjectFunction<T> = <RefObjectFunction<T>>((component) => {
|
|
15
|
-
'worklet';
|
|
16
31
|
// enters when ref is set by attaching to a component
|
|
17
32
|
if (component) {
|
|
18
|
-
tag.value =
|
|
19
|
-
? getShadowNodeWrapperFromHostInstance(component)
|
|
20
|
-
: getTag(component);
|
|
33
|
+
tag.value = getTagValueFunction(component);
|
|
21
34
|
fun.current = component;
|
|
22
35
|
}
|
|
23
36
|
return tag.value;
|
|
24
37
|
});
|
|
25
38
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
39
|
+
fun.current = null;
|
|
40
|
+
|
|
41
|
+
const remoteRef = makeShareableCloneRecursive({
|
|
42
|
+
__init: () => {
|
|
43
|
+
'worklet';
|
|
44
|
+
return () => tag.value;
|
|
45
|
+
},
|
|
30
46
|
});
|
|
47
|
+
registerShareableMapping(fun, remoteRef);
|
|
48
|
+
|
|
31
49
|
ref.current = fun;
|
|
32
50
|
}
|
|
33
51
|
|