react-native-reanimated 2.3.0-alpha.1 → 2.3.0-beta.2

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 (328) hide show
  1. package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +15 -8
  2. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +170 -166
  3. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +36 -34
  4. package/Common/cpp/Registries/EventHandlerRegistry.cpp +13 -6
  5. package/Common/cpp/Registries/MapperRegistry.cpp +19 -15
  6. package/Common/cpp/Registries/WorkletsCache.cpp +19 -9
  7. package/Common/cpp/SharedItems/FrozenObject.cpp +19 -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 +216 -143
  12. package/Common/cpp/Tools/JSIStoreValueUser.cpp +36 -24
  13. package/Common/cpp/Tools/Mapper.cpp +41 -29
  14. package/Common/cpp/Tools/RuntimeDecorator.cpp +103 -84
  15. package/Common/cpp/Tools/Scheduler.cpp +14 -6
  16. package/Common/cpp/Tools/WorkletEventHandler.cpp +1 -1
  17. package/Common/cpp/headers/LayoutAnimations/LayoutAnimationsProxy.h +12 -11
  18. package/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +45 -34
  19. package/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +28 -16
  20. package/Common/cpp/headers/Registries/EventHandlerRegistry.h +14 -8
  21. package/Common/cpp/headers/Registries/MapperRegistry.h +4 -4
  22. package/Common/cpp/headers/Registries/WorkletsCache.h +9 -7
  23. package/Common/cpp/headers/SharedItems/FrozenObject.h +15 -11
  24. package/Common/cpp/headers/SharedItems/HostFunctionHandler.h +6 -4
  25. package/Common/cpp/headers/SharedItems/MutableValue.h +21 -12
  26. package/Common/cpp/headers/SharedItems/MutableValueSetterProxy.h +10 -7
  27. package/Common/cpp/headers/SharedItems/RemoteObject.h +16 -8
  28. package/Common/cpp/headers/SharedItems/RuntimeManager.h +39 -21
  29. package/Common/cpp/headers/SharedItems/ShareableValue.h +31 -27
  30. package/Common/cpp/headers/SharedItems/SharedParent.h +7 -4
  31. package/Common/cpp/headers/SharedItems/ValueWrapper.h +80 -61
  32. package/Common/cpp/headers/SpecTools/ErrorHandler.h +17 -19
  33. package/Common/cpp/headers/Tools/JSIStoreValueUser.h +18 -13
  34. package/Common/cpp/headers/Tools/Mapper.h +24 -18
  35. package/Common/cpp/headers/Tools/PlatformDepMethodsHolder.h +12 -7
  36. package/Common/cpp/headers/Tools/ReanimatedHiddenHeaders.h +7 -7
  37. package/Common/cpp/headers/Tools/RuntimeDecorator.h +29 -23
  38. package/Common/cpp/headers/Tools/Scheduler.h +28 -33
  39. package/Common/cpp/headers/Tools/WorkletEventHandler.h +9 -7
  40. package/Common/cpp/hidden_headers/Logger.h +14 -14
  41. package/Common/cpp/hidden_headers/LoggerInterface.h +8 -9
  42. package/Common/cpp/hidden_headers/SpeedChecker.h +7 -8
  43. package/README.md +1 -1
  44. package/RNReanimated.podspec +4 -4
  45. package/android/build.gradle +80 -3
  46. package/android/react-native-reanimated-63-hermes.aar +0 -0
  47. package/android/react-native-reanimated-63-jsc.aar +0 -0
  48. package/android/react-native-reanimated-64-hermes.aar +0 -0
  49. package/android/react-native-reanimated-64-jsc.aar +0 -0
  50. package/android/react-native-reanimated-65-hermes.aar +0 -0
  51. package/android/react-native-reanimated-65-jsc.aar +0 -0
  52. package/android/react-native-reanimated-66-hermes.aar +0 -0
  53. package/android/react-native-reanimated-66-jsc.aar +0 -0
  54. package/ios/LayoutReanimation/REAAnimationsManager.h +19 -10
  55. package/ios/LayoutReanimation/REAAnimationsManager.m +195 -200
  56. package/ios/LayoutReanimation/REASnapshot.h +13 -0
  57. package/ios/LayoutReanimation/REASnapshot.m +29 -0
  58. package/ios/LayoutReanimation/REAUIManager.h +16 -0
  59. package/ios/LayoutReanimation/REAUIManager.mm +348 -0
  60. package/ios/Nodes/REAAlwaysNode.m +14 -15
  61. package/ios/Nodes/REABezierNode.m +8 -7
  62. package/ios/Nodes/REABlockNode.m +1 -1
  63. package/ios/Nodes/REACallFuncNode.h +0 -1
  64. package/ios/Nodes/REACallFuncNode.m +10 -8
  65. package/ios/Nodes/REAClockNodes.m +22 -20
  66. package/ios/Nodes/REAConcatNode.h +0 -1
  67. package/ios/Nodes/REAConcatNode.m +2 -2
  68. package/ios/Nodes/REACondNode.m +7 -5
  69. package/ios/Nodes/READebugNode.m +5 -4
  70. package/ios/Nodes/REAEventNode.m +1 -1
  71. package/ios/Nodes/REAFunctionNode.h +0 -1
  72. package/ios/Nodes/REAFunctionNode.m +2 -2
  73. package/ios/Nodes/REAJSCallNode.m +4 -5
  74. package/ios/Nodes/REANode.h +3 -4
  75. package/ios/Nodes/REANode.m +9 -11
  76. package/ios/Nodes/REAOperatorNode.m +68 -67
  77. package/ios/Nodes/REAParamNode.h +1 -3
  78. package/ios/Nodes/REAParamNode.m +15 -17
  79. package/ios/Nodes/REAPropsNode.h +1 -3
  80. package/ios/Nodes/REAPropsNode.m +19 -22
  81. package/ios/Nodes/REASetNode.h +0 -1
  82. package/ios/Nodes/REASetNode.m +7 -5
  83. package/ios/Nodes/REAStyleNode.h +0 -1
  84. package/ios/Nodes/REAStyleNode.m +2 -4
  85. package/ios/Nodes/REATransformNode.h +0 -1
  86. package/ios/Nodes/REATransformNode.m +3 -5
  87. package/ios/Nodes/REAValueNode.m +5 -7
  88. package/ios/REAEventDispatcher.m +3 -3
  89. package/ios/REAModule.h +0 -2
  90. package/ios/REAModule.m +29 -40
  91. package/ios/REANodesManager.h +11 -19
  92. package/ios/REANodesManager.m +105 -130
  93. package/ios/REAUtils.h +5 -3
  94. package/ios/Transitioning/RCTConvert+REATransition.m +45 -29
  95. package/ios/Transitioning/REAAllTransitions.h +2 -2
  96. package/ios/Transitioning/REAAllTransitions.m +14 -25
  97. package/ios/Transitioning/REATransition.h +8 -7
  98. package/ios/Transitioning/REATransition.m +19 -16
  99. package/ios/Transitioning/REATransitionAnimation.h +1 -1
  100. package/ios/Transitioning/REATransitionAnimation.m +2 -3
  101. package/ios/Transitioning/REATransitionManager.m +3 -3
  102. package/ios/native/NativeMethods.h +15 -5
  103. package/ios/native/NativeProxy.h +4 -3
  104. package/ios/native/NativeProxy.mm +19 -5
  105. package/ios/native/REAIOSErrorHandler.h +13 -10
  106. package/ios/native/REAIOSLogger.h +8 -8
  107. package/ios/native/REAIOSScheduler.h +5 -5
  108. package/ios/native/REAIOSScheduler.mm +7 -5
  109. package/ios/native/REAInitializer.h +37 -0
  110. package/ios/native/REAInitializer.mm +63 -0
  111. package/ios/native/UIResponder+Reanimated.mm +9 -48
  112. package/lib/ConfigHelper.js +1 -0
  113. package/lib/ReanimatedModule.native.js +10 -2
  114. package/lib/createAnimatedComponent.js +64 -30
  115. package/lib/reanimated1/core/AnimatedAlways.js +1 -1
  116. package/lib/reanimated1/core/AnimatedBezier.js +1 -1
  117. package/lib/reanimated1/core/AnimatedBlock.js +1 -1
  118. package/lib/reanimated1/core/AnimatedCall.js +1 -1
  119. package/lib/reanimated1/core/AnimatedCallFunc.js +1 -1
  120. package/lib/reanimated1/core/AnimatedConcat.js +1 -1
  121. package/lib/reanimated1/core/AnimatedCond.js +1 -1
  122. package/lib/reanimated1/core/AnimatedDebug.js +1 -1
  123. package/lib/reanimated1/core/AnimatedEvent.js +1 -1
  124. package/lib/reanimated1/core/AnimatedFunction.js +1 -1
  125. package/lib/reanimated1/core/AnimatedOperator.js +1 -1
  126. package/lib/reanimated1/core/AnimatedParam.js +1 -1
  127. package/lib/reanimated1/core/AnimatedProps.js +2 -2
  128. package/lib/reanimated1/core/AnimatedSet.js +1 -1
  129. package/lib/reanimated1/core/AnimatedStartClock.js +1 -1
  130. package/lib/reanimated1/core/AnimatedStopClock.js +1 -1
  131. package/lib/reanimated1/core/AnimatedStyle.js +1 -1
  132. package/lib/reanimated1/core/AnimatedTransform.js +1 -1
  133. package/lib/reanimated1/core/Core.test.js +30 -0
  134. package/lib/reanimated1/core/InternalAnimatedValue.js +1 -1
  135. package/lib/reanimated1/core/__mocks__/AnimatedProps.js +1 -1
  136. package/lib/reanimated1/derived/interpolate.js +1 -1
  137. package/lib/reanimated2/Colors.js +16 -12
  138. package/lib/reanimated2/NativeMethods.js +3 -14
  139. package/lib/reanimated2/{NativeReanimated.native.js → NativeReanimated/NativeReanimated.js} +19 -24
  140. package/lib/reanimated2/NativeReanimated/index.js +15 -0
  141. package/lib/reanimated2/PlatformChecker.js +16 -0
  142. package/lib/reanimated2/PropAdapters.js +14 -4
  143. package/lib/reanimated2/UpdateProps.js +14 -11
  144. package/lib/reanimated2/ViewDescriptorsSet.js +73 -0
  145. package/lib/reanimated2/WorkletEventHandler.js +15 -13
  146. package/lib/reanimated2/animation/commonTypes.js +1 -0
  147. package/lib/reanimated2/animation/decay.js +71 -0
  148. package/lib/reanimated2/animation/delay.js +64 -0
  149. package/lib/reanimated2/animation/index.js +8 -0
  150. package/lib/reanimated2/animation/repeat.js +69 -0
  151. package/lib/reanimated2/animation/sequence.js +72 -0
  152. package/lib/reanimated2/animation/spring.js +101 -0
  153. package/lib/reanimated2/animation/styleAnimation.js +166 -0
  154. package/lib/reanimated2/animation/timing.js +64 -0
  155. package/lib/reanimated2/animation/util.js +157 -0
  156. package/lib/reanimated2/commonTypes.js +1 -0
  157. package/lib/reanimated2/core.js +35 -39
  158. package/lib/reanimated2/globals.d.ts +47 -1
  159. package/lib/reanimated2/hook/Hooks.js +9 -0
  160. package/lib/reanimated2/hook/commonTypes.js +1 -0
  161. package/lib/reanimated2/hook/index.js +8 -0
  162. package/lib/reanimated2/hook/useAnimatedGestureHandler.js +50 -0
  163. package/lib/reanimated2/hook/useAnimatedReaction.js +37 -0
  164. package/lib/reanimated2/hook/useAnimatedRef.js +25 -0
  165. package/lib/reanimated2/hook/useAnimatedScrollHandler.js +41 -0
  166. package/lib/reanimated2/hook/useAnimatedStyle.js +376 -0
  167. package/lib/reanimated2/hook/useDerivedValue.js +36 -0
  168. package/lib/reanimated2/hook/useSharedValue.js +17 -0
  169. package/lib/reanimated2/hook/utils.js +175 -0
  170. package/lib/reanimated2/index.js +3 -2
  171. package/lib/reanimated2/interpolation.js +95 -86
  172. package/lib/reanimated2/jestUtils.js +0 -12
  173. package/lib/reanimated2/js-reanimated/JSReanimated.js +9 -10
  174. package/lib/reanimated2/js-reanimated/index.js +57 -1
  175. package/lib/reanimated2/layoutReanimation/LayoutAnimationRepository.js +58 -0
  176. package/lib/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js +69 -0
  177. package/lib/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +125 -0
  178. package/lib/reanimated2/layoutReanimation/animationBuilder/Keyframe.js +193 -0
  179. package/lib/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +1 -0
  180. package/lib/reanimated2/layoutReanimation/animationBuilder/index.js +3 -0
  181. package/lib/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +325 -207
  182. package/lib/reanimated2/layoutReanimation/defaultAnimations/Default.js +36 -0
  183. package/lib/reanimated2/layoutReanimation/defaultAnimations/Fade.js +235 -187
  184. package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +327 -269
  185. package/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +146 -0
  186. package/lib/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +85 -0
  187. package/lib/reanimated2/layoutReanimation/defaultAnimations/Roll.js +119 -0
  188. package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +289 -0
  189. package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +159 -121
  190. package/lib/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +83 -65
  191. package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +371 -277
  192. package/lib/reanimated2/layoutReanimation/defaultAnimations/index.js +4 -0
  193. package/lib/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +78 -0
  194. package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +128 -0
  195. package/lib/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +37 -0
  196. package/lib/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +41 -0
  197. package/lib/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +34 -0
  198. package/lib/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +46 -0
  199. package/lib/reanimated2/layoutReanimation/defaultTransitions/index.js +6 -0
  200. package/lib/reanimated2/layoutReanimation/index.js +3 -2
  201. package/lib/reanimated2/platform-specific/RNRenderer.web.js +2 -0
  202. package/lib/reanimated2/utils.js +9 -0
  203. package/libSo/fbjni/jni/arm64-v8a/libfbjni.so +0 -0
  204. package/libSo/fbjni/jni/armeabi-v7a/libfbjni.so +0 -0
  205. package/libSo/fbjni/jni/x86/libfbjni.so +0 -0
  206. package/libSo/fbjni/jni/x86_64/libfbjni.so +0 -0
  207. package/package.json +21 -10
  208. package/plugin.js +244 -85
  209. package/react-native-reanimated.d.ts +531 -453
  210. package/src/ConfigHelper.js +1 -0
  211. package/src/ReanimatedModule.native.js +10 -2
  212. package/src/createAnimatedComponent.js +64 -30
  213. package/src/reanimated1/core/AnimatedAlways.js +1 -1
  214. package/src/reanimated1/core/AnimatedBezier.js +1 -1
  215. package/src/reanimated1/core/AnimatedBlock.js +1 -1
  216. package/src/reanimated1/core/AnimatedCall.js +1 -1
  217. package/src/reanimated1/core/AnimatedCallFunc.js +1 -1
  218. package/src/reanimated1/core/AnimatedConcat.js +1 -1
  219. package/src/reanimated1/core/AnimatedCond.js +1 -1
  220. package/src/reanimated1/core/AnimatedDebug.js +1 -1
  221. package/src/reanimated1/core/AnimatedEvent.js +1 -1
  222. package/src/reanimated1/core/AnimatedFunction.js +1 -1
  223. package/src/reanimated1/core/AnimatedOperator.js +1 -1
  224. package/src/reanimated1/core/AnimatedParam.js +1 -1
  225. package/src/reanimated1/core/AnimatedProps.js +2 -2
  226. package/src/reanimated1/core/AnimatedSet.js +1 -1
  227. package/src/reanimated1/core/AnimatedStartClock.js +1 -1
  228. package/src/reanimated1/core/AnimatedStopClock.js +1 -1
  229. package/src/reanimated1/core/AnimatedStyle.js +1 -1
  230. package/src/reanimated1/core/AnimatedTransform.js +1 -1
  231. package/src/reanimated1/core/Core.test.js +30 -0
  232. package/src/reanimated1/core/InternalAnimatedValue.js +1 -1
  233. package/src/reanimated1/core/__mocks__/AnimatedProps.js +1 -1
  234. package/src/reanimated1/derived/interpolate.js +1 -1
  235. package/src/reanimated2/Colors.ts +30 -27
  236. package/src/reanimated2/Easing.ts +3 -1
  237. package/src/reanimated2/NativeMethods.ts +26 -16
  238. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +78 -0
  239. package/src/reanimated2/NativeReanimated/index.ts +18 -0
  240. package/src/reanimated2/PlatformChecker.ts +21 -0
  241. package/src/reanimated2/PropAdapters.ts +52 -34
  242. package/src/reanimated2/UpdateProps.ts +40 -20
  243. package/src/reanimated2/ViewDescriptorsSet.ts +108 -0
  244. package/src/reanimated2/WorkletEventHandler.ts +41 -23
  245. package/src/reanimated2/animation/commonTypes.ts +48 -0
  246. package/src/reanimated2/animation/decay.ts +141 -0
  247. package/src/reanimated2/animation/delay.ts +103 -0
  248. package/src/reanimated2/animation/index.ts +16 -0
  249. package/src/reanimated2/animation/repeat.ts +128 -0
  250. package/src/reanimated2/animation/sequence.ts +110 -0
  251. package/src/reanimated2/animation/spring.ts +165 -0
  252. package/src/reanimated2/animation/styleAnimation.ts +253 -0
  253. package/src/reanimated2/animation/timing.ts +109 -0
  254. package/src/reanimated2/animation/util.ts +242 -0
  255. package/src/reanimated2/commonTypes.ts +81 -0
  256. package/src/reanimated2/core.ts +128 -82
  257. package/src/reanimated2/globals.d.ts +47 -1
  258. package/src/reanimated2/hook/Hooks.ts +16 -0
  259. package/src/reanimated2/hook/commonTypes.ts +12 -0
  260. package/src/reanimated2/hook/index.ts +25 -0
  261. package/src/reanimated2/hook/useAnimatedGestureHandler.ts +110 -0
  262. package/src/reanimated2/hook/useAnimatedReaction.ts +49 -0
  263. package/src/reanimated2/hook/useAnimatedRef.ts +34 -0
  264. package/src/reanimated2/hook/useAnimatedScrollHandler.ts +83 -0
  265. package/src/reanimated2/hook/useAnimatedStyle.ts +538 -0
  266. package/src/reanimated2/hook/useDerivedValue.ts +48 -0
  267. package/src/reanimated2/hook/useSharedValue.ts +22 -0
  268. package/src/reanimated2/hook/utils.ts +259 -0
  269. package/src/reanimated2/index.ts +3 -2
  270. package/src/reanimated2/interpolation.ts +170 -101
  271. package/src/reanimated2/jestUtils.ts +0 -12
  272. package/src/reanimated2/js-reanimated/JSReanimated.ts +47 -22
  273. package/src/reanimated2/js-reanimated/Mapper.ts +1 -1
  274. package/src/reanimated2/js-reanimated/index.ts +71 -0
  275. package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.tsx +62 -0
  276. package/src/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.ts +91 -0
  277. package/src/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.ts +169 -0
  278. package/src/reanimated2/layoutReanimation/animationBuilder/Keyframe.ts +263 -0
  279. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +78 -0
  280. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +16 -0
  281. package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +243 -121
  282. package/src/reanimated2/layoutReanimation/defaultAnimations/Default.ts +43 -0
  283. package/src/reanimated2/layoutReanimation/defaultAnimations/Fade.ts +95 -53
  284. package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +114 -64
  285. package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +179 -0
  286. package/src/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.ts +93 -0
  287. package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +132 -0
  288. package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +333 -0
  289. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +84 -50
  290. package/src/reanimated2/layoutReanimation/defaultAnimations/Stretch.ts +41 -23
  291. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +234 -154
  292. package/src/reanimated2/layoutReanimation/defaultAnimations/index.ts +4 -0
  293. package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +104 -0
  294. package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +213 -0
  295. package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +60 -0
  296. package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +58 -0
  297. package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +41 -0
  298. package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +78 -0
  299. package/src/reanimated2/layoutReanimation/defaultTransitions/index.ts +6 -0
  300. package/src/reanimated2/layoutReanimation/index.ts +3 -2
  301. package/src/reanimated2/platform-specific/RNRenderer.web.ts +2 -0
  302. package/src/reanimated2/utils.ts +21 -0
  303. package/android/react-native-reanimated-62-hermes.aar +0 -0
  304. package/android/react-native-reanimated-62-jsc.aar +0 -0
  305. package/ios/LayoutReanimation/REAAnimationRootView.h +0 -12
  306. package/ios/LayoutReanimation/REAAnimationRootView.m +0 -16
  307. package/ios/LayoutReanimation/REAAnimationRootViewManager.h +0 -9
  308. package/ios/LayoutReanimation/REAAnimationRootViewManager.m +0 -49
  309. package/ios/LayoutReanimation/REAReactBatchObserver.h +0 -20
  310. package/ios/LayoutReanimation/REAReactBatchObserver.m +0 -125
  311. package/ios/LayoutReanimation/REASnapshooter.h +0 -19
  312. package/ios/LayoutReanimation/REASnapshooter.m +0 -64
  313. package/ios/LayoutReanimation/REAViewTraverser.h +0 -13
  314. package/ios/LayoutReanimation/REAViewTraverser.m +0 -40
  315. package/lib/reanimated2/Hooks.js +0 -732
  316. package/lib/reanimated2/NativeReanimated.js +0 -4
  317. package/lib/reanimated2/animations.js +0 -713
  318. package/lib/reanimated2/js-reanimated/index.web.js +0 -20
  319. package/lib/reanimated2/layoutReanimation/AnimatedRoot.js +0 -55
  320. package/lib/reanimated2/layoutReanimation/defaultAnimationsBuilder.js +0 -374
  321. package/src/reanimated2/Hooks.ts +0 -918
  322. package/src/reanimated2/NativeReanimated.native.ts +0 -61
  323. package/src/reanimated2/NativeReanimated.ts +0 -5
  324. package/src/reanimated2/animations.ts +0 -868
  325. package/src/reanimated2/js-reanimated/index.js +0 -0
  326. package/src/reanimated2/js-reanimated/index.web.ts +0 -29
  327. package/src/reanimated2/layoutReanimation/AnimatedRoot.tsx +0 -68
  328. package/src/reanimated2/layoutReanimation/defaultAnimationsBuilder.ts +0 -440
