react-native-reanimated 2.3.0-beta.4 → 2.4.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.
Files changed (109) hide show
  1. package/Common/cpp/Tools/RuntimeDecorator.cpp +17 -0
  2. package/LICENSE +1 -1
  3. package/README.md +1 -1
  4. package/android/build.gradle +5 -3
  5. package/android/expo/linking.gradle +46 -0
  6. package/android/expo/src/main/java/com/swmansion/reanimated/EXReanimatedAdapter.java +12 -0
  7. package/android/expo/src/main/java/expo/modules/adapters/reanimated/EXReanimatedPackage.java +26 -0
  8. package/android/react-native-reanimated-63-hermes.aar +0 -0
  9. package/android/react-native-reanimated-63-jsc.aar +0 -0
  10. package/android/react-native-reanimated-64-hermes.aar +0 -0
  11. package/android/react-native-reanimated-64-jsc.aar +0 -0
  12. package/android/react-native-reanimated-65-hermes.aar +0 -0
  13. package/android/react-native-reanimated-65-jsc.aar +0 -0
  14. package/android/react-native-reanimated-66-hermes.aar +0 -0
  15. package/android/react-native-reanimated-66-jsc.aar +0 -0
  16. package/android/react-native-reanimated-67-hermes.aar +0 -0
  17. package/android/react-native-reanimated-67-jsc.aar +0 -0
  18. package/expo-module.config.json +3 -0
  19. package/ios/LayoutReanimation/REAAnimationsManager.h +1 -1
  20. package/ios/LayoutReanimation/REAAnimationsManager.m +68 -19
  21. package/ios/LayoutReanimation/REAUIManager.mm +8 -7
  22. package/ios/Nodes/REAPropsNode.m +1 -1
  23. package/ios/native/NativeMethods.h +1 -1
  24. package/ios/native/NativeProxy.mm +10 -2
  25. package/ios/native/REAInitializer.mm +3 -4
  26. package/lib/Animated.js +3 -5
  27. package/lib/createAnimatedComponent.js +4 -2
  28. package/lib/index.js +3 -5
  29. package/lib/reanimated1/core/Core.test.js +1 -1
  30. package/lib/reanimated2/Colors.js +1 -97
  31. package/lib/reanimated2/Easing.js +5 -0
  32. package/lib/reanimated2/NativeMethods.js +15 -5
  33. package/lib/reanimated2/NativeReanimated/index.js +2 -2
  34. package/lib/reanimated2/component/FlatList.js +30 -0
  35. package/lib/reanimated2/component/WrappedComponents.js +9 -0
  36. package/lib/reanimated2/component/index.js +4 -0
  37. package/lib/reanimated2/core.js +9 -3
  38. package/lib/reanimated2/globals.d.ts +3 -0
  39. package/lib/reanimated2/hook/useAnimatedGestureHandler.js +1 -2
  40. package/lib/reanimated2/hook/useAnimatedStyle.js +31 -14
  41. package/lib/reanimated2/hook/utils.js +14 -11
  42. package/lib/reanimated2/index.js +2 -0
  43. package/lib/reanimated2/interpolateColor.js +98 -0
  44. package/lib/reanimated2/js-reanimated/JSReanimated.js +1 -1
  45. package/lib/reanimated2/js-reanimated/commonTypes.js +1 -0
  46. package/lib/reanimated2/layoutReanimation/defaultAnimations/Default.js +14 -14
  47. package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +8 -8
  48. package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +16 -16
  49. package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +15 -15
  50. package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +4 -4
  51. package/lib/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +20 -8
  52. package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +2 -2
  53. package/lib/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +8 -8
  54. package/lib/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +10 -10
  55. package/lib/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +8 -8
  56. package/lib/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +8 -8
  57. package/mock.js +2 -0
  58. package/package.json +8 -5
  59. package/plugin.js +3 -1
  60. package/react-native-reanimated.d.ts +101 -27
  61. package/src/Animated.js +3 -5
  62. package/src/createAnimatedComponent.tsx +13 -5
  63. package/src/reanimated1/core/Core.test.js +1 -1
  64. package/src/reanimated2/Colors.ts +6 -150
  65. package/src/reanimated2/Easing.ts +11 -0
  66. package/src/reanimated2/NativeMethods.ts +19 -6
  67. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +1 -0
  68. package/src/reanimated2/NativeReanimated/index.ts +2 -2
  69. package/src/reanimated2/animation/commonTypes.ts +44 -40
  70. package/src/reanimated2/animation/decay.ts +1 -1
  71. package/src/reanimated2/animation/delay.ts +2 -16
  72. package/src/reanimated2/animation/index.ts +7 -8
  73. package/src/reanimated2/animation/repeat.ts +2 -12
  74. package/src/reanimated2/animation/sequence.ts +3 -10
  75. package/src/reanimated2/animation/spring.ts +1 -1
  76. package/src/reanimated2/animation/styleAnimation.ts +1 -18
  77. package/src/reanimated2/animation/timing.ts +1 -1
  78. package/src/reanimated2/animation/util.ts +12 -9
  79. package/src/reanimated2/commonTypes.ts +48 -1
  80. package/src/reanimated2/component/FlatList.tsx +44 -0
  81. package/src/reanimated2/component/WrappedComponents.ts +11 -0
  82. package/src/reanimated2/component/index.ts +9 -0
  83. package/src/reanimated2/core.ts +10 -6
  84. package/src/reanimated2/globals.d.ts +3 -0
  85. package/src/reanimated2/hook/commonTypes.ts +5 -0
  86. package/src/reanimated2/hook/useAnimatedGestureHandler.ts +1 -2
  87. package/src/reanimated2/hook/useAnimatedRef.ts +1 -5
  88. package/src/reanimated2/hook/useAnimatedStyle.ts +35 -16
  89. package/src/reanimated2/hook/utils.ts +18 -17
  90. package/src/reanimated2/index.ts +2 -0
  91. package/src/reanimated2/interpolateColor.ts +178 -0
  92. package/src/reanimated2/js-reanimated/JSReanimated.ts +3 -4
  93. package/src/reanimated2/js-reanimated/Mapper.ts +1 -1
  94. package/src/reanimated2/js-reanimated/MapperRegistry.ts +1 -1
  95. package/src/reanimated2/js-reanimated/commonTypes.ts +51 -0
  96. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +39 -20
  97. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +5 -1
  98. package/src/reanimated2/layoutReanimation/defaultAnimations/Default.ts +21 -15
  99. package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +29 -24
  100. package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +61 -34
  101. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +48 -33
  102. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +17 -12
  103. package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +20 -8
  104. package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +14 -10
  105. package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +8 -8
  106. package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +20 -14
  107. package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +14 -8
  108. package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +24 -12
  109. package/src/reanimated2/utils.ts +1 -1
