react-native-reanimated 3.4.1 → 3.4.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 (144) hide show
  1. package/lib/module/Animated.js +60 -1
  2. package/lib/module/Animated.js.map +1 -1
  3. package/lib/module/createAnimatedComponent.js.map +1 -1
  4. package/lib/module/reanimated2/Easing.js +8 -0
  5. package/lib/module/reanimated2/Easing.js.map +1 -1
  6. package/lib/module/reanimated2/UpdateProps.js +2 -2
  7. package/lib/module/reanimated2/UpdateProps.js.map +1 -1
  8. package/lib/module/reanimated2/animation/commonTypes.js.map +1 -1
  9. package/lib/module/reanimated2/animation/decay.js.map +1 -1
  10. package/lib/module/reanimated2/animation/index.js +1 -1
  11. package/lib/module/reanimated2/animation/index.js.map +1 -1
  12. package/lib/module/reanimated2/animation/springUtils.js.map +1 -1
  13. package/lib/module/reanimated2/animation/styleAnimation.js +2 -2
  14. package/lib/module/reanimated2/animation/styleAnimation.js.map +1 -1
  15. package/lib/module/reanimated2/animation/timing.js.map +1 -1
  16. package/lib/module/reanimated2/animation/transformationMatrix/matrixUtils.js +6 -0
  17. package/lib/module/reanimated2/animation/transformationMatrix/matrixUtils.js.map +1 -1
  18. package/lib/module/reanimated2/animation/util.js +4 -19
  19. package/lib/module/reanimated2/animation/util.js.map +1 -1
  20. package/lib/module/reanimated2/commonTypes.js.map +1 -1
  21. package/lib/module/reanimated2/component/FlatList.js.map +1 -1
  22. package/lib/module/reanimated2/component/ScrollView.js.map +1 -1
  23. package/lib/module/reanimated2/fabricUtils.js +3 -1
  24. package/lib/module/reanimated2/fabricUtils.js.map +1 -1
  25. package/lib/module/reanimated2/globals.d.js.map +1 -1
  26. package/lib/module/reanimated2/helperTypes.js.map +1 -1
  27. package/lib/module/reanimated2/hook/commonTypes.js.map +1 -1
  28. package/lib/module/reanimated2/hook/index.js.map +1 -1
  29. package/lib/module/reanimated2/hook/useAnimatedGestureHandler.js +1 -1
  30. package/lib/module/reanimated2/hook/useAnimatedGestureHandler.js.map +1 -1
  31. package/lib/module/reanimated2/hook/useAnimatedRef.js +2 -2
  32. package/lib/module/reanimated2/hook/useAnimatedRef.js.map +1 -1
  33. package/lib/module/reanimated2/hook/useAnimatedStyle.js +1 -1
  34. package/lib/module/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  35. package/lib/module/reanimated2/hook/utils.js +2 -27
  36. package/lib/module/reanimated2/hook/utils.js.map +1 -1
  37. package/lib/module/reanimated2/index.js.map +1 -1
  38. package/lib/module/reanimated2/interpolateColor.js.map +1 -1
  39. package/lib/module/reanimated2/js-reanimated/commonTypes.js.map +1 -1
  40. package/lib/module/reanimated2/js-reanimated/index.js.map +1 -1
  41. package/lib/module/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js.map +1 -1
  42. package/lib/module/reanimated2/layoutReanimation/animationBuilder/Keyframe.js.map +1 -1
  43. package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  44. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js.map +1 -1
  45. package/lib/module/reanimated2/layoutReanimation/index.js.map +1 -1
  46. package/lib/module/reanimated2/mappers.js +1 -1
  47. package/lib/module/reanimated2/mappers.js.map +1 -1
  48. package/lib/module/reanimated2/mock.js +26 -0
  49. package/lib/module/reanimated2/mock.js.map +1 -1
  50. package/lib/module/reanimated2/mutables.js +0 -1
  51. package/lib/module/reanimated2/mutables.js.map +1 -1
  52. package/lib/module/reanimated2/platform-specific/checkCppVersion.js +3 -0
  53. package/lib/module/reanimated2/platform-specific/checkCppVersion.js.map +1 -1
  54. package/lib/module/reanimated2/platform-specific/jsVersion.js +1 -1
  55. package/lib/module/reanimated2/platform-specific/jsVersion.js.map +1 -1
  56. package/lib/module/reanimated2/valueSetter.js +0 -1
  57. package/lib/module/reanimated2/valueSetter.js.map +1 -1
  58. package/lib/module/setAndForwardRef.js.map +1 -1
  59. package/lib/typescript/Animated.d.ts +68 -3
  60. package/lib/typescript/createAnimatedComponent.d.ts +1 -26
  61. package/lib/typescript/reanimated2/Easing.d.ts +17 -9
  62. package/lib/typescript/reanimated2/UpdateProps.d.ts +5 -5
  63. package/lib/typescript/reanimated2/animation/commonTypes.d.ts +4 -3
  64. package/lib/typescript/reanimated2/animation/decay.d.ts +2 -4
  65. package/lib/typescript/reanimated2/animation/index.d.ts +3 -3
  66. package/lib/typescript/reanimated2/animation/springUtils.d.ts +1 -0
  67. package/lib/typescript/reanimated2/animation/styleAnimation.d.ts +2 -6
  68. package/lib/typescript/reanimated2/animation/timing.d.ts +4 -7
  69. package/lib/typescript/reanimated2/animation/transformationMatrix/matrixUtils.d.ts +1 -1
  70. package/lib/typescript/reanimated2/animation/util.d.ts +2 -4
  71. package/lib/typescript/reanimated2/commonTypes.d.ts +0 -4
  72. package/lib/typescript/reanimated2/component/FlatList.d.ts +2 -1
  73. package/lib/typescript/reanimated2/component/ScrollView.d.ts +1 -1
  74. package/lib/typescript/reanimated2/helperTypes.d.ts +11 -7
  75. package/lib/typescript/reanimated2/hook/commonTypes.d.ts +2 -2
  76. package/lib/typescript/reanimated2/hook/index.d.ts +1 -1
  77. package/lib/typescript/reanimated2/hook/useAnimatedGestureHandler.d.ts +2 -2
  78. package/lib/typescript/reanimated2/hook/useAnimatedRef.d.ts +4 -4
  79. package/lib/typescript/reanimated2/hook/useAnimatedStyle.d.ts +4 -5
  80. package/lib/typescript/reanimated2/hook/utils.d.ts +3 -11
  81. package/lib/typescript/reanimated2/index.d.ts +3 -1
  82. package/lib/typescript/reanimated2/interpolateColor.d.ts +2 -3
  83. package/lib/typescript/reanimated2/js-reanimated/commonTypes.d.ts +1 -43
  84. package/lib/typescript/reanimated2/js-reanimated/index.d.ts +3 -2
  85. package/lib/typescript/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.d.ts +4 -4
  86. package/lib/typescript/reanimated2/layoutReanimation/animationBuilder/Keyframe.d.ts +0 -11
  87. package/lib/typescript/reanimated2/layoutReanimation/animationBuilder/commonTypes.d.ts +3 -3
  88. package/lib/typescript/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.d.ts +13 -13
  89. package/lib/typescript/reanimated2/layoutReanimation/index.d.ts +1 -0
  90. package/lib/typescript/reanimated2/mappers.d.ts +0 -12
  91. package/lib/typescript/reanimated2/mock.d.ts +1 -76
  92. package/lib/typescript/reanimated2/mutables.d.ts +0 -1
  93. package/lib/typescript/reanimated2/platform-specific/jsVersion.d.ts +1 -1
  94. package/lib/typescript/reanimated2/valueSetter.d.ts +0 -1
  95. package/lib/typescript/setAndForwardRef.d.ts +1 -1
  96. package/package.json +3 -1
  97. package/src/Animated.ts +80 -6
  98. package/src/createAnimatedComponent.tsx +2 -2
  99. package/src/reanimated2/Easing.ts +18 -8
  100. package/src/reanimated2/UpdateProps.ts +13 -17
  101. package/src/reanimated2/animation/commonTypes.ts +3 -3
  102. package/src/reanimated2/animation/decay.ts +3 -1
  103. package/src/reanimated2/animation/index.ts +3 -3
  104. package/src/reanimated2/animation/springUtils.ts +2 -0
  105. package/src/reanimated2/animation/styleAnimation.ts +5 -5
  106. package/src/reanimated2/animation/timing.ts +6 -4
  107. package/src/reanimated2/animation/transformationMatrix/matrixUtils.tsx +4 -1
  108. package/src/reanimated2/animation/util.ts +5 -29
  109. package/src/reanimated2/commonTypes.ts +0 -25
  110. package/src/reanimated2/component/FlatList.tsx +3 -1
  111. package/src/reanimated2/component/ScrollView.tsx +1 -1
  112. package/src/reanimated2/fabricUtils.ts +1 -0
  113. package/src/reanimated2/globals.d.ts +3 -3
  114. package/src/reanimated2/helperTypes.ts +17 -7
  115. package/src/reanimated2/hook/commonTypes.ts +2 -3
  116. package/src/reanimated2/hook/index.ts +4 -1
  117. package/src/reanimated2/hook/useAnimatedGestureHandler.ts +2 -2
  118. package/src/reanimated2/hook/useAnimatedRef.ts +13 -10
  119. package/src/reanimated2/hook/useAnimatedStyle.ts +27 -26
  120. package/src/reanimated2/hook/utils.ts +5 -31
  121. package/src/reanimated2/index.ts +13 -1
  122. package/src/reanimated2/interpolateColor.ts +2 -2
  123. package/src/reanimated2/js-reanimated/commonTypes.ts +3 -3
  124. package/src/reanimated2/js-reanimated/index.ts +4 -3
  125. package/src/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.ts +4 -4
  126. package/src/reanimated2/layoutReanimation/animationBuilder/Keyframe.ts +5 -5
  127. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +3 -3
  128. package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +13 -13
  129. package/src/reanimated2/layoutReanimation/index.ts +1 -0
  130. package/src/reanimated2/mappers.ts +2 -2
  131. package/src/reanimated2/mock.ts +27 -0
  132. package/src/reanimated2/mutables.ts +0 -1
  133. package/src/reanimated2/platform-specific/checkCppVersion.ts +2 -0
  134. package/src/reanimated2/platform-specific/jsVersion.ts +1 -1
  135. package/src/reanimated2/valueSetter.ts +0 -1
  136. package/src/setAndForwardRef.ts +1 -1
  137. package/lib/module/reanimated2/js-reanimated/Mapper.js +0 -69
  138. package/lib/module/reanimated2/js-reanimated/Mapper.js.map +0 -1
  139. package/lib/module/reanimated2/js-reanimated/MapperRegistry.js +0 -109
  140. package/lib/module/reanimated2/js-reanimated/MapperRegistry.js.map +0 -1
  141. package/lib/typescript/reanimated2/js-reanimated/Mapper.d.ts +0 -14
  142. package/lib/typescript/reanimated2/js-reanimated/MapperRegistry.d.ts +0 -14
  143. package/src/reanimated2/js-reanimated/Mapper.ts +0 -94
  144. package/src/reanimated2/js-reanimated/MapperRegistry.ts +0 -133