@@ -0,0 +1,175 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import { processColor } from '../Colors';
3
+ import { makeRemote } from '../core';
4
+ import { isWeb } from '../PlatformChecker';
5
+ import { colorProps } from '../UpdateProps';
6
+ import WorkletEventHandler from '../WorkletEventHandler';
7
+ export function useEvent(handler, eventNames = [], rebuild = false) {
8
+ const initRef = useRef(null);
9
+ if (initRef.current === null) {
10
+ initRef.current = new WorkletEventHandler(handler, eventNames);
11
+ }
12
+ else if (rebuild) {
13
+ initRef.current.updateWorklet(handler);
14
+ }
15
+ useEffect(() => {
16
+ return () => {
17
+ initRef.current = null;
18
+ };
19
+ }, []);
20
+ return initRef;
21
+ }
22
+ export function useHandler(handlers, dependencies) {
23
+ const initRef = useRef(null);
24
+ if (initRef.current === null) {
25
+ initRef.current = {
26
+ context: makeRemote({}),
27
+ savedDependencies: [],
28
+ };
29
+ }
30
+ useEffect(() => {
31
+ return () => {
32
+ initRef.current = null;
33
+ };
34
+ }, []);
35
+ const { context, savedDependencies } = initRef.current;
36
+ dependencies = buildDependencies(dependencies, handlers);
37
+ const doDependenciesDiffer = !areDependenciesEqual(dependencies, savedDependencies);
38
+ initRef.current.savedDependencies = dependencies;
39
+ const useWeb = isWeb();
40
+ return { context, doDependenciesDiffer, useWeb };
41
+ }
42
+ // builds one big hash from multiple worklets' hashes
43
+ export function buildWorkletsHash(handlers) {
44
+ return Object.values(handlers).reduce((acc, worklet) =>
45
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
46
+ acc + worklet.__workletHash.toString(), '');
47
+ }
48
+ // builds dependencies array for gesture handlers
49
+ export function buildDependencies(dependencies, handlers) {
50
+ const handlersList = Object.values(handlers).filter((handler) => handler !== undefined);
51
+ if (!dependencies) {
52
+ dependencies = handlersList.map((handler) => {
53
+ return {
54
+ workletHash: handler.__workletHash,
55
+ closure: handler._closure,
56
+ };
57
+ });
58
+ }
59
+ else {
60
+ dependencies.push(buildWorkletsHash(handlersList));
61
+ }
62
+ return dependencies;
63
+ }
64
+ // this is supposed to work as useEffect comparison
65
+ export function areDependenciesEqual(nextDeps, prevDeps) {
66
+ function is(x, y) {
67
+ /* eslint-disable no-self-compare */
68
+ return (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y);
69
+ /* eslint-enable no-self-compare */
70
+ }
71
+ const objectIs = typeof Object.is === 'function' ? Object.is : is;
72
+ function areHookInputsEqual(nextDeps, prevDeps) {
73
+ if (!nextDeps || !prevDeps || prevDeps.length !== nextDeps.length) {
74
+ return false;
75
+ }
76
+ for (let i = 0; i < prevDeps.length; ++i) {
77
+ if (!objectIs(nextDeps[i], prevDeps[i])) {
78
+ return false;
79
+ }
80
+ }
81
+ return true;
82
+ }
83
+ return areHookInputsEqual(nextDeps, prevDeps);
84
+ }
85
+ export function hasColorProps(updates) {
86
+ const colorPropsSet = new Set(colorProps);
87
+ for (const key in updates) {
88
+ if (colorPropsSet.has(key)) {
89
+ return true;
90
+ }
91
+ }
92
+ return false;
93
+ }
94
+ export function parseColors(updates) {
95
+ 'worklet';
96
+ for (const key in updates) {
97
+ if (colorProps.indexOf(key) !== -1) {
98
+ updates[key] = processColor(updates[key]);
99
+ }
100
+ }
101
+ }
102
+ export function canApplyOptimalisation(upadterFn) {
103
+ const FUNCTIONLESS_FLAG = 0b00000001;
104
+ const STATEMENTLESS_FLAG = 0b00000010;
105
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
106
+ const optimalization = upadterFn.__optimalization;
107
+ return (optimalization & FUNCTIONLESS_FLAG && optimalization & STATEMENTLESS_FLAG);
108
+ }
109
+ export function isAnimated(prop) {
110
+ 'worklet';
111
+ const propsToCheck = [prop];
112
+ while (propsToCheck.length > 0) {
113
+ const currentProp = propsToCheck.pop();
114
+ if (Array.isArray(currentProp)) {
115
+ for (const item of currentProp) {
116
+ propsToCheck.push(item);
117
+ }
118
+ }
119
+ else if ((currentProp === null || currentProp === void 0 ? void 0 : currentProp.onFrame) !== undefined) {
120
+ return true;
121
+ }
122
+ else if (typeof currentProp === 'object') {
123
+ for (const item of Object.values(currentProp)) {
124
+ propsToCheck.push(item);
125
+ }
126
+ }
127
+ // if none of the above, it's not the animated prop, check next one
128
+ }
129
+ // when none of the props were animated return false
130
+ return false;
131
+ }
132
+ export function styleDiff(oldStyle, newStyle) {
133
+ 'worklet';
134
+ const diff = {};
135
+ Object.keys(oldStyle).forEach((key) => {
136
+ if (newStyle[key] === undefined) {
137
+ diff[key] = null;
138
+ }
139
+ });
140
+ Object.keys(newStyle).forEach((key) => {
141
+ const value = newStyle[key];
142
+ const oldValue = oldStyle[key];
143
+ if (isAnimated(value)) {
144
+ // do nothing
145
+ return;
146
+ }
147
+ if (oldValue !== value &&
148
+ JSON.stringify(oldValue) !== JSON.stringify(value)) {
149
+ // I'd use deep equal here but that'd take additional work and this was easier
150
+ diff[key] = value;
151
+ }
152
+ });
153
+ return diff;
154
+ }
155
+ export function getStyleWithoutAnimations(newStyle) {
156
+ 'worklet';
157
+ const diff = {};
158
+ for (const key in newStyle) {
159
+ const value = newStyle[key];
160
+ if (isAnimated(value)) {
161
+ continue;
162
+ }
163
+ diff[key] = value;
164
+ }
165
+ return diff;
166
+ }
167
+ export const validateAnimatedStyles = (styles) => {
168
+ 'worklet';
169
+ if (typeof styles !== 'object') {
170
+ throw new Error(`useAnimatedStyle has to return an object, found ${typeof styles} instead`);
171
+ }
172
+ else if (Array.isArray(styles)) {
173
+ throw new Error('useAnimatedStyle has to return an object and cannot return static styles combined with dynamic ones. Please do merging where a component receives props.');
174
+ }
175
+ };
@@ -1,9 +1,10 @@
1
1
  export * from './core';
