react-native-reanimated 2.3.0-alpha.3 → 2.3.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (264) hide show
  1. package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +15 -8
  2. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +176 -154
  3. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +49 -33
  4. package/Common/cpp/Registries/EventHandlerRegistry.cpp +14 -7
  5. package/Common/cpp/Registries/MapperRegistry.cpp +24 -20
  6. package/Common/cpp/Registries/WorkletsCache.cpp +19 -9
  7. package/Common/cpp/SharedItems/FrozenObject.cpp +17 -8
  8. package/Common/cpp/SharedItems/MutableValue.cpp +38 -25
  9. package/Common/cpp/SharedItems/MutableValueSetterProxy.cpp +11 -7
  10. package/Common/cpp/SharedItems/RemoteObject.cpp +9 -5
  11. package/Common/cpp/SharedItems/ShareableValue.cpp +211 -160
  12. package/Common/cpp/Tools/FeaturesConfig.cpp +5 -0
  13. package/Common/cpp/Tools/JSIStoreValueUser.cpp +25 -6
  14. package/Common/cpp/Tools/Mapper.cpp +30 -30
  15. package/Common/cpp/Tools/RuntimeDecorator.cpp +124 -86
  16. package/Common/cpp/Tools/Scheduler.cpp +6 -5
  17. package/Common/cpp/Tools/WorkletEventHandler.cpp +4 -2
  18. package/Common/cpp/headers/LayoutAnimations/LayoutAnimationsProxy.h +12 -11
  19. package/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +50 -31
  20. package/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +34 -16
  21. package/Common/cpp/headers/Registries/EventHandlerRegistry.h +15 -8
  22. package/Common/cpp/headers/Registries/MapperRegistry.h +5 -4
  23. package/Common/cpp/headers/Registries/WorkletsCache.h +9 -7
  24. package/Common/cpp/headers/SharedItems/FrozenObject.h +19 -11
  25. package/Common/cpp/headers/SharedItems/HostFunctionHandler.h +8 -4
  26. package/Common/cpp/headers/SharedItems/MutableValue.h +23 -12
  27. package/Common/cpp/headers/SharedItems/MutableValueSetterProxy.h +12 -7
  28. package/Common/cpp/headers/SharedItems/RemoteObject.h +19 -8
  29. package/Common/cpp/headers/SharedItems/RuntimeManager.h +26 -25
  30. package/Common/cpp/headers/SharedItems/ShareableValue.h +32 -27
  31. package/Common/cpp/headers/SharedItems/SharedParent.h +10 -7
  32. package/Common/cpp/headers/SharedItems/ValueWrapper.h +95 -72
  33. package/Common/cpp/headers/SpecTools/ErrorHandler.h +18 -19
  34. package/Common/cpp/headers/Tools/FeaturesConfig.h +19 -0
  35. package/Common/cpp/headers/Tools/JSIStoreValueUser.h +13 -16
  36. package/Common/cpp/headers/Tools/Mapper.h +19 -16
  37. package/Common/cpp/headers/Tools/PlatformDepMethodsHolder.h +17 -7
  38. package/Common/cpp/headers/Tools/ReanimatedHiddenHeaders.h +7 -11
  39. package/Common/cpp/headers/Tools/RuntimeDecorator.h +36 -27
  40. package/Common/cpp/headers/Tools/Scheduler.h +30 -35
  41. package/Common/cpp/headers/Tools/WorkletEventHandler.h +11 -8
  42. package/Common/cpp/hidden_headers/Logger.h +14 -14
  43. package/Common/cpp/hidden_headers/LoggerInterface.h +8 -9
  44. package/Common/cpp/hidden_headers/SpeedChecker.h +7 -8
  45. package/README.md +1 -1
  46. package/RNReanimated.podspec +24 -6
  47. package/android/build.gradle +38 -29
  48. package/android/react-native-reanimated-63-hermes.aar +0 -0
  49. package/android/react-native-reanimated-63-jsc.aar +0 -0
  50. package/android/react-native-reanimated-64-hermes.aar +0 -0
  51. package/android/react-native-reanimated-64-jsc.aar +0 -0
  52. package/android/react-native-reanimated-65-hermes.aar +0 -0
  53. package/android/react-native-reanimated-65-jsc.aar +0 -0
  54. package/android/react-native-reanimated-66-hermes.aar +0 -0
  55. package/android/react-native-reanimated-66-jsc.aar +0 -0
  56. package/android/react-native-reanimated-67-hermes.aar +0 -0
  57. package/android/react-native-reanimated-67-jsc.aar +0 -0
  58. package/ios/LayoutReanimation/REAAnimationsManager.h +10 -8
  59. package/ios/LayoutReanimation/REAAnimationsManager.m +91 -87
  60. package/ios/LayoutReanimation/REASnapshot.h +2 -2
  61. package/ios/LayoutReanimation/REASnapshot.m +8 -7
  62. package/ios/LayoutReanimation/REAUIManager.h +4 -4
  63. package/ios/LayoutReanimation/REAUIManager.mm +116 -70
  64. package/ios/Nodes/REAAlwaysNode.m +14 -15
  65. package/ios/Nodes/REABezierNode.m +8 -7
  66. package/ios/Nodes/REABlockNode.m +1 -1
  67. package/ios/Nodes/REACallFuncNode.h +0 -1
  68. package/ios/Nodes/REACallFuncNode.m +10 -8
  69. package/ios/Nodes/REAClockNodes.m +22 -20
  70. package/ios/Nodes/REAConcatNode.h +0 -1
  71. package/ios/Nodes/REAConcatNode.m +2 -2
  72. package/ios/Nodes/REACondNode.m +7 -5
  73. package/ios/Nodes/READebugNode.m +5 -4
  74. package/ios/Nodes/REAEventNode.m +1 -1
  75. package/ios/Nodes/REAFunctionNode.h +0 -1
  76. package/ios/Nodes/REAFunctionNode.m +2 -2
  77. package/ios/Nodes/REAJSCallNode.m +4 -5
  78. package/ios/Nodes/REANode.h +3 -4
  79. package/ios/Nodes/REANode.m +9 -11
  80. package/ios/Nodes/REAOperatorNode.m +68 -67
  81. package/ios/Nodes/REAParamNode.h +1 -3
  82. package/ios/Nodes/REAParamNode.m +15 -17
  83. package/ios/Nodes/REAPropsNode.h +1 -3
  84. package/ios/Nodes/REAPropsNode.m +19 -22
  85. package/ios/Nodes/REASetNode.h +0 -1
  86. package/ios/Nodes/REASetNode.m +7 -5
  87. package/ios/Nodes/REAStyleNode.h +0 -1
  88. package/ios/Nodes/REAStyleNode.m +2 -4
  89. package/ios/Nodes/REATransformNode.h +0 -1
  90. package/ios/Nodes/REATransformNode.m +3 -5
  91. package/ios/Nodes/REAValueNode.m +5 -7
  92. package/ios/REAEventDispatcher.m +4 -4
  93. package/ios/REAModule.h +0 -2
  94. package/ios/REAModule.m +29 -38
  95. package/ios/REANodesManager.h +11 -19
  96. package/ios/REANodesManager.m +106 -130
  97. package/ios/REAUtils.h +5 -3
  98. package/ios/RNGestureHandlerStateManager.h +5 -0
  99. package/ios/Transitioning/RCTConvert+REATransition.m +45 -29
  100. package/ios/Transitioning/REAAllTransitions.h +2 -2
  101. package/ios/Transitioning/REAAllTransitions.m +14 -25
  102. package/ios/Transitioning/REATransition.h +8 -7
  103. package/ios/Transitioning/REATransition.m +19 -16
  104. package/ios/Transitioning/REATransitionAnimation.h +1 -1
  105. package/ios/Transitioning/REATransitionAnimation.m +2 -3
  106. package/ios/Transitioning/REATransitionManager.m +3 -3
  107. package/ios/native/NativeMethods.h +20 -5
  108. package/ios/native/NativeMethods.mm +14 -6
  109. package/ios/native/NativeProxy.h +4 -2
  110. package/ios/native/NativeProxy.mm +84 -63
  111. package/ios/native/REAIOSErrorHandler.h +13 -10
  112. package/ios/native/REAIOSErrorHandler.mm +19 -15
  113. package/ios/native/REAIOSLogger.h +8 -8
  114. package/ios/native/REAIOSLogger.mm +10 -6
  115. package/ios/native/REAIOSScheduler.h +5 -5
  116. package/ios/native/REAIOSScheduler.mm +17 -10
  117. package/ios/native/REAInitializer.h +5 -7
  118. package/ios/native/REAInitializer.mm +43 -31
  119. package/ios/native/UIResponder+Reanimated.mm +2 -2
  120. package/lib/Animated.js +9 -1
  121. package/lib/ConfigHelper.js +121 -138
  122. package/lib/ReanimatedEventEmitter.js +0 -1
  123. package/lib/ReanimatedModule.js +0 -1
  124. package/lib/ReanimatedModule.macos.js +0 -1
  125. package/lib/ReanimatedModule.native.js +5 -6
  126. package/lib/ReanimatedModule.windows.js +0 -1
  127. package/lib/ReanimatedModuleCompat.js +64 -35
  128. package/lib/createAnimatedComponent.js +468 -487
  129. package/lib/index.js +9 -1
  130. package/lib/reanimated2/NativeMethods.js +7 -12
  131. package/lib/reanimated2/NativeReanimated/NativeReanimated.js +37 -0
  132. package/lib/reanimated2/NativeReanimated/index.js +15 -0
  133. package/lib/reanimated2/PropAdapters.js +0 -1
  134. package/lib/reanimated2/UpdateProps.js +6 -7
  135. package/lib/reanimated2/ViewDescriptorsSet.js +4 -4
  136. package/lib/reanimated2/WorkletEventHandler.js +15 -13
  137. package/lib/reanimated2/animation/delay.js +8 -2
  138. package/lib/reanimated2/animation/spring.js +2 -0
  139. package/lib/reanimated2/animation/styleAnimation.js +7 -3
  140. package/lib/reanimated2/animation/util.js +25 -2
  141. package/lib/reanimated2/core.js +41 -17
  142. package/lib/reanimated2/globals.d.ts +21 -1
  143. package/lib/reanimated2/hook/useAnimatedRef.js +1 -1
  144. package/lib/reanimated2/hook/useAnimatedStyle.js +3 -3
  145. package/lib/reanimated2/index.js +1 -0
  146. package/lib/reanimated2/interpolation.js +95 -87
  147. package/lib/reanimated2/js-reanimated/JSReanimated.js +13 -10
  148. package/lib/reanimated2/js-reanimated/Mapper.js +4 -3
  149. package/lib/reanimated2/js-reanimated/MapperRegistry.js +3 -6
  150. package/lib/reanimated2/js-reanimated/MutableValue.js +0 -2
  151. package/lib/reanimated2/js-reanimated/index.js +10 -8
  152. package/lib/reanimated2/layoutReanimation/LayoutAnimationRepository.js +33 -2
  153. package/lib/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js +27 -124
  154. package/lib/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +125 -0
  155. package/lib/reanimated2/layoutReanimation/animationBuilder/index.js +1 -2
  156. package/lib/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +115 -45
  157. package/lib/reanimated2/layoutReanimation/defaultAnimations/Default.js +7 -2
  158. package/lib/reanimated2/layoutReanimation/defaultAnimations/Fade.js +21 -21
  159. package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +25 -25
  160. package/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +19 -17
  161. package/lib/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +5 -5
  162. package/lib/reanimated2/layoutReanimation/defaultAnimations/Roll.js +9 -9
  163. package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +17 -17
  164. package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +19 -19
  165. package/lib/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +9 -9
  166. package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +33 -33
  167. package/lib/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +78 -0
  168. package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +128 -0
  169. package/lib/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +37 -0
  170. package/lib/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +41 -0
  171. package/lib/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +34 -0
  172. package/lib/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +46 -0
  173. package/lib/reanimated2/layoutReanimation/defaultTransitions/index.js +6 -0
  174. package/lib/reanimated2/layoutReanimation/index.js +1 -0
  175. package/lib/reanimated2/mock.js +3 -1
  176. package/lib/reanimated2/utils.js +9 -0
  177. package/lib/setAndForwardRef.js +14 -48
  178. package/libSo/fbjni/jni/arm64-v8a/libfbjni.so +0 -0
  179. package/libSo/fbjni/jni/armeabi-v7a/libfbjni.so +0 -0
  180. package/libSo/fbjni/jni/x86/libfbjni.so +0 -0
  181. package/libSo/fbjni/jni/x86_64/libfbjni.so +0 -0
  182. package/mock.js +1 -1
  183. package/package.json +28 -17
  184. package/plugin.js +220 -39
  185. package/react-native-reanimated.d.ts +542 -547
  186. package/src/Animated.js +9 -1
  187. package/src/{ConfigHelper.js → ConfigHelper.ts} +15 -7
  188. package/src/{ReanimatedEventEmitter.js → ReanimatedEventEmitter.ts} +0 -0
  189. package/src/{ReanimatedModule.js → ReanimatedModule.macos.ts} +0 -0
  190. package/src/{ReanimatedModule.native.js → ReanimatedModule.native.ts} +0 -0
  191. package/src/{ReanimatedModule.macos.js → ReanimatedModule.ts} +0 -0
  192. package/src/{ReanimatedModule.windows.js → ReanimatedModule.windows.ts} +0 -0
  193. package/src/ReanimatedModuleCompat.ts +51 -0
  194. package/src/{createAnimatedComponent.js → createAnimatedComponent.tsx} +285 -126
  195. package/src/reanimated2/NativeMethods.ts +34 -13
  196. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +72 -0
  197. package/src/reanimated2/NativeReanimated/index.ts +18 -0
  198. package/src/reanimated2/PropAdapters.ts +0 -1
  199. package/src/reanimated2/UpdateProps.ts +31 -15
  200. package/src/reanimated2/ViewDescriptorsSet.ts +15 -12
  201. package/src/reanimated2/WorkletEventHandler.ts +41 -23
  202. package/src/reanimated2/animation/commonTypes.ts +4 -4
  203. package/src/reanimated2/animation/decay.ts +2 -2
  204. package/src/reanimated2/animation/delay.ts +11 -5
  205. package/src/reanimated2/animation/index.ts +7 -7
  206. package/src/reanimated2/animation/repeat.ts +4 -4
  207. package/src/reanimated2/animation/sequence.ts +2 -2
  208. package/src/reanimated2/animation/spring.ts +6 -5
  209. package/src/reanimated2/animation/styleAnimation.ts +27 -15
  210. package/src/reanimated2/animation/timing.ts +5 -5
  211. package/src/reanimated2/animation/util.ts +47 -8
  212. package/src/reanimated2/commonTypes.ts +3 -0
  213. package/src/reanimated2/core.ts +80 -34
  214. package/src/reanimated2/globals.d.ts +21 -1
  215. package/src/reanimated2/hook/useAnimatedGestureHandler.ts +1 -1
  216. package/src/reanimated2/hook/useAnimatedRef.ts +13 -15
  217. package/src/reanimated2/hook/useAnimatedScrollHandler.ts +3 -3
  218. package/src/reanimated2/hook/useAnimatedStyle.ts +7 -7
  219. package/src/reanimated2/hook/utils.ts +4 -3
  220. package/src/reanimated2/index.ts +1 -0
  221. package/src/reanimated2/interpolation.ts +170 -103
  222. package/src/reanimated2/js-reanimated/JSReanimated.ts +37 -23
  223. package/src/reanimated2/js-reanimated/Mapper.ts +22 -9
  224. package/src/reanimated2/js-reanimated/MapperRegistry.ts +22 -19
  225. package/src/reanimated2/js-reanimated/MutableValue.ts +11 -11
  226. package/src/reanimated2/js-reanimated/index.ts +31 -14
  227. package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.ts +75 -0
  228. package/src/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.ts +29 -159
  229. package/src/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.ts +169 -0
  230. package/src/reanimated2/layoutReanimation/animationBuilder/Keyframe.ts +2 -2
  231. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +3 -9
  232. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +1 -5
  233. package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +162 -82
  234. package/src/reanimated2/layoutReanimation/defaultAnimations/Default.ts +7 -2
  235. package/src/reanimated2/layoutReanimation/defaultAnimations/Fade.ts +32 -32
  236. package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +38 -38
  237. package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +34 -32
  238. package/src/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.ts +8 -8
  239. package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +14 -14
  240. package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +26 -26
  241. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +28 -28
  242. package/src/reanimated2/layoutReanimation/defaultAnimations/Stretch.ts +14 -14
  243. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +50 -50
  244. package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +104 -0
  245. package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +213 -0
  246. package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +60 -0
  247. package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +58 -0
  248. package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +41 -0
  249. package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +78 -0
  250. package/src/reanimated2/layoutReanimation/defaultTransitions/index.ts +6 -0
  251. package/src/reanimated2/layoutReanimation/index.ts +1 -0
  252. package/src/reanimated2/mock.ts +3 -1
  253. package/src/reanimated2/utils.ts +21 -0
  254. package/src/{setAndForwardRef.js → setAndForwardRef.ts} +12 -2
  255. package/android/react-native-reanimated-62-hermes.aar +0 -0
  256. package/android/react-native-reanimated-62-jsc.aar +0 -0
  257. package/lib/reanimated2/NativeReanimated.js +0 -48
  258. package/lib/reanimated2/layoutReanimation/animationBuilder/BaseBounceAnimationBuilder.js +0 -55
  259. package/lib/reanimated2/layoutReanimation/animationBuilder/LayoutAnimationBuilder.js +0 -165
  260. package/src/ReanimatedModuleCompat.js +0 -37
  261. package/src/reanimated2/NativeReanimated.ts +0 -70
  262. package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.tsx +0 -41
  263. package/src/reanimated2/layoutReanimation/animationBuilder/BaseBounceAnimationBuilder.ts +0 -82
  264. package/src/reanimated2/layoutReanimation/animationBuilder/LayoutAnimationBuilder.ts +0 -217