@@ -16,6 +16,7 @@ declare module 'react-native-reanimated' {
16
16
  TextProps,
17
17
  ImageProps,
18
18
  ScrollViewProps,
19
+ FlatListProps,
19
20
  StyleProp,
20
21
  RegisteredStyle,
21
22
  ViewStyle,
@@ -26,6 +27,7 @@ declare module 'react-native-reanimated' {
26
27
  Text as ReactNativeText,
27
28
  Image as ReactNativeImage,
28
29
  ScrollView as ReactNativeScrollView,
30
+ FlatList as ReactNativeFlatList,
29
31
  NativeScrollEvent,
30
32
  NativeSyntheticEvent,
31
33
  ColorValue,
@@ -144,10 +146,14 @@ declare module 'react-native-reanimated' {
144
146
  >;
145
147
  };
146
148
 
147
- export type AnimateProps<P extends object> = {
148
- [K in keyof P]: K extends 'style'
149
- ? StyleProp<AnimateStyle<P[K]>>
150
- : P[K] | AnimatedNode<P[K]>;
149
+ export type StylesOrDefault<T> = 'style' extends keyof T
150
+ ? T['style']
151
+ : Record<string, unknown>;
152
+
153
+ export type AnimateProps<P extends Record<string, unknown>> = {
154
+ [K in keyof P]: P[K] | AnimatedNode<P[K]>;
155
+ } & {
156
+ style?: StyleProp<AnimateStyle<StylesOrDefault<P>>>;
151
157
  } & {
152
158
  animatedProps?: Partial<AnimateProps<P>>;
153
159
  layout?:
@@ -246,16 +252,31 @@ declare module 'react-native-reanimated' {
246
252
  export class View extends Component<AnimateProps<ViewProps>> {
247
253
  getNode(): ReactNativeView;
248
254
  }
255
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
256
+ export interface View extends ReactNativeView {}
249
257
  export class Text extends Component<AnimateProps<TextProps>> {
250
258
  getNode(): ReactNativeText;
251
259
  }
260
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
261
+ export interface Text extends ReactNativeText {}
252
262
  export class Image extends Component<AnimateProps<ImageProps>> {
253
263
  getNode(): ReactNativeImage;
254
264
  }
265
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
266
+ export interface Image extends ReactNativeImage {}
255
267
  export class ScrollView extends Component<AnimateProps<ScrollViewProps>> {
256
268
  getNode(): ReactNativeScrollView;
257
269
  }
270
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
271
+ export interface ScrollView extends ReactNativeScrollView {}
272
+
258
273
  export class Code extends Component<CodeProps> {}
274
+ export class FlatList<T> extends Component<AnimateProps<FlatListProps<T>>> {
275
+ itemLayoutAnimation: ILayoutAnimationBuilder;
276
+ getNode(): ReactNativeFlatList;
277
+ }
278
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
279
+ export interface FlatList<T> extends ReactNativeView<T> {}
259
280
 
260
281
  type Options<P> = {
261
282
  setNativeProps: (ref: any, props: P) => void;
@@ -451,34 +472,45 @@ declare module 'react-native-reanimated' {
451
472
  animations: AnimateStyle;
452
473
  };
453
474
 
454
- export type EntryExitAnimationsValues = {
455
- originX: number;
456
- originY: number;
457
- width: number;
458
- height: number;
459
- globalOriginX: number;
460
- globalOriginY: number;
461
- };
462
- export type EntryExitAnimationFunction = (
463
- targetValues: EntryExitAnimationsValues
464
- ) => LayoutAnimation;
475
+ export interface EntryAnimationsValues {
476
+ targetOriginX: number;
477
+ targetOriginY: number;
478
+ targetWidth: number;
479
+ targetHeight: number;
480
+ targetGlobalOriginX: number;
481
+ targetGlobalOriginY: number;
482
+ }
483
+
484
+ export interface ExitAnimationsValues {
485
+ currentOriginX: number;
486
+ currentOriginY: number;
487
+ currentWidth: number;
488
+ currentHeight: number;
489
+ currentGlobalOriginX: number;
490
+ currentGlobalOriginY: number;
491
+ }
492
+
493
+ export type EntryExitAnimationFunction =
494
+ | ((targetValues: EntryAnimationsValues) => LayoutAnimation)
495
+ | ((targetValues: ExitAnimationsValues) => LayoutAnimation);
465
496
 
466
497
  export type LayoutAnimationsValues = {
467
- originX: number;
468
- originY: number;
469
- width: number;
470
- height: number;
471
- globalOriginX: number;
472
- globalOriginY: number;
473
- boriginX: number;
474
- boriginY: number;
475
- bwidth: number;
476
- bheight: number;
477
- bglobalOriginX: number;
478
- bglobalOriginY: number;
498
+ currentOriginX: number;
499
+ currentOriginY: number;
500
+ currentWidth: number;
501
+ currentHeight: number;
502
+ currentGlobalOriginX: number;
503
+ currentGlobalOriginY: number;
504
+ targetOriginX: number;
505
+ targetOriginY: number;
506
+ targetWidth: number;
507
+ targetHeight: number;
508
+ targetGlobalOriginX: number;
509
+ targetGlobalOriginY: number;
479
510
  windowWidth: number;
480
511
  windowHeight: number;
481
512
  };
513
+
482
514
  export type LayoutAnimationFunction = (
483
515
  targetValues: LayoutAnimationsValues
484
516
  ) => LayoutAnimation;
@@ -594,6 +626,42 @@ declare module 'react-native-reanimated' {
594
626
  colorSpace?: 'RGB' | 'HSV'
595
627
  ): string | number;
596
628
 
629
+ export enum ColorSpace {
630
+ RGB = 0,
631
+ HSV = 1,
632
+ }
633
+
634
+ export interface InterpolateRGB {
635
+ r: number[];
636
+ g: number[];
637
+ b: number[];
638
+ a: number[];
639
+ }
640
+
641
+ export interface InterpolateHSV {
642
+ h: number[];
643
+ s: number[];
644
+ v: number[];
645
+ }
646
+
647
+ export interface InterpolateConfig {
648
+ inputRange: readonly number[];
649
+ outputRange: readonly (string | number)[];
650
+ colorSpace: ColorSpace;
651
+ cache: SharedValue<InterpolateRGB | InterpolateHSV | null>;
652
+ }
653
+
654
+ export function useInterpolateConfig(
655
+ inputRange: readonly number[],
656
+ outputRange: readonly (string | number)[],
657
+ colorSpace?: ColorSpace
658
+ ): SharedValue<InterpolateConfig>;
659
+
660
+ export function interpolateSharableColor(
661
+ value: number,
662
+ interpolateConfig: SharedValue<InterpolateConfig>
663
+ ): string | number;
664
+
597
665
  export function makeMutable<T>(initialValue: T): SharedValue<T>;
598
666
 
599
667
  type DependencyList = ReadonlyArray<any>;
@@ -965,6 +1033,12 @@ declare module 'react-native-reanimated' {
965
1033
  y1: number,
966
1034
  x2: number,
967
1035
  y2: number
1036
+ ): { factory: () => Animated.EasingFunction };
1037
+ bezierFn(
1038
+ x1: number,
1039
+ y1: number,
1040
+ x2: number,
1041
+ y2: number
968
1042
  ): Animated.EasingFunction;
969
1043
  in(easing: Animated.EasingFunction): Animated.EasingFunction;
970
1044
  out(easing: Animated.EasingFunction): Animated.EasingFunction;
package/src/Animated.js CHANGED
@@ -1,17 +1,15 @@
1
- import { Image, ScrollView, Text, View, LogBox } from 'react-native';
1
+ import { LogBox } from 'react-native';
2
2
  import createAnimatedComponent from './createAnimatedComponent';
3
3
  import {
4
4
  addWhitelistedNativeProps,
5
5
  addWhitelistedUIProps,
6
6
  } from './ConfigHelper';
7
7
  import * as reanimated1 from './reanimated1';
8
+ import ReanimatedComponents from './reanimated2/component';
8
9
 
9
10
  const Animated = {
10
11
  // components
11
- View: createAnimatedComponent(View),
12
- Text: createAnimatedComponent(Text),
13
- Image: createAnimatedComponent(Image),
14
- ScrollView: createAnimatedComponent(ScrollView),
12
+ ...ReanimatedComponents,
15
13
  createAnimatedComponent,
16
14
  // configuration
17
15
  addWhitelistedNativeProps,
@@ -36,7 +36,7 @@ import { initialUpdaterRun } from './reanimated2/animation';
36
36
  import {
37
37
  BaseAnimationBuilder,
38
38
  EntryExitAnimationFunction,
39
- LayoutAnimationFunction,
39
+ ILayoutAnimationBuilder,
40
40
  } from './reanimated2/layoutReanimation';
41
41
  import { SharedValue, StyleProps } from './reanimated2/commonTypes';
42
42
  import {
@@ -100,12 +100,17 @@ function onlyAnimatedStyles(styles: StyleProps[]) {
100
100
  return styles.filter((style) => style?.viewDescriptors);
101
101
  }
102
102
 
103
- function isSameAnimatedStyle(style1: StyleProps, style2: StyleProps): boolean {
103
+ function isSameAnimatedStyle(
104
+ style1?: StyleProps,
105
+ style2?: StyleProps
106
+ ): boolean {
104
107
  // We cannot use equality check to compare useAnimatedStyle outputs directly.
105
108
  // Instead, we can compare its viewsRefs.
106
- return style1.viewsRef === style2.viewsRef;
109
+ return style1?.viewsRef === style2?.viewsRef;
107
110
  }
108
111
 
112
+ const isSameAnimatedProps = isSameAnimatedStyle;
113
+
109
114
  const has = <K extends string>(
110
115
  key: K,
111
116
  x: unknown
@@ -133,7 +138,7 @@ export type AnimatedComponentProps<P extends Record<string, unknown>> = P & {
133
138
  animatedStyle?: StyleProps;
134
139
  layout?:
135
140
  | BaseAnimationBuilder
136
- | LayoutAnimationFunction
141
+ | ILayoutAnimationBuilder
137
142
  | typeof BaseAnimationBuilder;
138
143
  entering?:
139
144
  | BaseAnimationBuilder
@@ -481,7 +486,10 @@ export default function createAnimatedComponent(
481
486
  });
482
487
 
483
488
  // detach old animatedProps
484
- if (prevAnimatedProps && prevAnimatedProps !== this.props.animatedProps) {
489
+ if (
490
+ prevAnimatedProps &&
491
+ !isSameAnimatedProps(prevAnimatedProps, this.props.animatedProps)
492
+ ) {
485
493
  prevAnimatedProps.viewDescriptors!.remove(viewTag as number);
486
494
  }
487
495
 
@@ -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', () => {
@@ -9,11 +9,8 @@
9
9
  /* eslint no-bitwise: 0 */
10
10
  import { Platform } from 'react-native';
11
11
  import { makeRemote, makeShareable, isConfigured } from './core';
12
- import { interpolate } from './interpolation';
13
- // @ts-ignore JS file
14
- import { Extrapolate } from '../reanimated1/derived';
15
12
 
16
- interface RBG {
13
+ interface RGB {
17
14
  r: number;
18
15
  g: number;
19
16
  b: number;
@@ -475,9 +472,9 @@ export const rgbaColor = (
475
472
  * 0 <= r, g, b <= 255
476
473
  * returns 0 <= h, s, v <= 1
477
474
  */
478
- function RGBtoHSV(rgb: RBG): HSV;
479
- function RGBtoHSV(r: number, g: number, b: number): HSV;
480
- function RGBtoHSV(r: any, g?: any, b?: any): HSV {
475
+ export function RGBtoHSV(rgb: RGB): HSV;
476
+ export function RGBtoHSV(r: number, g: number, b: number): HSV;
477
+ export function RGBtoHSV(r: any, g?: any, b?: any): HSV {
481
478
  'worklet';
482
479
  /* eslint-disable */
483
480
  if (arguments.length === 1) {
@@ -528,8 +525,8 @@ function RGBtoHSV(r: any, g?: any, b?: any): HSV {
528
525
  * 0 <= h, s, v <= 1
529
526
  * returns 0 <= r, g, b <= 255
530
527
  */
531
- function HSVtoRGB(hsv: HSV): RBG;
532
- function HSVtoRGB(h: number, s: number, v: number): RBG;
528
+ function HSVtoRGB(hsv: HSV): RGB;
529
+ function HSVtoRGB(h: number, s: number, v: number): RGB;
533
530
  function HSVtoRGB(h: any, s?: any, v?: any) {
534
531
  'worklet';
535
532
  /* eslint-disable */
@@ -652,144 +649,3 @@ export function toRGBA(HSVA: ParsedColorArray): string {
652
649
  const { r, g, b } = HSVtoRGB(HSVA[0], HSVA[1], HSVA[2]);
653
650
  return `rgba(${r}, ${g}, ${b}, ${HSVA[3]})`;
654
651
  }
655
-
656
- const interpolateColorsHSV = (
657
- value: number,
658
- inputRange: readonly number[],
659
- colors: InterpolateCacheHSV
660
- ) => {
661
- 'worklet';
662
- const h = interpolate(value, inputRange, colors.h, Extrapolate.CLAMP);
663
- const s = interpolate(value, inputRange, colors.s, Extrapolate.CLAMP);
664
- const v = interpolate(value, inputRange, colors.v, Extrapolate.CLAMP);
665
- return hsvToColor(h, s, v);
666
- };
667
-
668
- const interpolateColorsRGB = (
669
- value: number,
670
- inputRange: readonly number[],
671
- colors: InterpolateCacheRGBA
672
- ) => {
673
- 'worklet';
674
- const r = interpolate(value, inputRange, colors.r, Extrapolate.CLAMP);
675
- const g = interpolate(value, inputRange, colors.g, Extrapolate.CLAMP);
676
- const b = interpolate(value, inputRange, colors.b, Extrapolate.CLAMP);
677
- const a = interpolate(value, inputRange, colors.a, Extrapolate.CLAMP);
678
- return rgbaColor(r, g, b, a);
679
- };
680
-
681
- interface InterpolateCacheRGBA {
682
- r: number[];
683
- g: number[];
684
- b: number[];
685
- a: number[];
686
- }
687
-
688
- const BUFFER_SIZE = 200;
689
- const hashOrderRGBA: any = new ArrayBuffer(BUFFER_SIZE);
690
- let curentHashIndexRGBA = 0;
691
- const interpolateCacheRGBA: { [name: string]: InterpolateCacheRGBA } = {};
692
-
693
- const getInterpolateCacheRGBA = (
694
- colors: readonly (string | number)[]
695
- ): InterpolateCacheRGBA => {
696
- 'worklet';
697
- const hash = colors.join('');
698
- const cache = interpolateCacheRGBA[hash];
699
- if (cache !== undefined) {
700
- return cache;
701
- }
702
-
703
- const r = [];
704
- const g = [];
705
- const b = [];
706
- const a = [];
707
- for (let i = 0; i < colors.length; ++i) {
708
- const color = colors[i];
709
- const proocessedColor = processColor(color);
710
- // explicit check in case if processedColor is 0
711
- if (proocessedColor !== null && proocessedColor !== undefined) {
712
- r.push(red(proocessedColor));
713
- g.push(green(proocessedColor));
714
- b.push(blue(proocessedColor));
715
- a.push(opacity(proocessedColor));
716
- }
717
- }
718
- const newCache = { r, g, b, a };
719
- const overrideHash = hashOrderRGBA[curentHashIndexRGBA];
720
- if (overrideHash) {
721
- delete interpolateCacheRGBA[overrideHash];
722
- }
723
- interpolateCacheRGBA[hash] = newCache;
724
- hashOrderRGBA[curentHashIndexRGBA] = hash;
725
- curentHashIndexRGBA = (curentHashIndexRGBA + 1) % BUFFER_SIZE;
726
- return newCache;
727
- };
728
-
729
- interface InterpolateCacheHSV {
730
- h: number[];
731
- s: number[];
732
- v: number[];
733
- }
734
-
735
- const hashOrderHSV: any = new ArrayBuffer(BUFFER_SIZE);
736
- let curentHashIndexHSV = 0;
737
- const interpolateCacheHSV: { [name: string]: InterpolateCacheHSV } = {};
738
-
739
- const getInterpolateCacheHSV = (
740
- colors: readonly (string | number)[]
741
- ): InterpolateCacheHSV => {
742
- 'worklet';
743
- const hash = colors.join('');
744
- const cache = interpolateCacheHSV[hash];
745
- if (cache !== undefined) {
746
- return cache;
747
- }
748
-
749
- const h = [];
750
- const s = [];
751
- const v = [];
752
- for (let i = 0; i < colors.length; ++i) {
753
- const color = colors[i];
754
- const proocessedColor = RGBtoHSV(processColor(color) as any);
755
- if (proocessedColor) {
756
- h.push(proocessedColor.h);
757
- s.push(proocessedColor.s);
758
- v.push(proocessedColor.v);
759
- }
760
- }
761
- const newCache = { h, s, v };
762
- const overrideHash = hashOrderHSV[curentHashIndexHSV];
763
- if (overrideHash) {
764
- delete interpolateCacheHSV[overrideHash];
765
- }
766
- interpolateCacheHSV[hash] = newCache;
767
- hashOrderHSV[curentHashIndexHSV] = hash;
768
- curentHashIndexHSV = (curentHashIndexHSV + 1) % BUFFER_SIZE;
769
- return newCache;
770
- };
771
-
772
- export const interpolateColor = (
773
- value: number,
774
- inputRange: readonly number[],
775
- outputRange: readonly (string | number)[],
776
- colorSpace: 'RGB' | 'HSV' = 'RGB'
777
- ): string | number => {
778
- 'worklet';
779
- if (colorSpace === 'HSV') {
780
- return interpolateColorsHSV(
781
- value,
782
- inputRange,
783
- getInterpolateCacheHSV(outputRange)
784
- );
785
- } else if (colorSpace === 'RGB') {
786
- return interpolateColorsRGB(
787
- value,
788
- inputRange,
789
- getInterpolateCacheRGBA(outputRange)
790
- );
791
- }
792
- throw new Error(
793
- `invalid color space provided: ${colorSpace}. Supported values are: ['RGB', 'HSV']`
794
- );
795
- };
@@ -221,6 +221,16 @@ function bezier(
221
221
  };
222
222
  }
223
223
 
224
+ function bezierFn(
225
+ x1: number,
226
+ y1: number,
227
+ x2: number,
228
+ y2: number
229
+ ): (x: number) => number {
230
+ 'worklet';
231
+ return Bezier(x1, y1, x2, y2);
232
+ }
233
+
224
234
  /**
225
235
  * Runs an easing function forwards.
226
236
  */
@@ -269,6 +279,7 @@ const EasingObject = {
269
279
  back,
270
280
  bounce,
271
281
  bezier,
282
+ bezierFn,
272
283
  in: in_,
273
284
  out,
274
285
  inOut,
@@ -3,8 +3,8 @@
3
3
  // @ts-nocheck
4
4
  import { Component } from 'react';
5
5
  import { findNodeHandle } from 'react-native';
6
- import { RefObjectFunction } from './hook/useAnimatedRef';
7
- import { isChromeDebugger } from './PlatformChecker';
6
+ import { RefObjectFunction } from './commonTypes';
7
+ import { shouldBeUseWeb } from './PlatformChecker';
8
8
 
9
9
  export function getTag(
10
10
  view: null | number | React.Component<any, any> | React.ComponentClass<any>
@@ -21,12 +21,24 @@ export interface MeasuredDimensions {
21
21
  pageY: number;
22
22
  }
23
23
 
24
+ const isNativeIndefined = shouldBeUseWeb();
25
+
24
26
  export function measure(
25
27
  animatedRef: RefObjectFunction<Component>
26
28
  ): MeasuredDimensions {
27
29
  'worklet';
28
- if (!_WORKLET && !isChromeDebugger()) {
29
- throw new Error('(measure) method cannot be used on RN side!');
30
+ if (!_WORKLET || isNativeIndefined) {
31
+ console.warn(
32
+ '[reanimated.measure] method cannot be used for web or Chrome Debugger'
33
+ );
34
+ return {
35
+ x: NaN,
36
+ y: NaN,
37
+ width: NaN,
38
+ height: NaN,
39
+ pageX: NaN,
40
+ pageY: NaN,
41
+ };
30
42
  }
31
43
  const viewTag = animatedRef();
32
44
  const result = _measure(viewTag);
@@ -43,7 +55,7 @@ export function scrollTo(
43
55
  animated: boolean
44
56
  ): void {
45
57
  'worklet';
46
- if (!_WORKLET && !isChromeDebugger()) {
58
+ if (!_WORKLET || isNativeIndefined) {
47
59
  return;
48
60
  }
49
61
  const viewTag = animatedRef();
@@ -52,10 +64,11 @@ export function scrollTo(
52
64
 
53
65
  export function setGestureState(handlerTag: number, newState: number): void {
54
66
  'worklet';
55
- if (!_WORKLET && !isChromeDebugger()) {
67
+ if (!_WORKLET || isNativeIndefined) {
56
68
  console.warn(
57
69
  '[Reanimated] You can not use setGestureState in non-worklet function.'
58
70
  );
71
+ return;
59
72
  }
60
73
  _setGestureState(handlerTag, newState);
61
74
  }
@@ -2,6 +2,7 @@ import { SharedValue } from '../commonTypes';
2
2
  import { Descriptor } from '../hook/commonTypes';
3
3
 
4
4
  const InnerNativeModule = global.__reanimatedModuleProxy;
5
+
5
6
  export class NativeReanimated {
6
7
  native: boolean;
7
8
  useOnlyV1: boolean;
@@ -1,10 +1,10 @@
1
1
  import reanimatedJS from '../js-reanimated';
2
- import { nativeShouldBeMock } from '../PlatformChecker';
2
+ import { shouldBeUseWeb } from '../PlatformChecker';
3
3
  import { Platform } from 'react-native';
4
4
  import { NativeReanimated } from './NativeReanimated';
5
5
 
6
6
  let exportedModule;
7
- if (nativeShouldBeMock()) {
7
+ if (shouldBeUseWeb()) {
8
8
  exportedModule = reanimatedJS;
9
9
  } else {
10
10
  exportedModule = new NativeReanimated();
@@ -1,48 +1,52 @@
1
- export type AnimatableValue = number | string | Array<number>;
1
+ import {
2
+ AnimatedStyle,
3
+ StyleProps,
4
+ AnimatableValue,
5
+ AnimationObject,
6
+ Animation,
7
+ Timestamp,
8
+ AnimationCallback,
9
+ } from '../commonTypes';
2
10
 
3
- export interface AnimationObject {
4
- [key: string]: any;
5
- callback: AnimationCallback;
6
- current?: AnimatableValue;
7
- toValue?: AnimationObject['current'];
8
- startValue?: AnimationObject['current'];
9
- finished?: boolean;
10
- strippedCurrent?: number;
11
- cancelled?: boolean;
12
-
13
- __prefix?: string;
14
- __suffix?: string;
15
- onFrame: (animation: any, timestamp: Timestamp) => boolean;
16
- onStart: (
17
- nextAnimation: any,
18
- current: any,
19
- timestamp: Timestamp,
20
- previousAnimation: any
21
- ) => void;
11
+ export interface HigherOrderAnimation {
12
+ isHigherOrder?: boolean;
22
13
  }
23
14
 
24
- export interface Animation<T extends AnimationObject> extends AnimationObject {
25
- onFrame: (animation: T, timestamp: Timestamp) => boolean;
26
- onStart: (
27
- nextAnimation: T,
28
- current: T extends NumericAnimation ? number : AnimatableValue,
29
- timestamp: Timestamp,
30
- previousAnimation: T
31
- ) => void;
32
- }
15
+ export type NextAnimation<T extends AnimationObject> = T | (() => T);
33
16
 
34
- export interface NumericAnimation {
35
- current?: number;
36
- }
37
- export interface HigherOrderAnimation {
38
- isHigherOrder?: boolean;
17
+ export interface DelayAnimation
18
+ extends Animation<DelayAnimation>,
19
+ HigherOrderAnimation {
20
+ startTime: Timestamp;
21
+ started: boolean;
22
+ previousAnimation: DelayAnimation | null;
23
+ current: AnimatableValue;
39
24
  }
40
25
 
41
- export type AnimationCallback = (
42
- finished?: boolean,
43
- current?: AnimatableValue
44
- ) => void;
26
+ export interface RepeatAnimation
27
+ extends Animation<RepeatAnimation>,
28
+ HigherOrderAnimation {
29
+ reps: number;
30
+ startValue: AnimatableValue;
31
+ toValue?: AnimatableValue;
32
+ previousAnimation?: RepeatAnimation;
33
+ }
45
34
 
46
- export type NextAnimation<T extends AnimationObject> = T | (() => T);
35
+ export interface SequenceAnimation
36
+ extends Animation<SequenceAnimation>,
37
+ HigherOrderAnimation {
38
+ animationIndex: number;
39
+ }
47
40
 
48
- export type Timestamp = number;
41
+ export interface StyleLayoutAnimation extends HigherOrderAnimation {
42
+ current: StyleProps;
43
+ styleAnimations: AnimatedStyle;
44
+ onFrame: (animation: StyleLayoutAnimation, timestamp: Timestamp) => boolean;
45
+ onStart: (
46
+ nextAnimation: StyleLayoutAnimation,
47
+ current: AnimatedStyle,
48
+ timestamp: Timestamp,
49
+ previousAnimation: StyleLayoutAnimation
50
+ ) => void;
51
+ callback?: AnimationCallback;
52
+ }
@@ -5,7 +5,7 @@ import {
5
5
  AnimationObject,
6
6
  AnimatableValue,
7
7
  Timestamp,
8
- } from './commonTypes';
8
+ } from '../commonTypes';
9
9
  import { Platform } from 'react-native';
10
10
 
11
11
  interface DecayConfig {
@@ -1,20 +1,6 @@
1
1
  import { defineAnimation } from './util';
2
- import {
3
- Animation,
4
- NextAnimation,
5
- Timestamp,
6
- HigherOrderAnimation,
7
- AnimatableValue,
8
- } from './commonTypes';
9
-
10
- export interface DelayAnimation
11
- extends Animation<DelayAnimation>,
12
- HigherOrderAnimation {
13
- startTime: Timestamp;
14
- started: boolean;
15
- previousAnimation: DelayAnimation | null;
16
- current: AnimatableValue;
17
- }
2
+ import { Animation, Timestamp, AnimatableValue } from '../commonTypes';
3
+ import { NextAnimation, DelayAnimation } from './commonTypes';
18
4
 
19
5
  export function withDelay(
20
6
  delayMs: number,