2
- export * from './Hooks';
3
- export * from './animations';
2
+ export * from './hook';
3
+ export * from './animation';
4
4
  export * from './interpolation';
5
5
  export * from './Easing';
6
6
  export * from './NativeMethods';
7
7
  export * from './Colors';
8
8
  export * from './PropAdapters';
9
9
  export * from './layoutReanimation';
10
+ export * from './utils';
@@ -1,118 +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 (__DEV__)
74
- validateType(type);
75
- if (typeof type === 'object') {
76
- if (coef * val < coef * ll) {
77
- return getVal(Object.assign(config, { type: type.extrapolateLeft }));
78
- }
79
- else if (coef * val > coef * ll) {
80
- return getVal(Object.assign(config, { type: type.extrapolateRight }));
81
- }
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);
82
77
  }
83
- if (coef * val < coef * ll || coef * val > coef * rr) {
84
- return getVal(config);
78
+ else if (coef * val > coef * rightEdgeOutput) {
79
+ return getVal(extrapolationConfig.extrapolateRight, coef, val, leftEdgeOutput, rightEdgeOutput, x);
85
80
  }
86
81
  return val;
87
82
  }
83
+ // TODO: support default values in worklets:
84
+ // e.g. function interpolate(x, input, output, type = Extrapolatation.CLAMP)
88
85
  export function interpolate(x, input, output, type) {
89
86
  'worklet';
90
- 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)) {
91
92
  console.warn(`interpolate() was renamed to interpolateNode() in Reanimated 2. Please use interpolateNode() instead`);
92
- // we can't use rest parameters in worklets at the moment
93
- // eslint-disable-next-line prefer-spread, prefer-rest-params
94
- return interpolateNode.apply(undefined, arguments);
93
+ return interpolateNode(x, {
94
+ inputRange: input,
95
+ outputRange: output,
96
+ extrapolateLeft: extrapolationConfig.extrapolateLeft,
97
+ extrapolateRight: extrapolationConfig.extrapolateRight,
98
+ });
95
99
  }