@@ -1,27 +1,29 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
- // @ts-nocheck
3
- export default class MapperRegistry {
4
- sortedMappers = [];
5
- mappers = new Map();
1
+ import JSReanimated from './JSReanimated';
2
+ import Mapper from './Mapper';
3
+
4
+ export default class MapperRegistry<T> {
5
+ sortedMappers: Mapper<T>[] = [];
6
+ mappers: Map<number, Mapper<T>> = new Map();
7
+ _module: JSReanimated;
6
8
 
7
9
  updatedSinceLastExecute = false;
8
10
 
9
- constructor(module) {
11
+ constructor(module: JSReanimated) {
10
12
  this._module = module;
11
13
  }
12
14
 
13
- startMapper(mapper) {
15
+ startMapper(mapper: Mapper<T>): number {
14
16
  this.mappers.set(mapper.id, mapper);
15
17
  this.updatedSinceLastExecute = true;
16
18
  return mapper.id;
17
19
  }
18
20
 
19
- stopMapper(id) {
21
+ stopMapper(id: number): void {
20
22
  this.mappers.delete(id);
21
23
  this.updatedSinceLastExecute = true;
22
24
  }
23
25
 
24
- execute() {
26
+ execute(): void {
25
27
  if (this.updatedSinceLastExecute) {
26
28
  this.updateOrder();
27
29
  this.updatedSinceLastExecute = false;
@@ -35,10 +37,10 @@ export default class MapperRegistry {
35
37
  }
36
38
  }
37
39
 
38
- updateOrder() {
40
+ updateOrder(): void {
39
41
  const nodes = [...this.mappers.values()].map((mapper) => new Node(mapper));
40
42
 
41
- const mappersById = {};
43
+ const mappersById: Record<number, Mapper<T>> = {};
42
44
  this.mappers.forEach((mapper) => {
43
45
  mappersById[mapper.id] = mapper;
44
46
  });
@@ -75,9 +77,9 @@ export default class MapperRegistry {
75
77
  }
76
78
  }
77
79
 
78
- const post = {};
80
+ const post: Record<number, number> = {};
79
81
  let postCounter = 1;
80
- const dfs = (node) => {
82
+ const dfs = (node: Node<T>) => {
81
83
  const index = nodes.indexOf(node);
82
84
  if (index === -1) {
83
85
  // this node has already been handled
@@ -99,7 +101,8 @@ export default class MapperRegistry {
99
101
  while (nodes.length) dfs(nodes[0]);
100
102
 
101
103
  const postArray = Object.keys(post).map((key) => {
102
- return [key, post[key]];
104
+ const num = parseInt(key);
105
+ return [num, post[num]];
103
106
  });
104
107
  postArray.sort((a, b) => {
105
108
  return b[1] - a[1];
@@ -114,16 +117,16 @@ export default class MapperRegistry {
114
117
  }
115
118
  }
116
119
 
117
- get needRunOnRender() {
120
+ get needRunOnRender(): boolean {
118
121
  return this.updatedSinceLastExecute;
119
122
  }
120
123
  }
121
124
 
122
- class Node {
123
- mapper = null;
124
- children = [];
125
+ class Node<T> {
126
+ mapper: Mapper<T>;
127
+ children: Node<T>[];
125
128
 
126
- constructor(mapper, _parents = [], children = []) {
129
+ constructor(mapper: Mapper<T>, children = []) {
127
130
  this.mapper = mapper;
128
131
  this.children = children;
129
132
  }
@@ -1,36 +1,36 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
- // @ts-nocheck
3
- export default class MutableValue {
1
+ export default class MutableValue<T> {
4
2
  static MUTABLE_ID = 1;
5
-
3
+ _id: number;
4
+ _value: T;
5
+ _setter: (value: T) => void;
6
6
  _animation = null;
7
- _listeners = [];
7
+ _listeners: (() => void)[] = [];
8
8
 
9
- constructor(value, setter) {
9
+ constructor(value: T, setter: (value: T) => void) {
10
10
  this._id = MutableValue.MUTABLE_ID++;
11
11
  this._value = value;
12
12
  this._setter = setter;
13
13
  }
14
14
 
15
- get value() {
15
+ get value(): T {
16
16
  return this._value;
17
17
  }
18
18
 
19
- set value(nextValue) {
19
+ set value(nextValue: T) {
20
20
  this._setter(nextValue);
21
21
  }
22
22
 
23
23
  // this changes the value finally and is supposed to be called from this._setter
24
- _setValue(newValue) {
24
+ _setValue(newValue: T): void {
25
25
  this._value = newValue;
26
26
  this._triggerListener();
27
27
  }
28
28
 
29
- addListener(listener) {
29
+ addListener(listener: () => void): void {
30
30
  this._listeners.push(listener);
31
31
  }
32
32
 
33
- _triggerListener() {
33
+ _triggerListener(): void {
34
34
  for (let i = 0, len = this._listeners.length; i < len; ++i) {
35
35
  this._listeners[i]();
36
36
  }
@@ -1,10 +1,18 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
- // @ts-nocheck
3
1
  import JSReanimated from './JSReanimated';
4
2
  import { shouldBeUseWeb } from '../PlatformChecker';
3
+ import { AnimatedStyle, StyleProps } from '../commonTypes';
5
4
 
6
5
  const reanimatedJS = new JSReanimated();
7
6
 
7
+ interface JSReanimatedComponent {
8
+ previousStyle: StyleProps;
9
+ setNativeProps: (style: StyleProps) => void;
10
+ props: Record<string, string | number>;
11
+ _touchableNode: {
12
+ setAttribute: (key: string, props: unknown) => void;
13
+ };
14
+ }
15
+
8
16
  if (shouldBeUseWeb()) {
9
17
  global._frameTimestamp = null;
10
18
  global._setGlobalConsole = (_val) => {
@@ -28,12 +36,21 @@ if (shouldBeUseWeb()) {
28
36
  "[Reanimated] You can't use 'scrollTo' method with Chrome Debugger or with web version"
29
37
  );
30
38
  };
39
+ global._setGestureState = () => {
40
+ console.warn(
41
+ "[Reanimated] You can't use 'setGestureState' method with Chrome Debugger or with web version"
42
+ );
43
+ };
31
44
  }
32
45
 
33
- export const _updatePropsJS = (updates, viewRef) => {
34
- if (viewRef?._component) {
46
+ export const _updatePropsJS = (
47
+ updates: StyleProps | AnimatedStyle,
48
+ viewRef: { _component?: JSReanimatedComponent }
49
+ ): void => {
50
+ if (viewRef._component) {
51
+ const component = viewRef._component;
35
52
  const [rawStyles] = Object.keys(updates).reduce(
36
- (acc, key) => {
53
+ (acc: [StyleProps, AnimatedStyle], key) => {
37
54
  const value = updates[key];
38
55
  const index = typeof value === 'function' ? 1 : 0;
39
56
  acc[index][key] = value;
@@ -42,18 +59,15 @@ export const _updatePropsJS = (updates, viewRef) => {
42
59
  [{}, {}]
43
60
  );
44
61
 
45
- if (typeof viewRef._component.setNativeProps === 'function') {
46
- setNativeProps(viewRef._component, rawStyles);
47
- } else if (Object.keys(viewRef._component.props).length > 0) {
48
- Object.keys(viewRef._component.props).forEach((key) => {
62
+ if (typeof component.setNativeProps === 'function') {
63
+ setNativeProps(component, rawStyles);
64
+ } else if (Object.keys(component.props).length > 0) {
65
+ Object.keys(component.props).forEach((key) => {
49
66
  if (!rawStyles[key]) {
50
67
  return;
51
68
  }
52
69
  const dashedKey = key.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());
53
- viewRef._component._touchableNode.setAttribute(
54
- dashedKey,
55
- rawStyles[key]
56
- );
70
+ component._touchableNode.setAttribute(dashedKey, rawStyles[key]);
57
71
  });
58
72
  } else {
59
73
  console.warn('It is not possible to manipulate component');
@@ -61,7 +75,10 @@ export const _updatePropsJS = (updates, viewRef) => {
61
75
  }
62
76
  };
63
77
 
64
- const setNativeProps = (component, style) => {
78
+ const setNativeProps = (
79
+ component: JSReanimatedComponent,
80
+ style: StyleProps
81
+ ): void => {
65
82
  const previousStyle = component.previousStyle ? component.previousStyle : {};
66
83
  const currentStyle = { ...previousStyle, ...style };
67
84
  component.previousStyle = currentStyle;
@@ -0,0 +1,75 @@
1
+ /* global _stopObservingProgress, _startObservingProgress */
2
+ import { runOnUI } from '../core';
3
+ import { withStyleAnimation } from '../animation/styleAnimation';
4
+ import { ColorProperties } from '../UpdateProps';
5
+ import { processColor } from '../Colors';
6
+
7
+ runOnUI(() => {
8
+ 'worklet';
9
+
10
+ const configs: Record<string, any> = {};
11
+ const enteringAnimationForTag: Record<string, any> = {};
12
+
13
+ global.LayoutAnimationRepository = {
14
+ configs,
15
+ registerConfig(tag, config) {
16
+ configs[tag] = config;
17
+ enteringAnimationForTag[tag] = null;
18
+ },
19
+ removeConfig(tag) {
20
+ delete configs[tag];
21
+ delete enteringAnimationForTag[tag];
22
+ },
23
+ startAnimationForTag(tag, type, yogaValues) {
24
+ if (configs[tag] == null) {
25
+ return; // :(
26
+ }
27
+ const style = configs[tag][type](yogaValues);
28
+ let currentAnimation = style.animations;
29
+ if (type === 'entering') {
30
+ enteringAnimationForTag[tag] = style;
31
+ } else if (type === 'layout' && enteringAnimationForTag[tag] !== null) {
32
+ const entryAniamtion = enteringAnimationForTag[tag].animations;
33
+ const layoutAnimation = style.animations;
34
+ currentAnimation = {};
35
+ for (const key in entryAniamtion) {
36
+ currentAnimation[key] = entryAniamtion[key];
37
+ }
38
+ for (const key in layoutAnimation) {
39
+ currentAnimation[key] = layoutAnimation[key];
40
+ }
41
+ }
42
+
43
+ const sv: { value: boolean; _value: boolean } = configs[tag].sv;
44
+ _stopObservingProgress(tag, false);
45
+ _startObservingProgress(tag, sv);
46
+
47
+ const backupColor: Record<string, string> = {};
48
+ for (const key in style.initialValues) {
49
+ if (ColorProperties.includes(key)) {
50
+ const value = style.initialValues[key];
51
+ backupColor[key] = value;
52
+ style.initialValues[key] = processColor(value);
53
+ }
54
+ }
55
+
56
+ sv.value = Object.assign({}, sv._value, style.initialValues);
57
+ _stopObservingProgress(tag, false);
58
+ const animation = withStyleAnimation(currentAnimation);
59
+
60
+ animation.callback = (finished?: boolean) => {
61
+ if (finished) {
62
+ _stopObservingProgress(tag, finished);
63
+ }
64
+ style.callback && style.callback(finished);
65
+ };
66
+
67
+ if (backupColor) {
68
+ configs[tag].sv._value = { ...configs[tag].sv.value, ...backupColor };
69
+ }
70
+
71
+ configs[tag].sv.value = animation;
72
+ _startObservingProgress(tag, sv);
73
+ },
74
+ };
75
+ })();
@@ -1,28 +1,18 @@
1
- import { withDelay, withTiming, withSpring } from '../../animation';
1
+ import { withDelay } from '../../animation';
2
2
  import {
3
3
  EntryExitAnimationFunction,
4
4
  AnimationFunction,
5
- BaseBuilderAnimationConfig,
6
- EntryExitAnimationBuild,
7
- LayoutAnimationAndConfig,
5
+ LayoutAnimationFunction,
8
6
  } from './commonTypes';
9
- import { EasingFn } from '../../Easing';
7
+
10
8
  export class BaseAnimationBuilder {
11
9
  durationV?: number;
12
- easingV?: EasingFn;
13
10
  delayV?: number;
14
- rotateV?: string;
15
- type?: AnimationFunction;
16
- dampingV?: number;
17
- massV?: number;
18
- stiffnessV?: number;
19
- overshootClampingV?: number;
20
- restDisplacementThresholdV?: number;
21
- restSpeedThresholdV?: number;
11
+ randomizeDelay = false;
22
12
  callbackV?: (finished: boolean) => void;
23
13
 
24
14
  static createInstance: () => BaseAnimationBuilder;
25
- build: EntryExitAnimationBuild = () => {
15
+ build = (): EntryExitAnimationFunction | LayoutAnimationFunction => {
26
16
  throw Error('Unimplemented method in child class.');
27
17
  };
28
18
 
@@ -36,16 +26,6 @@ export class BaseAnimationBuilder {
36
26
  return this;
37
27
  }
38
28
 
39
- static easing(easingFunction: EasingFn): BaseAnimationBuilder {
40
- const instance = this.createInstance();
41
- return instance.easing(easingFunction);
42
- }
43
-
44
- easing(easingFunction: EasingFn): BaseAnimationBuilder {
45
- this.easingV = easingFunction;
46
- return this;
47
- }
48
-
49
29
  static delay(delayMs: number): BaseAnimationBuilder {
50
30
  const instance = this.createInstance();
51
31
  return instance.delay(delayMs);
@@ -56,110 +36,47 @@ export class BaseAnimationBuilder {
56
36
  return this;
57
37
  }
58
38
 
59
- static rotate(degree: string): BaseAnimationBuilder {
60
- const instance = this.createInstance();
61
- return instance.rotate(degree);
62
- }
63
-
64
- rotate(degree: string): BaseAnimationBuilder {
65
- this.rotateV = degree;
66
- return this;
67
- }
68
-
69
- static springify(): BaseAnimationBuilder {
70
- const instance = this.createInstance();
71
- return instance.springify();
72
- }
73
-
74
- springify(): BaseAnimationBuilder {
75
- this.type = withSpring as AnimationFunction;
76
- return this;
77
- }
78
-
79
- static damping(damping: number): BaseAnimationBuilder {
80
- const instance = this.createInstance();
81
- return instance.damping(damping);
82
- }
83
-
84
- damping(damping: number): BaseAnimationBuilder {
85
- this.dampingV = damping;
86
- return this;
87
- }
88
-
89
- static mass(mass: number): BaseAnimationBuilder {
90
- const instance = this.createInstance();
91
- return instance.mass(mass);
92
- }
93
-
94
- mass(mass: number): BaseAnimationBuilder {
95
- this.massV = mass;
96
- return this;
97
- }
98
-
99
- static stiffness(stiffness: number): BaseAnimationBuilder {
100
- const instance = this.createInstance();
101
- return instance.stiffness(stiffness);
102
- }
103
-
104
- stiffness(stiffness: number): BaseAnimationBuilder {
105
- this.stiffnessV = stiffness;
106
- return this;
107
- }
108
-
109
- static overshootClamping(overshootClamping: number): BaseAnimationBuilder {
110
- const instance = this.createInstance();
111
- return instance.overshootClamping(overshootClamping);
112
- }
113
-
114
- overshootClamping(overshootClamping: number): BaseAnimationBuilder {
115
- this.overshootClampingV = overshootClamping;
116
- return this;
117
- }
118
-
119
- static restDisplacementThreshold(
120
- restDisplacementThreshold: number
39
+ static withCallback(
40
+ callback: (finished: boolean) => void
121
41
  ): BaseAnimationBuilder {
122
42
  const instance = this.createInstance();
123
- return instance.restDisplacementThreshold(restDisplacementThreshold);
43
+ return instance.withCallback(callback);
124
44
  }
125
45
 
126
- restDisplacementThreshold(
127
- restDisplacementThreshold: number
128
- ): BaseAnimationBuilder {
129
- this.restDisplacementThresholdV = restDisplacementThreshold;
46
+ withCallback(callback: (finsihed: boolean) => void): BaseAnimationBuilder {
47
+ this.callbackV = callback;
130
48
  return this;
131
49
  }
132
50
 
133
- static restSpeedThreshold(restSpeedThreshold: number): BaseAnimationBuilder {
134
- const instance = this.createInstance();
135
- return instance.restSpeedThreshold(restSpeedThreshold);
51
+ // 300ms is the default animation duration. If any animation has different default has to override this method.
52
+ static getDuration(): number {
53
+ return 300;
136
54
  }
137
55
 
138
- restSpeedThreshold(restSpeedThreshold: number): BaseAnimationBuilder {
139
- this.restSpeedThresholdV = restSpeedThreshold;
140
- return this;
56
+ getDuration(): number {
57
+ return this.durationV ?? 300;
141
58
  }
142
59
 
143
- static withCallback(
144
- callback: (finished: boolean) => void
145
- ): BaseAnimationBuilder {
60
+ static randomDelay(): BaseAnimationBuilder {
146
61
  const instance = this.createInstance();
147
- return instance.withCallback(callback);
62
+ return instance.randomDelay();
148
63
  }
149
64
 
150
- withCallback(callback: (finsihed: boolean) => void): BaseAnimationBuilder {
151
- this.callbackV = callback;
65
+ randomDelay(): BaseAnimationBuilder {
66
+ this.randomizeDelay = true;
152
67
  return this;
153
68
  }
154
69
 
155
- static build(): EntryExitAnimationFunction {
156
- const instance = this.createInstance();
157
- return instance.build();
70
+ // when randomizeDelay is set to true, randomize delay between 0 and provided value (or 1000ms if delay is not provided)
71
+ getDelay(): number {
72
+ return this.randomizeDelay
73
+ ? Math.random() * (this.delayV ?? 1000)
74
+ : this.delayV ?? 0;
158
75
  }
159
76
 
160
77
  getDelayFunction(): AnimationFunction {
161
- const delay = this.delayV;
162
- return delay
78
+ const isDelayProvided = this.randomizeDelay || this.delayV;
79
+ return isDelayProvided
163
80
  ? withDelay
164
81
  : (_, animation) => {
165
82
  'worklet';
@@ -167,55 +84,8 @@ export class BaseAnimationBuilder {
167
84
  };
168
85
  }
169
86
 
170
- getAnimationAndConfig(): LayoutAnimationAndConfig {
171
- const duration = this.durationV;
172
- const easing = this.easingV;
173
- const rotate = this.rotateV;
174
- const type = this.type ? this.type : (withTiming as AnimationFunction);
175
- const damping = this.dampingV;
176
- const mass = this.massV;
177
- const stiffness = this.stiffnessV;
178
- const overshootClamping = this.overshootClampingV;
179
- const restDisplacementThreshold = this.restDisplacementThresholdV;
180
- const restSpeedThreshold = this.restSpeedThresholdV;
181
-
182
- const animation = type;
183
-
184
- const config: BaseBuilderAnimationConfig = {};
185
-
186
- if (type === withTiming) {
187
- if (easing) {
188
- config.easing = easing;
189
- }
190
- if (duration) {
191
- config.duration = duration;
192
- }
193
- if (rotate) {
194
- config.rotate = rotate;
195
- }
196
- } else {
197
- if (damping) {
198
- config.damping = damping;
199
- }
200
- if (mass) {
201
- config.mass = mass;
202
- }
203
- if (stiffness) {
204
- config.stiffness = stiffness;
205
- }
206
- if (overshootClamping) {
207
- config.overshootClamping = overshootClamping;
208
- }
209
- if (restDisplacementThreshold) {
210
- config.restDisplacementThreshold = restDisplacementThreshold;
211
- }
212
- if (restSpeedThreshold) {
213
- config.restSpeedThreshold = restSpeedThreshold;
214
- }
215
- if (rotate) {
216
- config.rotate = rotate;
217
- }
218
- }
219
- return [animation, config];
87
+ static build(): EntryExitAnimationFunction | LayoutAnimationFunction {
88
+ const instance = this.createInstance();
89
+ return instance.build();
220
90
  }
221
91
  }