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
@@ -1,918 +0,0 @@
1
- /* global _frameTimestamp */
2
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
- // @ts-nocheck
4
- import { useEffect, useRef, useCallback } from 'react';
5
-
6
- import WorkletEventHandler from './WorkletEventHandler';
7
- import {
8
- startMapper,
9
- stopMapper,
10
- makeMutable,
11
- makeRemote,
12
- requestFrame,
13
- getTimestamp,
14
- } from './core';
15
- import updateProps, { updatePropsJestWrapper, colorProps } from './UpdateProps';
16
- import { initialUpdaterRun, cancelAnimation } from './animations';
17
- import { getTag } from './NativeMethods';
18
- import NativeReanimated from './NativeReanimated';
19
- import { Platform } from 'react-native';
20
- import { processColor } from './Colors';
21
-
22
- export function useSharedValue(init) {
23
- const ref = useRef(null);
24
- if (ref.current === null) {
25
- ref.current = makeMutable(init);
26
- }
27
-
28
- useEffect(() => {
29
- return () => {
30
- cancelAnimation(ref.current);
31
- };
32
- }, []);
33
-
34
- return ref.current;
35
- }
36
-
37
- export function useEvent(handler, eventNames = [], rebuild = false) {
38
- const initRef = useRef(null);
39
- if (initRef.current === null) {
40
- initRef.current = new WorkletEventHandler(handler, eventNames);
41
- } else if (rebuild) {
42
- initRef.current.updateWorklet(handler);
43
- }
44
-
45
- useEffect(() => {
46
- return () => {
47
- initRef.current = null;
48
- };
49
- }, []);
50
-
51
- return initRef;
52
- }
53
-
54
- function prepareAnimation(animatedProp, lastAnimation, lastValue) {
55
- 'worklet';
56
- if (Array.isArray(animatedProp)) {
57
- animatedProp.forEach((prop, index) =>
58
- prepareAnimation(
59
- prop,
60
- lastAnimation && lastAnimation[index],
61
- lastValue && lastValue[index]
62
- )
63
- );
64
- return animatedProp;
65
- }
66
- if (typeof animatedProp === 'object' && animatedProp.onFrame) {
67
- const animation = animatedProp;
68
-
69
- let value = animation.current;
70
- if (lastValue !== undefined) {
71
- if (typeof lastValue === 'object') {
72
- if (lastValue.value !== undefined) {
73
- // previously it was a shared value
74
- value = lastValue.value;
75
- } else if (lastValue.onFrame !== undefined) {
76
- if (lastAnimation?.current !== undefined) {
77
- // it was an animation before, copy its state
78
- value = lastAnimation.current;
79
- } else if (lastValue?.current !== undefined) {
80
- // it was initialized
81
- value = lastValue.current;
82
- }
83
- }
84
- } else {
85
- // previously it was a plain value, just set it as starting point
86
- value = lastValue;
87
- }
88
- }
89
-
90
- animation.callStart = (timestamp) => {
91
- animation.onStart(animation, value, timestamp, lastAnimation);
92
- };
93
- animation.callStart(getTimestamp());
94
- animation.callStart = null;
95
- } else if (typeof animatedProp === 'object') {
96
- // it is an object
97
- Object.keys(animatedProp).forEach((key) =>
98
- prepareAnimation(
99
- animatedProp[key],
100
- lastAnimation && lastAnimation[key],
101
- lastValue && lastValue[key]
102
- )
103
- );
104
- }
105
- }
106
-
107
- function runAnimations(animation, timestamp, key, result, animationsActive) {
108
- 'worklet';
109
- if (!animationsActive.value) {
110
- return true;
111
- }
112
- if (Array.isArray(animation)) {
113
- result[key] = [];
114
- let allFinished = true;
115
- animation.forEach((entry, index) => {
116
- if (
117
- !runAnimations(entry, timestamp, index, result[key], animationsActive)
118
- ) {
119
- allFinished = false;
120
- }
121
- });
122
- return allFinished;
123
- } else if (typeof animation === 'object' && animation.onFrame) {
124
- let finished = true;
125
- if (!animation.finished) {
126
- if (animation.callStart) {
127
- animation.callStart(timestamp);
128
- animation.callStart = null;
129
- }
130
- finished = animation.onFrame(animation, timestamp);
131
- animation.timestamp = timestamp;
132
- if (finished) {
133
- animation.finished = true;
134
- animation.callback && animation.callback(true /* finished */);
135
- }
136
- }
137
- result[key] = animation.current;
138
- return finished;
139
- } else if (typeof animation === 'object') {
140
- result[key] = {};
141
- let allFinished = true;
142
- Object.keys(animation).forEach((k) => {
143
- if (
144
- !runAnimations(
145
- animation[k],
146
- timestamp,
147
- k,
148
- result[key],
149
- animationsActive
150
- )
151
- ) {
152
- allFinished = false;
153
- }
154
- });
155
- return allFinished;
156
- } else {
157
- result[key] = animation;
158
- return true;
159
- }
160
- }
161
-
162
- function isAnimated(prop) {
163
- 'worklet';
164
- if (Array.isArray(prop)) {
165
- for (const item of prop) {
166
- for (const key in item) {
167
- if (item[key].onFrame !== undefined) {
168
- return true;
169
- }
170
- }
171
- }
172
- return false;
173
- }
174
- return prop?.onFrame !== undefined;
175
- }
176
-
177
- function styleDiff(oldStyle, newStyle) {
178
- 'worklet';
179
- const diff = {};
180
- Object.keys(oldStyle).forEach((key) => {
181
- if (newStyle[key] === undefined) {
182
- diff[key] = null;
183
- }
184
- });
185
- Object.keys(newStyle).forEach((key) => {
186
- const value = newStyle[key];
187
- const oldValue = oldStyle[key];
188
-
189
- if (isAnimated(value)) {
190
- // do nothing
191
- return;
192
- }
193
- if (
194
- oldValue !== value &&
195
- JSON.stringify(oldValue) !== JSON.stringify(value)
196
- ) {
197
- // I'd use deep equal here but that'd take additional work and this was easier
198
- diff[key] = value;
199
- }
200
- });
201
- return diff;
202
- }
203
-
204
- function getStyleWithoutAnimations(newStyle) {
205
- 'worklet';
206
- const diff = {};
207
-
208
- for (const key in newStyle) {
209
- const value = newStyle[key];
210
- if (isAnimated(value)) {
211
- continue;
212
- }
213
- diff[key] = value;
214
- }
215
- return diff;
216
- }
217
-
218
- const validateAnimatedStyles = (styles) => {
219
- 'worklet';
220
- if (typeof styles !== 'object') {
221
- throw new Error(
222
- `useAnimatedStyle has to return an object, found ${typeof styles} instead`
223
- );
224
- } else if (Array.isArray(styles)) {
225
- throw new Error(
226
- 'useAnimatedStyle has to return an object and cannot return static styles combined with dynamic ones. Please do merging where a component receives props.'
227
- );
228
- }
229
- };
230
-
231
- function styleUpdater(
232
- viewDescriptor,
233
- updater,
234
- state,
235
- maybeViewRef,
236
- animationsActive
237
- ) {
238
- 'worklet';
239
- const animations = state.animations || {};
240
- const newValues = updater() || {};
241
- const oldValues = state.last;
242
-
243
- let hasAnimations = false;
244
- for (const key in newValues) {
245
- const value = newValues[key];
246
- if (isAnimated(value)) {
247
- prepareAnimation(value, animations[key], oldValues[key]);
248
- animations[key] = value;
249
- hasAnimations = true;
250
- } else {
251
- delete animations[key];
252
- }
253
- }
254
-
255
- if (hasAnimations) {
256
- const frame = (timestamp) => {
257
- const { animations, last, isAnimationCancelled } = state;
258
- if (isAnimationCancelled) {
259
- state.isAnimationRunning = false;
260
- return;
261
- }
262
-
263
- const updates = {};
264
- let allFinished = true;
265
- for (const propName in animations) {
266
- const finished = runAnimations(
267
- animations[propName],
268
- timestamp,
269
- propName,
270
- updates,
271
- animationsActive
272
- );
273
- if (finished) {
274
- last[propName] = updates[propName];
275
- delete animations[propName];
276
- } else {
277
- allFinished = false;
278
- }
279
- }
280
-
281
- if (updates) {
282
- updateProps(viewDescriptor, updates, maybeViewRef);
283
- }
284
-
285
- if (!allFinished) {
286
- requestFrame(frame);
287
- } else {
288
- state.isAnimationRunning = false;
289
- }
290
- };
291
-
292
- state.animations = animations;
293
- if (!state.isAnimationRunning) {
294
- state.isAnimationCancelled = false;
295
- state.isAnimationRunning = true;
296
- if (_frameTimestamp) {
297
- frame(_frameTimestamp);
298
- } else {
299
- requestFrame(frame);
300
- }
301
- }
302
- state.last = Object.assign({}, oldValues, newValues);
303
- const style = getStyleWithoutAnimations(oldValues, newValues);
304
- if (style) {
305
- updateProps(viewDescriptor, style, maybeViewRef);
306
- }
307
- } else {
308
- state.isAnimationCancelled = true;
309
- state.animations = {};
310
- updateProps(viewDescriptor, newValues, maybeViewRef);
311
- }
312
- }
313
-
314
- function jestStyleUpdater(
315
- viewDescriptor,
316
- updater,
317
- state,
318
- maybeViewRef,
319
- animationsActive,
320
- animatedStyle,
321
- adapters = []
322
- ) {
323
- 'worklet';
324
- const animations = state.animations || {};
325
- const newValues = updater() || {};
326
- const oldValues = state.last;
327
-
328
- // extract animated props
329
- let hasAnimations = false;
330
- Object.keys(animations).forEach((key) => {
331
- const value = newValues[key];
332
- if (!isAnimated(value)) {
333
- delete animations[key];
334
- }
335
- });
336
- Object.keys(newValues).forEach((key) => {
337
- const value = newValues[key];
338
- if (isAnimated(value)) {
339
- prepareAnimation(value, animations[key], oldValues[key]);
340
- animations[key] = value;
341
- hasAnimations = true;
342
- }
343
- });
344
-
345
- function frame(timestamp) {
346
- const { animations, last, isAnimationCancelled } = state;
347
- if (isAnimationCancelled) {
348
- state.isAnimationRunning = false;
349
- return;
350
- }
351
-
352
- const updates = {};
353
- let allFinished = true;
354
- Object.keys(animations).forEach((propName) => {
355
- const finished = runAnimations(
356
- animations[propName],
357
- timestamp,
358
- propName,
359
- updates,
360
- animationsActive
361
- );
362
- if (finished) {
363
- last[propName] = updates[propName];
364
- delete animations[propName];
365
- } else {
366
- allFinished = false;
367
- }
368
- });
369
-
370
- if (Object.keys(updates).length) {
371
- updatePropsJestWrapper(
372
- viewDescriptor,
373
- updates,
374
- maybeViewRef,
375
- animatedStyle,
376
- adapters
377
- );
378
- }
379
-
380
- if (!allFinished) {
381
- requestFrame(frame);
382
- } else {
383
- state.isAnimationRunning = false;
384
- }
385
- }
386
-
387
- if (hasAnimations) {
388
- state.animations = animations;
389
- if (!state.isAnimationRunning) {
390
- state.isAnimationCancelled = false;
391
- state.isAnimationRunning = true;
392
- if (_frameTimestamp) {
393
- frame(_frameTimestamp);
394
- } else {
395
- requestFrame(frame);
396
- }
397
- }
398
- } else {
399
- state.isAnimationCancelled = true;
400
- state.animations = {};
401
- }
402
-
403
- // calculate diff
404
- const diff = styleDiff(oldValues, newValues);
405
- state.last = Object.assign({}, oldValues, newValues);
406
-
407
- if (Object.keys(diff).length !== 0) {
408
- updatePropsJestWrapper(
409
- viewDescriptor,
410
- diff,
411
- maybeViewRef,
412
- animatedStyle,
413
- adapters
414
- );
415
- }
416
- }
417
- const colorPropsSet = new Set(colorProps);
418
- const hasColorProps = (updates) => {
419
- for (const key in updates) {
420
- if (colorPropsSet.has(key)) {
421
- return true;
422
- }
423
- }
424
- return false;
425
- };
426
-
427
- const parseColors = (updates) => {
428
- 'worklet';
429
- for (const key in updates) {
430
- if (colorProps.indexOf(key) !== -1) {
431
- updates[key] = processColor(updates[key]);
432
- }
433
- }
434
- };
435
-
436
- const canApplyOptimalisation = (upadterFn) => {
437
- const FUNCTIONLESS_FLAG = 0b00000001;
438
- const STATEMENTLESS_FLAG = 0b00000010;
439
- const optimalization = upadterFn.__optimalization;
440
- return (
441
- optimalization & FUNCTIONLESS_FLAG && optimalization & STATEMENTLESS_FLAG
442
- );
443
- };
444
-
445
- export function useAnimatedStyle(updater, dependencies, adapters) {
446
- const viewDescriptor = useSharedValue({ tag: -1, name: null }, false);
447
- const initRef = useRef(null);
448
- const inputs = Object.values(updater._closure);
449
- const viewRef = useRef(null);
450
- adapters = !adapters || Array.isArray(adapters) ? adapters : [adapters];
451
- const adaptersHash = adapters ? buildWorkletsHash(adapters) : null;
452
- const animationsActive = useSharedValue(true);
453
- let animatedStyle;
454
- if (process.env.JEST_WORKER_ID) {
455
- animatedStyle = useRef({});
456
- }
457
-
458
- // build dependencies
459
- if (!dependencies) {
460
- dependencies = [...inputs, updater.__workletHash];
461
- } else {
462
- dependencies.push(updater.__workletHash);
463
- }
464
- adaptersHash && dependencies.push(adaptersHash);
465
-
466
- if (initRef.current === null) {
467
- const initial = initialUpdaterRun(updater);
468
- validateAnimatedStyles(initial);
469
- initRef.current = {
470
- initial,
471
- remoteState: makeRemote({ last: initial }),
472
- };
473
- }
474
-
475
- const { remoteState, initial } = initRef.current;
476
- const maybeViewRef = NativeReanimated.native ? undefined : viewRef;
477
-
478
- useEffect(() => {
479
- let fun;
480
- let upadterFn = updater;
481
- let optimalization = updater.__optimalization;
482
- if (adapters) {
483
- upadterFn = () => {
484
- 'worklet';
485
- const newValues = updater();
486
- adapters.forEach((adapter) => {
487
- adapter(newValues);
488
- });
489
- return newValues;
490
- };
491
- }
492
-
493
- if (canApplyOptimalisation(upadterFn) && Platform.OS !== 'web') {
494
- if (hasColorProps(upadterFn())) {
495
- upadterFn = () => {
496
- 'worklet';
497
- const style = upadterFn();
498
- parseColors(style);
499
- return style;
500
- };
501
- }
502
- } else if (Platform.OS !== 'web') {
503
- optimalization = 0;
504
- upadterFn = () => {
505
- 'worklet';
506
- const style = upadterFn();
507
- parseColors(style);
508
- return style;
509
- };
510
- }
511
- if (typeof updater.__optimalization !== undefined) {
512
- upadterFn.__optimalization = optimalization;
513
- }
514
-
515
- if (process.env.JEST_WORKER_ID) {
516
- fun = () => {
517
- 'worklet';
518
- jestStyleUpdater(
519
- viewDescriptor,
520
- updater,
521
- remoteState,
522
- maybeViewRef,
523
- animationsActive,
524
- animatedStyle,
525
- adapters
526
- );
527
- };
528
- } else {
529
- fun = () => {
530
- 'worklet';
531
- styleUpdater(
532
- viewDescriptor,
533
- upadterFn,
534
- remoteState,
535
- maybeViewRef,
536
- animationsActive
537
- );
538
- };
539
- }
540
- const mapperId = startMapper(
541
- fun,
542
- inputs,
543
- [],
544
- upadterFn,
545
- viewDescriptor.value.tag,
546
- viewDescriptor.value.name || 'RCTView'
547
- );
548
- return () => {
549
- stopMapper(mapperId);
550
- };
551
- }, dependencies);
552
-
553
- useEffect(() => {
554
- animationsActive.value = true;
555
- return () => {
556
- initRef.current = null;
557
- viewRef.current = null;
558
- animationsActive.value = false;
559
- };
560
- }, []);
561
-
562
- // check for invalid usage of shared values in returned object
563
- let wrongKey;
564
- const isObjectValid = (element, key) => {
565
- const result = typeof element === 'object' && element.value !== undefined;
566
- if (result) {
567
- wrongKey = key;
568
- }
569
- return !result;
570
- };
571
- const isError = Object.keys(initial).some((key) => {
572
- const element = initial[key];
573
- let result = false;
574
- // a case for transform that has a format of an array of objects
575
- if (Array.isArray(element)) {
576
- for (const elementArrayItem of element) {
577
- // this means unhandled format and it doesn't match the transform format
578
- if (typeof elementArrayItem !== 'object') {
579
- break;
580
- }
581
- const objectValue = Object.values(elementArrayItem)[0];
582
- result = isObjectValid(objectValue, key);
583
- if (!result) {
584
- break;
585
- }
586
- }
587
- } else {
588
- result = isObjectValid(element, key);
589
- }
590
- return !result;
591
- });
592
- if (isError && wrongKey !== undefined) {
593
- throw new Error(
594
- `invalid value passed to \`${wrongKey}\`, maybe you forgot to use \`.value\`?`
595
- );
596
- }
597
-
598
- if (process.env.JEST_WORKER_ID) {
599
- return { viewDescriptor, initial, viewRef, animatedStyle };
600
- } else {
601
- return { viewDescriptor, initial, viewRef };
602
- }
603
- }
604
-
605
- // TODO: we should make sure that when useAP is used we are not assigning styles
606
- // when you need styles to animated you should always use useAS
607
- export const useAnimatedProps = useAnimatedStyle;
608
-
609
- export function useDerivedValue(processor, dependencies) {
610
- const initRef = useRef(null);
611
- const inputs = Object.values(processor._closure);
612
-
613
- // build dependencies
614
- if (dependencies === undefined) {
615
- dependencies = [...inputs, processor.__workletHash];
616
- } else {
617
- dependencies.push(processor.__workletHash);
618
- }
619
-
620
- if (initRef.current === null) {
621
- initRef.current = makeMutable(initialUpdaterRun(processor));
622
- }
623
-
624
- const sharedValue = initRef.current;
625
-
626
- useEffect(() => {
627
- const fun = () => {
628
- 'worklet';
629
- sharedValue.value = processor();
630
- };
631
- const mapperId = startMapper(fun, inputs, [sharedValue]);
632
- return () => {
633
- stopMapper(mapperId);
634
- };
635
- }, dependencies);
636
-
637
- useEffect(() => {
638
- return () => {
639
- initRef.current = null;
640
- };
641
- }, []);
642
-
643
- return sharedValue;
644
- }
645
-
646
- // builds one big hash from multiple worklets' hashes
647
- function buildWorkletsHash(handlers) {
648
- return Object.keys(handlers).reduce(
649
- (previousValue, key) =>
650
- previousValue === null
651
- ? handlers[key].__workletHash
652
- : previousValue.toString() + handlers[key].__workletHash.toString(),
653
- null
654
- );
655
- }
656
-
657
- // builds dependencies array for gesture handlers
658
- function buildDependencies(dependencies, handlers) {
659
- if (!dependencies) {
660
- dependencies = Object.keys(handlers).map((handlerKey) => {
661
- const handler = handlers[handlerKey];
662
- return {
663
- workletHash: handler.__workletHash,
664
- closure: handler._closure,
665
- };
666
- });
667
- } else {
668
- dependencies.push(buildWorkletsHash(handlers));
669
- }
670
- return dependencies;
671
- }
672
-
673
- // this is supposed to work as useEffect comparison
674
- function areDependenciesEqual(nextDeps, prevDeps) {
675
- function is(x, y) {
676
- /* eslint-disable no-self-compare */
677
- return (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y);
678
- /* eslint-enable no-self-compare */
679
- }
680
- const objectIs = typeof Object.is === 'function' ? Object.is : is;
681
-
682
- function areHookInputsEqual(nextDeps, prevDeps) {
683
- if (!nextDeps || !prevDeps || prevDeps.length !== nextDeps.length) {
684
- return false;
685
- }
686
- for (let i = 0; i < prevDeps.length; ++i) {
687
- if (!objectIs(nextDeps[i], prevDeps[i])) {
688
- return false;
689
- }
690
- }
691
- return true;
692
- }
693
-
694
- return areHookInputsEqual(nextDeps, prevDeps);
695
- }
696
-
697
- export function useAnimatedGestureHandler(handlers, dependencies) {
698
- const initRef = useRef(null);
699
- if (initRef.current === null) {
700
- initRef.current = {
701
- context: makeRemote({}),
702
- savedDependencies: [],
703
- };
704
- }
705
-
706
- useEffect(() => {
707
- return () => {
708
- initRef.current = null;
709
- };
710
- }, []);
711
-
712
- const { context, savedDependencies } = initRef.current;
713
-
714
- dependencies = buildDependencies(dependencies, handlers);
715
-
716
- const dependenciesDiffer = !areDependenciesEqual(
717
- dependencies,
718
- savedDependencies
719
- );
720
- initRef.current.savedDependencies = dependencies;
721
-
722
- const handler = (event) => {
723
- 'worklet';
724
- event = Platform.OS === 'web' ? event.nativeEvent : event;
725
-
726
- const FAILED = 1;
727
- const BEGAN = 2;
728
- const CANCELLED = 3;
729
- const ACTIVE = 4;
730
- const END = 5;
731
-
732
- if (event.state === BEGAN && handlers.onStart) {
733
- handlers.onStart(event, context);
734
- }
735
- if (event.state === ACTIVE && handlers.onActive) {
736
- handlers.onActive(event, context);
737
- }
738
- if (event.oldState === ACTIVE && event.state === END && handlers.onEnd) {
739
- handlers.onEnd(event, context);
740
- }
741
- if (event.oldState === BEGAN && event.state === FAILED && handlers.onFail) {
742
- handlers.onFail(event, context);
743
- }
744
- if (
745
- event.oldState === ACTIVE &&
746
- event.state === CANCELLED &&
747
- handlers.onCancel
748
- ) {
749
- handlers.onCancel(event, context);
750
- }
751
- if (
752
- (event.oldState === BEGAN || event.oldState === ACTIVE) &&
753
- event.state !== BEGAN &&
754
- event.state !== ACTIVE &&
755
- handlers.onFinish
756
- ) {
757
- handlers.onFinish(
758
- event,
759
- context,
760
- event.state === CANCELLED || event.state === FAILED
761
- );
762
- }
763
- };
764
-
765
- if (Platform.OS === 'web') {
766
- return handler;
767
- }
768
-
769
- return useEvent(
770
- handler,
771
- ['onGestureHandlerStateChange', 'onGestureHandlerEvent'],
772
- dependenciesDiffer
773
- );
774
- }
775
-
776
- export function useAnimatedScrollHandler(handlers, dependencies) {
777
- const initRef = useRef(null);
778
- if (initRef.current === null) {
779
- initRef.current = {
780
- context: makeRemote({}),
781
- savedDependencies: [],
782
- };
783
- }
784
-
785
- useEffect(() => {
786
- return () => {
787
- initRef.current = null;
788
- };
789
- }, []);
790
-
791
- const { context, savedDependencies } = initRef.current;
792
-
793
- dependencies = buildDependencies(dependencies, handlers);
794
-
795
- const dependenciesDiffer = !areDependenciesEqual(
796
- dependencies,
797
- savedDependencies
798
- );
799
- initRef.current.savedDependencies = dependencies;
800
-
801
- // build event subscription array
802
- const subscribeForEvents = ['onScroll'];
803
- if (handlers.onBeginDrag !== undefined) {
804
- subscribeForEvents.push('onScrollBeginDrag');
805
- }
806
- if (handlers.onEndDrag !== undefined) {
807
- subscribeForEvents.push('onScrollEndDrag');
808
- }
809
- if (handlers.onMomentumBegin !== undefined) {
810
- subscribeForEvents.push('onMomentumScrollBegin');
811
- }
812
- if (handlers.onMomentumEnd !== undefined) {
813
- subscribeForEvents.push('onMomentumScrollEnd');
814
- }
815
-
816
- return useEvent(
817
- (event) => {
818
- 'worklet';
819
- const {
820
- onScroll,
821
- onBeginDrag,
822
- onEndDrag,
823
- onMomentumBegin,
824
- onMomentumEnd,
825
- } = handlers;
826
- if (event.eventName.endsWith('onScroll')) {
827
- if (onScroll) {
828
- onScroll(event, context);
829
- } else if (typeof handlers === 'function') {
830
- handlers(event, context);
831
- }
832
- } else if (onBeginDrag && event.eventName.endsWith('onScrollBeginDrag')) {
833
- onBeginDrag(event, context);
834
- } else if (onEndDrag && event.eventName.endsWith('onScrollEndDrag')) {
835
- onEndDrag(event, context);
836
- } else if (
837
- onMomentumBegin &&
838
- event.eventName.endsWith('onMomentumScrollBegin')
839
- ) {
840
- onMomentumBegin(event, context);
841
- } else if (
842
- onMomentumEnd &&
843
- event.eventName.endsWith('onMomentumScrollEnd')
844
- ) {
845
- onMomentumEnd(event, context);
846
- }
847
- },
848
- subscribeForEvents,
849
- dependenciesDiffer
850
- );
851
- }
852
-
853
- export function useAnimatedRef() {
854
- const tag = useSharedValue(-1);
855
- const ref = useRef(null);
856
-
857
- if (!ref.current) {
858
- const fun = function (component) {
859
- 'worklet';
860
- // enters when ref is set by attaching to a component
861
- if (component) {
862
- tag.value = getTag(component);
863
- fun.current = component;
864
- }
865
- return tag.value;
866
- };
867
-
868
- Object.defineProperty(fun, 'current', {
869
- value: null,
870
- writable: true,
871
- enumerable: false,
872
- });
873
- ref.current = fun;
874
- }
875
-
876
- return ref.current;
877
- }
878
-
879
- /**
880
- * @param prepare - worklet used for data preparation for the second parameter
881
- * @param react - worklet which takes data prepared by the one in the first parameter and performs certain actions
882
- * the first worklet defines the inputs, in other words on which shared values change will it be called.
883
- * the second one can modify any shared values but those which are mentioned in the first worklet. Beware of that, because this may result in endless loop and high cpu usage.
884
- */
885
- export function useAnimatedReaction(prepare, react, dependencies) {
886
- const previous = useSharedValue(null);
887
- if (dependencies === undefined) {
888
- dependencies = [
889
- Object.values(prepare._closure),
890
- Object.values(react._closure),
891
- prepare.__workletHash,
892
- react.__workletHash,
893
- ];
894
- } else {
895
- dependencies.push(prepare.__workletHash, react.__workletHash);
896
- }
897
-
898
- useEffect(() => {
899
- const fun = () => {
900
- 'worklet';
901
- const input = prepare();
902
- react(input, previous.value);
903
- previous.value = input;
904
- };
905
- const mapperId = startMapper(fun, Object.values(prepare._closure), []);
906
- return () => {
907
- stopMapper(mapperId);
908
- };
909
- }, dependencies);
910
- }
911
-
912
- export function useWorkletCallback(fun, deps) {
913
- return useCallback(fun, deps);
914
- }
915
-
916
- export function createWorklet(fun) {
917
- return fun;
918
- }