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
@@ -11,7 +11,7 @@ import {
11
11
  } from '../core';
12
12
  import updateProps, { updatePropsJestWrapper } from '../UpdateProps';
13
13
  import { initialUpdaterRun, Timestamp } from '../animation';
14
- import NativeReanimated from '../NativeReanimated';
14
+ import NativeReanimatedModule from '../NativeReanimated';
15
15
  import { useSharedValue } from './useSharedValue';
16
16
  import {
17
17
  buildWorkletsHash,
@@ -31,14 +31,13 @@ import {
31
31
  ViewRefSet,
32
32
  } from '../ViewDescriptorsSet';
33
33
  import { isJest, shouldBeUseWeb } from '../PlatformChecker';
34
- import { AnimationObject, PrimitiveValue } from '../animation/commonTypes';
34
+ import { AnimationObject } from '../animation/commonTypes';
35
35
  import {
36
36
  AdapterWorkletFunction,
37
37
  AnimatedStyle,
38
38
  BasicWorkletFunction,
39
39
  NestedObjectValues,
40
40
  SharedValue,
41
- WorkletFunction,
42
41
  } from '../commonTypes';
43
42
  export interface AnimatedStyleResult {
44
43
  viewDescriptors: ViewDescriptorsSet;
@@ -57,6 +56,7 @@ interface AnimatedState {
57
56
  interface AnimationRef {
58
57
  initial: {
59
58
  value: AnimatedStyle;
59
+ updater: () => AnimatedStyle;
60
60
  };
61
61
  remoteState: AnimatedState;
62
62
  sharableViewDescriptors: SharedValue<Descriptor[]>;
@@ -122,7 +122,7 @@ function prepareAnimation(
122
122
  function runAnimations(
123
123
  animation: AnimatedStyle,
124
124
  timestamp: Timestamp,
125
- key: PrimitiveValue,
125
+ key: number | string,
126
126
  result: AnimatedStyle,
127
127
  animationsActive: SharedValue<boolean>
128
128
  ): boolean {
@@ -270,7 +270,7 @@ function jestStyleUpdater(
270
270
  maybeViewRef: ViewRefSet<any> | undefined,
271
271
  animationsActive: SharedValue<boolean>,
272
272
  animatedStyle: MutableRefObject<AnimatedStyle>,
273
- adapters: WorkletFunction[] = []
273
+ adapters: AdapterWorkletFunction[] = []
274
274
  ): void {
275
275
  'worklet';
276
276
  const animations: AnimatedStyle = state.animations ?? {};
@@ -428,6 +428,7 @@ export function useAnimatedStyle<T extends AnimatedStyle>(
428
428
  initRef.current = {
429
429
  initial: {
430
430
  value: initialStyle,
431
+ updater: updater,
431
432
  },
432
433
  remoteState: makeRemote({ last: initialStyle }),
433
434
  sharableViewDescriptors: makeMutable([]),
@@ -441,9 +442,8 @@ export function useAnimatedStyle<T extends AnimatedStyle>(
441
442
 
442
443
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
443
444
  const { initial, remoteState, sharableViewDescriptors } = initRef.current!;
444
- const maybeViewRef = NativeReanimated.native ? undefined : viewsRef;
445
+ const maybeViewRef = NativeReanimatedModule.native ? undefined : viewsRef;
445
446
 
446
- initial.value = initialUpdaterRun(updater);
447
447
  useEffect(() => {
448
448
  let fun;
449
449
  let upadterFn = updater;
@@ -3,6 +3,7 @@ import { AnimationObject } from '../animation';
3
3
  import { processColor } from '../Colors';
4
4
  import {
5
5
  AnimatedStyle,
6
+ NativeEvent,
6
7
  NestedObjectValues,
7
8
  StyleProps,
8
9
  WorkletFunction,
@@ -31,12 +32,12 @@ export interface UseHandlerContext<TContext extends Context> {
31
32
  useWeb: boolean;
32
33
  }
33
34
 
34
- export function useEvent<T>(
35
+ export function useEvent<T extends NativeEvent<T>>(
35
36
  handler: (event: T) => void,
36
37
  eventNames: string[] = [],
37
38
  rebuild = false
38
- ): MutableRefObject<WorkletEventHandler | null> {
39
- const initRef = useRef<WorkletEventHandler | null>(null);
39
+ ): MutableRefObject<WorkletEventHandler<T> | null> {
40
+ const initRef = useRef<WorkletEventHandler<T> | null>(null);
40
41
  if (initRef.current === null) {
41
42
  initRef.current = new WorkletEventHandler(handler, eventNames);
42
43
  } else if (rebuild) {
@@ -7,3 +7,4 @@ export * from './NativeMethods';
7
7
  export * from './Colors';
8
8
  export * from './PropAdapters';
9
9
  export * from './layoutReanimation';
10
+ export * from './utils';
@@ -1,149 +1,216 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
- // @ts-nocheck
3
- import interpolateNode, {
4
- Extrapolate,
5
- } from '../reanimated1/derived/interpolate';
1
+ // @ts-ignore JS file
2
+ import interpolateNode from '../reanimated1/derived/interpolate';
6
3
 
7
- function getVal(config) {
4
+ export enum Extrapolation {
5
+ IDENTITY = 'identity',
6
+ CLAMP = 'clamp',
7
+ EXTEND = 'extend',
8
+ }
9
+
10
+ export interface InterpolatedNode {
11
+ __nodeId: number;
12
+ }
13
+
14
+ interface InterpolationNarrowedInput {
15
+ leftEdgeInput: number;
16
+ rightEdgeInput: number;
17
+ leftEdgeOutput: number;
18
+ rightEdgeOutput: number;
19
+ }
20
+
21
+ export interface ExtrapolationConfig {
22
+ extrapolateLeft?: Extrapolation | string;
23
+ extrapolateRight?: Extrapolation | string;
24
+ }
25
+
26
+ interface RequiredExtrapolationConfig {
27
+ extrapolateLeft: Extrapolation;
28
+ extrapolateRight: Extrapolation;
29
+ }
30
+
31
+ export type ExtrapolationType =
32
+ | ExtrapolationConfig
33
+ | Extrapolation
34
+ | string
35
+ | undefined;
36
+
37
+ function isNode(x: number | InterpolatedNode): x is InterpolatedNode {
8
38
  'worklet';
39
+ return (x as InterpolatedNode).__nodeId !== undefined;
40
+ }
9
41
 
10
- const { type, coef, val, ll, rr, x } = config;
42
+ function getVal(
43
+ type: Extrapolation,
44
+ coef: number,
45
+ val: number,
46
+ leftEdgeOutput: number,
47
+ rightEdgeOutput: number,
48
+ x: number
49
+ ): number {
50
+ 'worklet';
11
51
 
12
52
  switch (type) {
13
- case Extrapolate.IDENTITY:
53
+ case Extrapolation.IDENTITY:
14
54
  return x;
15
- case Extrapolate.CLAMP:
16
- if (coef * val < coef * ll) {
17
- return ll;
55
+ case Extrapolation.CLAMP:
56
+ if (coef * val < coef * leftEdgeOutput) {
57
+ return leftEdgeOutput;
18
58
  }
19
- return rr;
20
- case Extrapolate.EXTEND:
59
+ return rightEdgeOutput;
60
+ case Extrapolation.EXTEND:
21
61
  default:
22
62
  return val;
23
63
  }
24
64
  }
25
65
 
26
- function isExtrapolate(value) {
66
+ function isExtrapolate(value: string): value is Extrapolation {
27
67
  'worklet';
28
68
 
29
69
  return (
30
- value === Extrapolate.EXTEND ||
31
- value === Extrapolate.CLAMP ||
32
- value === Extrapolate.IDENTITY
70
+ value === Extrapolation.EXTEND ||
71
+ value === Extrapolation.CLAMP ||
72
+ value === Extrapolation.IDENTITY
33
73
  );
34
74
  }
35
75
 
36
- function validateType(type) {
76
+ // validates extrapolations type
77
+ // if type is correct, converts it to ExtrapolationConfig
78
+ function validateType(type: ExtrapolationType): RequiredExtrapolationConfig {
37
79
  'worklet';
38
-
39
- const EXTRAPOLATE_ERROR_MSG = `Reanimated: config object is not valid, please provide valid config, for example:
40
- interpolate(value, [inputRange], [outputRange], {
41
- extrapolateLeft: 'clamp',
42
- extrapolateRight: 'extend',
43
- })`;
44
-
45
- const EXTRAPOLATE_ERROR = (
46
- extrapolate
47
- ) => `Reanimated: not supported value for "${extrapolate}" \nSupported values: ["extend", "clamp", "identity"]\n Valid example:
48
- interpolate(value, [inputRange], [outputRange], {
49
- ${extrapolate}: 'clamp',
50
- })`;
51
-
52
- type = type ?? 'extend';
53
-
54
- // eslint-disable-next-line no-prototype-builtins
55
- const hasExtrapolateLeft = type.hasOwnProperty('extrapolateLeft');
56
- // eslint-disable-next-line no-prototype-builtins
57
- const hasExtrapolateRight = type.hasOwnProperty('extrapolateRight');
58
-
59
- if (
60
- typeof type === 'object' &&
61
- ((Object.keys(type).length === 2 &&
62
- !(hasExtrapolateLeft && hasExtrapolateRight)) ||
63
- (Object.keys(type).length === 1 &&
64
- !(hasExtrapolateLeft || hasExtrapolateRight)) ||
65
- Object.keys(type).length > 2)
66
- ) {
67
- throw new Error(EXTRAPOLATE_ERROR_MSG);
80
+ // initialize extrapolationConfig with default extrapolation
81
+ const extrapolationConfig: RequiredExtrapolationConfig = {
82
+ extrapolateLeft: Extrapolation.EXTEND,
83
+ extrapolateRight: Extrapolation.EXTEND,
84
+ };
85
+
86
+ if (!type) {
87
+ return extrapolationConfig;
68
88
  }
69
89
 
70
- if (typeof type === 'object') {
71
- if (hasExtrapolateLeft && !isExtrapolate(type.extrapolateLeft)) {
72
- throw new Error(EXTRAPOLATE_ERROR('extrapolateLeft'));
73
- }
74
-
75
- if (hasExtrapolateRight && !isExtrapolate(type.extrapolateRight)) {
76
- throw new Error(EXTRAPOLATE_ERROR('extrapolateRight'));
90
+ if (typeof type === 'string') {
91
+ if (!isExtrapolate(type)) {
92
+ throw new Error(
93
+ `Reanimated: not supported value for "interpolate" \nSupported values: ["extend", "clamp", "identity", Extrapolatation.CLAMP, Extrapolatation.EXTEND, Extrapolatation.IDENTITY]\n Valid example:
94
+ interpolate(value, [inputRange], [outputRange], "clamp")`
95
+ );
77
96
  }
97
+ extrapolationConfig.extrapolateLeft = type;
98
+ extrapolationConfig.extrapolateRight = type;
99
+ return extrapolationConfig;
78
100
  }
79
101
 
80
- if (typeof type === 'string' && !isExtrapolate(type)) {
102
+ // otherwise type is extrapolation config object
103
+ if (
104
+ (type.extrapolateLeft && !isExtrapolate(type.extrapolateLeft)) ||
105
+ (type.extrapolateRight && !isExtrapolate(type.extrapolateRight))
106
+ ) {
81
107
  throw new Error(
82
- `Reanimated: not supported value for "interpolate" \nSupported values: ["extend", "clamp", "identity"]\n Valid example:
83
- interpolate(value, [inputRange], [outputRange], "clamp")`
108
+ `Reanimated: not supported value for "interpolate" \nSupported values: ["extend", "clamp", "identity", Extrapolatation.CLAMP, Extrapolatation.EXTEND, Extrapolatation.IDENTITY]\n Valid example:
109
+ interpolate(value, [inputRange], [outputRange], {
110
+ extrapolateLeft: Extrapolation.CLAMP,
111
+ extrapolateRight: Extrapolation.IDENTITY
112
+ }})`
84
113
  );
85
114
  }
115
+
116
+ Object.assign(extrapolationConfig, type);
117
+ return extrapolationConfig;
86
118
  }
87
119
 
88
- // TODO: support default values in worklets:
89
- // e.g. function interpolate(x, input, output, type = Extrapolate.CLAMP)
90
- function internalInterpolate(x, l, r, ll, rr, type) {
120
+ function internalInterpolate(
121
+ x: number,
122
+ narrowedInput: InterpolationNarrowedInput,
123
+ extrapolationConfig: RequiredExtrapolationConfig
124
+ ) {
91
125
  'worklet';
92
- if (r - l === 0) return ll;
93
- const progress = (x - l) / (r - l);
94
- const val = ll + progress * (rr - ll);
95
- const coef = rr >= ll ? 1 : -1;
96
-
97
- const config = { type, coef, val, ll, rr, x };
98
-
99
- if (global.__DEV__) {
100
- validateType(type);
101
- }
102
-
103
- if (typeof type === 'object') {
104
- if (coef * val < coef * ll) {
105
- return getVal(Object.assign(config, { type: type.extrapolateLeft }));
106
- } else if (coef * val > coef * ll) {
107
- return getVal(Object.assign(config, { type: type.extrapolateRight }));
108
- }
109
- }
110
-
111
- if (coef * val < coef * ll || coef * val > coef * rr) {
112
- return getVal(config);
126
+ const {
127
+ leftEdgeInput,
128
+ rightEdgeInput,
129
+ leftEdgeOutput,
130
+ rightEdgeOutput,
131
+ } = narrowedInput;
132
+ if (rightEdgeInput - leftEdgeInput === 0) return leftEdgeOutput;
133
+ const progress = (x - leftEdgeInput) / (rightEdgeInput - leftEdgeInput);
134
+ const val = leftEdgeOutput + progress * (rightEdgeOutput - leftEdgeOutput);
135
+ const coef = rightEdgeOutput >= leftEdgeOutput ? 1 : -1;
136
+
137
+ if (coef * val < coef * leftEdgeOutput) {
138
+ return getVal(
139
+ extrapolationConfig.extrapolateLeft,
140
+ coef,
141
+ val,
142
+ leftEdgeOutput,
143
+ rightEdgeOutput,
144
+ x
145
+ );
146
+ } else if (coef * val > coef * rightEdgeOutput) {
147
+ return getVal(
148
+ extrapolationConfig.extrapolateRight,
149
+ coef,
150
+ val,
151
+ leftEdgeOutput,
152
+ rightEdgeOutput,
153
+ x
154
+ );
113
155
  }
114
156
 
115
157
  return val;
116
158
  }
117
159
 
118
- export function interpolate(x, input, output, type) {
160
+ // TODO: support default values in worklets:
161
+ // e.g. function interpolate(x, input, output, type = Extrapolatation.CLAMP)
162
+ export function interpolate(
163
+ x: number | InterpolatedNode,
164
+ input: readonly number[],
165
+ output: readonly number[],
166
+ type?: ExtrapolationType
167
+ ): number {
119
168
  'worklet';
120
- if (x && x.__nodeID) {
169
+ if (input.length < 2 || output.length < 2) {
170
+ throw Error(
171
+ 'Interpolation input and output should contain at least two values.'
172
+ );
173
+ }
174
+
175
+ const extrapolationConfig = validateType(type);
176
+
177
+ if (isNode(x)) {
121
178
  console.warn(
122
179
  `interpolate() was renamed to interpolateNode() in Reanimated 2. Please use interpolateNode() instead`
123
180
  );
124
- // we can't use rest parameters in worklets at the moment
125
- // eslint-disable-next-line prefer-spread, prefer-rest-params
126
- return interpolateNode.apply(undefined, arguments);
181
+ return interpolateNode(x, {
182
+ inputRange: input,
183
+ outputRange: output,
184
+ extrapolateLeft: extrapolationConfig.extrapolateLeft,
185
+ extrapolateRight: extrapolationConfig.extrapolateRight,
186
+ });
127
187
  }
128
188
 
129
189
  const length = input.length;
130
- let narrowedInput = [];
131
- if (x < input[0]) {
132
- narrowedInput = [input[0], input[1], output[0], output[1]];
133
- } else if (x > input[length - 1]) {
134
- narrowedInput = [
135
- input[length - 2],
136
- input[length - 1],
137
- output[length - 2],
138
- output[length - 1],
139
- ];
140
- } else {
141
- for (let i = 1; i < length; ++i) {
142
- if (x <= input[i]) {
143
- narrowedInput = [input[i - 1], input[i], output[i - 1], output[i]];
144
- break;
190
+ const narrowedInput: InterpolationNarrowedInput = {
191
+ leftEdgeInput: input[0],
192
+ rightEdgeInput: input[1],
193
+ leftEdgeOutput: output[0],
194
+ rightEdgeOutput: output[1],
195
+ };
196
+ if (length > 2) {
197
+ if (x > input[length - 1]) {
198
+ narrowedInput.leftEdgeInput = input[length - 2];
199
+ narrowedInput.rightEdgeInput = input[length - 1];
200
+ narrowedInput.leftEdgeOutput = output[length - 2];
201
+ narrowedInput.rightEdgeOutput = output[length - 1];
202
+ } else {
203
+ for (let i = 1; i < length; ++i) {
204
+ if (x <= input[i]) {
205
+ narrowedInput.leftEdgeInput = input[i - 1];
206
+ narrowedInput.rightEdgeInput = input[i];
207
+ narrowedInput.leftEdgeOutput = output[i - 1];
208
+ narrowedInput.rightEdgeOutput = output[i];
209
+ break;
210
+ }
145
211
  }
146
212
  }
147
213
  }
148
- return internalInterpolate.apply({}, [x].concat(narrowedInput).concat(type));
214
+
215
+ return internalInterpolate(x, narrowedInput, extrapolationConfig);
149
216
  }
@@ -1,35 +1,37 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
- // @ts-nocheck
3
1
  import MapperRegistry from './MapperRegistry';
4
2
  import MutableValue from './MutableValue';
5
3
  import Mapper from './Mapper';
4
+ import { NativeReanimated } from '../NativeReanimated/NativeReanimated';
5
+ import { Timestamp } from '../animation/commonTypes';
6
+ import { NestedObjectValues } from '../commonTypes';
7
+
8
+ export default class JSReanimated extends NativeReanimated {
9
+ _valueSetter?: <T>(value: T) => void = undefined;
6
10
 
7
- export default class JSReanimated {
8
- native = false;
9
- _valueSetter = undefined;
10
11
  _renderRequested = false;
11
12
  _mapperRegistry = new MapperRegistry(this);
12
- _frames = [];
13
- timeProvider = {};
13
+ _frames: ((timestamp: Timestamp) => void)[] = [];
14
+ timeProvider: { now: () => number };
14
15
 
15
16
  constructor() {
17
+ super(false);
16
18
  if (process.env.JEST_WORKER_ID) {
17
- this.timeProvider.now = () => Date.now();
19
+ this.timeProvider = { now: () => Date.now() };
18
20
  } else {
19
- this.timeProvider.now = () => window.performance.now();
21
+ this.timeProvider = { now: () => window.performance.now() };
20
22
  }
21
23
  }
22
24
 
23
- pushFrame(frame) {
25
+ pushFrame(frame: (timestamp: Timestamp) => void): void {
24
26
  this._frames.push(frame);
25
27
  this.maybeRequestRender();
26
28
  }
27
29
 
28
- getTimestamp() {
30
+ getTimestamp(): number {
29
31
  return this.timeProvider.now();
30
32
  }
31
33
 
32
- maybeRequestRender() {
34
+ maybeRequestRender(): void {
33
35
  if (!this._renderRequested) {
34
36
  this._renderRequested = true;
35
37
 
@@ -41,7 +43,7 @@ export default class JSReanimated {
41
43
  }
42
44
  }
43
45
 
44
- _onRender(timestampMs) {
46
+ _onRender(timestampMs: number): void {
45
47
  this._mapperRegistry.execute();
46
48
 
47
49
  const frames = [...this._frames];
@@ -56,38 +58,50 @@ export default class JSReanimated {
56
58
  }
57
59
  }
58
60
 
59
- installCoreFunctions(valueSetter) {
61
+ installCoreFunctions(valueSetter: <T>(value: T) => void): void {
60
62
  this._valueSetter = valueSetter;
61
63
  }
62
64
 
63
- makeShareable(value) {
65
+ makeShareable<T>(value: T): T {
64
66
  return value;
65
67
  }
66
68
 
67
- makeMutable(value) {
68
- return new MutableValue(value, this._valueSetter);
69
+ makeMutable<T>(value: T): MutableValue<T> {
70
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
71
+ return new MutableValue(value, this._valueSetter!);
69
72
  }
70
73
 
71
- makeRemote(object) {
72
- return object;
74
+ makeRemote<T>(object = {}): T {
75
+ return object as T;
73
76
  }
74
77
 
75
- startMapper(mapper, inputs = [], outputs = []) {
78
+ startMapper(
79
+ mapper: () => void,
80
+ inputs: NestedObjectValues<MutableValue<unknown>>[] = [],
81
+ outputs: NestedObjectValues<MutableValue<unknown>>[] = []
82
+ ): number {
76
83
  const instance = new Mapper(this, mapper, inputs, outputs);
77
84
  const mapperId = this._mapperRegistry.startMapper(instance);
78
85
  this.maybeRequestRender();
79
86
  return mapperId;
80
87
  }
81
88
 
82
- stopMapper(mapperId) {
89
+ stopMapper(mapperId: number): void {
83
90
  this._mapperRegistry.stopMapper(mapperId);
84
91
  }
85
92
 
86
- registerEventHandler(_eventHash, _eventHandler) {
93
+ registerEventHandler<T>(_: string, __: (event: T) => void): string {
87
94
  // noop
95
+ return '';
88
96
  }
89
97
 
90
- unregisterEventHandler(_registrationId) {
98
+ unregisterEventHandler(_: string): void {
91
99
  // noop
92
100
  }
101
+
102
+ enableLayoutAnimations() {
103
+ console.warn(
104
+ '[Reanimated] enableLayoutAnimations is not available for WEB yet'
105
+ );
106
+ }
93
107
  }
@@ -1,13 +1,22 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
- // @ts-nocheck
1
+ import { NestedObjectValues } from '../commonTypes';
2
+ import JSReanimated from './JSReanimated';
3
3
  import MutableValue from './MutableValue';
4
4
 
5
- export default class Mapper {
5
+ export default class Mapper<T> {
6
6
  static MAPPER_ID = 1;
7
+ id: number;
8
+ inputs: MutableValue<T>[];
9
+ outputs: MutableValue<T>[];
10
+ mapper: () => void;
7
11
 
8
12
  dirty = true;
9
13
 
10
- constructor(module, mapper, inputs = [], outputs = []) {
14
+ constructor(
15
+ module: JSReanimated,
16
+ mapper: () => void,
17
+ inputs: NestedObjectValues<MutableValue<T>>[] = [],
18
+ outputs: NestedObjectValues<MutableValue<T>>[] = []
19
+ ) {
11
20
  this.id = Mapper.MAPPER_ID++;
12
21
  this.inputs = this.extractMutablesFromArray(inputs);
13
22
  this.outputs = this.extractMutablesFromArray(outputs);
@@ -23,16 +32,20 @@ export default class Mapper {
23
32
  });
24
33
  }
25
34
 
26
- execute() {
35
+ execute(): void {
27
36
  this.dirty = false;
28
37
  this.mapper();
29
38
  }
30
39
 
31
- extractMutablesFromArray(array) {
32
- const res = [];
40
+ extractMutablesFromArray<T>(
41
+ array: NestedObjectValues<MutableValue<T>>
42
+ ): MutableValue<T>[] {
43
+ const res: MutableValue<T>[] = [];
33
44
 
34
- function extractMutables(value) {
35
- if (value instanceof MutableValue) {
45
+ function extractMutables(value: NestedObjectValues<MutableValue<T>>) {
46
+ if (value == null) {
47
+ // return;
48
+ } else if (value instanceof MutableValue) {
36
49
  res.push(value);
37
50
  } else if (Array.isArray(value)) {
38
51
  value.forEach((v) => extractMutables(v));