react-native-reanimated 2.3.0-beta.2 → 2.3.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 (168) hide show
  1. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +12 -3
  2. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +13 -0
  3. package/Common/cpp/Registries/EventHandlerRegistry.cpp +2 -2
  4. package/Common/cpp/Registries/MapperRegistry.cpp +5 -5
  5. package/Common/cpp/SharedItems/FrozenObject.cpp +1 -3
  6. package/Common/cpp/SharedItems/ShareableValue.cpp +8 -10
  7. package/Common/cpp/Tools/FeaturesConfig.cpp +5 -0
  8. package/Common/cpp/Tools/JSIStoreValueUser.cpp +8 -8
  9. package/Common/cpp/Tools/Mapper.cpp +1 -1
  10. package/Common/cpp/Tools/RuntimeDecorator.cpp +40 -4
  11. package/Common/cpp/Tools/WorkletEventHandler.cpp +3 -1
  12. package/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +5 -0
  13. package/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +6 -1
  14. package/Common/cpp/headers/Registries/EventHandlerRegistry.h +1 -0
  15. package/Common/cpp/headers/Registries/MapperRegistry.h +1 -0
  16. package/Common/cpp/headers/SharedItems/FrozenObject.h +4 -0
  17. package/Common/cpp/headers/SharedItems/HostFunctionHandler.h +2 -0
  18. package/Common/cpp/headers/SharedItems/MutableValue.h +2 -0
  19. package/Common/cpp/headers/SharedItems/MutableValueSetterProxy.h +3 -1
  20. package/Common/cpp/headers/SharedItems/RemoteObject.h +4 -1
  21. package/Common/cpp/headers/SharedItems/ShareableValue.h +2 -0
  22. package/Common/cpp/headers/SharedItems/SharedParent.h +9 -9
  23. package/Common/cpp/headers/SharedItems/ValueWrapper.h +32 -28
  24. package/Common/cpp/headers/SpecTools/ErrorHandler.h +1 -0
  25. package/Common/cpp/headers/Tools/FeaturesConfig.h +19 -0
  26. package/Common/cpp/headers/Tools/JSIStoreValueUser.h +2 -5
  27. package/Common/cpp/headers/Tools/Mapper.h +2 -0
  28. package/Common/cpp/headers/Tools/PlatformDepMethodsHolder.h +5 -0
  29. package/Common/cpp/headers/Tools/ReanimatedHiddenHeaders.h +1 -5
  30. package/Common/cpp/headers/Tools/RuntimeDecorator.h +10 -7
  31. package/Common/cpp/headers/Tools/Scheduler.h +2 -0
  32. package/Common/cpp/headers/Tools/WorkletEventHandler.h +2 -1
  33. package/Common/cpp/hidden_headers/Logger.h +2 -2
  34. package/Common/cpp/hidden_headers/LoggerInterface.h +1 -1
  35. package/README.md +1 -1
  36. package/RNReanimated.podspec +21 -3
  37. package/android/build.gradle +33 -13
  38. package/android/expo/linking.gradle +46 -0
  39. package/android/expo/src/main/java/com/swmansion/reanimated/EXReanimatedAdapter.java +12 -0
  40. package/android/expo/src/main/java/expo/modules/adapters/reanimated/EXReanimatedPackage.java +26 -0
  41. package/android/react-native-reanimated-63-hermes.aar +0 -0
  42. package/android/react-native-reanimated-63-jsc.aar +0 -0
  43. package/android/react-native-reanimated-64-hermes.aar +0 -0
  44. package/android/react-native-reanimated-64-jsc.aar +0 -0
  45. package/android/react-native-reanimated-65-hermes.aar +0 -0
  46. package/android/react-native-reanimated-65-jsc.aar +0 -0
  47. package/android/react-native-reanimated-66-hermes.aar +0 -0
  48. package/android/react-native-reanimated-66-jsc.aar +0 -0
  49. package/android/react-native-reanimated-67-hermes.aar +0 -0
  50. package/android/react-native-reanimated-67-jsc.aar +0 -0
  51. package/expo-module.config.json +3 -0
  52. package/ios/LayoutReanimation/REAAnimationsManager.m +65 -19
  53. package/ios/LayoutReanimation/REAUIManager.mm +101 -61
  54. package/ios/Nodes/REAPropsNode.m +1 -1
  55. package/ios/REAEventDispatcher.m +1 -1
  56. package/ios/REAModule.h +0 -2
  57. package/ios/REAModule.m +0 -3
  58. package/ios/REANodesManager.m +1 -0
  59. package/ios/RNGestureHandlerStateManager.h +5 -0
  60. package/ios/native/NativeMethods.h +5 -0
  61. package/ios/native/NativeMethods.mm +14 -6
  62. package/ios/native/NativeProxy.h +1 -0
  63. package/ios/native/NativeProxy.mm +84 -63
  64. package/ios/native/REAIOSErrorHandler.mm +19 -15
  65. package/ios/native/REAIOSLogger.mm +10 -6
  66. package/ios/native/REAIOSScheduler.mm +17 -10
  67. package/ios/native/REAInitializer.mm +39 -37
  68. package/ios/native/UIResponder+Reanimated.mm +2 -2
  69. package/lib/Animated.js +11 -5
  70. package/lib/ConfigHelper.js +121 -138
  71. package/lib/ReanimatedEventEmitter.js +0 -1
  72. package/lib/ReanimatedModule.js +0 -1
  73. package/lib/ReanimatedModule.macos.js +0 -1
  74. package/lib/ReanimatedModule.native.js +5 -6
  75. package/lib/ReanimatedModule.windows.js +0 -1
  76. package/lib/ReanimatedModuleCompat.js +64 -35
  77. package/lib/createAnimatedComponent.js +469 -499
  78. package/lib/index.js +11 -5
  79. package/lib/reanimated1/core/Core.test.js +1 -1
  80. package/lib/reanimated2/NativeMethods.js +7 -0
  81. package/lib/reanimated2/NativeReanimated/NativeReanimated.js +3 -0
  82. package/lib/reanimated2/PropAdapters.js +0 -1
  83. package/lib/reanimated2/UpdateProps.js +1 -1
  84. package/lib/reanimated2/ViewDescriptorsSet.js +4 -2
  85. package/lib/reanimated2/animation/spring.js +2 -0
  86. package/lib/reanimated2/animation/styleAnimation.js +5 -1
  87. package/lib/reanimated2/animation/util.js +23 -0
  88. package/lib/reanimated2/component/FlatList.js +30 -0
  89. package/lib/reanimated2/component/WrappedComponents.js +9 -0
  90. package/lib/reanimated2/component/index.js +4 -0
  91. package/lib/reanimated2/core.js +34 -6
  92. package/lib/reanimated2/globals.d.ts +8 -0
  93. package/lib/reanimated2/js-reanimated/JSReanimated.js +4 -0
  94. package/lib/reanimated2/js-reanimated/Mapper.js +4 -3
  95. package/lib/reanimated2/js-reanimated/MapperRegistry.js +3 -6
  96. package/lib/reanimated2/js-reanimated/MutableValue.js +0 -2
  97. package/lib/reanimated2/js-reanimated/index.js +10 -8
  98. package/lib/reanimated2/layoutReanimation/LayoutAnimationRepository.js +14 -5
  99. package/lib/reanimated2/layoutReanimation/defaultAnimations/Default.js +14 -14
  100. package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +8 -8
  101. package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +16 -16
  102. package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +16 -16
  103. package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +4 -4
  104. package/lib/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +20 -8
  105. package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +3 -3
  106. package/lib/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +8 -8
  107. package/lib/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +10 -10
  108. package/lib/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +8 -8
  109. package/lib/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +8 -8
  110. package/lib/reanimated2/mock.js +3 -1
  111. package/lib/setAndForwardRef.js +14 -48
  112. package/mock.js +1 -1
  113. package/package.json +27 -23
  114. package/plugin.js +111 -110
  115. package/react-native-reanimated.d.ts +56 -27
  116. package/src/Animated.js +11 -5
  117. package/src/{ConfigHelper.js → ConfigHelper.ts} +15 -7
  118. package/src/{ReanimatedEventEmitter.js → ReanimatedEventEmitter.ts} +0 -0
  119. package/src/{ReanimatedModule.js → ReanimatedModule.macos.ts} +0 -0
  120. package/src/{ReanimatedModule.native.js → ReanimatedModule.native.ts} +0 -0
  121. package/src/{ReanimatedModule.macos.js → ReanimatedModule.ts} +0 -0
  122. package/src/{ReanimatedModule.windows.js → ReanimatedModule.windows.ts} +0 -0
  123. package/src/ReanimatedModuleCompat.ts +51 -0
  124. package/src/{createAnimatedComponent.js → createAnimatedComponent.tsx} +278 -124
  125. package/src/reanimated1/core/Core.test.js +1 -1
  126. package/src/reanimated2/NativeMethods.ts +13 -1
  127. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +5 -11
  128. package/src/reanimated2/PropAdapters.ts +0 -1
  129. package/src/reanimated2/UpdateProps.ts +1 -1
  130. package/src/reanimated2/ViewDescriptorsSet.ts +6 -2
  131. package/src/reanimated2/animation/commonTypes.ts +4 -4
  132. package/src/reanimated2/animation/decay.ts +2 -2
  133. package/src/reanimated2/animation/delay.ts +3 -3
  134. package/src/reanimated2/animation/index.ts +7 -7
  135. package/src/reanimated2/animation/repeat.ts +4 -4
  136. package/src/reanimated2/animation/sequence.ts +2 -2
  137. package/src/reanimated2/animation/spring.ts +6 -5
  138. package/src/reanimated2/animation/styleAnimation.ts +24 -12
  139. package/src/reanimated2/animation/timing.ts +5 -5
  140. package/src/reanimated2/animation/util.ts +45 -6
  141. package/src/reanimated2/component/FlatList.tsx +44 -0
  142. package/src/reanimated2/component/WrappedComponents.ts +11 -0
  143. package/src/reanimated2/component/index.ts +9 -0
  144. package/src/reanimated2/core.ts +62 -17
  145. package/src/reanimated2/globals.d.ts +8 -0
  146. package/src/reanimated2/hook/useAnimatedStyle.ts +2 -2
  147. package/src/reanimated2/js-reanimated/JSReanimated.ts +15 -26
  148. package/src/reanimated2/js-reanimated/Mapper.ts +22 -9
  149. package/src/reanimated2/js-reanimated/MapperRegistry.ts +22 -19
  150. package/src/reanimated2/js-reanimated/MutableValue.ts +11 -11
  151. package/src/reanimated2/js-reanimated/index.ts +31 -14
  152. package/src/reanimated2/layoutReanimation/{LayoutAnimationRepository.tsx → LayoutAnimationRepository.ts} +18 -5
  153. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +39 -20
  154. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +5 -1
  155. package/src/reanimated2/layoutReanimation/defaultAnimations/Default.ts +21 -15
  156. package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +29 -24
  157. package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +61 -34
  158. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +49 -34
  159. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +17 -12
  160. package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +20 -8
  161. package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +9 -9
  162. package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +8 -8
  163. package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +20 -14
  164. package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +14 -8
  165. package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +24 -12
  166. package/src/reanimated2/mock.ts +3 -1
  167. package/src/{setAndForwardRef.js → setAndForwardRef.ts} +12 -2
  168. package/src/ReanimatedModuleCompat.js +0 -37
