react-native-reanimated 4.1.3 → 4.1.4

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 (115) hide show
  1. package/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.cpp +24 -4
  2. package/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.h +7 -0
  3. package/android/build.gradle +1 -0
  4. package/lib/module/Colors.js +5 -8
  5. package/lib/module/Colors.js.map +1 -1
  6. package/lib/module/ConfigHelper.js +5 -3
  7. package/lib/module/ConfigHelper.js.map +1 -1
  8. package/lib/module/ReanimatedModule/NativeReanimated.js +1 -1
  9. package/lib/module/ReanimatedModule/NativeReanimated.js.map +1 -1
  10. package/lib/module/ReanimatedModule/js-reanimated/index.js.map +1 -1
  11. package/lib/module/animation/spring/spring.js +3 -4
  12. package/lib/module/animation/spring/spring.js.map +1 -1
  13. package/lib/module/animation/spring/springUtils.js +12 -0
  14. package/lib/module/animation/spring/springUtils.js.map +1 -1
  15. package/lib/module/common/logger.js +15 -11
  16. package/lib/module/common/logger.js.map +1 -1
  17. package/lib/module/common/processors/colors.js +1 -4
  18. package/lib/module/common/processors/colors.js.map +1 -1
  19. package/lib/module/createAnimatedComponent/AnimatedComponent.js +16 -5
  20. package/lib/module/createAnimatedComponent/AnimatedComponent.js.map +1 -1
  21. package/lib/module/createAnimatedComponent/InlinePropManager.js +13 -14
  22. package/lib/module/createAnimatedComponent/InlinePropManager.js.map +1 -1
  23. package/lib/module/css/index.js +1 -1
  24. package/lib/module/css/index.js.map +1 -1
  25. package/lib/module/css/native/normalization/common/settings.js +2 -12
  26. package/lib/module/css/native/normalization/common/settings.js.map +1 -1
  27. package/lib/module/css/native/style/config.js +2 -2
  28. package/lib/module/css/native/style/config.js.map +1 -1
  29. package/lib/module/css/utils/parsers.js +11 -0
  30. package/lib/module/css/utils/parsers.js.map +1 -1
  31. package/lib/module/css/utils/props.js +0 -5
  32. package/lib/module/css/utils/props.js.map +1 -1
  33. package/lib/module/css/web/managers/CSSAnimationsManager.js +68 -42
  34. package/lib/module/css/web/managers/CSSAnimationsManager.js.map +1 -1
  35. package/lib/module/fabricUtils.js +9 -11
  36. package/lib/module/fabricUtils.js.map +1 -1
  37. package/lib/module/hook/useAnimatedRef.js +12 -6
  38. package/lib/module/hook/useAnimatedRef.js.map +1 -1
  39. package/lib/module/index.js +1 -0
  40. package/lib/module/index.js.map +1 -1
  41. package/lib/module/initializers.js +1 -3
  42. package/lib/module/initializers.js.map +1 -1
  43. package/lib/module/interpolateColor.js +75 -24
  44. package/lib/module/interpolateColor.js.map +1 -1
  45. package/lib/module/layoutReanimation/web/Easing.web.js +3 -0
  46. package/lib/module/layoutReanimation/web/Easing.web.js.map +1 -1
  47. package/lib/module/layoutReanimation/web/componentUtils.js +4 -3
  48. package/lib/module/layoutReanimation/web/componentUtils.js.map +1 -1
  49. package/lib/module/layoutReanimation/web/domUtils.js +1 -1
  50. package/lib/module/layoutReanimation/web/domUtils.js.map +1 -1
  51. package/lib/module/layoutReanimation/web/transition/Curved.web.js +1 -1
  52. package/lib/module/layoutReanimation/web/transition/Curved.web.js.map +1 -1
  53. package/lib/module/platform-specific/jsVersion.js +1 -1
  54. package/lib/typescript/Colors.d.ts +1 -1
  55. package/lib/typescript/Colors.d.ts.map +1 -1
  56. package/lib/typescript/ConfigHelper.d.ts.map +1 -1
  57. package/lib/typescript/ReanimatedModule/js-reanimated/index.d.ts +2 -1
  58. package/lib/typescript/ReanimatedModule/js-reanimated/index.d.ts.map +1 -1
  59. package/lib/typescript/animation/spring/spring.d.ts.map +1 -1
  60. package/lib/typescript/animation/spring/springUtils.d.ts +1 -0
  61. package/lib/typescript/animation/spring/springUtils.d.ts.map +1 -1
  62. package/lib/typescript/common/logger.d.ts +5 -5
  63. package/lib/typescript/common/logger.d.ts.map +1 -1
  64. package/lib/typescript/common/processors/colors.d.ts.map +1 -1
  65. package/lib/typescript/commonTypes.d.ts +1 -1
  66. package/lib/typescript/commonTypes.d.ts.map +1 -1
  67. package/lib/typescript/createAnimatedComponent/AnimatedComponent.d.ts.map +1 -1
  68. package/lib/typescript/createAnimatedComponent/InlinePropManager.d.ts.map +1 -1
  69. package/lib/typescript/css/index.d.ts +1 -1
  70. package/lib/typescript/css/index.d.ts.map +1 -1
  71. package/lib/typescript/css/native/normalization/common/settings.d.ts.map +1 -1
  72. package/lib/typescript/css/native/style/config.d.ts.map +1 -1
  73. package/lib/typescript/css/utils/parsers.d.ts +2 -1
  74. package/lib/typescript/css/utils/parsers.d.ts.map +1 -1
  75. package/lib/typescript/css/web/managers/CSSAnimationsManager.d.ts +2 -0
  76. package/lib/typescript/css/web/managers/CSSAnimationsManager.d.ts.map +1 -1
  77. package/lib/typescript/fabricUtils.d.ts.map +1 -1
  78. package/lib/typescript/hook/useAnimatedRef.d.ts.map +1 -1
  79. package/lib/typescript/index.d.ts +1 -0
  80. package/lib/typescript/index.d.ts.map +1 -1
  81. package/lib/typescript/initializers.d.ts.map +1 -1
  82. package/lib/typescript/interpolateColor.d.ts.map +1 -1
  83. package/lib/typescript/layoutReanimation/web/Easing.web.d.ts.map +1 -1
  84. package/lib/typescript/layoutReanimation/web/componentUtils.d.ts +1 -1
  85. package/lib/typescript/layoutReanimation/web/componentUtils.d.ts.map +1 -1
  86. package/lib/typescript/platform-specific/jsVersion.d.ts +1 -1
  87. package/package.json +1 -1
  88. package/src/Colors.ts +7 -10
  89. package/src/ConfigHelper.ts +9 -3
  90. package/src/ReanimatedModule/NativeReanimated.ts +1 -1
  91. package/src/ReanimatedModule/js-reanimated/index.ts +2 -1
  92. package/src/animation/spring/spring.ts +11 -6
  93. package/src/animation/spring/springUtils.ts +19 -0
  94. package/src/common/logger.ts +18 -11
  95. package/src/common/processors/colors.ts +1 -4
  96. package/src/commonTypes.ts +1 -1
  97. package/src/createAnimatedComponent/AnimatedComponent.tsx +17 -5
  98. package/src/createAnimatedComponent/InlinePropManager.ts +14 -15
  99. package/src/css/index.ts +1 -1
  100. package/src/css/native/normalization/common/settings.ts +2 -17
  101. package/src/css/native/style/config.ts +1 -1
  102. package/src/css/utils/parsers.ts +13 -1
  103. package/src/css/utils/props.ts +0 -8
  104. package/src/css/web/managers/CSSAnimationsManager.ts +85 -40
  105. package/src/fabricUtils.ts +12 -26
  106. package/src/hook/useAnimatedRef.ts +12 -9
  107. package/src/index.ts +1 -0
  108. package/src/initializers.ts +1 -9
  109. package/src/interpolateColor.ts +112 -43
  110. package/src/layoutReanimation/web/Easing.web.ts +4 -0
  111. package/src/layoutReanimation/web/componentUtils.ts +6 -4
  112. package/src/layoutReanimation/web/domUtils.ts +1 -1
  113. package/src/layoutReanimation/web/transition/Curved.web.ts +1 -1
  114. package/src/platform-specific/jsVersion.ts +1 -1
  115. package/src/privateGlobals.d.ts +1 -1
