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,23 +1,29 @@
1
- /* global _WORKLET _measure _scrollTo */
1
+ /* global _WORKLET _measure _scrollTo _setGestureState */
2
2
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
3
  // @ts-nocheck
4
+ import { Component } from 'react';
4
5
  import { findNodeHandle } from 'react-native';
6
+ import { RefObjectFunction } from './hook/useAnimatedRef';
5
7
  import { isChromeDebugger } from './PlatformChecker';
6
8
 
7
- export function getTag(view) {
9
+ export function getTag(
10
+ view: null | number | React.Component<any, any> | React.ComponentClass<any>
11
+ ): null | number {
8
12
  return findNodeHandle(view);
9
13
  }
10
14
 
11
- /**
12
- * fields that can be accessed:
13
- * x
14
- * y
15
- * width
16
- * height
17
- * pageX
18
- * pageY
19
- */
20
- export function measure(animatedRef) {
15
+ export interface MeasuredDimensions {
16
+ x: number;
17
+ y: number;
18
+ width: number;
19
+ height: number;
20
+ pageX: number;
21
+ pageY: number;
22
+ }
23
+
24
+ export function measure(
25
+ animatedRef: RefObjectFunction<Component>
26
+ ): MeasuredDimensions {
21
27
  'worklet';
22
28
  if (!_WORKLET && !isChromeDebugger()) {
23
29
  throw new Error('(measure) method cannot be used on RN side!');
@@ -30,7 +36,12 @@ export function measure(animatedRef) {
30
36
  return result;
31
37
  }
32
38
 
33
- export function scrollTo(animatedRef, x, y, animated) {
39
+ export function scrollTo(
40
+ animatedRef: RefObjectFunction<Component>,
41
+ x: number,
42
+ y: number,
43
+ animated: boolean
44
+ ): void {
34
45
  'worklet';
35
46
  if (!_WORKLET && !isChromeDebugger()) {
36
47
  return;
@@ -38,3 +49,13 @@ export function scrollTo(animatedRef, x, y, animated) {
38
49
  const viewTag = animatedRef();
39
50
  _scrollTo(viewTag, x, y, animated);
40
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
+ }
@@ -0,0 +1,72 @@
1
+ import { SharedValue } from '../commonTypes';
2
+ import { Descriptor } from '../hook/commonTypes';
3
+
4
+ const InnerNativeModule = global.__reanimatedModuleProxy;
5
+ export class NativeReanimated {
6
+ native: boolean;
7
+ useOnlyV1: boolean;
8
+
9
+ constructor(native = true) {
10
+ this.native = native;
11
+ this.useOnlyV1 = InnerNativeModule === null;
12
+ }
13
+
14
+ installCoreFunctions(valueSetter: <T>(value: T) => void): void {
15
+ return InnerNativeModule.installCoreFunctions(valueSetter);
16
+ }
17
+
18
+ makeShareable<T>(value: T): T {
19
+ return InnerNativeModule.makeShareable(value);
20
+ }
21
+
22
+ makeMutable<T>(value: T): SharedValue<T> {
23
+ return InnerNativeModule.makeMutable(value);
24
+ }
25
+
26
+ makeRemote<T>(object = {}): T {
27
+ return InnerNativeModule.makeRemote(object);
28
+ }
29
+
30
+ startMapper(
31
+ mapper: () => void,
32
+ inputs: any[] = [],
33
+ outputs: any[] = [],
34
+ updater: () => void,
35
+ viewDescriptors: Descriptor[] | SharedValue<Descriptor[]>
36
+ ): number {
37
+ return InnerNativeModule.startMapper(
38
+ mapper,
39
+ inputs,
40
+ outputs,
41
+ updater,
42
+ viewDescriptors
43
+ );
44
+ }
45
+
46
+ stopMapper(mapperId: number): void {
47
+ return InnerNativeModule.stopMapper(mapperId);
48
+ }
49
+
50
+ registerEventHandler<T>(
51
+ eventHash: string,
52
+ eventHandler: (event: T) => void
53
+ ): string {
54
+ return InnerNativeModule.registerEventHandler(eventHash, eventHandler);
55
+ }
56
+
57
+ unregisterEventHandler(id: string): void {
58
+ return InnerNativeModule.unregisterEventHandler(id);
59
+ }
60
+
61
+ getViewProp<T>(
62
+ viewTag: string,
63
+ propName: string,
64
+ callback?: (result: T) => void
65
+ ): Promise<T> {
66
+ return InnerNativeModule.getViewProp(viewTag, propName, callback);
67
+ }
68
+
69
+ enableLayoutAnimations(flag: boolean): void {
70
+ InnerNativeModule.enableLayoutAnimations(flag);
71
+ }
72
+ }
@@ -0,0 +1,18 @@
1
+ import reanimatedJS from '../js-reanimated';
2
+ import { nativeShouldBeMock } from '../PlatformChecker';
3
+ import { Platform } from 'react-native';
4
+ import { NativeReanimated } from './NativeReanimated';
5
+
6
+ let exportedModule;
7
+ if (nativeShouldBeMock()) {
8
+ exportedModule = reanimatedJS;
9
+ } else {
10
+ exportedModule = new NativeReanimated();
11
+ if (exportedModule.useOnlyV1 && Platform.OS === 'android') {
12
+ console.warn(
13
+ `If you want to use Reanimated 2 then go through our installation steps https://docs.swmansion.com/react-native-reanimated/docs/installation`
14
+ );
15
+ }
16
+ }
17
+
18
+ export default exportedModule as NativeReanimated;
@@ -1,4 +1,3 @@
1
- // @ts-ignore JS file
2
1
  import { addWhitelistedNativeProps } from '../ConfigHelper';
3
2
  import { AdapterWorkletFunction } from './commonTypes';
4
3
 
@@ -1,10 +1,12 @@
1
1
  /* global _updateProps */
2
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
- // @ts-nocheck
2
+ import { MutableRefObject } from 'react';
4
3
  import { processColor } from './Colors';
4
+ import { AnimatedStyle, SharedValue, StyleProps } from './commonTypes';
5
5
  import { makeShareable, isConfigured } from './core';
6
+ import { Descriptor } from './hook/commonTypes';
6
7
  import { _updatePropsJS } from './js-reanimated';
7
8
  import { shouldBeUseWeb } from './PlatformChecker';
9
+ import { ViewRefSet } from './ViewDescriptorsSet';
8
10
 
9
11
  // copied from react-native/Libraries/Components/View/ReactNativeStyleAttributes
10
12
  export const colorProps = [
@@ -24,18 +26,28 @@ export const colorProps = [
24
26
  'overlayColor',
25
27
  ];
26
28
 
27
- const ColorProperties = !isConfigured() ? [] : makeShareable(colorProps);
29
+ export const ColorProperties = !isConfigured() ? [] : makeShareable(colorProps);
28
30
 
29
31
  let updatePropsByPlatform;
30
32
  if (shouldBeUseWeb()) {
31
- updatePropsByPlatform = (_, updates, maybeViewRef) => {
33
+ updatePropsByPlatform = (
34
+ _: SharedValue<Descriptor[]>,
35
+ updates: StyleProps | AnimatedStyle,
36
+ maybeViewRef: ViewRefSet<any> | undefined
37
+ ): void => {
32
38
  'worklet';
33
- maybeViewRef.items.forEach((item, _) => {
34
- _updatePropsJS(updates, item);
35
- });
39
+ if (maybeViewRef) {
40
+ maybeViewRef.items.forEach((item, _) => {
41
+ _updatePropsJS(updates, item);
42
+ });
43
+ }
36
44
  };
37
45
  } else {
38
- updatePropsByPlatform = (viewDescriptors, updates, _) => {
46
+ updatePropsByPlatform = (
47
+ viewDescriptors: SharedValue<Descriptor[]>,
48
+ updates: StyleProps | AnimatedStyle,
49
+ _: ViewRefSet<any> | undefined
50
+ ): void => {
39
51
  'worklet';
40
52
 
41
53
  for (const key in updates) {
@@ -54,15 +66,19 @@ if (shouldBeUseWeb()) {
54
66
  };
55
67
  }
56
68
 
57
- export const updateProps = updatePropsByPlatform;
69
+ export const updateProps: (
70
+ viewDescriptor: SharedValue<Descriptor[]>,
71
+ updates: StyleProps | AnimatedStyle,
72
+ maybeViewRef: ViewRefSet<any> | undefined
73
+ ) => void = updatePropsByPlatform;
58
74
 
59
75
  export const updatePropsJestWrapper = (
60
- viewDescriptors,
61
- updates,
62
- maybeViewRef,
63
- animatedStyle,
64
- adapters
65
- ) => {
76
+ viewDescriptors: SharedValue<Descriptor[]>,
77
+ updates: AnimatedStyle,
78
+ maybeViewRef: ViewRefSet<any> | undefined,
79
+ animatedStyle: MutableRefObject<AnimatedStyle>,
80
+ adapters: ((updates: AnimatedStyle) => void)[]
81
+ ): void => {
66
82
  adapters.forEach((adapter) => {
67
83
  adapter(updates);
68
84
  });
@@ -1,8 +1,8 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
- // @ts-nocheck
3
1
  import { useRef } from 'react';
4
2
  import { makeMutable } from './core';
5
- import { SharedValue } from './hook/commonTypes';
3
+ import { SharedValue } from './commonTypes';
4
+ import { Descriptor } from './hook/commonTypes';
5
+ import { Platform } from 'react-native';
6
6
 
7
7
  export interface ViewRefSet<T> {
8
8
  items: Set<T>;
@@ -24,10 +24,13 @@ export interface ViewDescriptorsSet {
24
24
  ) => void;
25
25
  }
26
26
 
27
+ const scheduleUpdates =
28
+ Platform.OS === 'web' ? requestAnimationFrame : setImmediate;
29
+
27
30
  export function makeViewDescriptorsSet(): ViewDescriptorsSet {
28
- const ref = useRef(null);
31
+ const ref = useRef<ViewDescriptorsSet | null>(null);
29
32
  if (ref.current === null) {
30
- const data = {
33
+ const data: ViewDescriptorsSet = {
31
34
  batchToRemove: new Set(),
32
35
  tags: new Set(),
33
36
  waitForInsertSync: false,
@@ -45,7 +48,7 @@ export function makeViewDescriptorsSet(): ViewDescriptorsSet {
45
48
  if (!data.waitForInsertSync) {
46
49
  data.waitForInsertSync = true;
47
50
 
48
- setImmediate(() => {
51
+ scheduleUpdates(() => {
49
52
  data.sharableViewDescriptors.value = data.items;
50
53
  data.waitForInsertSync = false;
51
54
  });
@@ -58,7 +61,7 @@ export function makeViewDescriptorsSet(): ViewDescriptorsSet {
58
61
  if (!data.waitForRemoveSync) {
59
62
  data.waitForRemoveSync = true;
60
63
 
61
- setImmediate(() => {
64
+ scheduleUpdates(() => {
62
65
  const items = [];
63
66
  for (const item of data.items) {
64
67
  if (data.batchToRemove.has(item.tag)) {
@@ -87,18 +90,18 @@ export function makeViewDescriptorsSet(): ViewDescriptorsSet {
87
90
  return ref.current;
88
91
  }
89
92
 
90
- export function makeViewsRefSet(): ViewRefSet {
91
- const ref = useRef(null);
93
+ export function makeViewsRefSet<T>(): ViewRefSet<T> {
94
+ const ref = useRef<ViewRefSet<T> | null>(null);
92
95
  if (ref.current === null) {
93
- const data = {
96
+ const data: ViewRefSet<T> = {
94
97
  items: new Set(),
95
98
 
96
- add: (item) => {
99
+ add: (item: T) => {
97
100
  if (data.items.has(item)) return;
98
101
  data.items.add(item);
99
102
  },
100
103
 
101
- remove: (item) => {
104
+ remove: (item: T) => {
102
105
  data.items.delete(item);
103
106
  },
104
107
  };
@@ -1,38 +1,57 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
- // @ts-nocheck
3
- import NativeModule from './NativeReanimated';
1
+ import { NativeEvent } from './commonTypes';
2
+ import NativeReanimatedModule from './NativeReanimated';
4
3
 
5
- const jsListener = (eventName, handler) => (evt) => {
6
- handler({ ...evt.nativeEvent, eventName });
7
- };
4
+ function jsListener<T extends NativeEvent<T>>(
5
+ eventName: string,
6
+ handler: (event: T) => void
7
+ ) {
8
+ return (evt: T) => {
9
+ handler({ ...evt.nativeEvent, eventName });
10
+ };
11
+ }
8
12
 
9
- export default class WorkletEventHandler {
10
- constructor(worklet, eventNames: string[] = []) {
13
+ export default class WorkletEventHandler<T extends NativeEvent<T>> {
14
+ worklet: (event: T) => void;
15
+ eventNames: string[];
16
+ reattachNeeded: boolean;
17
+ listeners: Record<string, (event: T) => void>;
18
+ viewTag: number | undefined;
19
+ registrations: string[];
20
+ constructor(worklet: (event: T) => void, eventNames: string[] = []) {
11
21
  this.worklet = worklet;
12
22
  this.eventNames = eventNames;
13
23
  this.reattachNeeded = false;
24
+ this.listeners = {};
25
+ this.viewTag = undefined;
26
+ this.registrations = [];
14
27
 
15
- if (!NativeModule.native) {
16
- this.listeners = eventNames.reduce((acc, eventName) => {
17
- acc[eventName] = jsListener(eventName, worklet);
18
- return acc;
19
- }, {});
28
+ if (!NativeReanimatedModule.native) {
29
+ this.listeners = eventNames.reduce(
30
+ (acc: Record<string, (event: T) => void>, eventName: string) => {
31
+ acc[eventName] = jsListener(eventName, worklet);
32
+ return acc;
33
+ },
34
+ {}
35
+ );
20
36
  }
21
37
  }
22
38
 
23
- updateWorklet(newWorklet) {
39
+ updateWorklet(newWorklet: (event: T) => void): void {
24
40
  this.worklet = newWorklet;
25
41
  this.reattachNeeded = true;
26
42
  }
27
43
 
28
- registerForEvents(viewTag, fallbackEventName = undefined) {
44
+ registerForEvents(viewTag: number, fallbackEventName?: string): void {
29
45
  this.viewTag = viewTag;
30
46
  this.registrations = this.eventNames.map((eventName) =>
31
- NativeModule.registerEventHandler(viewTag + eventName, this.worklet)
47
+ NativeReanimatedModule.registerEventHandler(
48
+ viewTag + eventName,
49
+ this.worklet
50
+ )
32
51
  );
33
52
  if (this.registrations.length === 0 && fallbackEventName) {
34
53
  this.registrations.push(
35
- NativeModule.registerEventHandler(
54
+ NativeReanimatedModule.registerEventHandler(
36
55
  viewTag + fallbackEventName,
37
56
  this.worklet
38
57
  )
@@ -40,11 +59,10 @@ export default class WorkletEventHandler {
40
59
  }
41
60
  }
42
61
 
43
- unregisterFromEvents() {
44
- this.registrations &&
45
- this.registrations.forEach((id) =>
46
- NativeModule.unregisterEventHandler(id)
47
- );
48
- this.registrations = undefined;
62
+ unregisterFromEvents(): void {
63
+ this.registrations.forEach((id) =>
64
+ NativeReanimatedModule.unregisterEventHandler(id)
65
+ );
66
+ this.registrations = [];
49
67
  }
50
68
  }
@@ -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(
@@ -44,7 +44,9 @@ export function withDelay(
44
44
  animation.current = nextAnimation.current;
45
45
  return finished;
46
46
  } else if (previousAnimation) {
47
- const finished = previousAnimation.onFrame(previousAnimation, now);
47
+ const finished =
48
+ previousAnimation.finished ||
49
+ previousAnimation.onFrame(previousAnimation, now);
48
50
  animation.current = previousAnimation.current;
49
51
  if (finished) {
50
52
  animation.previousAnimation = null;
@@ -55,14 +57,18 @@ export function withDelay(
55
57
 
56
58
  function onStart(
57
59
  animation: DelayAnimation,
58
- value: PrimitiveValue,
60
+ value: AnimatableValue,
59
61
  now: Timestamp,
60
62
  previousAnimation: DelayAnimation
61
63
  ): void {
62
64
  animation.startTime = now;
63
65
  animation.started = false;
64
66
  animation.current = value;
65
- animation.previousAnimation = previousAnimation;
67
+ if (previousAnimation === animation) {
68
+ animation.previousAnimation = previousAnimation.previousAnimation;
69
+ } else {
70
+ animation.previousAnimation = previousAnimation;
71
+ }
66
72
  }
67
73
 
68
74
  const callback = (finished?: boolean): 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;