@@ -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', () => {
@@ -1,4 +1,6 @@
1
- /* global _WORKLET _measure _scrollTo */
1
+ /* global _WORKLET _measure _scrollTo _setGestureState */
2
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
+ // @ts-nocheck
2
4
  import { Component } from 'react';
3
5
  import { findNodeHandle } from 'react-native';
4
6
  import { RefObjectFunction } from './hook/useAnimatedRef';
@@ -47,3 +49,13 @@ export function scrollTo(
47
49
  const viewTag = animatedRef();
48
50
  _scrollTo(viewTag, x, y, animated);
49
51
  }
52
+
53
+ export function setGestureState(handlerTag: number, newState: number): void {
54
+ 'worklet';
55
+ if (!_WORKLET && !isChromeDebugger()) {
56
+ console.warn(
57
+ '[Reanimated] You can not use setGestureState in non-worklet function.'
58
+ );
59
+ }
60
+ _setGestureState(handlerTag, newState);
61
+ }
@@ -1,5 +1,3 @@
1
- import { AnimationObject } from '../animation';
2
- import { PrimitiveValue } from '../animation/commonTypes';
3
1
  import { SharedValue } from '../commonTypes';
4
2
  import { Descriptor } from '../hook/commonTypes';
5
3
 
@@ -13,15 +11,7 @@ export class NativeReanimated {
13
11
  this.useOnlyV1 = InnerNativeModule === null;
14
12
  }
