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,119 +1,127 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
- // @ts-nocheck
3
- import interpolateNode, { Extrapolate, } from '../reanimated1/derived/interpolate';
4
- function getVal(config) {
1
+ // @ts-ignore JS file
2
+ import interpolateNode from '../reanimated1/derived/interpolate';
3
+ export var Extrapolation;
4
+ (function (Extrapolation) {
5
+ Extrapolation["IDENTITY"] = "identity";
6
+ Extrapolation["CLAMP"] = "clamp";
7
+ Extrapolation["EXTEND"] = "extend";
8
+ })(Extrapolation || (Extrapolation = {}));
9
+ function isNode(x) {
10
+ 'worklet';
11
+ return x.__nodeId !== undefined;
12
+ }
13
+ function getVal(type, coef, val, leftEdgeOutput, rightEdgeOutput, x) {
5
14
  'worklet';
6
- const { type, coef, val, ll, rr, x } = config;
7
15
  switch (type) {
8
- case Extrapolate.IDENTITY:
16
+ case Extrapolation.IDENTITY:
9
17
  return x;
10
- case Extrapolate.CLAMP:
11
- if (coef * val < coef * ll) {
12
- return ll;
18
+ case Extrapolation.CLAMP:
19
+ if (coef * val < coef * leftEdgeOutput) {
20
+ return leftEdgeOutput;
13
21
  }
14
- return rr;
15
- case Extrapolate.EXTEND:
22
+ return rightEdgeOutput;
23
+ case Extrapolation.EXTEND:
16
24
  default:
17
25
  return val;
18
26
  }
19
27
  }
20
28
  function isExtrapolate(value) {
21
29
  'worklet';
22
- return (value === Extrapolate.EXTEND ||
23
- value === Extrapolate.CLAMP ||
24
- value === Extrapolate.IDENTITY);
30
+ return (value === Extrapolation.EXTEND ||
31
+ value === Extrapolation.CLAMP ||
32
+ value === Extrapolation.IDENTITY);
25
33
  }
34
+ // validates extrapolations type
35
+ // if type is correct, converts it to ExtrapolationConfig
26
36
  function validateType(type) {
27
37
  'worklet';
28
- const EXTRAPOLATE_ERROR_MSG = `Reanimated: config object is not valid, please provide valid config, for example:
29
- interpolate(value, [inputRange], [outputRange], {
30
- extrapolateLeft: 'clamp',
31
- extrapolateRight: 'extend',
32
- })`;
33
- const EXTRAPOLATE_ERROR = (extrapolate) => `Reanimated: not supported value for "${extrapolate}" \nSupported values: ["extend", "clamp", "identity"]\n Valid example:
34
- interpolate(value, [inputRange], [outputRange], {
35
- ${extrapolate}: 'clamp',
36
- })`;
37
- type = type !== null && type !== void 0 ? type : 'extend';
38
- // eslint-disable-next-line no-prototype-builtins
39
- const hasExtrapolateLeft = type.hasOwnProperty('extrapolateLeft');
40
- // eslint-disable-next-line no-prototype-builtins
41
- const hasExtrapolateRight = type.hasOwnProperty('extrapolateRight');
42
- if (typeof type === 'object' &&
43
- ((Object.keys(type).length === 2 &&
44
- !(hasExtrapolateLeft && hasExtrapolateRight)) ||
45
- (Object.keys(type).length === 1 &&
46
- !(hasExtrapolateLeft || hasExtrapolateRight)) ||
47
- Object.keys(type).length > 2)) {
48
- throw new Error(EXTRAPOLATE_ERROR_MSG);
38
+ // initialize extrapolationConfig with default extrapolation
39
+ const extrapolationConfig = {
40
+ extrapolateLeft: Extrapolation.EXTEND,
41
+ extrapolateRight: Extrapolation.EXTEND,
42
+ };
43
+ if (!type) {
44
+ return extrapolationConfig;
49
45
  }
50
- if (typeof type === 'object') {
51
- if (hasExtrapolateLeft && !isExtrapolate(type.extrapolateLeft)) {
52
- throw new Error(EXTRAPOLATE_ERROR('extrapolateLeft'));
53
- }
54
- if (hasExtrapolateRight && !isExtrapolate(type.extrapolateRight)) {
55
- throw new Error(EXTRAPOLATE_ERROR('extrapolateRight'));
46
+ if (typeof type === 'string') {
47
+ if (!isExtrapolate(type)) {
48
+ throw new Error(`Reanimated: not supported value for "interpolate" \nSupported values: ["extend", "clamp", "identity", Extrapolatation.CLAMP, Extrapolatation.EXTEND, Extrapolatation.IDENTITY]\n Valid example:
49
+ interpolate(value, [inputRange], [outputRange], "clamp")`);
56
50
  }
51
+ extrapolationConfig.extrapolateLeft = type;
52
+ extrapolationConfig.extrapolateRight = type;
53
+ return extrapolationConfig;
57
54
  }
58
- if (typeof type === 'string' && !isExtrapolate(type)) {
59
- throw new Error(`Reanimated: not supported value for "interpolate" \nSupported values: ["extend", "clamp", "identity"]\n Valid example:
60
- interpolate(value, [inputRange], [outputRange], "clamp")`);
55
+ // otherwise type is extrapolation config object
56
+ if ((type.extrapolateLeft && !isExtrapolate(type.extrapolateLeft)) ||
57
+ (type.extrapolateRight && !isExtrapolate(type.extrapolateRight))) {
58
+ throw new Error(`Reanimated: not supported value for "interpolate" \nSupported values: ["extend", "clamp", "identity", Extrapolatation.CLAMP, Extrapolatation.EXTEND, Extrapolatation.IDENTITY]\n Valid example:
59
+ interpolate(value, [inputRange], [outputRange], {
60
+ extrapolateLeft: Extrapolation.CLAMP,
61
+ extrapolateRight: Extrapolation.IDENTITY
62
+ }})`);
61
63
  }
64
+ Object.assign(extrapolationConfig, type);
65
+ return extrapolationConfig;
62
66
  }
63
- // TODO: support default values in worklets:
64
- // e.g. function interpolate(x, input, output, type = Extrapolate.CLAMP)
65
- function internalInterpolate(x, l, r, ll, rr, type) {
67
+ function internalInterpolate(x, narrowedInput, extrapolationConfig) {
66
68
  'worklet';
67
- if (r - l === 0)
68
- return ll;
69
- const progress = (x - l) / (r - l);
70
- const val = ll + progress * (rr - ll);
71
- const coef = rr >= ll ? 1 : -1;
72
- const config = { type, coef, val, ll, rr, x };
73
- if (global.__DEV__) {
74
- validateType(type);
75
- }
76
- if (typeof type === 'object') {
77
- if (coef * val < coef * ll) {
78
- return getVal(Object.assign(config, { type: type.extrapolateLeft }));
79
- }
80
- else if (coef * val > coef * ll) {
81
- return getVal(Object.assign(config, { type: type.extrapolateRight }));
82
- }
69
+ const { leftEdgeInput, rightEdgeInput, leftEdgeOutput, rightEdgeOutput, } = narrowedInput;
70
+ if (rightEdgeInput - leftEdgeInput === 0)
71
+ return leftEdgeOutput;
72
+ const progress = (x - leftEdgeInput) / (rightEdgeInput - leftEdgeInput);
73
+ const val = leftEdgeOutput + progress * (rightEdgeOutput - leftEdgeOutput);
74
+ const coef = rightEdgeOutput >= leftEdgeOutput ? 1 : -1;
75
+ if (coef * val < coef * leftEdgeOutput) {
76
+ return getVal(extrapolationConfig.extrapolateLeft, coef, val, leftEdgeOutput, rightEdgeOutput, x);
83
77
  }
84
- if (coef * val < coef * ll || coef * val > coef * rr) {
85
- return getVal(config);
78
+ else if (coef * val > coef * rightEdgeOutput) {
79
+ return getVal(extrapolationConfig.extrapolateRight, coef, val, leftEdgeOutput, rightEdgeOutput, x);
86
80
  }
87
81
  return val;
88
82
  }
83
+ // TODO: support default values in worklets:
84
+ // e.g. function interpolate(x, input, output, type = Extrapolatation.CLAMP)
89
85
  export function interpolate(x, input, output, type) {
90
86
  'worklet';
91
- if (x && x.__nodeID) {
87
+ if (input.length < 2 || output.length < 2) {
88
+ throw Error('Interpolation input and output should contain at least two values.');
89
+ }
90
+ const extrapolationConfig = validateType(type);
91
+ if (isNode(x)) {
92
92
  console.warn(`interpolate() was renamed to interpolateNode() in Reanimated 2. Please use interpolateNode() instead`);
93
- // we can't use rest parameters in worklets at the moment
94
- // eslint-disable-next-line prefer-spread, prefer-rest-params
95
- return interpolateNode.apply(undefined, arguments);
93
+ return interpolateNode(x, {
94
+ inputRange: input,
95
+ outputRange: output,
96
+ extrapolateLeft: extrapolationConfig.extrapolateLeft,
97
+ extrapolateRight: extrapolationConfig.extrapolateRight,
98
+ });
96
99
  }
97
100
  const length = input.length;
98
- let narrowedInput = [];
99
- if (x < input[0]) {
100
- narrowedInput = [input[0], input[1], output[0], output[1]];
101
- }
102
- else if (x > input[length - 1]) {
103
- narrowedInput = [
104
- input[length - 2],
105
- input[length - 1],
106
- output[length - 2],
107
- output[length - 1],
108
- ];
109
- }
110
- else {
111
- for (let i = 1; i < length; ++i) {
112
- if (x <= input[i]) {
113
- narrowedInput = [input[i - 1], input[i], output[i - 1], output[i]];
114
- break;
101
+ const narrowedInput = {
102
+ leftEdgeInput: input[0],
103
+ rightEdgeInput: input[1],
104
+ leftEdgeOutput: output[0],
105
+ rightEdgeOutput: output[1],
106
+ };
107
+ if (length > 2) {
108
+ if (x > input[length - 1]) {
109
+ narrowedInput.leftEdgeInput = input[length - 2];
110
+ narrowedInput.rightEdgeInput = input[length - 1];
111
+ narrowedInput.leftEdgeOutput = output[length - 2];
112
+ narrowedInput.rightEdgeOutput = output[length - 1];
113
+ }
114
+ else {
115
+ for (let i = 1; i < length; ++i) {
116
+ if (x <= input[i]) {
117
+ narrowedInput.leftEdgeInput = input[i - 1];
118
+ narrowedInput.rightEdgeInput = input[i];
119
+ narrowedInput.leftEdgeOutput = output[i - 1];
120
+ narrowedInput.rightEdgeOutput = output[i];
121
+ break;
122
+ }
115
123
  }
116
124
  }
117
125
  }
118
- return internalInterpolate.apply({}, [x].concat(narrowedInput).concat(type));
126
+ return internalInterpolate(x, narrowedInput, extrapolationConfig);
119
127
  }
@@ -1,21 +1,19 @@
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';
6
- export default class JSReanimated {
4
+ import { NativeReanimated } from '../NativeReanimated/NativeReanimated';
5
+ export default class JSReanimated extends NativeReanimated {
7
6
  constructor() {
8
- this.native = false;
7
+ super(false);
9
8
  this._valueSetter = undefined;
10
9
  this._renderRequested = false;
11
10
  this._mapperRegistry = new MapperRegistry(this);
12
11
  this._frames = [];
13
- this.timeProvider = {};
14
12
  if (process.env.JEST_WORKER_ID) {
15
- this.timeProvider.now = () => Date.now();
13
+ this.timeProvider = { now: () => Date.now() };
16
14
  }
17
15
  else {
18
- this.timeProvider.now = () => window.performance.now();
16
+ this.timeProvider = { now: () => window.performance.now() };
19
17
  }
20
18
  }
21
19
  pushFrame(frame) {
@@ -52,9 +50,10 @@ export default class JSReanimated {
52
50
  return value;
53
51
  }
54
52
  makeMutable(value) {
53
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
55
54
  return new MutableValue(value, this._valueSetter);
56
55
  }
57
- makeRemote(object) {
56
+ makeRemote(object = {}) {
58
57
  return object;
59
58
  }
60
59
  startMapper(mapper, inputs = [], outputs = []) {
@@ -66,10 +65,14 @@ export default class JSReanimated {
66
65
  stopMapper(mapperId) {
67
66
  this._mapperRegistry.stopMapper(mapperId);
68
67
  }
69
- registerEventHandler(_eventHash, _eventHandler) {
68
+ registerEventHandler(_, __) {
70
69
  // noop
70
+ return '';
71
71
  }
72
- unregisterEventHandler(_registrationId) {
72
+ unregisterEventHandler(_) {
73
73
  // noop
74
74
  }
75
+ enableLayoutAnimations() {
76
+ console.warn('[Reanimated] enableLayoutAnimations is not available for WEB yet');
77
+ }
75
78
  }
@@ -1,5 +1,3 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
- // @ts-nocheck
3
1
  import MutableValue from './MutableValue';
4
2
  export default class Mapper {
5
3
  constructor(module, mapper, inputs = [], outputs = []) {
@@ -23,7 +21,10 @@ export default class Mapper {
23
21
  extractMutablesFromArray(array) {
24
22
  const res = [];
25
23
  function extractMutables(value) {
26
- if (value instanceof MutableValue) {
24
+ if (value == null) {
25
+ // return;
26
+ }
27
+ else if (value instanceof MutableValue) {
27
28
  res.push(value);
28
29
  }
29
30
  else if (Array.isArray(value)) {
@@ -1,5 +1,3 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
- // @ts-nocheck
3
1
  export default class MapperRegistry {
4
2
  constructor(module) {
5
3
  this.sortedMappers = [];
@@ -78,7 +76,8 @@ export default class MapperRegistry {
78
76
  while (nodes.length)
79
77
  dfs(nodes[0]);
80
78
  const postArray = Object.keys(post).map((key) => {
81
- return [key, post[key]];
79
+ const num = parseInt(key);
80
+ return [num, post[num]];
82
81
  });
83
82
  postArray.sort((a, b) => {
84
83
  return b[1] - a[1];
@@ -95,9 +94,7 @@ export default class MapperRegistry {
95
94
  }
96
95
  }
97
96
  class Node {
98
- constructor(mapper, _parents = [], children = []) {
99
- this.mapper = null;
100
- this.children = [];
97
+ constructor(mapper, children = []) {
101
98
  this.mapper = mapper;
102
99
  this.children = children;
103
100
  }
@@ -1,5 +1,3 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
- // @ts-nocheck
3
1
  export default class MutableValue {
4
2
  constructor(value, setter) {
5
3
  this._animation = null;
@@ -1,5 +1,3 @@
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';
5
3
  const reanimatedJS = new JSReanimated();
@@ -22,25 +20,29 @@ if (shouldBeUseWeb()) {
22
20
  global._scrollTo = () => {
23
21
  console.warn("[Reanimated] You can't use 'scrollTo' method with Chrome Debugger or with web version");
24
22
  };
23
+ global._setGestureState = () => {
24
+ console.warn("[Reanimated] You can't use 'setGestureState' method with Chrome Debugger or with web version");
25
+ };
25
26
  }
26
27
  export const _updatePropsJS = (updates, viewRef) => {
27
- if (viewRef === null || viewRef === void 0 ? void 0 : viewRef._component) {
28
+ if (viewRef._component) {
29
+ const component = viewRef._component;
28
30
  const [rawStyles] = Object.keys(updates).reduce((acc, key) => {
29
31
  const value = updates[key];
30
32
  const index = typeof value === 'function' ? 1 : 0;
31
33
  acc[index][key] = value;
32
34
  return acc;
33
35
  }, [{}, {}]);
34
- if (typeof viewRef._component.setNativeProps === 'function') {
35
- setNativeProps(viewRef._component, rawStyles);
36
+ if (typeof component.setNativeProps === 'function') {
37
+ setNativeProps(component, rawStyles);
36
38
  }
37
- else if (Object.keys(viewRef._component.props).length > 0) {
38
- Object.keys(viewRef._component.props).forEach((key) => {
39
+ else if (Object.keys(component.props).length > 0) {
40
+ Object.keys(component.props).forEach((key) => {
39
41
  if (!rawStyles[key]) {
40
42
  return;
41
43
  }
42
44
  const dashedKey = key.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());
43
- viewRef._component._touchableNode.setAttribute(dashedKey, rawStyles[key]);
45
+ component._touchableNode.setAttribute(dashedKey, rawStyles[key]);
44
46
  });
45
47
  }
46
48
  else {
@@ -1,34 +1,65 @@
1
1
  /* global _stopObservingProgress, _startObservingProgress */
2
2
  import { runOnUI } from '../core';
3
3
  import { withStyleAnimation } from '../animation/styleAnimation';
4
+ import { ColorProperties } from '../UpdateProps';
5
+ import { processColor } from '../Colors';
4
6
  runOnUI(() => {
5
7
  'worklet';
6
8
  const configs = {};
9
+ const enteringAnimationForTag = {};
7
10
  global.LayoutAnimationRepository = {
8
11
  configs,
9
12
  registerConfig(tag, config) {
10
13
  configs[tag] = config;
14
+ enteringAnimationForTag[tag] = null;
11
15
  },
12
16
  removeConfig(tag) {
13
17
  delete configs[tag];
18
+ delete enteringAnimationForTag[tag];
14
19
  },
15
20
  startAnimationForTag(tag, type, yogaValues) {
16
21
  if (configs[tag] == null) {
17
22
  return; // :(
18
23
  }
19
24
  const style = configs[tag][type](yogaValues);
25
+ let currentAnimation = style.animations;
26
+ if (type === 'entering') {
27
+ enteringAnimationForTag[tag] = style;
28
+ }
29
+ else if (type === 'layout' && enteringAnimationForTag[tag] !== null) {
30
+ const entryAniamtion = enteringAnimationForTag[tag].animations;
31
+ const layoutAnimation = style.animations;
32
+ currentAnimation = {};
33
+ for (const key in entryAniamtion) {
34
+ currentAnimation[key] = entryAniamtion[key];
35
+ }
36
+ for (const key in layoutAnimation) {
37
+ currentAnimation[key] = layoutAnimation[key];
38
+ }
39
+ }
20
40
  const sv = configs[tag].sv;
21
41
  _stopObservingProgress(tag, false);
22
42
  _startObservingProgress(tag, sv);
23
- sv._value = Object.assign({}, sv._value, style.initialValues);
43
+ const backupColor = {};
44
+ for (const key in style.initialValues) {
45
+ if (ColorProperties.includes(key)) {
46
+ const value = style.initialValues[key];
47
+ backupColor[key] = value;
48
+ style.initialValues[key] = processColor(value);
49
+ }
50
+ }
51
+ sv.value = Object.assign({}, sv._value, style.initialValues);
24
52
  _stopObservingProgress(tag, false);
25
- const animation = withStyleAnimation(style.animations);
53
+ const animation = withStyleAnimation(currentAnimation);
26
54
  animation.callback = (finished) => {
27
55
  if (finished) {
28
56
  _stopObservingProgress(tag, finished);
29
57
  }
30
58
  style.callback && style.callback(finished);
31
59
  };
60
+ if (backupColor) {
61
+ configs[tag].sv._value = Object.assign(Object.assign({}, configs[tag].sv.value), backupColor);
62
+ }
32
63
  configs[tag].sv.value = animation;
33
64
  _startObservingProgress(tag, sv);
34
65
  },
@@ -1,6 +1,7 @@
1
- import { withDelay, withTiming, withSpring } from '../../animation';
1
+ import { withDelay } from '../../animation';
2
2
  export class BaseAnimationBuilder {
3
3
  constructor() {
4
+ this.randomizeDelay = false;
4
5
  this.build = () => {
5
6
  throw Error('Unimplemented method in child class.');
6
7
  };
@@ -13,14 +14,6 @@ export class BaseAnimationBuilder {
13
14
  this.durationV = durationMs;
14
15
  return this;
15
16
  }
16
- static easing(easingFunction) {
17
- const instance = this.createInstance();
18
- return instance.easing(easingFunction);
19
- }
20
- easing(easingFunction) {
21
- this.easingV = easingFunction;
22
- return this;
23
- }
24
17
  static delay(delayMs) {
25
18
  const instance = this.createInstance();
26
19
  return instance.delay(delayMs);
@@ -29,138 +22,48 @@ export class BaseAnimationBuilder {
29
22
  this.delayV = delayMs;
30
23
  return this;
31
24
  }
32
- static rotate(degree) {
33
- const instance = this.createInstance();
34
- return instance.rotate(degree);
35
- }
36
- rotate(degree) {
37
- this.rotateV = degree;
38
- return this;
39
- }
40
- static springify() {
41
- const instance = this.createInstance();
42
- return instance.springify();
43
- }
44
- springify() {
45
- this.type = withSpring;
46
- return this;
47
- }
48
- static damping(damping) {
49
- const instance = this.createInstance();
50
- return instance.damping(damping);
51
- }
52
- damping(damping) {
53
- this.dampingV = damping;
54
- return this;
55
- }
56
- static mass(mass) {
57
- const instance = this.createInstance();
58
- return instance.mass(mass);
59
- }
60
- mass(mass) {
61
- this.massV = mass;
62
- return this;
63
- }
64
- static stiffness(stiffness) {
65
- const instance = this.createInstance();
66
- return instance.stiffness(stiffness);
67
- }
68
- stiffness(stiffness) {
69
- this.stiffnessV = stiffness;
70
- return this;
71
- }
72
- static overshootClamping(overshootClamping) {
73
- const instance = this.createInstance();
74
- return instance.overshootClamping(overshootClamping);
75
- }
76
- overshootClamping(overshootClamping) {
77
- this.overshootClampingV = overshootClamping;
78
- return this;
79
- }
80
- static restDisplacementThreshold(restDisplacementThreshold) {
25
+ static withCallback(callback) {
81
26
  const instance = this.createInstance();
82
- return instance.restDisplacementThreshold(restDisplacementThreshold);
27
+ return instance.withCallback(callback);
83
28
  }
84
- restDisplacementThreshold(restDisplacementThreshold) {
85
- this.restDisplacementThresholdV = restDisplacementThreshold;
29
+ withCallback(callback) {
30
+ this.callbackV = callback;
86
31
  return this;
87
32
  }
88
- static restSpeedThreshold(restSpeedThreshold) {
89
- const instance = this.createInstance();
90
- return instance.restSpeedThreshold(restSpeedThreshold);
33
+ // 300ms is the default animation duration. If any animation has different default has to override this method.
34
+ static getDuration() {
35
+ return 300;
91
36
  }
92
- restSpeedThreshold(restSpeedThreshold) {
93
- this.restSpeedThresholdV = restSpeedThreshold;
94
- return this;
37
+ getDuration() {
38
+ var _a;
39
+ return (_a = this.durationV) !== null && _a !== void 0 ? _a : 300;
95
40
  }
96
- static withCallback(callback) {
41
+ static randomDelay() {
97
42
  const instance = this.createInstance();
98
- return instance.withCallback(callback);
43
+ return instance.randomDelay();
99
44
  }
100
- withCallback(callback) {
101
- this.callbackV = callback;
45
+ randomDelay() {
46
+ this.randomizeDelay = true;
102
47
  return this;
103
48
  }
104
- static build() {
105
- const instance = this.createInstance();
106
- return instance.build();
49
+ // when randomizeDelay is set to true, randomize delay between 0 and provided value (or 1000ms if delay is not provided)
50
+ getDelay() {
51
+ var _a, _b;
52
+ return this.randomizeDelay
53
+ ? Math.random() * ((_a = this.delayV) !== null && _a !== void 0 ? _a : 1000)
54
+ : (_b = this.delayV) !== null && _b !== void 0 ? _b : 0;
107
55
  }
108
56
  getDelayFunction() {
109
- const delay = this.delayV;
110
- return delay
57
+ const isDelayProvided = this.randomizeDelay || this.delayV;
58
+ return isDelayProvided
111
59
  ? withDelay
112
60
  : (_, animation) => {
113
61
  'worklet';
114
62
  return animation;
115
63
  };
116
64
  }
117
- getAnimationAndConfig() {
118
- const duration = this.durationV;
119
- const easing = this.easingV;
120
- const rotate = this.rotateV;
121
- const type = this.type ? this.type : withTiming;
122
- const damping = this.dampingV;
123
- const mass = this.massV;
124
- const stiffness = this.stiffnessV;
125
- const overshootClamping = this.overshootClampingV;
126
- const restDisplacementThreshold = this.restDisplacementThresholdV;
127
- const restSpeedThreshold = this.restSpeedThresholdV;
128
- const animation = type;
129
- const config = {};
130
- if (type === withTiming) {
131
- if (easing) {
132
- config.easing = easing;
133
- }
134
- if (duration) {
135
- config.duration = duration;
136
- }
137
- if (rotate) {
138
- config.rotate = rotate;
139
- }
140
- }
141
- else {
142
- if (damping) {
143
- config.damping = damping;
144
- }
145
- if (mass) {
146
- config.mass = mass;
147
- }
148
- if (stiffness) {
149
- config.stiffness = stiffness;
150
- }
151
- if (overshootClamping) {
152
- config.overshootClamping = overshootClamping;
153
- }
154
- if (restDisplacementThreshold) {
155
- config.restDisplacementThreshold = restDisplacementThreshold;
156
- }
157
- if (restSpeedThreshold) {
158
- config.restSpeedThreshold = restSpeedThreshold;
159
- }
160
- if (rotate) {
161
- config.rotate = rotate;
162
- }
163
- }
164
- return [animation, config];
65
+ static build() {
66
+ const instance = this.createInstance();
67
+ return instance.build();
165
68
  }
166
69
  }