@@ -148,7 +148,7 @@ const interpolateColorsLAB = (
148
148
  };
149
149
 
150
150
  const _splitColorsIntoChannels = (
151
- colors: readonly (string | number)[],
151
+ processedColors: readonly number[],
152
152
  convFromRgb: (color: { r: number; g: number; b: number }) => {
153
153
  ch1: number;
154
154
  ch2: number;
@@ -166,21 +166,17 @@ const _splitColorsIntoChannels = (
166
166
  const ch3: number[] = [];
167
167
  const alpha: number[] = [];
168
168
 
169
- for (let i = 0; i < colors.length; i++) {
170
- const color = colors[i];
171
- const processedColor = processColor(color);
172
- if (typeof processedColor === 'number') {
173
- const convertedColor = convFromRgb({
174
- r: red(processedColor),
175
- g: green(processedColor),
176
- b: blue(processedColor),
177
- });
178
-
179
- ch1.push(convertedColor.ch1);
180
- ch2.push(convertedColor.ch2);
181
- ch3.push(convertedColor.ch3);
182
- alpha.push(opacity(processedColor));
183
- }
169
+ for (const processedColor of processedColors) {
170
+ const convertedColor = convFromRgb({
171
+ r: red(processedColor),
172
+ g: green(processedColor),
173
+ b: blue(processedColor),
174
+ });
175
+
176
+ ch1.push(convertedColor.ch1);
177
+ ch2.push(convertedColor.ch2);
178
+ ch3.push(convertedColor.ch3);
179
+ alpha.push(opacity(processedColor));
184
180
  }
185
181
 
186
182
  return {
@@ -199,11 +195,11 @@ export interface InterpolateRGB {
199
195
  }
200
196
 
201
197
  const getInterpolateRGB = (
202
- colors: readonly (string | number)[]
198
+ processedColors: readonly number[]
203
199
  ): InterpolateRGB => {
204
200
  'worklet';
205
201
  const { ch1, ch2, ch3, alpha } = _splitColorsIntoChannels(
206
- colors,
202
+ processedColors,
207
203
  (color) => ({
208
204
  ch1: color.r,
209
205
  ch2: color.g,
@@ -227,17 +223,20 @@ export interface InterpolateHSV {
227
223
  }
228
224
 
229
225
  const getInterpolateHSV = (
230
- colors: readonly (string | number)[]
226
+ processedColors: readonly number[]
231
227
  ): InterpolateHSV => {
232
228
  'worklet';
233
- const { ch1, ch2, ch3, alpha } = _splitColorsIntoChannels(colors, (color) => {
234
- const hsvColor = RGBtoHSV(color.r, color.g, color.b);
235
- return {
236
- ch1: hsvColor.h,
237
- ch2: hsvColor.s,
238
- ch3: hsvColor.v,
239
- };
240
- });
229
+ const { ch1, ch2, ch3, alpha } = _splitColorsIntoChannels(
230
+ processedColors,
231
+ (color) => {
232
+ const hsvColor = RGBtoHSV(color.r, color.g, color.b);
233
+ return {
234
+ ch1: hsvColor.h,
235
+ ch2: hsvColor.s,
236
+ ch3: hsvColor.v,
237
+ };
238
+ }
239
+ );
241
240
 
242
241
  return {
243
242
  h: ch1,
@@ -255,18 +254,20 @@ interface InterpolateLAB {
255
254
  }
256
255
 
257
256
  const getInterpolateLAB = (
258
- colors: readonly (string | number)[]
257
+ processedColors: readonly number[]
259
258
  ): InterpolateLAB => {
260
259
  'worklet';
261
-
262
- const { ch1, ch2, ch3, alpha } = _splitColorsIntoChannels(colors, (color) => {
263
- const labColor = culori.oklab.convert.fromRgb(color);
264
- return {
265
- ch1: labColor.l,
266
- ch2: labColor.a,
267
- ch3: labColor.b,
268
- };
269
- });
260
+ const { ch1, ch2, ch3, alpha } = _splitColorsIntoChannels(
261
+ processedColors,
262
+ (color) => {
263
+ const labColor = culori.oklab.convert.fromRgb(color);
264
+ return {
265
+ ch1: labColor.l,
266
+ ch2: labColor.a,
267
+ ch3: labColor.b,
268
+ };
269
+ }
270
+ );
270
271
 
271
272
  return {
272
273
  l: ch1,
@@ -276,6 +277,69 @@ const getInterpolateLAB = (
276
277
  };
277
278
  };
278
279
 
280
+ const TRANSPARENCY_MASK = 0x00ffffff; // AARRGGBB
281
+
282
+ /**
283
+ * Processes color ranges to handle transparent color interpolation by replacing
284
+ * 'transparent' values with RGBA values that preserve the RGB channels from
285
+ * neighboring colors while setting alpha to 0.
286
+ *
287
+ * @example
288
+ * // Transparent between colors gets RGB from both neighbors
289
+ * ['red', 'transparent', 'blue'] → ['rgba(255, 0, 0, 1)', 'rgba(255, 0, 0, 0)', 'rgba(0, 0, 255, 0)', 'rgba(0, 0, 255, 1)']
290
+ *
291
+ * // Consecutive transparent values are consolidated if possible
292
+ * ['transparent', 'transparent', 'red'] → ['rgba(255, 0, 0, 0)', 'rgba(255, 0, 0, 1)']
293
+ */
294
+ function processColorRanges(
295
+ inputRange: readonly number[],
296
+ outputRange: readonly (number | string)[]
297
+ ): [readonly number[], readonly number[]] {
298
+ 'worklet';
299
+ const processedInputRange: number[] = [];
300
+ const processedOutputRange: number[] = [];
301
+ let isPrevTransparent = false;
302
+
303
+ for (let i = 0; i < inputRange.length; i++) {
304
+ const color = outputRange[i];
305
+ const processedColor = processColor(color);
306
+
307
+ const isTransparent = color === 'transparent';
308
+
309
+ if (typeof processedColor === 'number') {
310
+ if (isPrevTransparent) {
311
+ // Ensure that we animate from the correct RGB values (the same as in the
312
+ // current color) with alpha 0 when animating from transparent to a color.
313
+ processedInputRange.push(inputRange[i - 1]);
314
+ processedOutputRange.push(processedColor & TRANSPARENCY_MASK);
315
+ }
316
+ // Add current color to the output range
317
+ processedInputRange.push(inputRange[i]);
318
+ processedOutputRange.push(processedColor);
319
+ } else if (!isPrevTransparent) {
320
+ // If the transparent color is encountered after the non-transparent color,
321
+ // then we add the last processed color with alpha 0 to the output range.
322
+ if (isTransparent && i > 0) {
323
+ const lastProcessedColor =
324
+ processedOutputRange[processedOutputRange.length - 1];
325
+ processedInputRange.push(inputRange[i]);
326
+ processedOutputRange.push(lastProcessedColor & TRANSPARENCY_MASK);
327
+ }
328
+ } else if (i === inputRange.length - 1 && !processedOutputRange.length) {
329
+ // If the end of the input range is reached, the previous color was transparent
330
+ // and the output range is empty, that means all colors were transparent,
331
+ // so we can add just 2 transparent colors to the output range.
332
+ const lastindex = inputRange.length - 1;
333
+ processedInputRange.push(inputRange[0], inputRange[lastindex]);
334
+ processedOutputRange.push(0, 0);
335
+ }
336
+
337
+ isPrevTransparent = isTransparent;
338
+ }
339
+
340
+ return [processedInputRange, processedOutputRange];
341
+ }
342
+
279
343
  /**
280
344
  * Lets you map a value from a range of numbers to a range of colors using
281
345
  * linear interpolation.
@@ -318,25 +382,30 @@ export function interpolateColor(
318
382
  options: InterpolationOptions = {}
319
383
  ): string | number {
320
384
  'worklet';
385
+ const [processedInputRange, processedOutputRange] = processColorRanges(
386
+ inputRange,
387
+ outputRange
388
+ );
389
+
321
390
  if (colorSpace === 'HSV') {
322
391
  return interpolateColorsHSV(
323
392
  value,
324
- inputRange,
325
- getInterpolateHSV(outputRange),
393
+ processedInputRange,
394
+ getInterpolateHSV(processedOutputRange),
326
395
  options
327
396
  );
328
397
  } else if (colorSpace === 'RGB') {
329
398
  return interpolateColorsRGB(
330
399
  value,
331
- inputRange,
332
- getInterpolateRGB(outputRange),
400
+ processedInputRange,
401
+ getInterpolateRGB(processedOutputRange),
333
402
  options
334
403
  );
335
404
  } else if (colorSpace === 'LAB') {
336
405
  return interpolateColorsLAB(
337
406
  value,
338
- inputRange,
339
- getInterpolateLAB(outputRange),
407
+ processedInputRange,
408
+ getInterpolateLAB(processedOutputRange),
340
409
  options
341
410
  );
342
411
  }
@@ -29,6 +29,10 @@ export function getEasingByName(easingName: WebEasingsNames) {
29
29
  export function maybeGetBezierEasing(
30
30
  easing: EasingFunctionFactory
31
31
  ): null | string {
32
+ if (typeof easing === 'string') {
33
+ return null;
34
+ }
35
+
32
36
  if (!('factory' in easing)) {
33
37
  return null;
34
38
  }
@@ -190,7 +190,7 @@ export function setElementAnimation(
190
190
  }
191
191
 
192
192
  const maybeRemoveElement = () => {
193
- if (element.reanimatedDummy && parent?.contains(element)) {
193
+ if (element.isDummy && parent?.contains(element)) {
194
194
  element.removedAfterAnimation = true;
195
195
  parent.removeChild(element);
196
196
  }
@@ -318,16 +318,18 @@ function getElementScrollValue(element: HTMLElement): ScrollOffsets {
318
318
  }
319
319
 
320
320
  export function handleExitingAnimation(
321
- element: HTMLElement,
321
+ element: ReanimatedHTMLElement,
322
322
  animationConfig: AnimationConfig
323
323
  ) {
324
324
  const parent = element.offsetParent;
325
325
  const dummy = element.cloneNode() as ReanimatedHTMLElement;
326
- dummy.reanimatedDummy = true;
327
326
 
328
- element.style.animationName = '';
327
+ dummy.isDummy = true;
329
328
  dummy.style.animationName = '';
330
329
 
330
+ element.dummyClone = dummy;
331
+ element.style.animationName = '';
332
+
331
333
  // Moving elements in DOM resets their scroll positions
332
334
  // so we memorize them here and restore after
333
335
  const scrollPositions = new Map<Element, { top: number; left: number }>();
@@ -174,7 +174,7 @@ function findDescendantWithExitingAnimation(
174
174
  return;
175
175
  }
176
176
 
177
- if (node.reanimatedDummy && node.removedAfterAnimation === undefined) {
177
+ if (node.isDummy && node.removedAfterAnimation === undefined) {
178
178
  reattachElementToAncestor(node, root);
179
179
  }
180
180
 
@@ -93,7 +93,7 @@ function prepareDummy(
93
93
  };
94
94
 
95
95
  const dummy = element.cloneNode(true) as ReanimatedHTMLElement;
96
- dummy.reanimatedDummy = true;
96
+ dummy.isDummy = true;
97
97
  resetStyle(dummy);
98
98
 
99
99
  return { dummy, dummyAnimationConfig };
@@ -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.1.3';
7
+ export const jsVersion = '4.1.4';
@@ -56,7 +56,7 @@ declare global {
56
56
  | undefined;
57
57
  var _frameCallbackRegistry: FrameCallbackRegistryUI;
58
58
  var console: Console;
59
- var __reanimatedLoggerConfig: LoggerConfigInternal;
59
+ var __reanimatedLoggerConfig: LoggerConfigInternal | undefined;
60
60
  var __mapperRegistry: MapperRegistry;
61
61
  var __sensorContainer: SensorContainer;
62
62
  var LayoutAnimationsManager: LayoutAnimationsManager;