15
13
 
16
- installCoreFunctions(
17
- valueSetter: (
18
- value:
19
- | (() => AnimationObject)
20
- | AnimationObject
21
- | PrimitiveValue
22
- | Descriptor
23
- ) => void
24
- ): void {
14
+ installCoreFunctions(valueSetter: <T>(value: T) => void): void {
25
15
  return InnerNativeModule.installCoreFunctions(valueSetter);
26
16
  }
27
17
 
@@ -75,4 +65,8 @@ export class NativeReanimated {
75
65
  ): Promise<T> {
76
66
  return InnerNativeModule.getViewProp(viewTag, propName, callback);
77
67
  }
68
+
69
+ enableLayoutAnimations(flag: boolean): void {
70
+ InnerNativeModule.enableLayoutAnimations(flag);
71
+ }
78
72
  }
@@ -1,4 +1,3 @@
1
- // @ts-ignore JS file
2
1
  import { addWhitelistedNativeProps } from '../ConfigHelper';
3
2
  import { AdapterWorkletFunction } from './commonTypes';
4
3
 
@@ -26,7 +26,7 @@ export const colorProps = [
26
26
  'overlayColor',
27
27
  ];
28
28
 
29
- const ColorProperties = !isConfigured() ? [] : makeShareable(colorProps);
29
+ export const ColorProperties = !isConfigured() ? [] : makeShareable(colorProps);
30
30
 