@@ -1,4 +1,4 @@
1
- import type { EasingFn, EasingFactoryFn } from '../Easing';
1
+ import type { EasingFunction, EasingFunctionFactory } from '../Easing';
2
2
  import { Easing } from '../Easing';
3
3
  import { defineAnimation } from './util';
4
4
  import type {
@@ -10,12 +10,14 @@ import type {
10
10
 
11
11
  interface TimingConfig {
12
12
  duration?: number;
13
- easing?: EasingFn | EasingFactoryFn;
13
+ easing?: EasingFunction | EasingFunctionFactory;
14
14
  }
15
15
 
16
+ export type WithTimingConfig = TimingConfig;
17
+
16
18
  export interface TimingAnimation extends Animation<TimingAnimation> {
17
19
  type: string;
18
- easing: EasingFn;
20
+ easing: EasingFunction;
19
21
  startValue: AnimatableValue;
20
22
  startTime: Timestamp;
21
23
  progress: number;
@@ -23,7 +25,7 @@ export interface TimingAnimation extends Animation<TimingAnimation> {
23
25
  current: AnimatableValue;
24
26
  }
25
27
 
26
- export interface InnerTimingAnimation
28
+ interface InnerTimingAnimation
27
29
  extends Omit<TimingAnimation, 'toValue' | 'current'> {
28
30
  toValue: number;
29
31
  current: number;
@@ -11,7 +11,7 @@ export type AffineMatrix = FixedLengthArray<FixedLengthArray<number, 4>, 4>;
11
11
 
12
12
  export type AffineMatrixFlat = FixedLengthArray<number, 16>;
13
13
 
14
- export type TransformMatrixDecomposition = Record<
14
+ type TransformMatrixDecomposition = Record<
15
15
  'translationMatrix' | 'scaleMatrix' | 'rotationMatrix' | 'skewMatrix',
16
16
  AffineMatrix
17
17
  >;
@@ -34,6 +34,7 @@ export function isAffineMatrixFlat(x: unknown): x is AffineMatrixFlat {
34
34
  );
35
35
  }
36
36
 
37
+ // ts-prune-ignore-next This function is exported to be tested
37
38
  export function isAffineMatrix(x: unknown): x is AffineMatrix {
38
39
  'worklet';
39
40
  return (
@@ -53,6 +54,7 @@ export function flatten(matrix: AffineMatrix): AffineMatrixFlat {
53
54
  return matrix.flat() as AffineMatrixFlat;
54
55
  }
55
56
 
57
+ // ts-prune-ignore-next This function is exported to be tested
56
58
  export function unflatten(m: AffineMatrixFlat): AffineMatrix {
57
59
  'worklet';
58
60
  return [
@@ -334,6 +336,7 @@ function gramSchmidtAlgorithm(matrix: AffineMatrix): {
334
336
  };
335
337
  }
336
338
 
339
+ // ts-prune-ignore-next This function is exported to be tested
337
340
  export function decomposeMatrix(
338
341
  unknownTypeMatrix: AffineMatrixFlat | AffineMatrix
339
342
  ): TransformMatrixDecomposition {
@@ -1,8 +1,4 @@
1
- import type {
2
- HigherOrderAnimation,
3
- NextAnimation,
4
- StyleLayoutAnimation,
5
- } from './commonTypes';
1
+ import type { HigherOrderAnimation, StyleLayoutAnimation } from './commonTypes';
6
2
  import type { ParsedColorArray } from '../Colors';
7
3
  import {
8
4
  isColor,
@@ -11,9 +7,7 @@ import {
11
7
  toGammaSpace,
12
8
  toLinearSpace,
13
9
  } from '../Colors';
14
-
15
10
  import type {
16
- AnimatedStyle,
17
11
  SharedValue,
18
12
  AnimatableValue,
19
13
  Animation,
@@ -37,8 +31,6 @@ import {
37
31
 
38
32
  let IN_STYLE_UPDATER = false;
39
33
 
40
- export type UserUpdater = () => AnimatedStyle;
41
-
42
34
  export function initialUpdaterRun<T>(updater: () => T): T {
43
35
  IN_STYLE_UPDATER = true;
44
36
  const result = updater();
@@ -203,7 +195,7 @@ function decorateAnimation<T extends AnimationObject | StyleLayoutAnimation>(
203
195
  animation[i].current = RGBACurrent[index];
204
196
  const result = animation[i].onFrame(animation[i], timestamp);
205
197
  // We really need to assign this value to result, instead of passing it directly - otherwise once "finished" is false, onFrame won't be called
206
- finished &&= result;
198
+ finished = finished && result;
207
199
  res.push(animation[i].current);
208
200
  });
209
201
 
@@ -248,7 +240,7 @@ function decorateAnimation<T extends AnimationObject | StyleLayoutAnimation>(
248
240
  let finished = true;
249
241
  const result = animation[0].onFrame(animation[0], timestamp);
250
242
  // We really need to assign this value to result, instead of passing it directly - otherwise once "finished" is false, onFrame won't be called
251
- finished &&= result;
243
+ finished = finished && result;
252
244
 
253
245
  const progress = animation[0].current / 100;
254
246
 
@@ -330,7 +322,7 @@ function decorateAnimation<T extends AnimationObject | StyleLayoutAnimation>(
330
322
  (animation.current as Array<number>).forEach((_, i) => {
331
323
  const result = animation[i].onFrame(animation[i], timestamp);
332
324
  // We really need to assign this value to result, instead of passing it directly - otherwise once "finished" is false, onFrame won't be called
333
- finished &&= result;
325
+ finished = finished && result;
334
326
  (animation.current as Array<number>)[i] = animation[i].current;
335
327
  });
336
328
 
@@ -370,7 +362,7 @@ function decorateAnimation<T extends AnimationObject | StyleLayoutAnimation>(
370
362
  for (const key in animation.current as AnimatableValueObject) {
371
363
  const result = animation[key].onFrame(animation[key], timestamp);
372
364
  // We really need to assign this value to result, instead of passing it directly - otherwise once "finished" is false, onFrame won't be called
373
- finished &&= result;
365
+ finished = finished && result;
374
366
  newObject[key] = animation[key].current;
375
367
  }
376
368
  animation.current = newObject;
@@ -449,19 +441,3 @@ export function cancelAnimation<T>(sharedValue: SharedValue<T>): void {
449
441
  // setting the current value cancels the animation if one is currently running
450
442
  sharedValue.value = sharedValue.value; // eslint-disable-line no-self-assign
451
443
  }
452
-
453
- // TODO it should work only if there was no animation before.
454
- export function withStartValue(
455
- startValue: AnimatableValue,
456
- animation: NextAnimation<AnimationObject>
457
- ): Animation<AnimationObject> {
458
- 'worklet';
459
- return defineAnimation(startValue, () => {
460
- 'worklet';
461
- if (!_WORKLET && typeof animation === 'function') {
462
- animation = animation();
463
- }
464
- (animation as Animation<AnimationObject>).current = startValue;
465
- return animation as Animation<AnimationObject>;
466
- });
467
- }
@@ -37,31 +37,6 @@ export interface StyleProps extends ViewStyle, TextStyle {
37
37
  [key: string]: any;
38
38
  }
39
39
 
40
- export interface AnimatedStyle extends Record<string, AnimationObject> {
41
- [key: string]: any;
42
- transform?: Array<
43
- | Record<'matrix', number[] | AnimationObject>
44
- | Partial<
45
- Record<
46
- | 'perspective'
47
- | 'scale'
48
- | 'scaleX'
49
- | 'scaleY'
50
- | 'translateX'
51
- | 'translateY',
52
- number | AnimationObject
53
- >
54
- >
55
- | Partial<
56
- Record<
57
- 'rotate' | 'rotateX' | 'rotateY' | 'rotateZ' | 'skewX' | 'skewY',
58
- string | AnimationObject
59
- >
60
- >
61
- | Record<string, AnimationObject>
62
- >;
63
- }
64
-
65
40
  export interface SharedValue<T> {
66
41
  value: T;
67
42
  addListener: (listenerID: number, listener: (value: T) => void) => void;
@@ -41,6 +41,8 @@ interface ReanimatedFlatListPropsWithLayout<T> extends FlatListProps<T> {
41
41
  itemLayoutAnimation?: ILayoutAnimationBuilder;
42
42
  }
43
43
 
44
+ export type FlatListPropsWithLayout<T> = ReanimatedFlatListPropsWithLayout<T>;
45
+
44
46
  // TODO TYPESCRIPT This is a temporary type to get rid of .d.ts file.
45
47
  declare class ReanimatedFlatListClass<T> extends Component<
46
48
  AnimateProps<ReanimatedFlatListPropsWithLayout<T>>
@@ -48,7 +50,7 @@ declare class ReanimatedFlatListClass<T> extends Component<
48
50
  getNode(): FlatList;
49
51
  }
50
52
 
51
- export interface ReanimatedFlatListProps<ItemT> extends FlatListProps<ItemT> {
53
+ interface ReanimatedFlatListProps<ItemT> extends FlatListProps<ItemT> {
52
54
  itemLayoutAnimation?: ILayoutAnimationBuilder;
53
55
  }
54
56
 
@@ -7,7 +7,7 @@ import type { SharedValue } from '../commonTypes';
7
7
  import type { AnimateProps } from '../helperTypes';
8
8
  import { useAnimatedRef, useScrollViewOffset } from '../hook';
9
9
 
10
- interface AnimatedScrollViewProps extends ScrollViewProps {
10
+ export interface AnimatedScrollViewProps extends ScrollViewProps {
11
11
  scrollViewOffset?: SharedValue<number>;
12
12
  }
13
13
 
@@ -14,6 +14,7 @@ let findHostInstance_DEPRECATED: (ref: React.Component) => HostInstance;
14
14
  if (global._IS_FABRIC) {
15
15
  try {
16
16
  findHostInstance_DEPRECATED =
17
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
17
18
  require('react-native/Libraries/Renderer/shims/ReactFabric').findHostInstance_DEPRECATED;
18
19
  } catch (e) {
19
20
  throw new Error(
@@ -1,7 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  /* eslint-disable no-var */
3
3
  import type {
4
- AnimatedStyle,
5
4
  StyleProps,
6
5
  MeasuredDimensions,
7
6
  MapperRegistry,
@@ -10,6 +9,7 @@ import type {
10
9
  ShadowNodeWrapper,
11
10
  ComplexWorkletFunction,
12
11
  } from './commonTypes';
12
+ import type { AnimatedStyle } from './helperTypes';
13
13
  import type { FrameCallbackRegistryUI } from './frameCallback/FrameCallbackRegistryUI';
14
14
  import type { NativeReanimatedModule } from './NativeReanimated/NativeReanimated';
15
15
  import type { SensorContainer } from './SensorContainer';
@@ -49,7 +49,7 @@ declare global {
49
49
  operations: {
50
50
  tag: number;
51
51
  name: string;
52
- updates: StyleProps | AnimatedStyle;
52
+ updates: StyleProps | AnimatedStyle<any>;
53
53
  }[]
54
54
  ) => void)
55
55
  | undefined;
@@ -57,7 +57,7 @@ declare global {
57
57
  | ((
58
58
  operations: {
59
59
  shadowNodeWrapper: ShadowNodeWrapper;
60
- updates: StyleProps | AnimatedStyle;
60
+ updates: StyleProps | AnimatedStyle<any>;
61
61
  }[]
62
62
  ) => void)
63
63
  | undefined;
@@ -23,21 +23,28 @@ import type { ReanimatedKeyframe } from './layoutReanimation/animationBuilder/Ke
23
23
  import type { SharedTransition } from './layoutReanimation/sharedTransitions';
24
24
  import type { DependencyList } from './hook/commonTypes';
25
25
 
26
- type Adaptable<T> = T | ReadonlyArray<T | ReadonlyArray<T>> | SharedValue<T>;
26
+ export type Adaptable<T> =
27
+ | T
28
+ | ReadonlyArray<T | ReadonlyArray<T>>
29
+ | SharedValue<T>;
27
30
 
28
- type AdaptTransforms<T> = {
31
+ export type AdaptTransforms<T> = {
29
32
  [P in keyof T]: Adaptable<T[P]>;
30
33
  };
31
34
 
32
35
  type TransformsStyle = Pick<RNTransformsStyle, 'transform'>;
33
36
 
34
- type TransformStyleTypes = TransformsStyle['transform'] extends
37
+ export type TransformStyleTypes = TransformsStyle['transform'] extends
35
38
  | readonly (infer T)[]
39
+ | string
36
40
  | undefined
37
41
  ? T
38
42
  : never;
39
- type AnimatedTransform = AdaptTransforms<TransformStyleTypes>[];
43
+ export type AnimatedTransform = AdaptTransforms<TransformStyleTypes>[];
40
44
 
45
+ /**
46
+ * @deprecated Please use `AnimatedStyle` type instead.
47
+ */
41
48
  export type AnimateStyle<S> = {
42
49
  [K in keyof S]: K extends 'transform'
43
50
  ? AnimatedTransform
@@ -50,13 +57,15 @@ export type AnimateStyle<S> = {
50
57
  : S[K] | SharedValue<AnimatableValue>;
51
58
  };
52
59
 
60
+ export type AnimatedStyle<S> = AnimateStyle<S>;
61
+
53
62
  // provided types can either be their original types (like backgroundColor: pink)
54
63
  // or inline shared values/derived values
55
64
  type MaybeSharedValue<S> = {
56
65
  [K in keyof S]: S[K] | Readonly<SharedValue<Extract<S[K], AnimatableValue>>>;
57
66
  };
58
67
 
59
- type StylesOrDefault<T> = 'style' extends keyof T
68
+ export type StylesOrDefault<T> = 'style' extends keyof T
60
69
  ? MaybeSharedValue<T['style']>
61
70
  : Record<string, unknown>;
62
71
 
@@ -81,12 +90,12 @@ type PickStyleProps<T> = Pick<
81
90
 
82
91
  type StyleAnimatedProps<P extends object> = {
83
92
  [K in keyof PickStyleProps<P>]: StyleProp<
84
- AnimateStyle<P[K] | MaybeSharedValue<P[K]>>
93
+ AnimatedStyle<P[K] | MaybeSharedValue<P[K]>>
85
94
  >;
86
95
  };
87
96
 
88
97
  type JustStyleAnimatedProp<P extends object> = {
89
- style?: StyleProp<AnimateStyle<StylesOrDefault<P>>>;
98
+ style?: StyleProp<AnimatedStyle<StylesOrDefault<P>>>;
90
99
  };
91
100
 
92
101
  type NonStyleAnimatedProps<P extends object> = {
@@ -123,6 +132,7 @@ export type AnimateProps<P extends object> = NonStyleAnimatedProps<P> &
123
132
  animatedProps?: Partial<AnimatedPropsProp<P>>;
124
133
  };
125
134
 
135
+ // ts-prune-ignore-next This will be used soon
126
136
  export type AnimatedProps<P extends object> = AnimateProps<P>;
127
137
 
128
138
  export type AnimatedPropsAdapterFunction = (
@@ -1,3 +1,4 @@
1
+ import type { Component } from 'react';
1
2
  import type { Context, ShadowNodeWrapper } from '../commonTypes';
2
3
 
3
4
  export type DependencyList = Array<unknown> | undefined;
@@ -13,12 +14,10 @@ export interface Descriptor {
13
14
  shadowNodeWrapper: ShadowNodeWrapper;
14
15
  }
15
16
 
16
- export interface RefObjectFunction<T> {
17
+ export interface AnimatedRef<T extends Component> {
17
18
  current: T | null;
18
19
  (component?: T):
19
20
  | number // Paper
20
21
  | ShadowNodeWrapper // Fabric
21
22
  | HTMLElement; // web
22
23
  }
23
-
24
- export type AnimatedRef<T> = RefObjectFunction<T>;
@@ -8,7 +8,10 @@ export {
8
8
  export { useSharedValue } from './useSharedValue';
9
9
  export { useReducedMotion } from './useReducedMotion';
10
10
  export { useAnimatedStyle } from './useAnimatedStyle';
11
- export type { AnimatedStyleResult } from './useAnimatedStyle';
11
+ export type {
12
+ AnimatedStyleResult,
13
+ AnimatedStyleProp,
14
+ } from './useAnimatedStyle';
12
15
  export { useAnimatedGestureHandler } from './useAnimatedGestureHandler';
13
16
  export type {
14
17
  GestureHandlerEvent,
@@ -16,7 +16,7 @@ export interface GestureHandlers<T, TContext extends Context> {
16
16
  onFinish?: Handler<T, TContext>;
17
17
  }
18
18
 
19
- export const EventType = {
19
+ const EventType = {
20
20
  UNDETERMINED: 0,
21
21
  FAILED: 1,
22
22
  BEGAN: 2,
@@ -25,7 +25,7 @@ export const EventType = {
25
25
  END: 5,
26
26
  };
27
27
 
28
- export interface GestureHandlerNativeEvent {
28
+ interface GestureHandlerNativeEvent {
29
29
  handlerTag: number;
30
30
  numberOfPointers: number;
31
31
  state: (typeof EventType)[keyof typeof EventType];
@@ -1,7 +1,7 @@
1
1
  import type { Component } from 'react';
2
2
  import { useRef } from 'react';
3
3
  import { useSharedValue } from './useSharedValue';
4
- import type { AnimatedRef, RefObjectFunction } from './commonTypes';
4
+ import type { AnimatedRef } from './commonTypes';
5
5
  import type { ShadowNodeWrapper } from '../commonTypes';
6
6
  import { getShadowNodeWrapperFromRef } from '../fabricUtils';
7
7
  import {
@@ -9,13 +9,14 @@ import {
9
9
  registerShareableMapping,
10
10
  } from '../shareables';
11
11
  import { findNodeHandle } from 'react-native';
12
-
13
- interface ComponentRef extends Component {
14
- getNativeScrollRef?: () => ComponentRef;
15
- getScrollableNode?: () => ComponentRef;
12
+ interface MaybeScrollableComponent extends Component {
13
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ getNativeScrollRef?: any;
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ getScrollableNode?: any;
16
17
  }
17
18
 
18
- function getComponentOrScrollableRef(component: ComponentRef): ComponentRef {
19
+ function getComponentOrScrollable(component: MaybeScrollableComponent) {
19
20
  if (global._IS_FABRIC && component.getNativeScrollRef) {
20
21
  return component.getNativeScrollRef();
21
22
  } else if (!global._IS_FABRIC && component.getScrollableNode) {
@@ -28,15 +29,17 @@ const getTagValueFunction = global._IS_FABRIC
28
29
  ? getShadowNodeWrapperFromRef
29
30
  : findNodeHandle;
30
31
 
31
- export function useAnimatedRef<T extends ComponentRef>(): AnimatedRef<T> {
32
+ export function useAnimatedRef<
33
+ T extends MaybeScrollableComponent
34
+ >(): AnimatedRef<T> {
32
35
  const tag = useSharedValue<number | ShadowNodeWrapper | null>(-1);
33
- const ref = useRef<RefObjectFunction<T>>();
36
+ const ref = useRef<AnimatedRef<T>>();
34
37
 
35
38
  if (!ref.current) {
36
- const fun: RefObjectFunction<T> = <RefObjectFunction<T>>((component) => {
39
+ const fun: AnimatedRef<T> = <AnimatedRef<T>>((component) => {
37
40
  // enters when ref is set by attaching to a component
38
41
  if (component) {
39
- tag.value = getTagValueFunction(getComponentOrScrollableRef(component));
42
+ tag.value = getTagValueFunction(getComponentOrScrollable(component));
40
43
  fun.current = component;
41
44
  }
42
45
  return tag.value;
@@ -20,7 +20,6 @@ import type {
20
20
  AnimationObject,
21
21
  Timestamp,
22
22
  AdapterWorkletFunction,
23
- AnimatedStyle,
24
23
  BasicWorkletFunction,
25
24
  BasicWorkletFunctionOptional,
26
25
  NestedObjectValues,
@@ -33,26 +32,26 @@ import type {
33
32
  TextStyle,
34
33
  ViewStyle,
35
34
  } from 'react-native';
36
- import type { AnimateStyle } from '../helperTypes';
35
+ import type { AnimatedStyle } from '../helperTypes';
37
36
 
38
37
  export interface AnimatedStyleResult {
39
38
  viewDescriptors: ViewDescriptorsSet;
40
- initial: AnimatedStyle;
39
+ initial: AnimatedStyle<any>;
41
40
  viewsRef: ViewRefSet<any>;
42
- animatedStyle?: MutableRefObject<AnimatedStyle>;
41
+ animatedStyle?: MutableRefObject<AnimatedStyle<any>>;
43
42
  }
44
43
 
45
44
  interface AnimatedState {
46
- last: AnimatedStyle;
47
- animations: AnimatedStyle;
45
+ last: AnimatedStyle<any>;
46
+ animations: AnimatedStyle<any>;
48
47
  isAnimationRunning: boolean;
49
48
  isAnimationCancelled: boolean;
50
49
  }
51
50
 
52
51
  interface AnimationRef {
53
52
  initial: {
54
- value: AnimatedStyle;
55
- updater: () => AnimatedStyle;
53
+ value: AnimatedStyle<any>;
54
+ updater: () => AnimatedStyle<any>;
56
55
  };
57
56
  remoteState: AnimatedState;
58
57
  viewDescriptors: ViewDescriptorsSet;
@@ -60,9 +59,9 @@ interface AnimationRef {
60
59
 
61
60
  function prepareAnimation(
62
61
  frameTimestamp: number,
63
- animatedProp: AnimatedStyle,
64
- lastAnimation: AnimatedStyle,
65
- lastValue: AnimatedStyle
62
+ animatedProp: AnimatedStyle<any>,
63
+ lastAnimation: AnimatedStyle<any>,
64
+ lastValue: AnimatedStyle<any>
66
65
  ): void {
67
66
  'worklet';
68
67
  if (Array.isArray(animatedProp)) {
@@ -119,10 +118,10 @@ function prepareAnimation(
119
118
  }
120
119
 
121
120
  function runAnimations(
122
- animation: AnimatedStyle,
121
+ animation: AnimatedStyle<any>,
123
122
  timestamp: Timestamp,
124
123
  key: number | string,
125
- result: AnimatedStyle,
124
+ result: AnimatedStyle<any>,
126
125
  animationsActive: SharedValue<boolean>
127
126
  ): boolean {
128
127
  'worklet';
@@ -181,7 +180,7 @@ function runAnimations(
181
180
 
182
181
  function styleUpdater(
183
182
  viewDescriptors: SharedValue<Descriptor[]>,
184
- updater: BasicWorkletFunction<AnimatedStyle>,
183
+ updater: BasicWorkletFunction<AnimatedStyle<any>>,
185
184
  state: AnimatedState,
186
185
  maybeViewRef: ViewRefSet<any> | undefined,
187
186
  animationsActive: SharedValue<boolean>
@@ -217,7 +216,7 @@ function styleUpdater(
217
216
  return;
218
217
  }
219
218
 
220
- const updates: AnimatedStyle = {};
219
+ const updates: AnimatedStyle<any> = {};
221
220
  let allFinished = true;
222
221
  for (const propName in animations) {
223
222
  const finished = runAnimations(
@@ -269,15 +268,15 @@ function styleUpdater(
269
268
 
270
269
  function jestStyleUpdater(
271
270
  viewDescriptors: SharedValue<Descriptor[]>,
272
- updater: BasicWorkletFunction<AnimatedStyle>,
271
+ updater: BasicWorkletFunction<AnimatedStyle<any>>,
273
272
  state: AnimatedState,
274
273
  maybeViewRef: ViewRefSet<any> | undefined,
275
274
  animationsActive: SharedValue<boolean>,
276
- animatedStyle: MutableRefObject<AnimatedStyle>,
275
+ animatedStyle: MutableRefObject<AnimatedStyle<any>>,
277
276
  adapters: AdapterWorkletFunction[] = []
278
277
  ): void {
279
278
  'worklet';
280
- const animations: AnimatedStyle = state.animations ?? {};
279
+ const animations: AnimatedStyle<any> = state.animations ?? {};
281
280
  const newValues = updater() ?? {};
282
281
  const oldValues = state.last;
283
282
 
@@ -307,7 +306,7 @@ function jestStyleUpdater(
307
306
  return;
308
307
  }
309
308
 
310
- const updates: AnimatedStyle = {};
309
+ const updates: AnimatedStyle<any> = {};
311
310
  let allFinished = true;
312
311
  Object.keys(animations).forEach((propName) => {
313
312
  const finished = runAnimations(
@@ -400,8 +399,10 @@ function checkSharedValueUsage(
400
399
  }
401
400
  }
402
401
 
403
- // TODO TYPESCRIPT This is a temporary type to get rid of .d.ts file.
404
- type AnimatedStyleProp<T> = AnimateStyle<T> | RegisteredStyle<AnimateStyle<T>>;
402
+ // This type is kept for backward compatibility.
403
+ export type AnimatedStyleProp<T> =
404
+ | AnimatedStyle<T>
405
+ | RegisteredStyle<AnimatedStyle<T>>;
405
406
 
406
407
  // TODO TYPESCRIPT This is a temporary type to get rid of .d.ts file.
407
408
  type useAnimatedStyleType = <
@@ -411,7 +412,7 @@ type useAnimatedStyleType = <
411
412
  deps?: DependencyList | null
412
413
  ) => T;
413
414
 
414
- export const useAnimatedStyle = function <T extends AnimatedStyle>(
415
+ export const useAnimatedStyle = function <T extends AnimatedStyle<any>>(
415
416
  // animated style cannot be an array
416
417
  updater: BasicWorkletFunction<T extends Array<unknown> ? never : T>,
417
418
  dependencies?: DependencyList,
@@ -440,9 +441,9 @@ For more, see the docs: https://docs.swmansion.com/react-native-reanimated/docs/
440
441
  : [];
441
442
  const adaptersHash = adapters ? buildWorkletsHash(adaptersArray) : null;
442
443
  const animationsActive = useSharedValue<boolean>(true);
443
- const animatedStyle: MutableRefObject<AnimatedStyle> = useRef<AnimatedStyle>(
444
- {}
445
- );
444
+ const animatedStyle: MutableRefObject<AnimatedStyle<any>> = useRef<
445
+ AnimatedStyle<any>
446
+ >({});
446
447
 
447
448
  // build dependencies
448
449
  if (!dependencies) {
@@ -453,7 +454,7 @@ For more, see the docs: https://docs.swmansion.com/react-native-reanimated/docs/
453
454
  adaptersHash && dependencies.push(adaptersHash);
454
455
 
455
456
  if (!initRef.current) {
456
- const initialStyle: AnimatedStyle = initialUpdaterRun(updater);
457
+ const initialStyle: AnimatedStyle<any> = initialUpdaterRun(updater);
457
458
  validateAnimatedStyles(initialStyle);
458
459
  initRef.current = {
459
460
  initial: {
@@ -1,17 +1,15 @@
1
1
  import type { MutableRefObject } from 'react';
2
2
  import { useEffect, useRef } from 'react';
3
- import { processColor } from '../Colors';
4
3
  import type {
5
- AnimatedStyle,
6
4
  Context,
7
5
  NativeEvent,
8
6
  NestedObjectValues,
9
7
  WorkletFunction,
10
8
  AnimationObject,
11
9
  } from '../commonTypes';
10
+ import type { AnimatedStyle } from '../helperTypes';
12
11
  import { makeRemote } from '../core';
13
12
  import { isWeb, isJest } from '../PlatformChecker';
14
- import { colorProps } from '../UpdateProps';
15
13
  import WorkletEventHandler from '../WorkletEventHandler';
16
14
  import type { ContextWithDependencies, DependencyList } from './commonTypes';
17
15
  import type { NativeSyntheticEvent } from 'react-native';
@@ -23,7 +21,7 @@ interface Handlers<T, TContext extends Context> {
23
21
  [key: string]: Handler<T, TContext> | undefined;
24
22
  }
25
23
 
26
- export interface UseHandlerContext<TContext extends Context> {
24
+ interface UseHandlerContext<TContext extends Context> {
27
25
  context: TContext;
28
26
  doDependenciesDiffer: boolean;
29
27
  useWeb: boolean;
@@ -104,7 +102,7 @@ export function buildWorkletsHash(
104
102
  }
105
103
 
106
104
  // builds dependencies array for gesture handlers
107
- export function buildDependencies(
105
+ function buildDependencies(
108
106
  dependencies: DependencyList,
109
107
  handlers: Record<string, WorkletFunction | undefined>
110
108
  ): Array<unknown> {
@@ -126,7 +124,7 @@ export function buildDependencies(
126
124
  }
127
125
 
128
126
  // this is supposed to work as useEffect comparison
129
- export function areDependenciesEqual(
127
+ function areDependenciesEqual(
130
128
  nextDeps: DependencyList,
131
129
  prevDeps: DependencyList
132
130
  ): boolean {
@@ -156,30 +154,6 @@ export function areDependenciesEqual(
156
154
  return areHookInputsEqual(nextDeps, prevDeps);
157
155
  }
158
156
 
159
- export function hasColorProps(updates: AnimatedStyle): boolean {
160
- const colorPropsSet = new Set(colorProps);
161
- for (const key in updates) {
162
- if (colorPropsSet.has(key)) {
163
- return true;
164
- }
165
- }
166
- return false;
167
- }
168
-
169
- export function parseColors(updates: AnimatedStyle): void {
170
- 'worklet';
171
- for (const key in updates) {
172
- if (colorProps.indexOf(key) !== -1) {
173
- // value could be an animation in which case processColor will recognize it and will return undefined
174
- // -> in such a case we don't want to override style of that key
175
- const processedColor = processColor(updates[key]);
176
- if (processedColor !== undefined) {
177
- updates[key] = processedColor;
178
- }
179
- }
180
- }
181
- }
182
-
183
157
  export function isAnimated(prop: NestedObjectValues<AnimationObject>): boolean {
184
158
  'worklet';
185
159
  if (Array.isArray(prop)) {
@@ -209,7 +183,7 @@ export function shallowEqual(a: any, b: any) {
209
183
  return true;
210
184
  }
211
185
 
212
- export const validateAnimatedStyles = (styles: AnimatedStyle): void => {
186
+ export const validateAnimatedStyles = (styles: AnimatedStyle<any>): void => {
213
187
  'worklet';
214
188
  if (typeof styles !== 'object') {
215
189
  throw new Error(