96
100
  const length = input.length;
97
- let narrowedInput = [];
98
- if (x < input[0]) {
99
- narrowedInput = [input[0], input[1], output[0], output[1]];
100
- }
101
- else if (x > input[length - 1]) {
102
- narrowedInput = [
103
- input[length - 2],
104
- input[length - 1],
105
- output[length - 2],
106
- output[length - 1],
107
- ];
108
- }
109
- else {
110
- for (let i = 1; i < length; ++i) {
111
- if (x <= input[i]) {
112
- narrowedInput = [input[i - 1], input[i], output[i - 1], output[i]];
113
- 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
+ }
114
123
  }
115
124
  }
116
125
  }
117
- return internalInterpolate.apply({}, [x].concat(narrowedInput).concat(type));
126
+ return internalInterpolate(x, narrowedInput, extrapolationConfig);
118
127
  }
@@ -149,18 +149,6 @@ export const setUpTests = (userConfig = {}) => {
149
149
  return compareStyle(received, expectedStyle, config);
150
150
  },
151
151
  });
152
- jest.mock('./js-reanimated', () => require('./js-reanimated/index.web'));
153
- jest.mock('../ReanimatedModule', () => require('../ReanimatedModuleCompat'));
154
- jest.mock('./NativeReanimated', () => {
155
- let module;
156
- try {
157
- module = require('./NativeReanimated.js');
158
- }
159
- catch (_a) {
160
- module = require('./NativeReanimated.ts');
161
- }
162
- return module.default;
163
- });
164
152
  };
