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/src/reanimated2/core.ts
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
|
import {
|
|
6
6
|
BasicWorkletFunction,
|
|
7
7
|
WorkletFunction,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from './commonTypes';
|
|
11
11
|
import {
|
|
12
12
|
AnimationObject,
|
|
13
|
-
|
|
13
|
+
AnimatableValue,
|
|
14
14
|
Timestamp,
|
|
15
15
|
} from './animation/commonTypes';
|
|
16
16
|
import { Descriptor } from './hook/commonTypes';
|
|
@@ -31,11 +31,17 @@ export type ReanimatedConsole = Pick<
|
|
|
31
31
|
Console,
|
|
32
32
|
'debug' | 'log' | 'warn' | 'info' | 'error'
|
|
33
33
|
>;
|
|
34
|
+
|
|
35
|
+
export type WorkletValue =
|
|
36
|
+
| (() => AnimationObject)
|
|
37
|
+
| AnimationObject
|
|
38
|
+
| AnimatableValue
|
|
39
|
+
| Descriptor;
|
|
34
40
|
interface WorkletValueSetterContext {
|
|
35
41
|
_animation?: AnimationObject | null;
|
|
36
|
-
_value?:
|
|
37
|
-
value?:
|
|
38
|
-
_setValue?: (val:
|
|
42
|
+
_value?: AnimatableValue | Descriptor;
|
|
43
|
+
value?: AnimatableValue;
|
|
44
|
+
_setValue?: (val: AnimatableValue | Descriptor) => void;
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
const testWorklet: BasicWorkletFunction<void> = () => {
|
|
@@ -183,9 +189,9 @@ export function getTimestamp(): number {
|
|
|
183
189
|
return _getTimestamp();
|
|
184
190
|
}
|
|
185
191
|
|
|
186
|
-
function workletValueSetter(
|
|
192
|
+
function workletValueSetter<T extends WorkletValue>(
|
|
187
193
|
this: WorkletValueSetterContext,
|
|
188
|
-
value:
|
|
194
|
+
value: T
|
|
189
195
|
): void {
|
|
190
196
|
'worklet';
|
|
191
197
|
const previousAnimation = this._animation;
|
|
@@ -200,7 +206,9 @@ function workletValueSetter(
|
|
|
200
206
|
(value as AnimationObject).onFrame !== undefined)
|
|
201
207
|
) {
|
|
202
208
|
const animation: AnimationObject =
|
|
203
|
-
typeof value === 'function'
|
|
209
|
+
typeof value === 'function'
|
|
210
|
+
? (value as () => AnimationObject)()
|
|
211
|
+
: (value as AnimationObject);
|
|
204
212
|
// prevent setting again to the same value
|
|
205
213
|
// and triggering the mappers that treat this value as an input
|
|
206
214
|
// 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)
|
|
@@ -244,15 +252,15 @@ function workletValueSetter(
|
|
|
244
252
|
if (this._value === value) {
|
|
245
253
|
return;
|
|
246
254
|
}
|
|
247
|
-
this._value = value as Descriptor |
|
|
255
|
+
this._value = value as Descriptor | AnimatableValue;
|
|
248
256
|
}
|
|
249
257
|
}
|
|
250
258
|
|
|
251
259
|
// We cannot use pushFrame
|
|
252
260
|
// so we use own implementation for js
|
|
253
|
-
function workletValueSetterJS(
|
|
261
|
+
function workletValueSetterJS<T extends WorkletValue>(
|
|
254
262
|
this: WorkletValueSetterContext,
|
|
255
|
-
value:
|
|
263
|
+
value: T
|
|
256
264
|
): void {
|
|
257
265
|
const previousAnimation = this._animation;
|
|
258
266
|
if (previousAnimation) {
|
|
@@ -267,7 +275,9 @@ function workletValueSetterJS(
|
|
|
267
275
|
) {
|
|
268
276
|
// animated set
|
|
269
277
|
const animation: AnimationObject =
|
|
270
|
-
typeof value === 'function'
|
|
278
|
+
typeof value === 'function'
|
|
279
|
+
? (value as () => AnimationObject)()
|
|
280
|
+
: (value as AnimationObject);
|
|
271
281
|
let initializeAnimation: ((timestamp: number) => void) | null = (
|
|
272
282
|
timestamp: number
|
|
273
283
|
) => {
|
|
@@ -284,7 +294,7 @@ function workletValueSetterJS(
|
|
|
284
294
|
}
|
|
285
295
|
const finished = animation.onFrame(animation, timestamp);
|
|
286
296
|
animation.timestamp = timestamp;
|
|
287
|
-
this._setValue && this._setValue(animation.current as
|
|
297
|
+
this._setValue && this._setValue(animation.current as AnimatableValue);
|
|
288
298
|
if (finished) {
|
|
289
299
|
animation.callback && animation.callback(true /* finished */);
|
|
290
300
|
} else {
|
|
@@ -296,7 +306,7 @@ function workletValueSetterJS(
|
|
|
296
306
|
|
|
297
307
|
requestFrame(step);
|
|
298
308
|
} else {
|
|
299
|
-
this._setValue && this._setValue(value as
|
|
309
|
+
this._setValue && this._setValue(value as AnimatableValue | Descriptor);
|
|
300
310
|
}
|
|
301
311
|
}
|
|
302
312
|
|
|
@@ -356,11 +366,13 @@ export function runOnJS<A extends any[], R>(
|
|
|
356
366
|
|
|
357
367
|
if (!NativeReanimatedModule.useOnlyV1) {
|
|
358
368
|
NativeReanimatedModule.installCoreFunctions(
|
|
359
|
-
NativeReanimatedModule.native
|
|
369
|
+
NativeReanimatedModule.native
|
|
370
|
+
? (workletValueSetter as <T>(value: T) => void)
|
|
371
|
+
: (workletValueSetterJS as <T>(value: T) => void)
|
|
360
372
|
);
|
|
361
373
|
|
|
362
|
-
|
|
363
|
-
|
|
374
|
+
if (!isWeb() && isConfigured()) {
|
|
375
|
+
const capturableConsole = console;
|
|
364
376
|
runOnUI(() => {
|
|
365
377
|
'worklet';
|
|
366
378
|
const console = {
|
|
@@ -371,5 +383,38 @@ if (!NativeReanimatedModule.useOnlyV1) {
|
|
|
371
383
|
info: runOnJS(capturableConsole.info),
|
|
372
384
|
};
|
|
373
385
|
_setGlobalConsole(console);
|
|
386
|
+
global.performance = {
|
|
387
|
+
now: global._chronoNow,
|
|
388
|
+
};
|
|
374
389
|
})();
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
type FeaturesConfig = {
|
|
394
|
+
enableLayoutAnimations: boolean;
|
|
395
|
+
setByUser: boolean;
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
let featuresConfig: FeaturesConfig = {
|
|
399
|
+
enableLayoutAnimations: false,
|
|
400
|
+
setByUser: false,
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
export function enableLayoutAnimations(
|
|
404
|
+
flag: boolean,
|
|
405
|
+
isCallByUser = true
|
|
406
|
+
): void {
|
|
407
|
+
if (isCallByUser) {
|
|
408
|
+
featuresConfig = {
|
|
409
|
+
enableLayoutAnimations: flag,
|
|
410
|
+
setByUser: true,
|
|
411
|
+
};
|
|
412
|
+
NativeReanimatedModule.enableLayoutAnimations(flag);
|
|
413
|
+
} else if (
|
|
414
|
+
!featuresConfig.setByUser &&
|
|
415
|
+
featuresConfig.enableLayoutAnimations !== flag
|
|
416
|
+
) {
|
|
417
|
+
featuresConfig.enableLayoutAnimations = flag;
|
|
418
|
+
NativeReanimatedModule.enableLayoutAnimations(flag);
|
|
419
|
+
}
|
|
375
420
|
}
|
|
@@ -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;
|
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
ViewRefSet,
|
|
32
32
|
} from '../ViewDescriptorsSet';
|
|
33
33
|
import { isJest, shouldBeUseWeb } from '../PlatformChecker';
|
|
34
|
-
import { AnimationObject
|
|
34
|
+
import { AnimationObject } from '../animation/commonTypes';
|
|
35
35
|
import {
|
|
36
36
|
AdapterWorkletFunction,
|
|
37
37
|
AnimatedStyle,
|
|
@@ -122,7 +122,7 @@ function prepareAnimation(
|
|
|
122
122
|
function runAnimations(
|
|
123
123
|
animation: AnimatedStyle,
|
|
124
124
|
timestamp: Timestamp,
|
|
125
|
-
key:
|
|
125
|
+
key: number | string,
|
|
126
126
|
result: AnimatedStyle,
|
|
127
127
|
animationsActive: SharedValue<boolean>
|
|
128
128
|
): boolean {
|
|
@@ -2,21 +2,11 @@ import MapperRegistry from './MapperRegistry';
|
|
|
2
2
|
import MutableValue from './MutableValue';
|
|
3
3
|
import Mapper from './Mapper';
|
|
4
4
|
import { NativeReanimated } from '../NativeReanimated/NativeReanimated';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
PrimitiveValue,
|
|
8
|
-
Timestamp,
|
|
9
|
-
} from '../animation/commonTypes';
|
|
10
|
-
import { Descriptor } from '../hook/commonTypes';
|
|
5
|
+
import { Timestamp } from '../animation/commonTypes';
|
|
6
|
+
import { NestedObjectValues } from '../commonTypes';
|
|
11
7
|
|
|
12
8
|
export default class JSReanimated extends NativeReanimated {
|
|
13
|
-
_valueSetter?: (
|
|
14
|
-
value:
|
|
15
|
-
| (() => AnimationObject)
|
|
16
|
-
| AnimationObject
|
|
17
|
-
| PrimitiveValue
|
|
18
|
-
| Descriptor
|
|
19
|
-
) => void = undefined;
|
|
9
|
+
_valueSetter?: <T>(value: T) => void = undefined;
|
|
20
10
|
|
|
21
11
|
_renderRequested = false;
|
|
22
12
|
_mapperRegistry = new MapperRegistry(this);
|
|
@@ -68,15 +58,7 @@ export default class JSReanimated extends NativeReanimated {
|
|
|
68
58
|
}
|
|
69
59
|
}
|
|
70
60
|
|
|
71
|
-
installCoreFunctions(
|
|
72
|
-
valueSetter: (
|
|
73
|
-
value:
|
|
74
|
-
| (() => AnimationObject)
|
|
75
|
-
| AnimationObject
|
|
76
|
-
| PrimitiveValue
|
|
77
|
-
| Descriptor
|
|
78
|
-
) => void
|
|
79
|
-
): void {
|
|
61
|
+
installCoreFunctions(valueSetter: <T>(value: T) => void): void {
|
|
80
62
|
this._valueSetter = valueSetter;
|
|
81
63
|
}
|
|
82
64
|
|
|
@@ -84,8 +66,9 @@ export default class JSReanimated extends NativeReanimated {
|
|
|
84
66
|
return value;
|
|
85
67
|
}
|
|
86
68
|
|
|
87
|
-
makeMutable<T>(value: T): MutableValue {
|
|
88
|
-
|
|
69
|
+
makeMutable<T>(value: T): MutableValue<T> {
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
71
|
+
return new MutableValue(value, this._valueSetter!);
|
|
89
72
|
}
|
|
90
73
|
|
|
91
74
|
makeRemote<T>(object = {}): T {
|
|
@@ -94,8 +77,8 @@ export default class JSReanimated extends NativeReanimated {
|
|
|
94
77
|
|
|
95
78
|
startMapper(
|
|
96
79
|
mapper: () => void,
|
|
97
|
-
inputs:
|
|
98
|
-
outputs:
|
|
80
|
+
inputs: NestedObjectValues<MutableValue<unknown>>[] = [],
|
|
81
|
+
outputs: NestedObjectValues<MutableValue<unknown>>[] = []
|
|
99
82
|
): number {
|
|
100
83
|
const instance = new Mapper(this, mapper, inputs, outputs);
|
|
101
84
|
const mapperId = this._mapperRegistry.startMapper(instance);
|
|
@@ -115,4 +98,10 @@ export default class JSReanimated extends NativeReanimated {
|
|
|
115
98
|
unregisterEventHandler(_: string): void {
|
|
116
99
|
// noop
|
|
117
100
|
}
|
|
101
|
+
|
|
102
|
+
enableLayoutAnimations() {
|
|
103
|
+
console.warn(
|
|
104
|
+
'[Reanimated] enableLayoutAnimations is not available for WEB yet'
|
|
105
|
+
);
|
|
106
|
+
}
|
|
118
107
|
}
|
|
@@ -1,13 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { NestedObjectValues } from '../commonTypes';
|
|
2
|
+
import JSReanimated from './JSReanimated';
|
|
3
3
|
import MutableValue from './MutableValue';
|
|
4
4
|
|
|
5
|
-
export default class Mapper {
|
|
5
|
+
export default class Mapper<T> {
|
|
6
6
|
static MAPPER_ID = 1;
|
|
7
|
+
id: number;
|
|
8
|
+
inputs: MutableValue<T>[];
|
|
9
|
+
outputs: MutableValue<T>[];
|
|
10
|
+
mapper: () => void;
|
|
7
11
|
|
|
8
12
|
dirty = true;
|
|
9
13
|
|
|
10
|
-
constructor(
|
|
14
|
+
constructor(
|
|
15
|
+
module: JSReanimated,
|
|
16
|
+
mapper: () => void,
|
|
17
|
+
inputs: NestedObjectValues<MutableValue<T>>[] = [],
|
|
18
|
+
outputs: NestedObjectValues<MutableValue<T>>[] = []
|
|
19
|
+
) {
|
|
11
20
|
this.id = Mapper.MAPPER_ID++;
|
|
12
21
|
this.inputs = this.extractMutablesFromArray(inputs);
|
|
13
22
|
this.outputs = this.extractMutablesFromArray(outputs);
|
|
@@ -23,16 +32,20 @@ export default class Mapper {
|
|
|
23
32
|
});
|
|
24
33
|
}
|
|
25
34
|
|
|
26
|
-
execute() {
|
|
35
|
+
execute(): void {
|
|
27
36
|
this.dirty = false;
|
|
28
37
|
this.mapper();
|
|
29
38
|
}
|
|
30
39
|
|
|
31
|
-
extractMutablesFromArray(
|
|
32
|
-
|
|
40
|
+
extractMutablesFromArray<T>(
|
|
41
|
+
array: NestedObjectValues<MutableValue<T>>
|
|
42
|
+
): MutableValue<T>[] {
|
|
43
|
+
const res: MutableValue<T>[] = [];
|
|
33
44
|
|
|
34
|
-
function extractMutables(value) {
|
|
35
|
-
if (value
|
|
45
|
+
function extractMutables(value: NestedObjectValues<MutableValue<T>>) {
|
|
46
|
+
if (value == null) {
|
|
47
|
+
// return;
|
|
48
|
+
} else if (value instanceof MutableValue) {
|
|
36
49
|
res.push(value);
|
|
37
50
|
} else if (Array.isArray(value)) {
|
|
38
51
|
value.forEach((v) => extractMutables(v));
|
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import JSReanimated from './JSReanimated';
|
|
2
|
+
import Mapper from './Mapper';
|
|
3
|
+
|
|
4
|
+
export default class MapperRegistry<T> {
|
|
5
|
+
sortedMappers: Mapper<T>[] = [];
|
|
6
|
+
mappers: Map<number, Mapper<T>> = new Map();
|
|
7
|
+
_module: JSReanimated;
|
|
6
8
|
|
|
7
9
|
updatedSinceLastExecute = false;
|
|
8
10
|
|
|
9
|
-
constructor(module) {
|
|
11
|
+
constructor(module: JSReanimated) {
|
|
10
12
|
this._module = module;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
startMapper(mapper) {
|
|
15
|
+
startMapper(mapper: Mapper<T>): number {
|
|
14
16
|
this.mappers.set(mapper.id, mapper);
|
|
15
17
|
this.updatedSinceLastExecute = true;
|
|
16
18
|
return mapper.id;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
stopMapper(id) {
|
|
21
|
+
stopMapper(id: number): void {
|
|
20
22
|
this.mappers.delete(id);
|
|
21
23
|
this.updatedSinceLastExecute = true;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
execute() {
|
|
26
|
+
execute(): void {
|
|
25
27
|
if (this.updatedSinceLastExecute) {
|
|
26
28
|
this.updateOrder();
|
|
27
29
|
this.updatedSinceLastExecute = false;
|
|
@@ -35,10 +37,10 @@ export default class MapperRegistry {
|
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
updateOrder() {
|
|
40
|
+
updateOrder(): void {
|
|
39
41
|
const nodes = [...this.mappers.values()].map((mapper) => new Node(mapper));
|
|
40
42
|
|
|
41
|
-
const mappersById = {};
|
|
43
|
+
const mappersById: Record<number, Mapper<T>> = {};
|
|
42
44
|
this.mappers.forEach((mapper) => {
|
|
43
45
|
mappersById[mapper.id] = mapper;
|
|
44
46
|
});
|
|
@@ -75,9 +77,9 @@ export default class MapperRegistry {
|
|
|
75
77
|
}
|
|
76
78
|
}
|
|
77
79
|
|
|
78
|
-
const post = {};
|
|
80
|
+
const post: Record<number, number> = {};
|
|
79
81
|
let postCounter = 1;
|
|
80
|
-
const dfs = (node) => {
|
|
82
|
+
const dfs = (node: Node<T>) => {
|
|
81
83
|
const index = nodes.indexOf(node);
|
|
82
84
|
if (index === -1) {
|
|
83
85
|
// this node has already been handled
|
|
@@ -99,7 +101,8 @@ export default class MapperRegistry {
|
|
|
99
101
|
while (nodes.length) dfs(nodes[0]);
|
|
100
102
|
|
|
101
103
|
const postArray = Object.keys(post).map((key) => {
|
|
102
|
-
|
|
104
|
+
const num = parseInt(key);
|
|
105
|
+
return [num, post[num]];
|
|
103
106
|
});
|
|
104
107
|
postArray.sort((a, b) => {
|
|
105
108
|
return b[1] - a[1];
|
|
@@ -114,16 +117,16 @@ export default class MapperRegistry {
|
|
|
114
117
|
}
|
|
115
118
|
}
|
|
116
119
|
|
|
117
|
-
get needRunOnRender() {
|
|
120
|
+
get needRunOnRender(): boolean {
|
|
118
121
|
return this.updatedSinceLastExecute;
|
|
119
122
|
}
|
|
120
123
|
}
|
|
121
124
|
|
|
122
|
-
class Node {
|
|
123
|
-
mapper
|
|
124
|
-
children
|
|
125
|
+
class Node<T> {
|
|
126
|
+
mapper: Mapper<T>;
|
|
127
|
+
children: Node<T>[];
|
|
125
128
|
|
|
126
|
-
constructor(mapper
|
|
129
|
+
constructor(mapper: Mapper<T>, children = []) {
|
|
127
130
|
this.mapper = mapper;
|
|
128
131
|
this.children = children;
|
|
129
132
|
}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
// @ts-nocheck
|
|
3
|
-
export default class MutableValue {
|
|
1
|
+
export default class MutableValue<T> {
|
|
4
2
|
static MUTABLE_ID = 1;
|
|
5
|
-
|
|
3
|
+
_id: number;
|
|
4
|
+
_value: T;
|
|
5
|
+
_setter: (value: T) => void;
|
|
6
6
|
_animation = null;
|
|
7
|
-
_listeners = [];
|
|
7
|
+
_listeners: (() => void)[] = [];
|
|
8
8
|
|
|
9
|
-
constructor(value, setter) {
|
|
9
|
+
constructor(value: T, setter: (value: T) => void) {
|
|
10
10
|
this._id = MutableValue.MUTABLE_ID++;
|
|
11
11
|
this._value = value;
|
|
12
12
|
this._setter = setter;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
get value() {
|
|
15
|
+
get value(): T {
|
|
16
16
|
return this._value;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
set value(nextValue) {
|
|
19
|
+
set value(nextValue: T) {
|
|
20
20
|
this._setter(nextValue);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
// this changes the value finally and is supposed to be called from this._setter
|
|
24
|
-
_setValue(newValue) {
|
|
24
|
+
_setValue(newValue: T): void {
|
|
25
25
|
this._value = newValue;
|
|
26
26
|
this._triggerListener();
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
addListener(listener) {
|
|
29
|
+
addListener(listener: () => void): void {
|
|
30
30
|
this._listeners.push(listener);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
_triggerListener() {
|
|
33
|
+
_triggerListener(): void {
|
|
34
34
|
for (let i = 0, len = this._listeners.length; i < len; ++i) {
|
|
35
35
|
this._listeners[i]();
|
|
36
36
|
}
|
|
@@ -1,10 +1,18 @@
|
|
|
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';
|
|
3
|
+
import { AnimatedStyle, StyleProps } from '../commonTypes';
|
|
5
4
|
|
|
6
5
|
const reanimatedJS = new JSReanimated();
|
|
7
6
|
|
|
7
|
+
interface JSReanimatedComponent {
|
|
8
|
+
previousStyle: StyleProps;
|
|
9
|
+
setNativeProps: (style: StyleProps) => void;
|
|
10
|
+
props: Record<string, string | number>;
|
|
11
|
+
_touchableNode: {
|
|
12
|
+
setAttribute: (key: string, props: unknown) => void;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
8
16
|
if (shouldBeUseWeb()) {
|
|
9
17
|
global._frameTimestamp = null;
|
|
10
18
|
global._setGlobalConsole = (_val) => {
|
|
@@ -28,12 +36,21 @@ if (shouldBeUseWeb()) {
|
|
|
28
36
|
"[Reanimated] You can't use 'scrollTo' method with Chrome Debugger or with web version"
|
|
29
37
|
);
|
|
30
38
|
};
|
|
39
|
+
global._setGestureState = () => {
|
|
40
|
+
console.warn(
|
|
41
|
+
"[Reanimated] You can't use 'setGestureState' method with Chrome Debugger or with web version"
|
|
42
|
+
);
|
|
43
|
+
};
|
|
31
44
|
}
|
|
32
45
|
|
|
33
|
-
export const _updatePropsJS = (
|
|
34
|
-
|
|
46
|
+
export const _updatePropsJS = (
|
|
47
|
+
updates: StyleProps | AnimatedStyle,
|
|
48
|
+
viewRef: { _component?: JSReanimatedComponent }
|
|
49
|
+
): void => {
|
|
50
|
+
if (viewRef._component) {
|
|
51
|
+
const component = viewRef._component;
|
|
35
52
|
const [rawStyles] = Object.keys(updates).reduce(
|
|
36
|
-
(acc, key) => {
|
|
53
|
+
(acc: [StyleProps, AnimatedStyle], key) => {
|
|
37
54
|
const value = updates[key];
|
|
38
55
|
const index = typeof value === 'function' ? 1 : 0;
|
|
39
56
|
acc[index][key] = value;
|
|
@@ -42,18 +59,15 @@ export const _updatePropsJS = (updates, viewRef) => {
|
|
|
42
59
|
[{}, {}]
|
|
43
60
|
);
|
|
44
61
|
|
|
45
|
-
if (typeof
|
|
46
|
-
setNativeProps(
|
|
47
|
-
} else if (Object.keys(
|
|
48
|
-
Object.keys(
|
|
62
|
+
if (typeof component.setNativeProps === 'function') {
|
|
63
|
+
setNativeProps(component, rawStyles);
|
|
64
|
+
} else if (Object.keys(component.props).length > 0) {
|
|
65
|
+
Object.keys(component.props).forEach((key) => {
|
|
49
66
|
if (!rawStyles[key]) {
|
|
50
67
|
return;
|
|
51
68
|
}
|
|
52
69
|
const dashedKey = key.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());
|
|
53
|
-
|
|
54
|
-
dashedKey,
|
|
55
|
-
rawStyles[key]
|
|
56
|
-
);
|
|
70
|
+
component._touchableNode.setAttribute(dashedKey, rawStyles[key]);
|
|
57
71
|
});
|
|
58
72
|
} else {
|
|
59
73
|
console.warn('It is not possible to manipulate component');
|
|
@@ -61,7 +75,10 @@ export const _updatePropsJS = (updates, viewRef) => {
|
|
|
61
75
|
}
|
|
62
76
|
};
|
|
63
77
|
|
|
64
|
-
const setNativeProps = (
|
|
78
|
+
const setNativeProps = (
|
|
79
|
+
component: JSReanimatedComponent,
|
|
80
|
+
style: StyleProps
|
|
81
|
+
): void => {
|
|
65
82
|
const previousStyle = component.previousStyle ? component.previousStyle : {};
|
|
66
83
|
const currentStyle = { ...previousStyle, ...style };
|
|
67
84
|
component.previousStyle = currentStyle;
|
|
@@ -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
|
|
|
5
7
|
runOnUI(() => {
|
|
6
8
|
'worklet';
|
|
@@ -36,13 +38,22 @@ runOnUI(() => {
|
|
|
36
38
|
for (const key in layoutAnimation) {
|
|
37
39
|
currentAnimation[key] = layoutAnimation[key];
|
|
38
40
|
}
|
|
39
|
-
enteringAnimationForTag[tag] = null;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
const sv: { value: boolean; _value: boolean } = configs[tag].sv;
|
|
43
44
|
_stopObservingProgress(tag, false);
|
|
44
45
|
_startObservingProgress(tag, sv);
|
|
45
|
-
|
|
46
|
+
|
|
47
|
+
const backupColor: Record<string, string> = {};
|
|
48
|
+
for (const key in style.initialValues) {
|
|
49
|
+
if (ColorProperties.includes(key)) {
|
|
50
|
+
const value = style.initialValues[key];
|
|
51
|
+
backupColor[key] = value;
|
|
52
|
+
style.initialValues[key] = processColor(value);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
sv.value = Object.assign({}, sv._value, style.initialValues);
|
|
46
57
|
_stopObservingProgress(tag, false);
|
|
47
58
|
const animation = withStyleAnimation(currentAnimation);
|
|
48
59
|
|
|
@@ -51,10 +62,12 @@ runOnUI(() => {
|
|
|
51
62
|
_stopObservingProgress(tag, finished);
|
|
52
63
|
}
|
|
53
64
|
style.callback && style.callback(finished);
|
|
54
|
-
if (type === 'entering') {
|
|
55
|
-
enteringAnimationForTag[tag] = null;
|
|
56
|
-
}
|
|
57
65
|
};
|
|
66
|
+
|
|
67
|
+
if (backupColor) {
|
|
68
|
+
configs[tag].sv._value = { ...configs[tag].sv.value, ...backupColor };
|
|
69
|
+
}
|
|
70
|
+
|
|
58
71
|
configs[tag].sv.value = animation;
|
|
59
72
|
_startObservingProgress(tag, sv);
|
|
60
73
|
},
|
|
@@ -14,32 +14,43 @@ export type LayoutAnimation = {
|
|
|
14
14
|
|
|
15
15
|
export type AnimationFunction = (a?: any, b?: any, c?: any) => any; // this is just a temporary mock
|
|
16
16
|
|
|
17
|
-
export interface
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
export interface EntryAnimationsValues {
|
|
18
|
+
targetOriginX: number;
|
|
19
|
+
targetOriginY: number;
|
|
20
|
+
targetWidth: number;
|
|
21
|
+
targetHeight: number;
|
|
22
|
+
targetGlobalOriginX: number;
|
|
23
|
+
targetGlobalOriginY: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ExitAnimationsValues {
|
|
27
|
+
currentOriginX: number;
|
|
28
|
+
currentOriginY: number;
|
|
29
|
+
currentWidth: number;
|
|
30
|
+
currentHeight: number;
|
|
31
|
+
currentGlobalOriginX: number;
|
|
32
|
+
currentGlobalOriginY: number;
|
|
24
33
|
}
|
|
25
34
|
|
|
26
35
|
export type EntryExitAnimationFunction = (
|
|
27
|
-
targetValues:
|
|
36
|
+
targetValues: EntryAnimationsValues | ExitAnimationsValues
|
|
28
37
|
) => LayoutAnimation;
|
|
29
38
|
|
|
39
|
+
export type AnimationConfigFunction<T> = (targetValues: T) => LayoutAnimation;
|
|
40
|
+
|
|
30
41
|
export interface LayoutAnimationsValues {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
currentOriginX: number;
|
|
43
|
+
currentOriginY: number;
|
|
44
|
+
currentWidth: number;
|
|
45
|
+
currentHeight: number;
|
|
46
|
+
currentGlobalOriginX: number;
|
|
47
|
+
currentGlobalOriginY: number;
|
|
48
|
+
targetOriginX: number;
|
|
49
|
+
targetOriginY: number;
|
|
50
|
+
targetWidth: number;
|
|
51
|
+
targetHeight: number;
|
|
52
|
+
targetGlobalOriginX: number;
|
|
53
|
+
targetGlobalOriginY: number;
|
|
43
54
|
windowWidth: number;
|
|
44
55
|
windowHeight: number;
|
|
45
56
|
}
|
|
@@ -76,3 +87,11 @@ export type LayoutAnimationAndConfig = [
|
|
|
76
87
|
export interface IEntryExitAnimationBuilder {
|
|
77
88
|
build: () => EntryExitAnimationFunction;
|
|
78
89
|
}
|
|
90
|
+
|
|
91
|
+
export interface IEntryAnimationBuilder {
|
|
92
|
+
build: () => AnimationConfigFunction<EntryAnimationsValues>;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface IExitAnimationBuilder {
|
|
96
|
+
build: () => AnimationConfigFunction<ExitAnimationsValues>;
|
|
97
|
+
}
|