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
|
@@ -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', () => {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
/* global _WORKLET _measure _scrollTo */
|
|
1
|
+
/* global _WORKLET _measure _scrollTo _setGestureState */
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3
|
+
// @ts-nocheck
|
|
2
4
|
import { Component } from 'react';
|
|
3
5
|
import { findNodeHandle } from 'react-native';
|
|
4
6
|
import { RefObjectFunction } from './hook/useAnimatedRef';
|
|
@@ -47,3 +49,13 @@ export function scrollTo(
|
|
|
47
49
|
const viewTag = animatedRef();
|
|
48
50
|
_scrollTo(viewTag, x, y, animated);
|
|
49
51
|
}
|
|
52
|
+
|
|
53
|
+
export function setGestureState(handlerTag: number, newState: number): void {
|
|
54
|
+
'worklet';
|
|
55
|
+
if (!_WORKLET && !isChromeDebugger()) {
|
|
56
|
+
console.warn(
|
|
57
|
+
'[Reanimated] You can not use setGestureState in non-worklet function.'
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
_setGestureState(handlerTag, newState);
|
|
61
|
+
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { AnimationObject } from '../animation';
|
|
2
|
-
import { PrimitiveValue } from '../animation/commonTypes';
|
|
3
1
|
import { SharedValue } from '../commonTypes';
|
|
4
2
|
import { Descriptor } from '../hook/commonTypes';
|
|
5
3
|
|
|
@@ -13,15 +11,7 @@ export class NativeReanimated {
|
|
|
13
11
|
this.useOnlyV1 = InnerNativeModule === null;
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
installCoreFunctions(
|
|
17
|
-
valueSetter: (
|
|
18
|
-
value:
|
|
19
|
-
| (() => AnimationObject)
|
|
20
|
-
| AnimationObject
|
|
21
|
-
| PrimitiveValue
|
|
22
|
-
| Descriptor
|
|
23
|
-
) => void
|
|
24
|
-
): void {
|
|
14
|
+
installCoreFunctions(valueSetter: <T>(value: T) => void): void {
|
|
25
15
|
return InnerNativeModule.installCoreFunctions(valueSetter);
|
|
26
16
|
}
|
|
27
17
|
|
|
@@ -75,4 +65,8 @@ export class NativeReanimated {
|
|
|
75
65
|
): Promise<T> {
|
|
76
66
|
return InnerNativeModule.getViewProp(viewTag, propName, callback);
|
|
77
67
|
}
|
|
68
|
+
|
|
69
|
+
enableLayoutAnimations(flag: boolean): void {
|
|
70
|
+
InnerNativeModule.enableLayoutAnimations(flag);
|
|
71
|
+
}
|
|
78
72
|
}
|
|
@@ -26,7 +26,7 @@ export const colorProps = [
|
|
|
26
26
|
'overlayColor',
|
|
27
27
|
];
|
|
28
28
|
|
|
29
|
-
const ColorProperties = !isConfigured() ? [] : makeShareable(colorProps);
|
|
29
|
+
export const ColorProperties = !isConfigured() ? [] : makeShareable(colorProps);
|
|
30
30
|
|
|
31
31
|
let updatePropsByPlatform;
|
|
32
32
|
if (shouldBeUseWeb()) {
|
|
@@ -2,6 +2,7 @@ import { useRef } from 'react';
|
|
|
2
2
|
import { makeMutable } from './core';
|
|
3
3
|
import { SharedValue } from './commonTypes';
|
|
4
4
|
import { Descriptor } from './hook/commonTypes';
|
|
5
|
+
import { Platform } from 'react-native';
|
|
5
6
|
|
|
6
7
|
export interface ViewRefSet<T> {
|
|
7
8
|
items: Set<T>;
|
|
@@ -23,6 +24,9 @@ export interface ViewDescriptorsSet {
|
|
|
23
24
|
) => void;
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
const scheduleUpdates =
|
|
28
|
+
Platform.OS === 'web' ? requestAnimationFrame : setImmediate;
|
|
29
|
+
|
|
26
30
|
export function makeViewDescriptorsSet(): ViewDescriptorsSet {
|
|
27
31
|
const ref = useRef<ViewDescriptorsSet | null>(null);
|
|
28
32
|
if (ref.current === null) {
|
|
@@ -44,7 +48,7 @@ export function makeViewDescriptorsSet(): ViewDescriptorsSet {
|
|
|
44
48
|
if (!data.waitForInsertSync) {
|
|
45
49
|
data.waitForInsertSync = true;
|
|
46
50
|
|
|
47
|
-
|
|
51
|
+
scheduleUpdates(() => {
|
|
48
52
|
data.sharableViewDescriptors.value = data.items;
|
|
49
53
|
data.waitForInsertSync = false;
|
|
50
54
|
});
|
|
@@ -57,7 +61,7 @@ export function makeViewDescriptorsSet(): ViewDescriptorsSet {
|
|
|
57
61
|
if (!data.waitForRemoveSync) {
|
|
58
62
|
data.waitForRemoveSync = true;
|
|
59
63
|
|
|
60
|
-
|
|
64
|
+
scheduleUpdates(() => {
|
|
61
65
|
const items = [];
|
|
62
66
|
for (const item of data.items) {
|
|
63
67
|
if (data.batchToRemove.has(item.tag)) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type AnimatableValue = number | string | Array<number>;
|
|
2
2
|
|
|
3
3
|
export interface AnimationObject {
|
|
4
4
|
[key: string]: any;
|
|
5
5
|
callback: AnimationCallback;
|
|
6
|
-
current?:
|
|
6
|
+
current?: AnimatableValue;
|
|
7
7
|
toValue?: AnimationObject['current'];
|
|
8
8
|
startValue?: AnimationObject['current'];
|
|
9
9
|
finished?: boolean;
|
|
@@ -25,7 +25,7 @@ export interface Animation<T extends AnimationObject> extends AnimationObject {
|
|
|
25
25
|
onFrame: (animation: T, timestamp: Timestamp) => boolean;
|
|
26
26
|
onStart: (
|
|
27
27
|
nextAnimation: T,
|
|
28
|
-
current: T extends NumericAnimation ? number :
|
|
28
|
+
current: T extends NumericAnimation ? number : AnimatableValue,
|
|
29
29
|
timestamp: Timestamp,
|
|
30
30
|
previousAnimation: T
|
|
31
31
|
) => void;
|
|
@@ -40,7 +40,7 @@ export interface HigherOrderAnimation {
|
|
|
40
40
|
|
|
41
41
|
export type AnimationCallback = (
|
|
42
42
|
finished?: boolean,
|
|
43
|
-
current?:
|
|
43
|
+
current?: AnimatableValue
|
|
44
44
|
) => void;
|
|
45
45
|
|
|
46
46
|
export type NextAnimation<T extends AnimationObject> = T | (() => T);
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
Animation,
|
|
4
4
|
AnimationCallback,
|
|
5
5
|
AnimationObject,
|
|
6
|
-
|
|
6
|
+
AnimatableValue,
|
|
7
7
|
Timestamp,
|
|
8
8
|
} from './commonTypes';
|
|
9
9
|
import { Platform } from 'react-native';
|
|
@@ -27,7 +27,7 @@ export interface DecayAnimation extends Animation<DecayAnimation> {
|
|
|
27
27
|
startTimestamp: Timestamp;
|
|
28
28
|
initialVelocity: number;
|
|
29
29
|
velocity: number;
|
|
30
|
-
current:
|
|
30
|
+
current: AnimatableValue;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export interface InnerDecayAnimation
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
NextAnimation,
|
|
5
5
|
Timestamp,
|
|
6
6
|
HigherOrderAnimation,
|
|
7
|
-
|
|
7
|
+
AnimatableValue,
|
|
8
8
|
} from './commonTypes';
|
|
9
9
|
|
|
10
10
|
export interface DelayAnimation
|
|
@@ -13,7 +13,7 @@ export interface DelayAnimation
|
|
|
13
13
|
startTime: Timestamp;
|
|
14
14
|
started: boolean;
|
|
15
15
|
previousAnimation: DelayAnimation | null;
|
|
16
|
-
current:
|
|
16
|
+
current: AnimatableValue;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export function withDelay(
|
|
@@ -57,7 +57,7 @@ export function withDelay(
|
|
|
57
57
|
|
|
58
58
|
function onStart(
|
|
59
59
|
animation: DelayAnimation,
|
|
60
|
-
value:
|
|
60
|
+
value: AnimatableValue,
|
|
61
61
|
now: Timestamp,
|
|
62
62
|
previousAnimation: DelayAnimation
|
|
63
63
|
): void {
|
|
@@ -7,10 +7,10 @@ export {
|
|
|
7
7
|
Timestamp,
|
|
8
8
|
} from './commonTypes';
|
|
9
9
|
export { cancelAnimation, defineAnimation, initialUpdaterRun } from './util';
|
|
10
|
-
export { withTiming } from './timing';
|
|
11
|
-
export { withSpring } from './spring';
|
|
12
|
-
export { withDecay } from './decay';
|
|
13
|
-
export { withDelay } from './delay';
|
|
14
|
-
export { withRepeat } from './repeat';
|
|
15
|
-
export { withSequence } from './sequence';
|
|
16
|
-
export { withStyleAnimation } from './styleAnimation';
|
|
10
|
+
export { withTiming, TimingAnimation } from './timing';
|
|
11
|
+
export { withSpring, SpringAnimation } from './spring';
|
|
12
|
+
export { withDecay, DecayAnimation } from './decay';
|
|
13
|
+
export { withDelay, DelayAnimation } from './delay';
|
|
14
|
+
export { withRepeat, RepeatAnimation } from './repeat';
|
|
15
|
+
export { withSequence, SequenceAnimation } from './sequence';
|
|
16
|
+
export { withStyleAnimation, StyleLayoutAnimation } from './styleAnimation';
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
Animation,
|
|
4
4
|
AnimationCallback,
|
|
5
5
|
NextAnimation,
|
|
6
|
-
|
|
6
|
+
AnimatableValue,
|
|
7
7
|
Timestamp,
|
|
8
8
|
HigherOrderAnimation,
|
|
9
9
|
} from './commonTypes';
|
|
@@ -12,8 +12,8 @@ export interface RepeatAnimation
|
|
|
12
12
|
extends Animation<RepeatAnimation>,
|
|
13
13
|
HigherOrderAnimation {
|
|
14
14
|
reps: number;
|
|
15
|
-
startValue:
|
|
16
|
-
toValue?:
|
|
15
|
+
startValue: AnimatableValue;
|
|
16
|
+
toValue?: AnimatableValue;
|
|
17
17
|
previousAnimation?: RepeatAnimation;
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -81,7 +81,7 @@ export function withRepeat(
|
|
|
81
81
|
|
|
82
82
|
function onStart(
|
|
83
83
|
animation: RepeatAnimation,
|
|
84
|
-
value:
|
|
84
|
+
value: AnimatableValue,
|
|
85
85
|
now: Timestamp,
|
|
86
86
|
previousAnimation: RepeatAnimation
|
|
87
87
|
): void {
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
Animation,
|
|
4
4
|
Timestamp,
|
|
5
5
|
NextAnimation,
|
|
6
|
-
|
|
6
|
+
AnimatableValue,
|
|
7
7
|
HigherOrderAnimation,
|
|
8
8
|
AnimationObject,
|
|
9
9
|
} from './commonTypes';
|
|
@@ -66,7 +66,7 @@ export function withSequence(
|
|
|
66
66
|
|
|
67
67
|
function onStart(
|
|
68
68
|
animation: SequenceAnimation,
|
|
69
|
-
value:
|
|
69
|
+
value: AnimatableValue,
|
|
70
70
|
now: Timestamp,
|
|
71
71
|
previousAnimation: SequenceAnimation
|
|
72
72
|
): void {
|
|
@@ -2,12 +2,11 @@ import { defineAnimation } from './util';
|
|
|
2
2
|
import {
|
|
3
3
|
Animation,
|
|
4
4
|
AnimationCallback,
|
|
5
|
-
|
|
5
|
+
AnimatableValue,
|
|
6
6
|
Timestamp,
|
|
7
7
|
} from './commonTypes';
|
|
8
8
|
|
|
9
9
|
interface SpringConfig {
|
|
10
|
-
// [key: string]: any;
|
|
11
10
|
mass?: number;
|
|
12
11
|
stiffness?: number;
|
|
13
12
|
overshootClamping?: boolean;
|
|
@@ -18,8 +17,8 @@ interface SpringConfig {
|
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
export interface SpringAnimation extends Animation<SpringAnimation> {
|
|
21
|
-
current:
|
|
22
|
-
toValue:
|
|
20
|
+
current: AnimatableValue;
|
|
21
|
+
toValue: AnimatableValue;
|
|
23
22
|
velocity: number;
|
|
24
23
|
lastTimestamp: Timestamp;
|
|
25
24
|
}
|
|
@@ -31,7 +30,7 @@ export interface InnerSpringAnimation
|
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
export function withSpring(
|
|
34
|
-
toValue:
|
|
33
|
+
toValue: AnimatableValue,
|
|
35
34
|
userConfig?: SpringConfig,
|
|
36
35
|
callback?: AnimationCallback
|
|
37
36
|
): Animation<SpringAnimation> {
|
|
@@ -131,6 +130,8 @@ export function withSpring(
|
|
|
131
130
|
animation.velocity = 0;
|
|
132
131
|
animation.current = toValue;
|
|
133
132
|
}
|
|
133
|
+
// clear lastTimestamp to avoid using stale value by the next spring animation that starts after this one
|
|
134
|
+
animation.lastTimestamp = 0;
|
|
134
135
|
return true;
|
|
135
136
|
}
|
|
136
137
|
return false;
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
Timestamp,
|
|
4
4
|
HigherOrderAnimation,
|
|
5
5
|
AnimationCallback,
|
|
6
|
-
|
|
6
|
+
AnimatableValue,
|
|
7
7
|
AnimationObject,
|
|
8
8
|
Animation,
|
|
9
9
|
} from './commonTypes';
|
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
StyleProps,
|
|
15
15
|
} from '../commonTypes';
|
|
16
16
|
import { withTiming } from './timing';
|
|
17
|
+
import { ColorProperties } from '../UpdateProps';
|
|
18
|
+
import { processColor } from '../Colors';
|
|
17
19
|
|
|
18
20
|
export interface StyleLayoutAnimation extends HigherOrderAnimation {
|
|
19
21
|
current: StyleProps;
|
|
@@ -32,28 +34,31 @@ export interface StyleLayoutAnimation extends HigherOrderAnimation {
|
|
|
32
34
|
// if path cannot be resolved returns undefined
|
|
33
35
|
export function resolvePath<T>(
|
|
34
36
|
obj: NestedObject<T>,
|
|
35
|
-
path:
|
|
37
|
+
path: AnimatableValue[] | AnimatableValue
|
|
36
38
|
): NestedObjectValues<T> | undefined {
|
|
37
39
|
'worklet';
|
|
38
|
-
const keys:
|
|
40
|
+
const keys: AnimatableValue[] = Array.isArray(path) ? path : [path];
|
|
39
41
|
return keys.reduce<NestedObjectValues<T> | undefined>((acc, current) => {
|
|
40
42
|
if (Array.isArray(acc) && typeof current === 'number') {
|
|
41
43
|
return acc[current];
|
|
42
|
-
} else if (typeof acc === 'object' && current in acc) {
|
|
43
|
-
return (acc as { [key: string]: NestedObjectValues<T> })[
|
|
44
|
+
} else if (typeof acc === 'object' && (current as number | string) in acc) {
|
|
45
|
+
return (acc as { [key: string]: NestedObjectValues<T> })[
|
|
46
|
+
current as number | string
|
|
47
|
+
];
|
|
44
48
|
}
|
|
45
49
|
return undefined;
|
|
46
50
|
}, obj);
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
// set value at given path
|
|
54
|
+
type Path = Array<string | number> | string | number;
|
|
50
55
|
export function setPath<T>(
|
|
51
56
|
obj: NestedObject<T>,
|
|
52
|
-
path:
|
|
57
|
+
path: Path,
|
|
53
58
|
value: NestedObjectValues<T>
|
|
54
59
|
): void {
|
|
55
60
|
'worklet';
|
|
56
|
-
const keys:
|
|
61
|
+
const keys: Path = Array.isArray(path) ? path : [path];
|
|
57
62
|
let currObj: NestedObjectValues<T> = obj;
|
|
58
63
|
for (let i = 0; i < keys.length - 1; i++) {
|
|
59
64
|
// creates entry if there isn't one
|
|
@@ -76,7 +81,7 @@ export function setPath<T>(
|
|
|
76
81
|
|
|
77
82
|
interface NestedObjectEntry<T> {
|
|
78
83
|
value: NestedObjectValues<T>;
|
|
79
|
-
path:
|
|
84
|
+
path: (string | number)[];
|
|
80
85
|
}
|
|
81
86
|
|
|
82
87
|
export function withStyleAnimation(
|
|
@@ -131,6 +136,13 @@ export function withStyleAnimation(
|
|
|
131
136
|
} else {
|
|
132
137
|
stillGoing = true;
|
|
133
138
|
}
|
|
139
|
+
|
|
140
|
+
if (ColorProperties.includes(currentEntry.path[0] as string)) {
|
|
141
|
+
currentStyleAnimation.current = processColor(
|
|
142
|
+
currentStyleAnimation.current
|
|
143
|
+
) as number;
|
|
144
|
+
}
|
|
145
|
+
|
|
134
146
|
setPath(
|
|
135
147
|
animation.current,
|
|
136
148
|
currentEntry.path,
|
|
@@ -148,13 +160,13 @@ export function withStyleAnimation(
|
|
|
148
160
|
previousAnimation: StyleLayoutAnimation
|
|
149
161
|
): void => {
|
|
150
162
|
const entriesToCheck: NestedObjectEntry<
|
|
151
|
-
AnimationObject |
|
|
163
|
+
AnimationObject | AnimatableValue
|
|
152
164
|
>[] = [{ value: styleAnimations, path: [] }];
|
|
153
165
|
while (entriesToCheck.length > 0) {
|
|
154
166
|
const currentEntry: NestedObjectEntry<
|
|
155
|
-
AnimationObject |
|
|
167
|
+
AnimationObject | AnimatableValue
|
|
156
168
|
> = entriesToCheck.pop() as NestedObjectEntry<
|
|
157
|
-
AnimationObject |
|
|
169
|
+
AnimationObject | AnimatableValue
|
|
158
170
|
>;
|
|
159
171
|
if (Array.isArray(currentEntry.value)) {
|
|
160
172
|
for (let index = 0; index < currentEntry.value.length; index++) {
|
|
@@ -189,7 +201,7 @@ export function withStyleAnimation(
|
|
|
189
201
|
!currentEntry.value.onStart
|
|
190
202
|
) {
|
|
191
203
|
currentAnimation = withTiming(
|
|
192
|
-
currentEntry.value as
|
|
204
|
+
currentEntry.value as AnimatableValue,
|
|
193
205
|
{ duration: 0 }
|
|
194
206
|
);
|
|
195
207
|
setPath(
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
Animation,
|
|
5
5
|
AnimationCallback,
|
|
6
6
|
Timestamp,
|
|
7
|
-
|
|
7
|
+
AnimatableValue,
|
|
8
8
|
} from './commonTypes';
|
|
9
9
|
|
|
10
10
|
interface TimingConfig {
|
|
@@ -15,11 +15,11 @@ interface TimingConfig {
|
|
|
15
15
|
export interface TimingAnimation extends Animation<TimingAnimation> {
|
|
16
16
|
type: string;
|
|
17
17
|
easing: EasingFn;
|
|
18
|
-
startValue:
|
|
18
|
+
startValue: AnimatableValue;
|
|
19
19
|
startTime: Timestamp;
|
|
20
20
|
progress: number;
|
|
21
|
-
toValue:
|
|
22
|
-
current:
|
|
21
|
+
toValue: AnimatableValue;
|
|
22
|
+
current: AnimatableValue;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export interface InnerTimingAnimation
|
|
@@ -29,7 +29,7 @@ export interface InnerTimingAnimation
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export function withTiming(
|
|
32
|
-
toValue:
|
|
32
|
+
toValue: AnimatableValue,
|
|
33
33
|
userConfig?: TimingConfig,
|
|
34
34
|
callback?: AnimationCallback
|
|
35
35
|
): Animation<TimingAnimation> {
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
AnimationObject,
|
|
4
4
|
HigherOrderAnimation,
|
|
5
5
|
NextAnimation,
|
|
6
|
-
|
|
6
|
+
AnimatableValue,
|
|
7
7
|
Timestamp,
|
|
8
8
|
} from './commonTypes';
|
|
9
9
|
/* global _WORKLET */
|
|
@@ -32,7 +32,7 @@ interface RecognizedPrefixSuffix {
|
|
|
32
32
|
strippedValue: number;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
function recognizePrefixSuffix(value:
|
|
35
|
+
function recognizePrefixSuffix(value: string | number): RecognizedPrefixSuffix {
|
|
36
36
|
'worklet';
|
|
37
37
|
if (typeof value === 'string') {
|
|
38
38
|
const match = value.match(
|
|
@@ -68,7 +68,7 @@ function decorateAnimation<T extends AnimationObject | StyleLayoutAnimation>(
|
|
|
68
68
|
|
|
69
69
|
const prefNumberSuffOnStart = (
|
|
70
70
|
animation: Animation<AnimationObject>,
|
|
71
|
-
value:
|
|
71
|
+
value: string | number,
|
|
72
72
|
timestamp: number,
|
|
73
73
|
previousAnimation: Animation<AnimationObject>
|
|
74
74
|
) => {
|
|
@@ -78,7 +78,7 @@ function decorateAnimation<T extends AnimationObject | StyleLayoutAnimation>(
|
|
|
78
78
|
animation.__suffix = suffix;
|
|
79
79
|
animation.strippedCurrent = strippedValue;
|
|
80
80
|
const { strippedValue: strippedToValue } = recognizePrefixSuffix(
|
|
81
|
-
animation.toValue as
|
|
81
|
+
animation.toValue as string | number
|
|
82
82
|
);
|
|
83
83
|
animation.current = strippedValue;
|
|
84
84
|
animation.startValue = strippedValue;
|
|
@@ -167,6 +167,41 @@ function decorateAnimation<T extends AnimationObject | StyleLayoutAnimation>(
|
|
|
167
167
|
return finished;
|
|
168
168
|
};
|
|
169
169
|
|
|
170
|
+
const arrayOnStart = (
|
|
171
|
+
animation: Animation<AnimationObject>,
|
|
172
|
+
value: Array<number>,
|
|
173
|
+
timestamp: Timestamp,
|
|
174
|
+
previousAnimation: Animation<AnimationObject>
|
|
175
|
+
): void => {
|
|
176
|
+
value.forEach((v, i) => {
|
|
177
|
+
animation[i] = Object.assign({}, animationCopy);
|
|
178
|
+
animation[i].current = v;
|
|
179
|
+
animation[i].toValue = (animation.toValue as Array<number>)[i];
|
|
180
|
+
animation[i].onStart(
|
|
181
|
+
animation[i],
|
|
182
|
+
v,
|
|
183
|
+
timestamp,
|
|
184
|
+
previousAnimation ? previousAnimation[i] : undefined
|
|
185
|
+
);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
animation.current = value;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const arrayOnFrame = (
|
|
192
|
+
animation: Animation<AnimationObject>,
|
|
193
|
+
timestamp: Timestamp
|
|
194
|
+
): boolean => {
|
|
195
|
+
let finished = true;
|
|
196
|
+
(animation.current as Array<number>).forEach((v, i) => {
|
|
197
|
+
// @ts-ignore: disable-next-line
|
|
198
|
+
finished &= animation[i].onFrame(animation[i], timestamp);
|
|
199
|
+
(animation.current as Array<number>)[i] = animation[i].current;
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
return finished;
|
|
203
|
+
};
|
|
204
|
+
|
|
170
205
|
animation.onStart = (
|
|
171
206
|
animation: Animation<AnimationObject>,
|
|
172
207
|
value: number,
|
|
@@ -177,6 +212,10 @@ function decorateAnimation<T extends AnimationObject | StyleLayoutAnimation>(
|
|
|
177
212
|
colorOnStart(animation, value, timestamp, previousAnimation);
|
|
178
213
|
animation.onFrame = colorOnFrame;
|
|
179
214
|
return;
|
|
215
|
+
} else if (Array.isArray(value)) {
|
|
216
|
+
arrayOnStart(animation, value, timestamp, previousAnimation);
|
|
217
|
+
animation.onFrame = arrayOnFrame;
|
|
218
|
+
return;
|
|
180
219
|
} else if (typeof value === 'string') {
|
|
181
220
|
prefNumberSuffOnStart(animation, value, timestamp, previousAnimation);
|
|
182
221
|
animation.onFrame = prefNumberSuffOnFrame;
|
|
@@ -196,7 +235,7 @@ type AnimationToDecoration<
|
|
|
196
235
|
? NextAnimation<RepeatAnimation>
|
|
197
236
|
: T extends SequenceAnimation
|
|
198
237
|
? NextAnimation<SequenceAnimation>
|
|
199
|
-
:
|
|
238
|
+
: AnimatableValue | T;
|
|
200
239
|
|
|
201
240
|
export function defineAnimation<
|
|
202
241
|
T extends AnimationObject | StyleLayoutAnimation
|
|
@@ -227,7 +266,7 @@ export function cancelAnimation<T>(sharedValue: SharedValue<T>): void {
|
|
|
227
266
|
|
|
228
267
|
// TODO it should work only if there was no animation before.
|
|
229
268
|
export function withStartValue(
|
|
230
|
-
startValue:
|
|
269
|
+
startValue: AnimatableValue,
|
|
231
270
|
animation: NextAnimation<AnimationObject>
|
|
232
271
|
): Animation<AnimationObject> {
|
|
233
272
|
'worklet';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FlatList, FlatListProps, LayoutChangeEvent } from 'react-native';
|
|
3
|
+
import WrappedComponents from './WrappedComponents';
|
|
4
|
+
import createAnimatedComponent from '../../createAnimatedComponent';
|
|
5
|
+
import { ILayoutAnimationBuilder } from '../layoutReanimation/animationBuilder/commonTypes';
|
|
6
|
+
|
|
7
|
+
const AnimatedFlatList = createAnimatedComponent(FlatList as any) as any;
|
|
8
|
+
|
|
9
|
+
const createCellRenderer = (itemLayoutAnimation?: ILayoutAnimationBuilder) => {
|
|
10
|
+
const cellRenderer: React.FC<{
|
|
11
|
+
onLayout: (event: LayoutChangeEvent) => void;
|
|
12
|
+
}> = (props) => {
|
|
13
|
+
return (
|
|
14
|
+
<WrappedComponents.View
|
|
15
|
+
layout={itemLayoutAnimation}
|
|
16
|
+
onLayout={props.onLayout}>
|
|
17
|
+
{props.children}
|
|
18
|
+
</WrappedComponents.View>
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return cellRenderer;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
interface ReanimatedFlatlistProps<ItemT> extends FlatListProps<ItemT> {
|
|
26
|
+
itemLayoutAnimation?: ILayoutAnimationBuilder;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type ReanimatedFlatListFC<T = any> = React.FC<ReanimatedFlatlistProps<T>>;
|
|
30
|
+
|
|
31
|
+
const ReanimatedFlatlist: ReanimatedFlatListFC = ({
|
|
32
|
+
itemLayoutAnimation,
|
|
33
|
+
...restProps
|
|
34
|
+
}) => {
|
|
35
|
+
const cellRenderer = React.useMemo(
|
|
36
|
+
() => createCellRenderer(itemLayoutAnimation),
|
|
37
|
+
[]
|
|
38
|
+
);
|
|
39
|
+
return (
|
|
40
|
+
<AnimatedFlatList {...restProps} CellRendererComponent={cellRenderer} />
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export default ReanimatedFlatlist;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Image, ScrollView, Text, View } from 'react-native';
|
|
2
|
+
import createAnimatedComponent from '../../createAnimatedComponent';
|
|
3
|
+
|
|
4
|
+
const WrappedComponents = {
|
|
5
|
+
View: createAnimatedComponent(View),
|
|
6
|
+
Text: createAnimatedComponent(Text as any),
|
|
7
|
+
Image: createAnimatedComponent(Image as any),
|
|
8
|
+
ScrollView: createAnimatedComponent(ScrollView),
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default WrappedComponents;
|