165
153
  export const getAnimatedStyle = (received) => {
166
154
  return getCurrentStyle(received);
@@ -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) {
@@ -54,7 +52,7 @@ export default class JSReanimated {
54
52
  makeMutable(value) {
55
53
  return new MutableValue(value, this._valueSetter);
56
54
  }
57
- makeRemote(object) {
55
+ makeRemote(object = {}) {
58
56
  return object;
59
57
  }
60
58
  startMapper(mapper, inputs = [], outputs = []) {
@@ -66,10 +64,11 @@ export default class JSReanimated {
66
64
  stopMapper(mapperId) {
67
65
  this._mapperRegistry.stopMapper(mapperId);
68
66
  }
69
- registerEventHandler(_eventHash, _eventHandler) {
67
+ registerEventHandler(_, __) {
70
68
  // noop
69
+ return '';
71
70
  }
72
- unregisterEventHandler(_registrationId) {
71
+ unregisterEventHandler(_) {
73
72
  // noop
74
73
  }
75
74
  }
@@ -1 +1,57 @@
1
- "use strict";
1
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
+ // @ts-nocheck
3
+ import JSReanimated from './JSReanimated';
4
+ import { shouldBeUseWeb } from '../PlatformChecker';
5
+ const reanimatedJS = new JSReanimated();
6
+ if (shouldBeUseWeb()) {
7
+ global._frameTimestamp = null;
8
+ global._setGlobalConsole = (_val) => {
9
+ // noop
10
+ };
11
+ global._measure = () => {
12
+ console.warn("[Reanimated] You can't use 'measue' method with Chrome Debugger or with web version");
13
+ return {
14
+ x: 0,
15
+ y: 0,
16
+ width: 0,
17
+ height: 0,
18
+ pageX: 0,
19
+ pageY: 0,
20
+ };
21
+ };
22
+ global._scrollTo = () => {
23
+ console.warn("[Reanimated] You can't use 'scrollTo' method with Chrome Debugger or with web version");
24
+ };
25
+ }
26
+ export const _updatePropsJS = (updates, viewRef) => {
27
+ if (viewRef === null || viewRef === void 0 ? void 0 : viewRef._component) {
28
+ const [rawStyles] = Object.keys(updates).reduce((acc, key) => {
29
+ const value = updates[key];
30
+ const index = typeof value === 'function' ? 1 : 0;
31
+ acc[index][key] = value;
32
+ return acc;
33
+ }, [{}, {}]);
34
+ if (typeof viewRef._component.setNativeProps === 'function') {
35
+ setNativeProps(viewRef._component, rawStyles);
36
+ }
37
+ else if (Object.keys(viewRef._component.props).length > 0) {
38
+ Object.keys(viewRef._component.props).forEach((key) => {
39
+ if (!rawStyles[key]) {
40
+ return;
41
+ }
42
+ const dashedKey = key.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());
43
+ viewRef._component._touchableNode.setAttribute(dashedKey, rawStyles[key]);
44
+ });
45
+ }
46
+ else {
47
+ console.warn('It is not possible to manipulate component');
48
+ }
49
+ }
50
+ };
51
+ const setNativeProps = (component, style) => {
52
+ const previousStyle = component.previousStyle ? component.previousStyle : {};
53
+ const currentStyle = Object.assign(Object.assign({}, previousStyle), style);
54
+ component.previousStyle = currentStyle;
55
+ component.setNativeProps({ style: currentStyle });
56
+ };
57
+ export default reanimatedJS;
@@ -0,0 +1,58 @@
1
+ /* global _stopObservingProgress, _startObservingProgress */
2
+ import { runOnUI } from '../core';
3
+ import { withStyleAnimation } from '../animation/styleAnimation';
4
+ runOnUI(() => {
5
+ 'worklet';
6
+ const configs = {};
7
+ const enteringAnimationForTag = {};
8
+ global.LayoutAnimationRepository = {
9
+ configs,
10
+ registerConfig(tag, config) {
11
+ configs[tag] = config;
12
+ enteringAnimationForTag[tag] = null;
13
+ },
14
+ removeConfig(tag) {
15
+ delete configs[tag];
16
+ delete enteringAnimationForTag[tag];
17
+ },
18
+ startAnimationForTag(tag, type, yogaValues) {
19
+ if (configs[tag] == null) {
20
+ return; // :(
21
+ }
22
+ const style = configs[tag][type](yogaValues);
23
+ let currentAnimation = style.animations;
24
+ if (type === 'entering') {
25
+ enteringAnimationForTag[tag] = style;
26
+ }
27
+ else if (type === 'layout' && enteringAnimationForTag[tag] !== null) {
28
+ const entryAniamtion = enteringAnimationForTag[tag].animations;
29
+ const layoutAnimation = style.animations;
30
+ currentAnimation = {};
31
+ for (const key in entryAniamtion) {
32
+ currentAnimation[key] = entryAniamtion[key];
33
+ }
34
+ for (const key in layoutAnimation) {
35
+ currentAnimation[key] = layoutAnimation[key];
36
+ }
37
+ enteringAnimationForTag[tag] = null;
38
+ }
39
+ const sv = configs[tag].sv;
40
+ _stopObservingProgress(tag, false);
41
+ _startObservingProgress(tag, sv);
42
+ sv._value = Object.assign({}, sv._value, style.initialValues);
43
+ _stopObservingProgress(tag, false);
44
+ const animation = withStyleAnimation(currentAnimation);
45
+ animation.callback = (finished) => {
46
+ if (finished) {
47
+ _stopObservingProgress(tag, finished);
48
+ }
49
+ style.callback && style.callback(finished);
50
+ if (type === 'entering') {
51
+ enteringAnimationForTag[tag] = null;
52
+ }
53
+ };
54
+ configs[tag].sv.value = animation;
55
+ _startObservingProgress(tag, sv);
56
+ },
57
+ };
58
+ })();
@@ -0,0 +1,69 @@
1
+ import { withDelay } from '../../animation';
2
+ export class BaseAnimationBuilder {
3
+ constructor() {
4
+ this.randomizeDelay = false;
5
+ this.build = () => {
6
+ throw Error('Unimplemented method in child class.');
7
+ };
8
+ }
9
+ static duration(durationMs) {
10
+ const instance = this.createInstance();
11
+ return instance.duration(durationMs);
12
+ }
13
+ duration(durationMs) {
14
+ this.durationV = durationMs;
15
+ return this;
16
+ }
17
+ static delay(delayMs) {
18
+ const instance = this.createInstance();
19
+ return instance.delay(delayMs);
20
+ }
21
+ delay(delayMs) {
22
+ this.delayV = delayMs;
23
+ return this;
24
+ }
25
+ static withCallback(callback) {
26
+ const instance = this.createInstance();
27
+ return instance.withCallback(callback);
28
+ }
29
+ withCallback(callback) {
30
+ this.callbackV = callback;
31
+ return this;
32
+ }
33
+ // 300ms is the default animation duration. If any animation has different default has to override this method.
34
+ static getDuration() {
35
+ return 300;
36
+ }
37
+ getDuration() {
38
+ var _a;
39
+ return (_a = this.durationV) !== null && _a !== void 0 ? _a : 300;
40
+ }
41
+ static randomDelay() {
42
+ const instance = this.createInstance();
43
+ return instance.randomDelay();
44
+ }
45
+ randomDelay() {
46
+ this.randomizeDelay = true;
47
+ return this;
48
+ }
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;
55
+ }
56
+ getDelayFunction() {
57
+ const isDelayProvided = this.randomizeDelay || this.delayV;
58
+ return isDelayProvided
59
+ ? withDelay
60
+ : (_, animation) => {
61
+ 'worklet';
62
+ return animation;
63
+ };
64
+ }
65
+ static build() {
66
+ const instance = this.createInstance();
67
+ return instance.build();
68
+ }
69
+ }