31
31
  let updatePropsByPlatform;
32
32
  if (shouldBeUseWeb()) {
@@ -2,6 +2,7 @@ import { useRef } from 'react';
2
2
  import { makeMutable } from './core';
3
3
  import { SharedValue } from './commonTypes';
4
4
  import { Descriptor } from './hook/commonTypes';
5
+ import { Platform } from 'react-native';
5
6
 
6
7
  export interface ViewRefSet<T> {
7
8
  items: Set<T>;
@@ -23,6 +24,9 @@ export interface ViewDescriptorsSet {
23
24
  ) => void;
24
25
  }
25
26
 
27
+ const scheduleUpdates =
28
+ Platform.OS === 'web' ? requestAnimationFrame : setImmediate;
29
+
26
30
  export function makeViewDescriptorsSet(): ViewDescriptorsSet {
27
31
  const ref = useRef<ViewDescriptorsSet | null>(null);
28
32
  if (ref.current === null) {
@@ -44,7 +48,7 @@ export function makeViewDescriptorsSet(): ViewDescriptorsSet {
44
48
  if (!data.waitForInsertSync) {
45
49
  data.waitForInsertSync = true;
46
50
 
47
- setImmediate(() => {
51
+ scheduleUpdates(() => {
48
52
  data.sharableViewDescriptors.value = data.items;
49
53
  data.waitForInsertSync = false;
50
54
  });
@@ -57,7 +61,7 @@ export function makeViewDescriptorsSet(): ViewDescriptorsSet {
57
61
  if (!data.waitForRemoveSync) {
58
62
  data.waitForRemoveSync = true;
59
63
 
60
- setImmediate(() => {
64
+ scheduleUpdates(() => {
61
65
  const items = [];
62
66
  for (const item of data.items) {
63
67
  if (data.batchToRemove.has(item.tag)) {
@@ -1,9 +1,9 @@
1
- export type PrimitiveValue = number | string;
1
+ export type AnimatableValue = number | string | Array<number>;
2
2
 
3
3
  export interface AnimationObject {
4
4
  [key: string]: any;
5
5
  callback: AnimationCallback;
6
- current?: PrimitiveValue;
6
+ current?: AnimatableValue;
7
7
  toValue?: AnimationObject['current'];
8
8
  startValue?: AnimationObject['current'];
9
9
  finished?: boolean;
@@ -25,7 +25,7 @@ export interface Animation<T extends AnimationObject> extends AnimationObject {
25
25
  onFrame: (animation: T, timestamp: Timestamp) => boolean;
26
26
  onStart: (
27
27
  nextAnimation: T,
28
- current: T extends NumericAnimation ? number : PrimitiveValue,
28
+ current: T extends NumericAnimation ? number : AnimatableValue,
29
29
  timestamp: Timestamp,
30
30
  previousAnimation: T
31
31
  ) => void;
@@ -40,7 +40,7 @@ export interface HigherOrderAnimation {
40
40
 
41
41
  export type AnimationCallback = (
42
42
  finished?: boolean,
43
- current?: PrimitiveValue
43
+ current?: AnimatableValue
44
44
  ) => void;
45
45
 
46
46
  export type NextAnimation<T extends AnimationObject> = T | (() => T);
@@ -3,7 +3,7 @@ import {
3
3
  Animation,
4
4
  AnimationCallback,
5
5
  AnimationObject,
6
- PrimitiveValue,
6
+ AnimatableValue,
7
7
  Timestamp,
8
8
  } from './commonTypes';
9
9
  import { Platform } from 'react-native';
@@ -27,7 +27,7 @@ export interface DecayAnimation extends Animation<DecayAnimation> {
27
27
  startTimestamp: Timestamp;
28
28
  initialVelocity: number;
29
29
  velocity: number;
30
- current: PrimitiveValue;
30
+ current: AnimatableValue;
31
31
  }
32
32
 
33
33
  export interface InnerDecayAnimation
@@ -4,7 +4,7 @@ import {
4
4
  NextAnimation,
5
5
  Timestamp,
6
6
  HigherOrderAnimation,
7
- PrimitiveValue,
7
+ AnimatableValue,
8
8
  } from './commonTypes';
9
9
 
10
10
  export interface DelayAnimation
@@ -13,7 +13,7 @@ export interface DelayAnimation
13
13
  startTime: Timestamp;
14
14
  started: boolean;
15
15
  previousAnimation: DelayAnimation | null;
16
- current: PrimitiveValue;
16
+ current: AnimatableValue;
17
17
  }
18
18
 
19
19
  export function withDelay(
@@ -57,7 +57,7 @@ export function withDelay(
57
57
 
58
58
  function onStart(
59
59
  animation: DelayAnimation,
60
- value: PrimitiveValue,
60
+ value: AnimatableValue,
61
61
  now: Timestamp,
62
62
  previousAnimation: DelayAnimation
63
63
  ): void {
@@ -7,10 +7,10 @@ export {
7
7
  Timestamp,
8
8
  } from './commonTypes';
9
9
  export { cancelAnimation, defineAnimation, initialUpdaterRun } from './util';
10
- export { withTiming } from './timing';
11
- export { withSpring } from './spring';
12
- export { withDecay } from './decay';
13
- export { withDelay } from './delay';
14
- export { withRepeat } from './repeat';
15
- export { withSequence } from './sequence';
16
- export { withStyleAnimation } from './styleAnimation';
10
+ export { withTiming, TimingAnimation } from './timing';
11
+ export { withSpring, SpringAnimation } from './spring';
12
+ export { withDecay, DecayAnimation } from './decay';
13
+ export { withDelay, DelayAnimation } from './delay';
14
+ export { withRepeat, RepeatAnimation } from './repeat';
15
+ export { withSequence, SequenceAnimation } from './sequence';
16
+ export { withStyleAnimation, StyleLayoutAnimation } from './styleAnimation';
@@ -3,7 +3,7 @@ import {
3
3
  Animation,
4
4
  AnimationCallback,
5
5
  NextAnimation,
6
- PrimitiveValue,
6
+ AnimatableValue,
7
7
  Timestamp,
8
8
  HigherOrderAnimation,
9
9
  } from './commonTypes';
@@ -12,8 +12,8 @@ export interface RepeatAnimation
12
12
  extends Animation<RepeatAnimation>,
13
13
  HigherOrderAnimation {
14
14
  reps: number;
15
- startValue: PrimitiveValue;
16
- toValue?: PrimitiveValue;
15
+ startValue: AnimatableValue;
16
+ toValue?: AnimatableValue;
17
17
  previousAnimation?: RepeatAnimation;
18
18
  }
19
19
 
@@ -81,7 +81,7 @@ export function withRepeat(
81
81
 
82
82
  function onStart(
83
83
  animation: RepeatAnimation,
84
- value: PrimitiveValue,
84
+ value: AnimatableValue,
85
85
  now: Timestamp,
86
86
  previousAnimation: RepeatAnimation
87
87
  ): void {
@@ -3,7 +3,7 @@ import {
3
3
  Animation,
4
4
  Timestamp,
5
5
  NextAnimation,
6
- PrimitiveValue,
6
+ AnimatableValue,
7
7
  HigherOrderAnimation,
8
8
  AnimationObject,
9
9
  } from './commonTypes';
@@ -66,7 +66,7 @@ export function withSequence(
66
66
 
67
67
  function onStart(
68
68
  animation: SequenceAnimation,
69
- value: PrimitiveValue,
69
+ value: AnimatableValue,
70
70
  now: Timestamp,
71
71
  previousAnimation: SequenceAnimation
72
72
  ): void {
@@ -2,12 +2,11 @@ import { defineAnimation } from './util';
2
2
  import {
3
3
  Animation,
4
4
  AnimationCallback,
5
- PrimitiveValue,
5
+ AnimatableValue,
6
6
  Timestamp,
7
7
  } from './commonTypes';
8
8
 
9
9
  interface SpringConfig {
10
- // [key: string]: any;
11
10
  mass?: number;
12
11
  stiffness?: number;
13
12
  overshootClamping?: boolean;
@@ -18,8 +17,8 @@ interface SpringConfig {
18
17
  }
19
18
 
20
19
  export interface SpringAnimation extends Animation<SpringAnimation> {
21
- current: PrimitiveValue;
22
- toValue: PrimitiveValue;
20
+ current: AnimatableValue;
21
+ toValue: AnimatableValue;
23
22
  velocity: number;
24
23
  lastTimestamp: Timestamp;
25
24
  }
@@ -31,7 +30,7 @@ export interface InnerSpringAnimation
31
30
  }
32
31
 
33
32
  export function withSpring(
34
- toValue: PrimitiveValue,
33
+ toValue: AnimatableValue,
35
34
  userConfig?: SpringConfig,
36
35
  callback?: AnimationCallback
37
36
  ): Animation<SpringAnimation> {
@@ -131,6 +130,8 @@ export function withSpring(
131
130
  animation.velocity = 0;
132
131
  animation.current = toValue;
133
132
  }
133
+ // clear lastTimestamp to avoid using stale value by the next spring animation that starts after this one
134
+ animation.lastTimestamp = 0;
134
135
  return true;
135
136
  }
136
137
  return false;
@@ -3,7 +3,7 @@ import {
3
3
  Timestamp,
4
4
  HigherOrderAnimation,
5
5
  AnimationCallback,
6
- PrimitiveValue,
6
+ AnimatableValue,
7
7
  AnimationObject,
8
8
  Animation,
9
9
  } from './commonTypes';
@@ -14,6 +14,8 @@ import {
14
14
  StyleProps,
15
15
  } from '../commonTypes';
16
16
  import { withTiming } from './timing';
17
+ import { ColorProperties } from '../UpdateProps';
18
+ import { processColor } from '../Colors';
17
19
 
18
20
  export interface StyleLayoutAnimation extends HigherOrderAnimation {
19
21
  current: StyleProps;
@@ -32,28 +34,31 @@ export interface StyleLayoutAnimation extends HigherOrderAnimation {
32
34
  // if path cannot be resolved returns undefined
33
35
  export function resolvePath<T>(
34
36
  obj: NestedObject<T>,
35
- path: PrimitiveValue[] | PrimitiveValue
37
+ path: AnimatableValue[] | AnimatableValue
36
38
  ): NestedObjectValues<T> | undefined {
37
39
  'worklet';
38
- const keys: PrimitiveValue[] = Array.isArray(path) ? path : [path];
40
+ const keys: AnimatableValue[] = Array.isArray(path) ? path : [path];
39
41
  return keys.reduce<NestedObjectValues<T> | undefined>((acc, current) => {
40
42
  if (Array.isArray(acc) && typeof current === 'number') {
41
43
  return acc[current];
42
- } else if (typeof acc === 'object' && current in acc) {
43
- return (acc as { [key: string]: NestedObjectValues<T> })[current];
44
+ } else if (typeof acc === 'object' && (current as number | string) in acc) {
45
+ return (acc as { [key: string]: NestedObjectValues<T> })[
46
+ current as number | string
47
+ ];
44
48
  }
45
49
  return undefined;
46
50
  }, obj);
47
51
  }
48
52
 
49
53
  // set value at given path
54
+ type Path = Array<string | number> | string | number;
50
55
  export function setPath<T>(
51
56
  obj: NestedObject<T>,
52
- path: PrimitiveValue[] | PrimitiveValue,
57
+ path: Path,
53
58
  value: NestedObjectValues<T>
54
59
  ): void {
55
60
  'worklet';
56
- const keys: PrimitiveValue[] = Array.isArray(path) ? path : [path];
61
+ const keys: Path = Array.isArray(path) ? path : [path];
57
62
  let currObj: NestedObjectValues<T> = obj;
58
63
  for (let i = 0; i < keys.length - 1; i++) {
59
64
  // creates entry if there isn't one
@@ -76,7 +81,7 @@ export function setPath<T>(
76
81
 
77
82
  interface NestedObjectEntry<T> {
78
83
  value: NestedObjectValues<T>;
79
- path: PrimitiveValue[];
84
+ path: (string | number)[];
80
85
  }
81
86
 
82
87
  export function withStyleAnimation(
@@ -131,6 +136,13 @@ export function withStyleAnimation(
131
136
  } else {
132
137
  stillGoing = true;
133
138
  }
139
+
140
+ if (ColorProperties.includes(currentEntry.path[0] as string)) {
141
+ currentStyleAnimation.current = processColor(
142
+ currentStyleAnimation.current
143
+ ) as number;
144
+ }
145
+
134
146
  setPath(
135
147
  animation.current,
136
148
  currentEntry.path,
@@ -148,13 +160,13 @@ export function withStyleAnimation(
148
160
  previousAnimation: StyleLayoutAnimation
149
161
  ): void => {
150
162
  const entriesToCheck: NestedObjectEntry<
151
- AnimationObject | PrimitiveValue
163
+ AnimationObject | AnimatableValue
152
164
  >[] = [{ value: styleAnimations, path: [] }];
153
165
  while (entriesToCheck.length > 0) {
154
166
  const currentEntry: NestedObjectEntry<
155
- AnimationObject | PrimitiveValue
167
+ AnimationObject | AnimatableValue
156
168
  > = entriesToCheck.pop() as NestedObjectEntry<
157
- AnimationObject | PrimitiveValue
169
+ AnimationObject | AnimatableValue
158
170
  >;
159
171
  if (Array.isArray(currentEntry.value)) {
160
172
  for (let index = 0; index < currentEntry.value.length; index++) {
@@ -189,7 +201,7 @@ export function withStyleAnimation(
189
201
  !currentEntry.value.onStart
190
202
  ) {
191
203
  currentAnimation = withTiming(
192
- currentEntry.value as PrimitiveValue,
204
+ currentEntry.value as AnimatableValue,
193
205
  { duration: 0 }
194
206
  );
195
207
  setPath(
@@ -4,7 +4,7 @@ import {
4
4
  Animation,
5
5
  AnimationCallback,
6
6
  Timestamp,
7
- PrimitiveValue,
7
+ AnimatableValue,
8
8
  } from './commonTypes';
9
9
 
10
10
  interface TimingConfig {
@@ -15,11 +15,11 @@ interface TimingConfig {
15
15
  export interface TimingAnimation extends Animation<TimingAnimation> {
16
16
  type: string;
17
17
  easing: EasingFn;
18
- startValue: PrimitiveValue;
18
+ startValue: AnimatableValue;
19
19
  startTime: Timestamp;
20
20
  progress: number;
21
- toValue: PrimitiveValue;
22
- current: PrimitiveValue;
21
+ toValue: AnimatableValue;
22
+ current: AnimatableValue;
23
23
  }
24
24
 
25
25
  export interface InnerTimingAnimation
@@ -29,7 +29,7 @@ export interface InnerTimingAnimation
29
29
  }
30
30
 
31
31
  export function withTiming(
32
- toValue: PrimitiveValue,
32
+ toValue: AnimatableValue,
33
33
  userConfig?: TimingConfig,
34
34
  callback?: AnimationCallback
35
35
  ): Animation<TimingAnimation> {
@@ -3,7 +3,7 @@ import {
3
3
  AnimationObject,
4
4
  HigherOrderAnimation,
5
5
  NextAnimation,
6
- PrimitiveValue,
6
+ AnimatableValue,
7
7
  Timestamp,
8
8
  } from './commonTypes';
9
9
  /* global _WORKLET */
@@ -32,7 +32,7 @@ interface RecognizedPrefixSuffix {
32
32
  strippedValue: number;
33
33
  }
34
34
 
35
- function recognizePrefixSuffix(value: PrimitiveValue): RecognizedPrefixSuffix {
35
+ function recognizePrefixSuffix(value: string | number): RecognizedPrefixSuffix {
36
36
  'worklet';
37
37
  if (typeof value === 'string') {
38
38
  const match = value.match(
@@ -68,7 +68,7 @@ function decorateAnimation<T extends AnimationObject | StyleLayoutAnimation>(
68
68
 
69
69
  const prefNumberSuffOnStart = (
70
70
  animation: Animation<AnimationObject>,
71
- value: PrimitiveValue,
71
+ value: string | number,
72
72
  timestamp: number,
73
73
  previousAnimation: Animation<AnimationObject>
74
74
  ) => {
@@ -78,7 +78,7 @@ function decorateAnimation<T extends AnimationObject | StyleLayoutAnimation>(
78
78
  animation.__suffix = suffix;
79
79
  animation.strippedCurrent = strippedValue;
80
80
  const { strippedValue: strippedToValue } = recognizePrefixSuffix(
81
- animation.toValue as PrimitiveValue
81
+ animation.toValue as string | number
82
82
  );
83
83
  animation.current = strippedValue;
84
84
  animation.startValue = strippedValue;
@@ -167,6 +167,41 @@ function decorateAnimation<T extends AnimationObject | StyleLayoutAnimation>(
167
167
  return finished;
168
168
  };
169
169
 
170
+ const arrayOnStart = (
171
+ animation: Animation<AnimationObject>,
172
+ value: Array<number>,
173
+ timestamp: Timestamp,
174
+ previousAnimation: Animation<AnimationObject>
175
+ ): void => {
176
+ value.forEach((v, i) => {
177
+ animation[i] = Object.assign({}, animationCopy);
178
+ animation[i].current = v;
179
+ animation[i].toValue = (animation.toValue as Array<number>)[i];
180
+ animation[i].onStart(
181
+ animation[i],
182
+ v,
183
+ timestamp,
184
+ previousAnimation ? previousAnimation[i] : undefined
185
+ );
186
+ });
187
+
188
+ animation.current = value;
189
+ };
190
+
191
+ const arrayOnFrame = (
192
+ animation: Animation<AnimationObject>,
193
+ timestamp: Timestamp
194
+ ): boolean => {
195
+ let finished = true;
196
+ (animation.current as Array<number>).forEach((v, i) => {
197
+ // @ts-ignore: disable-next-line
198
+ finished &= animation[i].onFrame(animation[i], timestamp);
199
+ (animation.current as Array<number>)[i] = animation[i].current;
200
+ });
201
+
202
+ return finished;
203
+ };
204
+
170
205
  animation.onStart = (
171
206
  animation: Animation<AnimationObject>,
172
207
  value: number,
@@ -177,6 +212,10 @@ function decorateAnimation<T extends AnimationObject | StyleLayoutAnimation>(
177
212
  colorOnStart(animation, value, timestamp, previousAnimation);
178
213
  animation.onFrame = colorOnFrame;
179
214
  return;
215
+ } else if (Array.isArray(value)) {
216
+ arrayOnStart(animation, value, timestamp, previousAnimation);
217
+ animation.onFrame = arrayOnFrame;
218
+ return;
180
219
  } else if (typeof value === 'string') {
181
220
  prefNumberSuffOnStart(animation, value, timestamp, previousAnimation);
182
221
  animation.onFrame = prefNumberSuffOnFrame;
@@ -196,7 +235,7 @@ type AnimationToDecoration<
196
235
  ? NextAnimation<RepeatAnimation>
197
236
  : T extends SequenceAnimation
198
237
  ? NextAnimation<SequenceAnimation>
199
- : PrimitiveValue | T;
238
+ : AnimatableValue | T;
200
239
 
201
240
  export function defineAnimation<
202
241
  T extends AnimationObject | StyleLayoutAnimation
@@ -227,7 +266,7 @@ export function cancelAnimation<T>(sharedValue: SharedValue<T>): void {
227
266
 
228
267
  // TODO it should work only if there was no animation before.
229
268
  export function withStartValue(
230
- startValue: PrimitiveValue,
269
+ startValue: AnimatableValue,
231
270
  animation: NextAnimation<AnimationObject>
232
271
  ): Animation<AnimationObject> {
233
272
  'worklet';
@@ -0,0 +1,44 @@
1
+ import React from 'react';
2
+ import { FlatList, FlatListProps, LayoutChangeEvent } from 'react-native';
3
+ import WrappedComponents from './WrappedComponents';
4
+ import createAnimatedComponent from '../../createAnimatedComponent';
5
+ import { ILayoutAnimationBuilder } from '../layoutReanimation/animationBuilder/commonTypes';
6
+
7
+ const AnimatedFlatList = createAnimatedComponent(FlatList as any) as any;
8
+
9
+ const createCellRenderer = (itemLayoutAnimation?: ILayoutAnimationBuilder) => {
10
+ const cellRenderer: React.FC<{
11
+ onLayout: (event: LayoutChangeEvent) => void;
12
+ }> = (props) => {
13
+ return (
14
+ <WrappedComponents.View
15
+ layout={itemLayoutAnimation}
16
+ onLayout={props.onLayout}>
17
+ {props.children}
18
+ </WrappedComponents.View>
19
+ );
20
+ };
21
+
22
+ return cellRenderer;
23
+ };
24
+
25
+ interface ReanimatedFlatlistProps<ItemT> extends FlatListProps<ItemT> {
26
+ itemLayoutAnimation?: ILayoutAnimationBuilder;
27
+ }
28
+
29
+ type ReanimatedFlatListFC<T = any> = React.FC<ReanimatedFlatlistProps<T>>;
30
+
31
+ const ReanimatedFlatlist: ReanimatedFlatListFC = ({
32
+ itemLayoutAnimation,
33
+ ...restProps
34
+ }) => {
35
+ const cellRenderer = React.useMemo(
36
+ () => createCellRenderer(itemLayoutAnimation),
37
+ []
38
+ );
39
+ return (
40
+ <AnimatedFlatList {...restProps} CellRendererComponent={cellRenderer} />
41
+ );
42
+ };
43
+
44
+ export default ReanimatedFlatlist;
@@ -0,0 +1,11 @@
1
+ import { Image, ScrollView, Text, View } from 'react-native';
2
+ import createAnimatedComponent from '../../createAnimatedComponent';
3
+
4
+ const WrappedComponents = {
5
+ View: createAnimatedComponent(View),
6
+ Text: createAnimatedComponent(Text as any),
7
+ Image: createAnimatedComponent(Image as any),
8
+ ScrollView: createAnimatedComponent(ScrollView),
9
+ };
10
+
11
+ export default WrappedComponents;
@@ -0,0 +1,9 @@
1
+ import ReanimatedFlatlist from './FlatList';
2
+ import WrappedComponents from './WrappedComponents';
3
+
4
+ const ReanimatedComponents = {
5
+ ...WrappedComponents,
6
+ FlatList: ReanimatedFlatlist,
7
+ };
8
+
9
+ export default ReanimatedComponents;