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.
Files changed (85) hide show
  1. package/Common/cpp/reanimated/CSS/common/values/CSSNumber.cpp +5 -9
  2. package/Common/cpp/reanimated/CSS/common/values/CSSNumber.h +2 -6
  3. package/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.cpp +34 -2
  4. package/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.h +15 -1
  5. package/Common/cpp/reanimated/Fabric/ReanimatedMountHook.cpp +9 -0
  6. package/Common/cpp/reanimated/Fabric/ReanimatedMountHook.h +3 -0
  7. package/Common/cpp/reanimated/Fabric/updates/AnimatedPropsRegistry.cpp +135 -33
  8. package/Common/cpp/reanimated/Fabric/updates/AnimatedPropsRegistry.h +37 -3
  9. package/Common/cpp/reanimated/Fabric/updates/SynchronousWritesTracker.cpp +103 -0
  10. package/Common/cpp/reanimated/Fabric/updates/SynchronousWritesTracker.h +74 -0
  11. package/Common/cpp/reanimated/Fabric/updates/UpdatesRegistry.cpp +43 -0
  12. package/Common/cpp/reanimated/Fabric/updates/UpdatesRegistry.h +13 -0
  13. package/Common/cpp/reanimated/Fabric/updates/UpdatesRegistryManager.cpp +14 -1
  14. package/Common/cpp/reanimated/Fabric/updates/UpdatesRegistryManager.h +3 -0
  15. package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp +318 -134
  16. package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.h +27 -6
  17. package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.cpp +32 -17
  18. package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.h +17 -1
  19. package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.cpp +14 -13
  20. package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.h +5 -2
  21. package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h +57 -9
  22. package/Common/cpp/reanimated/LayoutAnimations/PropsDiffer.h +2 -2
  23. package/Common/cpp/reanimated/LayoutAnimations/SharedTransitions.cpp +11 -11
  24. package/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp +114 -11
  25. package/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.h +12 -2
  26. package/Common/cpp/reanimated/Tools/PlatformDepMethodsHolder.h +17 -1
  27. package/Common/cpp/reanimated/Tools/TextMetrics.h +22 -0
  28. package/android/src/main/cpp/reanimated/android/NativeProxy.cpp +32 -3
  29. package/android/src/main/cpp/reanimated/android/NativeProxy.h +3 -0
  30. package/android/src/main/java/com/swmansion/reanimated/NativeProxy.kt +108 -9
  31. package/android/src/main/java/com/swmansion/reanimated/NodesManager.kt +2 -4
  32. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/EventHandler.kt +4 -3
  33. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensor.kt +1 -1
  34. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.kt +44 -33
  35. package/apple/reanimated/apple/REAReducedMotion.h +1 -3
  36. package/apple/reanimated/apple/REASynchronousPropsRewriter.h +18 -0
  37. package/apple/reanimated/apple/REASynchronousPropsRewriter.mm +37 -0
  38. package/apple/reanimated/apple/ReanimatedModule.mm +7 -0
  39. package/apple/reanimated/apple/keyboardObserver/REAKeyboardEventObserver.mm +20 -3
  40. package/apple/reanimated/apple/native/PlatformDepMethodsHolderImpl.mm +52 -1
  41. package/jest/resolver.js +4 -1
  42. package/lib/module/PropsRegistryGarbageCollector.js +43 -25
  43. package/lib/module/PropsRegistryGarbageCollector.js.map +1 -1
  44. package/lib/module/ReanimatedModule/NativeReanimated.js +2 -2
  45. package/lib/module/ReanimatedModule/NativeReanimated.js.map +1 -1
  46. package/lib/module/animation/timing.js +15 -2
  47. package/lib/module/animation/timing.js.map +1 -1
  48. package/lib/module/commonTypes.js.map +1 -1
  49. package/lib/module/createAnimatedComponent/AnimatedComponent.js +1 -1
  50. package/lib/module/createAnimatedComponent/AnimatedComponent.js.map +1 -1
  51. package/lib/module/createAnimatedComponent/AnimatedComponent.native.js +10 -34
  52. package/lib/module/createAnimatedComponent/AnimatedComponent.native.js.map +1 -1
  53. package/lib/module/platform-specific/jsVersion.js +1 -1
  54. package/lib/module/platformFunctions/setNativeProps.native.js +2 -1
  55. package/lib/module/platformFunctions/setNativeProps.native.js.map +1 -1
  56. package/lib/module/updateProps/updateProps.native.js +5 -4
  57. package/lib/module/updateProps/updateProps.native.js.map +1 -1
  58. package/lib/typescript/PropsRegistryGarbageCollector.d.ts +2 -2
  59. package/lib/typescript/PropsRegistryGarbageCollector.d.ts.map +1 -1
  60. package/lib/typescript/ReanimatedModule/reanimatedModuleProxy.d.ts +1 -1
  61. package/lib/typescript/ReanimatedModule/reanimatedModuleProxy.d.ts.map +1 -1
  62. package/lib/typescript/animation/timing.d.ts.map +1 -1
  63. package/lib/typescript/commonTypes.d.ts +3 -1
  64. package/lib/typescript/commonTypes.d.ts.map +1 -1
  65. package/lib/typescript/createAnimatedComponent/AnimatedComponent.d.ts +1 -1
  66. package/lib/typescript/createAnimatedComponent/AnimatedComponent.d.ts.map +1 -1
  67. package/lib/typescript/createAnimatedComponent/AnimatedComponent.native.d.ts +1 -1
  68. package/lib/typescript/createAnimatedComponent/AnimatedComponent.native.d.ts.map +1 -1
  69. package/lib/typescript/createAnimatedComponent/commonTypes.d.ts +1 -1
  70. package/lib/typescript/createAnimatedComponent/commonTypes.d.ts.map +1 -1
  71. package/lib/typescript/platform-specific/jsVersion.d.ts +1 -1
  72. package/lib/typescript/updateProps/updateProps.native.d.ts.map +1 -1
  73. package/package.json +9 -7
  74. package/src/PropsRegistryGarbageCollector.ts +46 -25
  75. package/src/ReanimatedModule/NativeReanimated.ts +2 -2
  76. package/src/ReanimatedModule/reanimatedModuleProxy.ts +1 -1
  77. package/src/animation/timing.ts +20 -2
  78. package/src/commonTypes.ts +3 -1
  79. package/src/createAnimatedComponent/AnimatedComponent.native.tsx +5 -30
  80. package/src/createAnimatedComponent/AnimatedComponent.tsx +1 -1
  81. package/src/createAnimatedComponent/commonTypes.ts +1 -1
  82. package/src/platform-specific/jsVersion.ts +1 -1
  83. package/src/platformFunctions/setNativeProps.native.ts +3 -1
  84. package/src/privateGlobals.d.ts +1 -0
  85. 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 { StyleProps } from './commonTypes';
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
- for (const { viewTag, styleProps } of settledUpdates) {
47
- if (styleProps === null) {
48
- continue;
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
- unprocessProps(styleProps);
52
- component?._syncStylePropsBackToReact(styleProps);
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 unprocessProps(props: StyleProps) {
72
+ export function unprocessSettledUpdate({
73
+ props,
74
+ style,
75
+ keysLastWrittenByAnimatedStyle,
76
+ }: Omit<SettledUpdate, 'viewTag'>) {
72
77
  unprocessColorsInProps(props);
73
- unprocessBoxShadow(props);
74
- unprocessBackgroundImage(props);
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
- function unprocessBoxShadow(props: StyleProps) {
78
- if (Array.isArray(props.boxShadow)) {
79
- // @ts-ignore props is readonly
80
- props.boxShadow = props.boxShadow.map((boxShadow) => ({
81
- ...boxShadow,
82
- color: unprocessColor(boxShadow.color),
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(props: StyleProps) {
88
- if (!Array.isArray(props.backgroundImage)) {
89
- return;
111
+ function unprocessBackgroundImage(value: unknown) {
112
+ if (!Array.isArray(value)) {
113
+ return value;
90
114
  }
91
- // @ts-ignore props is readonly
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,
@@ -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
- const runtime = now - startTime;
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
- const progress = animation.easing(runtime / config.duration);
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;
@@ -393,7 +393,9 @@ export type ShadowNodeWrapper = {
393
393
 
394
394
  export type SettledUpdate = {
395
395
  viewTag: number;
396
- styleProps: StyleProps | null;
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(settledUpdates: StyleProps) {
146
+ _syncStylePropsBackToReact(props: StyleProps, style: StyleProps) {
147
147
  if (!FORCE_REACT_RENDER_FOR_SETTLED_ANIMATIONS) {
148
148
  return;
149
149
  }
150
- // Settled updates arrive as one bag with no style-vs-props origin, so
151
- // partition them by the keys of attached animated props — only values
152
- // from `useAnimatedProps` or shared values passed as inline top-level
153
- // props may be passed as top-level props, all the other ones are
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
 
@@ -179,7 +179,7 @@ export default class AnimatedComponent
179
179
  }
180
180
  }
181
181
 
182
- _syncStylePropsBackToReact(_props: StyleProps) {
182
+ _syncStylePropsBackToReact(_props: StyleProps, _style: StyleProps) {
183
183
  // noop
184
184
  }
185
185
 
@@ -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>[];
@@ -4,4 +4,4 @@
4
4
  * version used to build the native part of the library in runtime. Remember to
5
5
  * keep this in sync with the version declared in `package.json`
6
6
  */
7
- export const jsVersion = '4.7.0';
7
+ export const jsVersion = '4.7.2';
@@ -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!([{ shadowNodeWrapper, updates }]);
48
+ global._updateProps!([
49
+ { shadowNodeWrapper, updates, isAnimatedProps: false },
50
+ ]);
49
51
  }
50
52
 
51
53
  function setNativePropsJest() {
@@ -42,6 +42,7 @@ declare global {
42
42
  shadowNodeWrapper: ShadowNodeWrapper;
43
43
 
44
44
  updates: PropUpdates;
45
+ isAnimatedProps: boolean;
45
46
  }[]
46
47
  ) => void)
47
48
  | undefined;
@@ -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(viewDescriptors: ViewDescriptorsWrapper, updates: PropUpdates) {
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) {