react-native-reanimated 4.7.0 → 4.7.2
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/reanimated/CSS/common/values/CSSNumber.cpp +5 -9
- package/Common/cpp/reanimated/CSS/common/values/CSSNumber.h +2 -6
- package/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.cpp +34 -2
- package/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.h +15 -1
- package/Common/cpp/reanimated/Fabric/ReanimatedMountHook.cpp +9 -0
- package/Common/cpp/reanimated/Fabric/ReanimatedMountHook.h +3 -0
- package/Common/cpp/reanimated/Fabric/updates/AnimatedPropsRegistry.cpp +135 -33
- package/Common/cpp/reanimated/Fabric/updates/AnimatedPropsRegistry.h +37 -3
- package/Common/cpp/reanimated/Fabric/updates/SynchronousWritesTracker.cpp +103 -0
- package/Common/cpp/reanimated/Fabric/updates/SynchronousWritesTracker.h +74 -0
- package/Common/cpp/reanimated/Fabric/updates/UpdatesRegistry.cpp +43 -0
- package/Common/cpp/reanimated/Fabric/updates/UpdatesRegistry.h +13 -0
- package/Common/cpp/reanimated/Fabric/updates/UpdatesRegistryManager.cpp +14 -1
- package/Common/cpp/reanimated/Fabric/updates/UpdatesRegistryManager.h +3 -0
- package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp +318 -134
- package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.h +27 -6
- package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.cpp +32 -17
- package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.h +17 -1
- package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.cpp +14 -13
- package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.h +5 -2
- package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h +57 -9
- package/Common/cpp/reanimated/LayoutAnimations/PropsDiffer.h +2 -2
- package/Common/cpp/reanimated/LayoutAnimations/SharedTransitions.cpp +11 -11
- package/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp +114 -11
- package/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.h +12 -2
- package/Common/cpp/reanimated/Tools/PlatformDepMethodsHolder.h +17 -1
- package/Common/cpp/reanimated/Tools/TextMetrics.h +22 -0
- package/android/src/main/cpp/reanimated/android/NativeProxy.cpp +32 -3
- package/android/src/main/cpp/reanimated/android/NativeProxy.h +3 -0
- package/android/src/main/java/com/swmansion/reanimated/NativeProxy.kt +108 -9
- package/android/src/main/java/com/swmansion/reanimated/NodesManager.kt +2 -4
- package/android/src/main/java/com/swmansion/reanimated/nativeProxy/EventHandler.kt +4 -3
- package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensor.kt +1 -1
- package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.kt +44 -33
- package/apple/reanimated/apple/REAReducedMotion.h +1 -3
- package/apple/reanimated/apple/REASynchronousPropsRewriter.h +18 -0
- package/apple/reanimated/apple/REASynchronousPropsRewriter.mm +37 -0
- package/apple/reanimated/apple/ReanimatedModule.mm +7 -0
- package/apple/reanimated/apple/keyboardObserver/REAKeyboardEventObserver.mm +20 -3
- package/apple/reanimated/apple/native/PlatformDepMethodsHolderImpl.mm +52 -1
- package/jest/resolver.js +4 -1
- package/lib/module/PropsRegistryGarbageCollector.js +43 -25
- package/lib/module/PropsRegistryGarbageCollector.js.map +1 -1
- package/lib/module/ReanimatedModule/NativeReanimated.js +2 -2
- package/lib/module/ReanimatedModule/NativeReanimated.js.map +1 -1
- package/lib/module/animation/timing.js +15 -2
- package/lib/module/animation/timing.js.map +1 -1
- package/lib/module/commonTypes.js.map +1 -1
- package/lib/module/createAnimatedComponent/AnimatedComponent.js +1 -1
- package/lib/module/createAnimatedComponent/AnimatedComponent.js.map +1 -1
- package/lib/module/createAnimatedComponent/AnimatedComponent.native.js +10 -34
- package/lib/module/createAnimatedComponent/AnimatedComponent.native.js.map +1 -1
- package/lib/module/platform-specific/jsVersion.js +1 -1
- package/lib/module/platformFunctions/setNativeProps.native.js +2 -1
- package/lib/module/platformFunctions/setNativeProps.native.js.map +1 -1
- package/lib/module/updateProps/updateProps.native.js +5 -4
- package/lib/module/updateProps/updateProps.native.js.map +1 -1
- package/lib/typescript/PropsRegistryGarbageCollector.d.ts +2 -2
- package/lib/typescript/PropsRegistryGarbageCollector.d.ts.map +1 -1
- package/lib/typescript/ReanimatedModule/reanimatedModuleProxy.d.ts +1 -1
- package/lib/typescript/ReanimatedModule/reanimatedModuleProxy.d.ts.map +1 -1
- package/lib/typescript/animation/timing.d.ts.map +1 -1
- package/lib/typescript/commonTypes.d.ts +3 -1
- package/lib/typescript/commonTypes.d.ts.map +1 -1
- package/lib/typescript/createAnimatedComponent/AnimatedComponent.d.ts +1 -1
- package/lib/typescript/createAnimatedComponent/AnimatedComponent.d.ts.map +1 -1
- package/lib/typescript/createAnimatedComponent/AnimatedComponent.native.d.ts +1 -1
- package/lib/typescript/createAnimatedComponent/AnimatedComponent.native.d.ts.map +1 -1
- package/lib/typescript/createAnimatedComponent/commonTypes.d.ts +1 -1
- package/lib/typescript/createAnimatedComponent/commonTypes.d.ts.map +1 -1
- package/lib/typescript/platform-specific/jsVersion.d.ts +1 -1
- package/lib/typescript/updateProps/updateProps.native.d.ts.map +1 -1
- package/package.json +9 -7
- package/src/PropsRegistryGarbageCollector.ts +46 -25
- package/src/ReanimatedModule/NativeReanimated.ts +2 -2
- package/src/ReanimatedModule/reanimatedModuleProxy.ts +1 -1
- package/src/animation/timing.ts +20 -2
- package/src/commonTypes.ts +3 -1
- package/src/createAnimatedComponent/AnimatedComponent.native.tsx +5 -30
- package/src/createAnimatedComponent/AnimatedComponent.tsx +1 -1
- package/src/createAnimatedComponent/commonTypes.ts +1 -1
- package/src/platform-specific/jsVersion.ts +1 -1
- package/src/platformFunctions/setNativeProps.native.ts +3 -1
- package/src/privateGlobals.d.ts +1 -0
- package/src/updateProps/updateProps.native.ts +10 -3
|
@@ -5,11 +5,12 @@ import type {
|
|
|
5
5
|
ProcessedColorStop,
|
|
6
6
|
ProcessedDirection,
|
|
7
7
|
} from './common/style/processors/backgroundImage';
|
|
8
|
+
import type { ProcessedColor } from './common/style/processors/colors';
|
|
8
9
|
import {
|
|
9
10
|
unprocessColor,
|
|
10
11
|
unprocessColorsInProps,
|
|
11
12
|
} from './common/style/processors/colors';
|
|
12
|
-
import type {
|
|
13
|
+
import type { SettledUpdate } from './commonTypes';
|
|
13
14
|
import type { IAnimatedComponentInternal } from './createAnimatedComponent/commonTypes';
|
|
14
15
|
import { ReanimatedModule } from './ReanimatedModule';
|
|
15
16
|
|
|
@@ -42,14 +43,14 @@ export const PropsRegistryGarbageCollector = {
|
|
|
42
43
|
},
|
|
43
44
|
|
|
44
45
|
syncPropsBackToReact() {
|
|
45
|
-
const settledUpdates = ReanimatedModule.getSettledUpdates(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
46
|
+
const settledUpdates = ReanimatedModule.getSettledUpdates([
|
|
47
|
+
...this.viewsMap.keys(),
|
|
48
|
+
]);
|
|
49
|
+
for (const settledUpdate of settledUpdates) {
|
|
50
|
+
const { viewTag, props, style } = settledUpdate;
|
|
50
51
|
const component = this.viewsMap.get(viewTag);
|
|
51
|
-
|
|
52
|
-
component?._syncStylePropsBackToReact(
|
|
52
|
+
unprocessSettledUpdate(settledUpdate);
|
|
53
|
+
component?._syncStylePropsBackToReact(props, style);
|
|
53
54
|
}
|
|
54
55
|
},
|
|
55
56
|
|
|
@@ -68,30 +69,50 @@ export const PropsRegistryGarbageCollector = {
|
|
|
68
69
|
},
|
|
69
70
|
};
|
|
70
71
|
|
|
71
|
-
export function
|
|
72
|
+
export function unprocessSettledUpdate({
|
|
73
|
+
props,
|
|
74
|
+
style,
|
|
75
|
+
keysLastWrittenByAnimatedStyle,
|
|
76
|
+
}: Omit<SettledUpdate, 'viewTag'>) {
|
|
72
77
|
unprocessColorsInProps(props);
|
|
73
|
-
|
|
74
|
-
|
|
78
|
+
unprocessColorsInProps(style);
|
|
79
|
+
for (const key of keysLastWrittenByAnimatedStyle) {
|
|
80
|
+
const unprocess = STYLE_BUILDER_VALUE_UNPROCESSORS[key];
|
|
81
|
+
if (!unprocess) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
for (const settledValues of [props, style]) {
|
|
85
|
+
if (key in settledValues) {
|
|
86
|
+
settledValues[key] = unprocess(settledValues[key]);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
75
90
|
}
|
|
76
91
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
92
|
+
const STYLE_BUILDER_VALUE_UNPROCESSORS: Partial<
|
|
93
|
+
Record<string, (value: unknown) => unknown>
|
|
94
|
+
> = {
|
|
95
|
+
boxShadow: unprocessBoxShadow,
|
|
96
|
+
backgroundImage: unprocessBackgroundImage,
|
|
97
|
+
// eslint-disable-next-line camelcase
|
|
98
|
+
experimental_backgroundImage: unprocessBackgroundImage,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
function unprocessBoxShadow(value: unknown) {
|
|
102
|
+
if (!Array.isArray(value)) {
|
|
103
|
+
return value;
|
|
84
104
|
}
|
|
105
|
+
return (value as { color: ProcessedColor }[]).map((boxShadow) => ({
|
|
106
|
+
...boxShadow,
|
|
107
|
+
color: unprocessColor(boxShadow.color),
|
|
108
|
+
}));
|
|
85
109
|
}
|
|
86
110
|
|
|
87
|
-
function unprocessBackgroundImage(
|
|
88
|
-
if (!Array.isArray(
|
|
89
|
-
return;
|
|
111
|
+
function unprocessBackgroundImage(value: unknown) {
|
|
112
|
+
if (!Array.isArray(value)) {
|
|
113
|
+
return value;
|
|
90
114
|
}
|
|
91
|
-
|
|
92
|
-
props.backgroundImage = (
|
|
93
|
-
props.backgroundImage as ProcessedBackgroundImageValue[]
|
|
94
|
-
).map((backgroundImage) => {
|
|
115
|
+
return (value as ProcessedBackgroundImageValue[]).map((backgroundImage) => {
|
|
95
116
|
const colorStops = backgroundImage.colorStops.map(unprocessColorStop);
|
|
96
117
|
if (backgroundImage.type === 'linear-gradient') {
|
|
97
118
|
return {
|
|
@@ -240,8 +240,8 @@ See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooti
|
|
|
240
240
|
this.#reanimatedModuleProxy.unregisterCSSTransition(viewTag);
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
-
getSettledUpdates(): SettledUpdate[] {
|
|
244
|
-
return this.#reanimatedModuleProxy.getSettledUpdates();
|
|
243
|
+
getSettledUpdates(registeredViewTags: number[]): SettledUpdate[] {
|
|
244
|
+
return this.#reanimatedModuleProxy.getSettledUpdates(registeredViewTags);
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
registerPseudoStyles(
|
|
@@ -97,7 +97,7 @@ export interface ReanimatedModuleProxy {
|
|
|
97
97
|
|
|
98
98
|
unregisterCSSTransition(viewTag: number): void;
|
|
99
99
|
|
|
100
|
-
getSettledUpdates(): SettledUpdate[];
|
|
100
|
+
getSettledUpdates(registeredViewTags: number[]): SettledUpdate[];
|
|
101
101
|
|
|
102
102
|
registerPseudoStyles(
|
|
103
103
|
shadowNodeWrapper: ShadowNodeWrapper,
|
package/src/animation/timing.ts
CHANGED
|
@@ -101,7 +101,20 @@ export const withTiming = function (
|
|
|
101
101
|
function timing(animation: InnerTimingAnimation, now: Timestamp): boolean {
|
|
102
102
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
103
103
|
const { toValue, startTime, startValue } = animation;
|
|
104
|
-
|
|
104
|
+
let runtime = now - startTime;
|
|
105
|
+
|
|
106
|
+
if (runtime < 0) {
|
|
107
|
+
// `startTime` comes from `global.__frameTimestamp ||
|
|
108
|
+
// global._getAnimationTimestamp()` (see `valueSetter`). An animation
|
|
109
|
+
// started outside a frame flush - from a gesture callback, for
|
|
110
|
+
// instance - takes the second branch and reads the clock at that
|
|
111
|
+
// instant, while the frame that first progresses it passes its vsync
|
|
112
|
+
// timestamp, which is earlier. The first tick then sees a small
|
|
113
|
+
// negative runtime. This can potentially cause glitches during
|
|
114
|
+
// animations.
|
|
115
|
+
animation.startTime = now;
|
|
116
|
+
runtime = 0;
|
|
117
|
+
}
|
|
105
118
|
|
|
106
119
|
if (runtime >= config.duration) {
|
|
107
120
|
// reset startTime to avoid reusing finished animation config in `start` method
|
|
@@ -109,7 +122,12 @@ export const withTiming = function (
|
|
|
109
122
|
animation.current = toValue;
|
|
110
123
|
return true;
|
|
111
124
|
}
|
|
112
|
-
|
|
125
|
+
|
|
126
|
+
const normalizedTime = Math.min(
|
|
127
|
+
Math.max(runtime / config.duration, 0),
|
|
128
|
+
1
|
|
129
|
+
);
|
|
130
|
+
const progress = animation.easing(normalizedTime);
|
|
113
131
|
animation.current =
|
|
114
132
|
(startValue as number) + (toValue - (startValue as number)) * progress;
|
|
115
133
|
return false;
|
package/src/commonTypes.ts
CHANGED
|
@@ -393,7 +393,9 @@ export type ShadowNodeWrapper = {
|
|
|
393
393
|
|
|
394
394
|
export type SettledUpdate = {
|
|
395
395
|
viewTag: number;
|
|
396
|
-
|
|
396
|
+
props: StyleProps;
|
|
397
|
+
style: StyleProps;
|
|
398
|
+
keysLastWrittenByAnimatedStyle: string[];
|
|
397
399
|
};
|
|
398
400
|
|
|
399
401
|
export enum KeyboardState {
|
|
@@ -143,39 +143,14 @@ export default class AnimatedComponent
|
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
_syncStylePropsBackToReact(
|
|
146
|
+
_syncStylePropsBackToReact(props: StyleProps, style: StyleProps) {
|
|
147
147
|
if (!FORCE_REACT_RENDER_FOR_SETTLED_ANIMATIONS) {
|
|
148
148
|
return;
|
|
149
149
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
// style-only.
|
|
155
|
-
const animatedPropsKeys = new Set([
|
|
156
|
-
...this._animatedProps.flatMap((animatedProp) =>
|
|
157
|
-
Object.keys(animatedProp.initial?.value ?? {})
|
|
158
|
-
),
|
|
159
|
-
...Object.keys(this._InlinePropManager._inlineTopLevelProps),
|
|
160
|
-
]);
|
|
161
|
-
if (animatedPropsKeys.size === 0) {
|
|
162
|
-
this.setState((state) => ({
|
|
163
|
-
settledStyle: { ...state.settledStyle, ...settledUpdates },
|
|
164
|
-
}));
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
this.setState((state) => {
|
|
168
|
-
const settledProps = { ...state.settledProps };
|
|
169
|
-
const settledStyle = { ...state.settledStyle };
|
|
170
|
-
for (const key in settledUpdates) {
|
|
171
|
-
if (animatedPropsKeys.has(key)) {
|
|
172
|
-
settledProps[key] = settledUpdates[key];
|
|
173
|
-
} else {
|
|
174
|
-
settledStyle[key] = settledUpdates[key];
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return { settledProps, settledStyle };
|
|
178
|
-
});
|
|
150
|
+
this.setState((state) => ({
|
|
151
|
+
settledProps: { ...state.settledProps, ...props },
|
|
152
|
+
settledStyle: { ...state.settledStyle, ...style },
|
|
153
|
+
}));
|
|
179
154
|
// TODO(future): revert changes when animated styles are detached
|
|
180
155
|
}
|
|
181
156
|
|
|
@@ -152,7 +152,7 @@ export interface IAnimatedComponentInternal extends IAnimatedComponentInternalBa
|
|
|
152
152
|
_NativeEventsManager?: INativeEventsManager;
|
|
153
153
|
context: React.ContextType<typeof SkipEnteringContext>;
|
|
154
154
|
setNativeProps: (props: StyleProps) => void;
|
|
155
|
-
_syncStylePropsBackToReact: (props: StyleProps) => void;
|
|
155
|
+
_syncStylePropsBackToReact: (props: StyleProps, style: StyleProps) => void;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
export type NestedArray<T> = T | NestedArray<T>[];
|
|
@@ -45,7 +45,9 @@ function setNativePropsNative(
|
|
|
45
45
|
const shadowNodeWrapper = (animatedRef as AnimatedRefOnUI)
|
|
46
46
|
.value as ShadowNodeWrapper;
|
|
47
47
|
processColorsInProps(updates);
|
|
48
|
-
global._updateProps!([
|
|
48
|
+
global._updateProps!([
|
|
49
|
+
{ shadowNodeWrapper, updates, isAnimatedProps: false },
|
|
50
|
+
]);
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
function setNativePropsJest() {
|
package/src/privateGlobals.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ const updateProps: (
|
|
|
27
27
|
viewDescriptors: ViewDescriptorsWrapper,
|
|
28
28
|
updates: PropUpdates,
|
|
29
29
|
isAnimatedProps?: boolean
|
|
30
|
-
) => void = (viewDescriptors, updates, isAnimatedProps) => {
|
|
30
|
+
) => void = (viewDescriptors, updates, isAnimatedProps = false) => {
|
|
31
31
|
'worklet';
|
|
32
32
|
|
|
33
33
|
// TODO: Remove this if once we have SVG props builder implemented
|
|
@@ -53,7 +53,8 @@ const updateProps: (
|
|
|
53
53
|
// Use props builder only for style updaters, since animated props
|
|
54
54
|
// can contain any properties of different types, depending on the
|
|
55
55
|
// component, which we cannot process properly with the props builder.
|
|
56
|
-
isAnimatedProps ? updates : stylePropsBuilder.build(updates)
|
|
56
|
+
isAnimatedProps ? updates : stylePropsBuilder.build(updates),
|
|
57
|
+
isAnimatedProps
|
|
57
58
|
);
|
|
58
59
|
};
|
|
59
60
|
|
|
@@ -66,6 +67,7 @@ function updateJSProps(operations: JSPropsOperation[]) {
|
|
|
66
67
|
type NativePropsOperation = {
|
|
67
68
|
shadowNodeWrapper: ShadowNodeWrapper;
|
|
68
69
|
updates: StyleProps;
|
|
70
|
+
isAnimatedProps: boolean;
|
|
69
71
|
};
|
|
70
72
|
|
|
71
73
|
function createUpdatePropsManager() {
|
|
@@ -91,7 +93,11 @@ function createUpdatePropsManager() {
|
|
|
91
93
|
}, {});
|
|
92
94
|
|
|
93
95
|
return {
|
|
94
|
-
update(
|
|
96
|
+
update(
|
|
97
|
+
viewDescriptors: ViewDescriptorsWrapper,
|
|
98
|
+
updates: PropUpdates,
|
|
99
|
+
isAnimatedProps: boolean
|
|
100
|
+
) {
|
|
95
101
|
viewDescriptors.value.forEach(({ tag, shadowNodeWrapper }) => {
|
|
96
102
|
const viewTag = tag as number;
|
|
97
103
|
const { nativePropUpdates, jsPropUpdates } = processViewUpdates(
|
|
@@ -103,6 +109,7 @@ function createUpdatePropsManager() {
|
|
|
103
109
|
nativeOperations.push({
|
|
104
110
|
shadowNodeWrapper,
|
|
105
111
|
updates: nativePropUpdates,
|
|
112
|
+
isAnimatedProps,
|
|
106
113
|
});
|
|
107
114
|
}
|
|
108
115
|
if (jsPropUpdates) {
|