react-native-reanimated 3.0.0-rc.9 → 3.0.0

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 (329) hide show
  1. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +30 -12
  2. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.h +2 -0
  3. package/Common/cpp/Fabric/FabricUtils.cpp +3 -107
  4. package/Common/cpp/Fabric/FabricUtils.h +3 -24
  5. package/Common/cpp/Fabric/ReanimatedUIManagerBinding.cpp +54 -37
  6. package/Common/cpp/LayoutAnimations/LayoutAnimationType.h +8 -0
  7. package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.cpp +81 -26
  8. package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.h +20 -3
  9. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +105 -109
  10. package/Common/cpp/NativeModules/NativeReanimatedModule.h +19 -12
  11. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +15 -7
  12. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.h +6 -2
  13. package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.cpp +20 -1
  14. package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.h +9 -0
  15. package/Common/cpp/ReanimatedRuntime/ReanimatedRuntime.cpp +5 -1
  16. package/Common/cpp/Registries/EventHandlerRegistry.cpp +8 -34
  17. package/Common/cpp/Registries/EventHandlerRegistry.h +7 -13
  18. package/Common/cpp/SharedItems/Shareables.cpp +9 -63
  19. package/Common/cpp/SharedItems/Shareables.h +77 -72
  20. package/Common/cpp/Tools/CollectionUtils.h +14 -0
  21. package/Common/cpp/Tools/JsiUtils.cpp +26 -0
  22. package/Common/cpp/Tools/JsiUtils.h +176 -0
  23. package/Common/cpp/Tools/PlatformDepMethodsHolder.h +5 -5
  24. package/Common/cpp/Tools/ReanimatedVersion.cpp +17 -0
  25. package/Common/cpp/Tools/ReanimatedVersion.h +11 -0
  26. package/Common/cpp/Tools/RuntimeDecorator.cpp +49 -230
  27. package/Common/cpp/Tools/RuntimeDecorator.h +0 -2
  28. package/Common/cpp/Tools/WorkletEventHandler.cpp +3 -2
  29. package/Common/cpp/Tools/WorkletEventHandler.h +14 -6
  30. package/RNReanimated.podspec +2 -1
  31. package/android/CMakeLists.txt +188 -181
  32. package/android/build.gradle +362 -311
  33. package/android/proguard-rules.pro +2 -0
  34. package/android/src/fabric/java/com/swmansion/reanimated/NativeProxy.java +63 -295
  35. package/android/src/main/cpp/LayoutAnimations.cpp +35 -5
  36. package/android/src/main/cpp/LayoutAnimations.h +23 -6
  37. package/android/src/main/cpp/NativeProxy.cpp +143 -98
  38. package/android/src/main/cpp/NativeProxy.h +22 -28
  39. package/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java +5 -4
  40. package/android/src/main/java/com/swmansion/reanimated/Utils.java +7 -1
  41. package/android/src/main/java/com/swmansion/reanimated/keyboardObserver/ReanimatedKeyboardEventListener.java +10 -3
  42. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java +218 -35
  43. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/LayoutAnimations.java +43 -17
  44. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/NativeMethodsHolder.java +6 -2
  45. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/SharedElement.java +19 -0
  46. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/SharedTransitionManager.java +610 -0
  47. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/Snapshot.java +93 -23
  48. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/AnimationFrameCallback.java +19 -0
  49. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/EventHandler.java +35 -0
  50. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/KeyboardEventDataUpdater.java +16 -0
  51. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/NativeProxyCommon.java +206 -0
  52. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/SensorSetter.java +17 -0
  53. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensor.java +9 -3
  54. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorContainer.java +3 -4
  55. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.java +31 -7
  56. package/android/src/paper/java/com/swmansion/reanimated/NativeProxy.java +90 -307
  57. package/android/src/reactNativeVersionPatch/ReanimatedUIManager/70/com/swmansion/reanimated/ReanimatedUIManagerFactory.java +16 -0
  58. package/android/src/reactNativeVersionPatch/ReanimatedUIManager/latest/com/swmansion/reanimated/ReanimatedUIManagerFactory.java +63 -0
  59. package/android/src/reactNativeVersionPatch/ReanimatedUIManager/latest/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +271 -0
  60. package/android/src/reactNativeVersionPatch/nativeHierarchyManager/latest/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +76 -20
  61. package/ios/LayoutReanimation/REAAnimationsManager.h +28 -4
  62. package/ios/LayoutReanimation/REAAnimationsManager.m +216 -61
  63. package/ios/LayoutReanimation/REAFrame.h +10 -0
  64. package/ios/LayoutReanimation/REAFrame.m +15 -0
  65. package/ios/LayoutReanimation/REAScreensHelper.h +19 -0
  66. package/ios/LayoutReanimation/REAScreensHelper.m +106 -0
  67. package/ios/LayoutReanimation/REASharedElement.h +15 -0
  68. package/ios/LayoutReanimation/REASharedElement.m +16 -0
  69. package/ios/LayoutReanimation/REASharedTransitionManager.h +17 -0
  70. package/ios/LayoutReanimation/REASharedTransitionManager.m +632 -0
  71. package/ios/LayoutReanimation/REASnapshot.h +1 -0
  72. package/ios/LayoutReanimation/REASnapshot.m +96 -11
  73. package/ios/LayoutReanimation/REAUIManager.mm +64 -17
  74. package/ios/REAModule.mm +2 -7
  75. package/ios/REANodesManager.mm +1 -21
  76. package/ios/keyboardObserver/REAKeyboardEventObserver.m +72 -36
  77. package/ios/native/NativeProxy.mm +75 -114
  78. package/ios/native/REAInitializer.mm +2 -7
  79. package/ios/native/REAJSIUtils.h +60 -2
  80. package/ios/sensor/ReanimatedSensor.h +6 -2
  81. package/ios/sensor/ReanimatedSensor.m +43 -7
  82. package/ios/sensor/ReanimatedSensorContainer.h +4 -1
  83. package/ios/sensor/ReanimatedSensorContainer.m +8 -2
  84. package/lib/commonjs/createAnimatedComponent.js +232 -28
  85. package/lib/commonjs/createAnimatedComponent.js.map +1 -1
  86. package/lib/commonjs/reanimated2/Colors.js +43 -22
  87. package/lib/commonjs/reanimated2/Colors.js.map +1 -1
  88. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js +16 -33
  89. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  90. package/lib/commonjs/reanimated2/animation/styleAnimation.js +5 -1
  91. package/lib/commonjs/reanimated2/animation/styleAnimation.js.map +1 -1
  92. package/lib/commonjs/reanimated2/animation/util.js +17 -15
  93. package/lib/commonjs/reanimated2/animation/util.js.map +1 -1
  94. package/lib/commonjs/reanimated2/commonTypes.js +33 -1
  95. package/lib/commonjs/reanimated2/commonTypes.js.map +1 -1
  96. package/lib/commonjs/reanimated2/core.js +33 -14
  97. package/lib/commonjs/reanimated2/core.js.map +1 -1
  98. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js +2 -2
  99. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
  100. package/lib/commonjs/reanimated2/globals.d.js.map +1 -1
  101. package/lib/commonjs/reanimated2/hook/index.js +0 -6
  102. package/lib/commonjs/reanimated2/hook/index.js.map +1 -1
  103. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js +5 -2
  104. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  105. package/lib/commonjs/reanimated2/hook/useAnimatedReaction.js +13 -1
  106. package/lib/commonjs/reanimated2/hook/useAnimatedReaction.js.map +1 -1
  107. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js +1 -1
  108. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js.map +1 -1
  109. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js +89 -16
  110. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  111. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js +43 -40
  112. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  113. package/lib/commonjs/reanimated2/hook/useDerivedValue.js +13 -1
  114. package/lib/commonjs/reanimated2/hook/useDerivedValue.js.map +1 -1
  115. package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js +2 -2
  116. package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js.map +1 -1
  117. package/lib/commonjs/reanimated2/hook/utils.js +18 -65
  118. package/lib/commonjs/reanimated2/hook/utils.js.map +1 -1
  119. package/lib/commonjs/reanimated2/index.js +13 -0
  120. package/lib/commonjs/reanimated2/index.js.map +1 -1
  121. package/lib/commonjs/reanimated2/initializers.js +71 -32
  122. package/lib/commonjs/reanimated2/initializers.js.map +1 -1
  123. package/lib/commonjs/reanimated2/interpolateColor.js +96 -19
  124. package/lib/commonjs/reanimated2/interpolateColor.js.map +1 -1
  125. package/lib/commonjs/reanimated2/jestUtils.js +1 -1
  126. package/lib/commonjs/reanimated2/jestUtils.js.map +1 -1
  127. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js +103 -13
  128. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  129. package/lib/commonjs/reanimated2/js-reanimated/Mapper.js +22 -0
  130. package/lib/commonjs/reanimated2/js-reanimated/Mapper.js.map +1 -1
  131. package/lib/commonjs/reanimated2/js-reanimated/WebSensor.js +2 -0
  132. package/lib/commonjs/reanimated2/js-reanimated/WebSensor.js.map +1 -0
  133. package/lib/commonjs/reanimated2/js-reanimated/commonTypes.js.map +1 -1
  134. package/lib/commonjs/reanimated2/js-reanimated/global.js +0 -2
  135. package/lib/commonjs/reanimated2/js-reanimated/global.js.map +1 -1
  136. package/lib/commonjs/reanimated2/js-reanimated/index.js +0 -1
  137. package/lib/commonjs/reanimated2/js-reanimated/index.js.map +1 -1
  138. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +11 -0
  139. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  140. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js +8 -0
  141. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  142. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js +17 -9
  143. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
  144. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +16 -23
  145. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
  146. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -14
  147. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
  148. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -14
  149. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
  150. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Slide.js +8 -15
  151. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
  152. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +16 -23
  153. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
  154. package/lib/commonjs/reanimated2/layoutReanimation/index.js +13 -0
  155. package/lib/commonjs/reanimated2/layoutReanimation/index.js.map +1 -1
  156. package/lib/commonjs/reanimated2/layoutReanimation/sharedTransitions/index.js +94 -0
  157. package/lib/commonjs/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -0
  158. package/lib/commonjs/reanimated2/mappers.js +18 -6
  159. package/lib/commonjs/reanimated2/mappers.js.map +1 -1
  160. package/lib/commonjs/reanimated2/mock.js +20 -1
  161. package/lib/commonjs/reanimated2/mock.js.map +1 -1
  162. package/lib/commonjs/reanimated2/mutables.js +4 -2
  163. package/lib/commonjs/reanimated2/mutables.js.map +1 -1
  164. package/lib/commonjs/reanimated2/platform-specific/checkVersion.js +42 -0
  165. package/lib/commonjs/reanimated2/platform-specific/checkVersion.js.map +1 -0
  166. package/lib/commonjs/reanimated2/platform-specific/checkVersion.web.js +15 -0
  167. package/lib/commonjs/reanimated2/platform-specific/checkVersion.web.js.map +1 -0
  168. package/lib/commonjs/reanimated2/pluginUtils.js +11 -0
  169. package/lib/commonjs/reanimated2/pluginUtils.js.map +1 -0
  170. package/lib/commonjs/reanimated2/shareables.js +36 -15
  171. package/lib/commonjs/reanimated2/shareables.js.map +1 -1
  172. package/lib/commonjs/reanimated2/threads.js +114 -4
  173. package/lib/commonjs/reanimated2/threads.js.map +1 -1
  174. package/lib/commonjs/reanimated2/utils.js +7 -0
  175. package/lib/commonjs/reanimated2/utils.js.map +1 -1
  176. package/lib/commonjs/reanimated2/valueSetter.js +1 -3
  177. package/lib/commonjs/reanimated2/valueSetter.js.map +1 -1
  178. package/lib/module/createAnimatedComponent.js +229 -29
  179. package/lib/module/createAnimatedComponent.js.map +1 -1
  180. package/lib/module/reanimated2/Colors.js +35 -19
  181. package/lib/module/reanimated2/Colors.js.map +1 -1
  182. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js +16 -32
  183. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  184. package/lib/module/reanimated2/animation/styleAnimation.js +5 -1
  185. package/lib/module/reanimated2/animation/styleAnimation.js.map +1 -1
  186. package/lib/module/reanimated2/animation/util.js +17 -16
  187. package/lib/module/reanimated2/animation/util.js.map +1 -1
  188. package/lib/module/reanimated2/commonTypes.js +29 -0
  189. package/lib/module/reanimated2/commonTypes.js.map +1 -1
  190. package/lib/module/reanimated2/core.js +32 -7
  191. package/lib/module/reanimated2/core.js.map +1 -1
  192. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js +2 -2
  193. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
  194. package/lib/module/reanimated2/globals.d.js.map +1 -1
  195. package/lib/module/reanimated2/hook/index.js +1 -1
  196. package/lib/module/reanimated2/hook/index.js.map +1 -1
  197. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js +5 -2
  198. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  199. package/lib/module/reanimated2/hook/useAnimatedReaction.js +12 -1
  200. package/lib/module/reanimated2/hook/useAnimatedReaction.js.map +1 -1
  201. package/lib/module/reanimated2/hook/useAnimatedRef.js +2 -2
  202. package/lib/module/reanimated2/hook/useAnimatedRef.js.map +1 -1
  203. package/lib/module/reanimated2/hook/useAnimatedSensor.js +88 -13
  204. package/lib/module/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  205. package/lib/module/reanimated2/hook/useAnimatedStyle.js +46 -43
  206. package/lib/module/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  207. package/lib/module/reanimated2/hook/useDerivedValue.js +12 -1
  208. package/lib/module/reanimated2/hook/useDerivedValue.js.map +1 -1
  209. package/lib/module/reanimated2/hook/useScrollViewOffset.js +2 -2
  210. package/lib/module/reanimated2/hook/useScrollViewOffset.js.map +1 -1
  211. package/lib/module/reanimated2/hook/utils.js +17 -60
  212. package/lib/module/reanimated2/hook/utils.js.map +1 -1
  213. package/lib/module/reanimated2/index.js +1 -0
  214. package/lib/module/reanimated2/index.js.map +1 -1
  215. package/lib/module/reanimated2/initializers.js +72 -33
  216. package/lib/module/reanimated2/initializers.js.map +1 -1
  217. package/lib/module/reanimated2/interpolateColor.js +96 -19
  218. package/lib/module/reanimated2/interpolateColor.js.map +1 -1
  219. package/lib/module/reanimated2/jestUtils.js +1 -1
  220. package/lib/module/reanimated2/jestUtils.js.map +1 -1
  221. package/lib/module/reanimated2/js-reanimated/JSReanimated.js +103 -13
  222. package/lib/module/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  223. package/lib/module/reanimated2/js-reanimated/Mapper.js +21 -0
  224. package/lib/module/reanimated2/js-reanimated/Mapper.js.map +1 -1
  225. package/lib/module/reanimated2/js-reanimated/WebSensor.js +2 -0
  226. package/lib/module/reanimated2/js-reanimated/WebSensor.js.map +1 -0
  227. package/lib/module/reanimated2/js-reanimated/commonTypes.js.map +1 -1
  228. package/lib/module/reanimated2/js-reanimated/global.js +0 -2
  229. package/lib/module/reanimated2/js-reanimated/global.js.map +1 -1
  230. package/lib/module/reanimated2/js-reanimated/index.js +0 -1
  231. package/lib/module/reanimated2/js-reanimated/index.js.map +1 -1
  232. package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +9 -1
  233. package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  234. package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js +1 -0
  235. package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  236. package/lib/module/reanimated2/layoutReanimation/animationsManager.js +15 -8
  237. package/lib/module/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
  238. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +16 -21
  239. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
  240. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -12
  241. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
  242. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -12
  243. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
  244. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js +8 -13
  245. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
  246. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +16 -21
  247. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
  248. package/lib/module/reanimated2/layoutReanimation/index.js +1 -0
  249. package/lib/module/reanimated2/layoutReanimation/index.js.map +1 -1
  250. package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js +82 -0
  251. package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -0
  252. package/lib/module/reanimated2/mappers.js +16 -6
  253. package/lib/module/reanimated2/mappers.js.map +1 -1
  254. package/lib/module/reanimated2/mock.js +20 -1
  255. package/lib/module/reanimated2/mock.js.map +1 -1
  256. package/lib/module/reanimated2/mutables.js +4 -2
  257. package/lib/module/reanimated2/mutables.js.map +1 -1
  258. package/lib/module/reanimated2/platform-specific/checkVersion.js +35 -0
  259. package/lib/module/reanimated2/platform-specific/checkVersion.js.map +1 -0
  260. package/lib/module/reanimated2/platform-specific/checkVersion.web.js +8 -0
  261. package/lib/module/reanimated2/platform-specific/checkVersion.web.js.map +1 -0
  262. package/lib/module/reanimated2/pluginUtils.js +4 -0
  263. package/lib/module/reanimated2/pluginUtils.js.map +1 -0
  264. package/lib/module/reanimated2/shareables.js +36 -12
  265. package/lib/module/reanimated2/shareables.js.map +1 -1
  266. package/lib/module/reanimated2/threads.js +105 -4
  267. package/lib/module/reanimated2/threads.js.map +1 -1
  268. package/lib/module/reanimated2/utils.js +5 -0
  269. package/lib/module/reanimated2/utils.js.map +1 -1
  270. package/lib/module/reanimated2/valueSetter.js +1 -2
  271. package/lib/module/reanimated2/valueSetter.js.map +1 -1
  272. package/package.json +10 -10
  273. package/{plugin.js → plugin/index.js} +128 -249
  274. package/react-native-reanimated.d.ts +57 -10
  275. package/scripts/reanimated_utils.rb +15 -2
  276. package/src/createAnimatedComponent.tsx +238 -28
  277. package/src/reanimated2/Colors.ts +38 -11
  278. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +52 -39
  279. package/src/reanimated2/animation/styleAnimation.ts +8 -1
  280. package/src/reanimated2/animation/util.ts +29 -16
  281. package/src/reanimated2/commonTypes.ts +28 -1
  282. package/src/reanimated2/core.ts +42 -9
  283. package/src/reanimated2/frameCallback/FrameCallbackRegistryUI.ts +2 -2
  284. package/src/reanimated2/globals.d.ts +12 -15
  285. package/src/reanimated2/hook/index.ts +1 -1
  286. package/src/reanimated2/hook/useAnimatedKeyboard.ts +10 -4
  287. package/src/reanimated2/hook/useAnimatedReaction.ts +12 -5
  288. package/src/reanimated2/hook/useAnimatedRef.ts +1 -4
  289. package/src/reanimated2/hook/useAnimatedSensor.ts +88 -11
  290. package/src/reanimated2/hook/useAnimatedStyle.ts +44 -36
  291. package/src/reanimated2/hook/useDerivedValue.ts +8 -1
  292. package/src/reanimated2/hook/useScrollViewOffset.ts +2 -2
  293. package/src/reanimated2/hook/utils.ts +15 -61
  294. package/src/reanimated2/index.ts +1 -0
  295. package/src/reanimated2/initializers.ts +76 -35
  296. package/src/reanimated2/interpolateColor.ts +104 -20
  297. package/src/reanimated2/jestUtils.ts +1 -1
  298. package/src/reanimated2/js-reanimated/JSReanimated.ts +98 -15
  299. package/src/reanimated2/js-reanimated/Mapper.ts +32 -0
  300. package/src/reanimated2/js-reanimated/WebSensor.ts +34 -0
  301. package/src/reanimated2/js-reanimated/commonTypes.ts +0 -1
  302. package/src/reanimated2/js-reanimated/global.ts +0 -1
  303. package/src/reanimated2/js-reanimated/index.ts +0 -1
  304. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +13 -1
  305. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +1 -0
  306. package/src/reanimated2/layoutReanimation/animationsManager.ts +17 -9
  307. package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +16 -19
  308. package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +14 -11
  309. package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +21 -11
  310. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +32 -11
  311. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +36 -19
  312. package/src/reanimated2/layoutReanimation/index.ts +1 -0
  313. package/src/reanimated2/layoutReanimation/sharedTransitions/index.ts +87 -0
  314. package/src/reanimated2/mappers.ts +17 -6
  315. package/src/reanimated2/mock.ts +24 -1
  316. package/src/reanimated2/mutables.ts +2 -0
  317. package/src/reanimated2/platform-specific/checkVersion.ts +39 -0
  318. package/src/reanimated2/platform-specific/checkVersion.web.ts +6 -0
  319. package/src/reanimated2/pluginUtils.ts +8 -0
  320. package/src/reanimated2/shareables.ts +45 -16
  321. package/src/reanimated2/threads.ts +103 -1
  322. package/src/reanimated2/utils.ts +6 -0
  323. package/src/reanimated2/valueSetter.ts +1 -2
  324. package/lib/commonjs/reanimated2/time.js +0 -55
  325. package/lib/commonjs/reanimated2/time.js.map +0 -1
  326. package/lib/module/reanimated2/time.js +0 -37
  327. package/lib/module/reanimated2/time.js.map +0 -1
  328. package/src/reanimated2/time.ts +0 -30
  329. /package/android/src/{main/java → reactNativeVersionPatch/ReanimatedUIManager/70}/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +0 -0
@@ -19,29 +19,96 @@ export const Extrapolate = {
19
19
  IDENTITY: 'identity',
20
20
  };
21
21
 
22
+ export type InterpolationOptions = {
23
+ gamma?: number;
24
+ useCorrectedHSVInterpolation?: boolean;
25
+ };
26
+
22
27
  const interpolateColorsHSV = (
23
28
  value: number,
24
29
  inputRange: readonly number[],
25
- colors: InterpolateHSV
30
+ colors: InterpolateHSV,
31
+ options: InterpolationOptions
26
32
  ) => {
27
33
  'worklet';
28
- const h = interpolate(value, inputRange, colors.h, Extrapolate.CLAMP);
34
+ let h = 0;
35
+ const { useCorrectedHSVInterpolation = true } = options;
36
+ if (useCorrectedHSVInterpolation) {
37
+ // if the difference between hues in a range is > 180 deg
38
+ // then move the hue at the right end of the range +/- 360 deg
39
+ // and add the next point in the original place + 0.00001 with original hue
40
+ // to not break the next range
41
+ const correctedInputRange = [inputRange[0]];
42
+ const originalH = colors.h;
43
+ const correctedH = [originalH[0]];
44
+
45
+ for (let i = 1; i < originalH.length; ++i) {
46
+ const d = originalH[i] - originalH[i - 1];
47
+ if (originalH[i] > originalH[i - 1] && d > 0.5) {
48
+ correctedInputRange.push(inputRange[i]);
49
+ correctedInputRange.push(inputRange[i] + 0.00001);
50
+ correctedH.push(originalH[i] - 1);
51
+ correctedH.push(originalH[i]);
52
+ } else if (originalH[i] < originalH[i - 1] && d < -0.5) {
53
+ correctedInputRange.push(inputRange[i]);
54
+ correctedInputRange.push(inputRange[i] + 0.00001);
55
+ correctedH.push(originalH[i] + 1);
56
+ correctedH.push(originalH[i]);
57
+ } else {
58
+ correctedInputRange.push(inputRange[i]);
59
+ correctedH.push(originalH[i]);
60
+ }
61
+ }
62
+ h =
63
+ (interpolate(value, correctedInputRange, correctedH, Extrapolate.CLAMP) +
64
+ 1) %
65
+ 1;
66
+ } else {
67
+ h = interpolate(value, inputRange, colors.h, Extrapolate.CLAMP);
68
+ }
29
69
  const s = interpolate(value, inputRange, colors.s, Extrapolate.CLAMP);
30
70
  const v = interpolate(value, inputRange, colors.v, Extrapolate.CLAMP);
31
- return hsvToColor(h, s, v);
71
+ const a = interpolate(value, inputRange, colors.a, Extrapolate.CLAMP);
72
+ return hsvToColor(h, s, v, a);
73
+ };
74
+
75
+ const toLinearSpace = (x: number[], gamma: number): number[] => {
76
+ 'worklet';
77
+ return x.map((v) => Math.pow(v / 255, gamma));
78
+ };
79
+
80
+ const toGammaSpace = (x: number, gamma: number): number => {
81
+ 'worklet';
82
+ return Math.round(Math.pow(x, 1 / gamma) * 255);
32
83
  };
33
84
 
34
85
  const interpolateColorsRGB = (
35
86
  value: number,
36
87
  inputRange: readonly number[],
37
- colors: InterpolateRGB
88
+ colors: InterpolateRGB,
89
+ options: InterpolationOptions
38
90
  ) => {
39
91
  'worklet';
40
- const r = interpolate(value, inputRange, colors.r, Extrapolate.CLAMP);
41
- const g = interpolate(value, inputRange, colors.g, Extrapolate.CLAMP);
42
- const b = interpolate(value, inputRange, colors.b, Extrapolate.CLAMP);
92
+ const { gamma = 2.2 } = options;
93
+ let { r: outputR, g: outputG, b: outputB } = colors;
94
+ if (gamma !== 1) {
95
+ outputR = toLinearSpace(outputR, gamma);
96
+ outputG = toLinearSpace(outputG, gamma);
97
+ outputB = toLinearSpace(outputB, gamma);
98
+ }
99
+ const r = interpolate(value, inputRange, outputR, Extrapolate.CLAMP);
100
+ const g = interpolate(value, inputRange, outputG, Extrapolate.CLAMP);
101
+ const b = interpolate(value, inputRange, outputB, Extrapolate.CLAMP);
43
102
  const a = interpolate(value, inputRange, colors.a, Extrapolate.CLAMP);
44
- return rgbaColor(r, g, b, a);
103
+ if (gamma === 1) {
104
+ return rgbaColor(r, g, b, a);
105
+ }
106
+ return rgbaColor(
107
+ toGammaSpace(r, gamma),
108
+ toGammaSpace(g, gamma),
109
+ toGammaSpace(b, gamma),
110
+ a
111
+ );
45
112
  };
46
113
 
47
114
  interface InterpolateRGB {
@@ -78,6 +145,7 @@ interface InterpolateHSV {
78
145
  h: number[];
79
146
  s: number[];
80
147
  v: number[];
148
+ a: number[];
81
149
  }
82
150
 
83
151
  const getInterpolateHSV = (
@@ -87,36 +155,47 @@ const getInterpolateHSV = (
87
155
  const h = [];
88
156
  const s = [];
89
157
  const v = [];
158
+ const a = [];
90
159
  for (let i = 0; i < colors.length; ++i) {
91
160
  const color = colors[i];
92
- const processedColor = RGBtoHSV(processColor(color) as any);
93
- if (processedColor) {
94
- h.push(processedColor.h);
95
- s.push(processedColor.s);
96
- v.push(processedColor.v);
161
+ const processedColor = processColor(color) as any;
162
+ if (typeof processedColor === 'number') {
163
+ const processedHSVColor = RGBtoHSV(
164
+ red(processedColor),
165
+ green(processedColor),
166
+ blue(processedColor)
167
+ );
168
+
169
+ h.push(processedHSVColor.h);
170
+ s.push(processedHSVColor.s);
171
+ v.push(processedHSVColor.v);
172
+ a.push(opacity(processedColor));
97
173
  }
98
174
  }
99
- return { h, s, v };
175
+ return { h, s, v, a };
100
176
  };
101
177
 
102
178
  export const interpolateColor = (
103
179
  value: number,
104
180
  inputRange: readonly number[],
105
181
  outputRange: readonly (string | number)[],
106
- colorSpace: 'RGB' | 'HSV' = 'RGB'
182
+ colorSpace: 'RGB' | 'HSV' = 'RGB',
183
+ options: InterpolationOptions = {}
107
184
  ): string | number => {
108
185
  'worklet';
109
186
  if (colorSpace === 'HSV') {
110
187
  return interpolateColorsHSV(
111
188
  value,
112
189
  inputRange,
113
- getInterpolateHSV(outputRange)
190
+ getInterpolateHSV(outputRange),
191
+ options
114
192
  );
115
193
  } else if (colorSpace === 'RGB') {
116
194
  return interpolateColorsRGB(
117
195
  value,
118
196
  inputRange,
119
- getInterpolateRGB(outputRange)
197
+ getInterpolateRGB(outputRange),
198
+ options
120
199
  );
121
200
  }
122
201
  throw new Error(
@@ -134,18 +213,21 @@ export interface InterpolateConfig {
134
213
  outputRange: readonly (string | number)[];
135
214
  colorSpace: ColorSpace;
136
215
  cache: SharedValue<InterpolateRGB | InterpolateHSV | null>;
216
+ options: InterpolationOptions;
137
217
  }
138
218
 
139
219
  export function useInterpolateConfig(
140
220
  inputRange: readonly number[],
141
221
  outputRange: readonly (string | number)[],
142
- colorSpace = ColorSpace.RGB
222
+ colorSpace = ColorSpace.RGB,
223
+ options: InterpolationOptions = {}
143
224
  ): SharedValue<InterpolateConfig> {
144
225
  return useSharedValue<InterpolateConfig>({
145
226
  inputRange,
146
227
  outputRange,
147
228
  colorSpace,
148
229
  cache: makeMutable<InterpolateRGB | InterpolateHSV | null>(null),
230
+ options,
149
231
  });
150
232
  }
151
233
 
@@ -163,7 +245,8 @@ export const interpolateSharableColor = (
163
245
  return interpolateColorsRGB(
164
246
  value,
165
247
  interpolateConfig.value.inputRange,
166
- colors as InterpolateRGB
248
+ colors as InterpolateRGB,
249
+ interpolateConfig.value.options
167
250
  );
168
251
  } else if (interpolateConfig.value.colorSpace === ColorSpace.HSV) {
169
252
  if (!colors) {
@@ -173,7 +256,8 @@ export const interpolateSharableColor = (
173
256
  return interpolateColorsHSV(
174
257
  value,
175
258
  interpolateConfig.value.inputRange,
176
- colors as InterpolateHSV
259
+ colors as InterpolateHSV,
260
+ interpolateConfig.value.options
177
261
  );
178
262
  }
179
263
  throw new Error(
@@ -149,7 +149,7 @@ const afterTest = () => {
149
149
 
150
150
  export const withReanimatedTimer = (animationTest) => {
151
151
  console.warn(
152
- 'This method is deprecated, you shoulddefine your own before and after test hooks to enable jest.useFakeTimers(). Check out the documentation for details on testing'
152
+ 'This method is deprecated, you should define your own before and after test hooks to enable jest.useFakeTimers(). Check out the documentation for details on testing'
153
153
  );
154
154
  beforeTest();
155
155
  animationTest();
@@ -1,18 +1,18 @@
1
1
  import { NativeReanimated } from '../NativeReanimated/NativeReanimated';
2
- import { ShareableRef } from '../commonTypes';
3
- import { isJest } from '../PlatformChecker';
2
+ import {
3
+ SensorType,
4
+ ShareableRef,
5
+ Value3D,
6
+ ValueRotation,
7
+ } from '../commonTypes';
8
+ import { WebSensor } from './WebSensor';
4
9
 
5
10
  export default class JSReanimated extends NativeReanimated {
11
+ nextSensorId = 0;
12
+ sensors = new Map<number, WebSensor>();
13
+
6
14
  constructor() {
7
15
  super(false);
8
- if (isJest()) {
9
- // on node < 16 jest have problems mocking performance.now method which
10
- // results in the tests failing, since date precision isn't that important
11
- // for tests, we use Date.now instead
12
- this.getTimestamp = () => Date.now();
13
- } else {
14
- this.getTimestamp = () => window.performance.now();
15
- }
16
16
  }
17
17
 
18
18
  makeShareableClone<T>(value: T): ShareableRef<T> {
@@ -52,13 +52,62 @@ export default class JSReanimated extends NativeReanimated {
52
52
  );
53
53
  }
54
54
 
55
- registerSensor(): number {
56
- console.warn('[Reanimated] useAnimatedSensor is not available on web yet.');
57
- return -1;
55
+ registerSensor(
56
+ sensorType: SensorType,
57
+ interval: number,
58
+ iosReferenceFrame: number,
59
+ eventHandler: (data: Value3D | ValueRotation) => void
60
+ ): number {
61
+ if (!(this.getSensorName(sensorType) in window)) {
62
+ return -1;
63
+ }
64
+
65
+ const sensor: WebSensor = this.initializeSensor(sensorType, interval);
66
+ let callback;
67
+ if (sensorType === SensorType.ROTATION) {
68
+ callback = () => {
69
+ const [qw, qx, qy, qz] = sensor.quaternion;
70
+
71
+ // reference: https://stackoverflow.com/questions/5782658/extracting-yaw-from-a-quaternion
72
+ const yaw = Math.atan2(
73
+ 2.0 * (qy * qz + qw * qx),
74
+ qw * qw - qx * qx - qy * qy + qz * qz
75
+ );
76
+ const pitch = Math.sin(-2.0 * (qx * qz - qw * qy));
77
+ const roll = Math.atan2(
78
+ 2.0 * (qx * qy + qw * qz),
79
+ qw * qw + qx * qx - qy * qy - qz * qz
80
+ );
81
+ eventHandler({
82
+ qw,
83
+ qx,
84
+ qy,
85
+ qz,
86
+ yaw,
87
+ pitch,
88
+ roll,
89
+ interfaceOrientation: 0,
90
+ });
91
+ };
92
+ } else {
93
+ callback = () => {
94
+ const { x, y, z } = sensor;
95
+ eventHandler({ x, y, z, interfaceOrientation: 0 });
96
+ };
97
+ }
98
+ sensor.addEventListener('reading', callback);
99
+ sensor.start();
100
+
101
+ this.sensors.set(this.nextSensorId, sensor);
102
+ return this.nextSensorId++;
58
103
  }
59
104
 
60
- unregisterSensor(): void {
61
- // noop
105
+ unregisterSensor(id: number): void {
106
+ const sensor: WebSensor | undefined = this.sensors.get(id);
107
+ if (sensor !== undefined) {
108
+ sensor.stop();
109
+ this.sensors.delete(id);
110
+ }
62
111
  }
63
112
 
64
113
  subscribeForKeyboardEvents(_: ShareableRef<number>): number {
@@ -71,4 +120,38 @@ export default class JSReanimated extends NativeReanimated {
71
120
  unsubscribeFromKeyboardEvents(_: number): void {
72
121
  // noop
73
122
  }
123
+
124
+ initializeSensor(sensorType: SensorType, interval: number): WebSensor {
125
+ const config =
126
+ interval <= 0
127
+ ? { referenceFrame: 'device' }
128
+ : { frequency: 1000 / interval };
129
+ switch (sensorType) {
130
+ case SensorType.ACCELEROMETER:
131
+ return new window.Accelerometer(config);
132
+ case SensorType.GYROSCOPE:
133
+ return new window.Gyroscope(config);
134
+ case SensorType.GRAVITY:
135
+ return new window.GravitySensor(config);
136
+ case SensorType.MAGNETIC_FIELD:
137
+ return new window.Magnetometer(config);
138
+ case SensorType.ROTATION:
139
+ return new window.AbsoluteOrientationSensor(config);
140
+ }
141
+ }
142
+
143
+ getSensorName(sensorType: SensorType): string {
144
+ switch (sensorType) {
145
+ case SensorType.ACCELEROMETER:
146
+ return 'Accelerometer';
147
+ case SensorType.GRAVITY:
148
+ return 'GravitySensor';
149
+ case SensorType.GYROSCOPE:
150
+ return 'Gyroscope';
151
+ case SensorType.MAGNETIC_FIELD:
152
+ return 'Magnetometer';
153
+ case SensorType.ROTATION:
154
+ return 'AbsoluteOrientationSensor';
155
+ }
156
+ }
74
157
  }
@@ -1,4 +1,5 @@
1
1
  import { NestedObjectValues } from '../commonTypes';
2
+ import { shouldBeUseWeb } from '../PlatformChecker';
2
3
  import { JSReanimated } from './commonTypes';
3
4
  import MutableValue from './MutableValue';
4
5
 
@@ -49,6 +50,9 @@ export default class Mapper<T> {
49
50
  res.push(value);
50
51
  } else if (Array.isArray(value)) {
51
52
  value.forEach((v) => extractMutables(v));
53
+ } else if (isWebDomElement(value)) {
54
+ // do nothing on dom elements
55
+ // without this check, we get a "Maximum call size exceeded error"
52
56
  } else if (typeof value === 'object') {
53
57
  Object.keys(value).forEach((key) => {
54
58
  extractMutables(value[key]);
@@ -60,3 +64,31 @@ export default class Mapper<T> {
60
64
  return res;
61
65
  }
62
66
  }
67
+
68
+ function isWebDomElement(value: any) {
69
+ if (!shouldBeUseWeb()) {
70
+ return false;
71
+ }
72
+
73
+ // https://stackoverflow.com/a/384380/7869175
74
+ function isWebNode(o: any) {
75
+ return typeof Node === 'object'
76
+ ? o instanceof Node
77
+ : o &&
78
+ typeof o === 'object' &&
79
+ typeof o.nodeType === 'number' &&
80
+ typeof o.nodeName === 'string';
81
+ }
82
+
83
+ function isWebElement(o: any) {
84
+ return typeof HTMLElement === 'object'
85
+ ? o instanceof HTMLElement // DOM2
86
+ : o &&
87
+ typeof o === 'object' &&
88
+ o !== null &&
89
+ o.nodeType === 1 &&
90
+ typeof o.nodeName === 'string';
91
+ }
92
+
93
+ return isWebNode(value) || isWebElement(value);
94
+ }
@@ -0,0 +1,34 @@
1
+ export declare class WebSensor {
2
+ start: () => void;
3
+ stop: () => void;
4
+ addEventListener: (eventType: string, eventHandler: () => void) => void;
5
+ quaternion: [number, number, number, number];
6
+ x: number;
7
+ y: number;
8
+ z: number;
9
+ }
10
+
11
+ type configOptions =
12
+ | {
13
+ referenceFrame: string;
14
+ frequency?: undefined;
15
+ }
16
+ | {
17
+ frequency: number;
18
+ referenceFrame?: undefined;
19
+ };
20
+
21
+ interface Constructable<T> {
22
+ new (config: configOptions): T;
23
+ }
24
+
25
+ declare global {
26
+ interface Window {
27
+ Accelerometer: Constructable<WebSensor>;
28
+ GravitySensor: Constructable<WebSensor>;
29
+ Gyroscope: Constructable<WebSensor>;
30
+ Magnetometer: Constructable<WebSensor>;
31
+ AbsoluteOrientationSensor: Constructable<WebSensor>;
32
+ Sensor: Constructable<WebSensor>;
33
+ }
34
+ }
@@ -32,7 +32,6 @@ export interface JSReanimated {
32
32
  _frames: ((timestamp: Timestamp) => void)[];
33
33
  timeProvider: { now: () => number };
34
34
  pushFrame(frame: (timestamp: Timestamp) => void): void;
35
- getTimestamp(): number;
36
35
  maybeRequestRender(): void;
37
36
  _onRender(timestampMs: number): void;
38
37
  installCoreFunctions(valueSetter: <T>(value: T) => void): void;
@@ -3,7 +3,6 @@
3
3
  import { shouldBeUseWeb } from '../PlatformChecker';
4
4
  const initializeGlobalsForWeb = () => {
5
5
  if (shouldBeUseWeb()) {
6
- global._frameTimestamp = null;
7
6
  global._measure = () => {
8
7
  console.warn(
9
8
  "[Reanimated] You can't use `measure` with Chrome Debugger or with web version"
@@ -5,7 +5,6 @@ const reanimatedJS = new JSReanimated();
5
5
 
6
6
  global._makeShareableClone = (c) => c;
7
7
  global._scheduleOnJS = setImmediate;
8
- global._getTimestamp = reanimatedJS.getTimestamp.bind(reanimatedJS);
9
8
 
10
9
  interface JSReanimatedComponent {
11
10
  previousStyle: StyleProps;
@@ -21,6 +21,8 @@ export interface EntryAnimationsValues {
21
21
  targetHeight: number;
22
22
  targetGlobalOriginX: number;
23
23
  targetGlobalOriginY: number;
24
+ windowWidth: number;
25
+ windowHeight: number;
24
26
  }
25
27
 
26
28
  export interface ExitAnimationsValues {
@@ -30,6 +32,8 @@ export interface ExitAnimationsValues {
30
32
  currentHeight: number;
31
33
  currentGlobalOriginX: number;
32
34
  currentGlobalOriginY: number;
35
+ windowWidth: number;
36
+ windowHeight: number;
33
37
  }
34
38
 
35
39
  export type EntryExitAnimationFunction = (
@@ -39,6 +43,7 @@ export type EntryExitAnimationFunction = (
39
43
  export type AnimationConfigFunction<T> = (targetValues: T) => LayoutAnimation;
40
44
 
41
45
  export interface LayoutAnimationsValues {
46
+ [key: string]: number;
42
47
  currentOriginX: number;
43
48
  currentOriginY: number;
44
49
  currentWidth: number;
@@ -55,13 +60,20 @@ export interface LayoutAnimationsValues {
55
60
  windowHeight: number;
56
61
  }
57
62
 
63
+ export enum LayoutAnimationType {
64
+ ENTERING = 1,
65
+ EXITING = 2,
66
+ LAYOUT = 3,
67
+ SHARED_ELEMENT_TRANSITION = 4,
68
+ }
69
+
58
70
  export type LayoutAnimationFunction = (
59
71
  targetValues: LayoutAnimationsValues
60
72
  ) => LayoutAnimation;
61
73
 
62
74
  export type LayoutAnimationStartFunction = (
63
75
  tag: number,
64
- type: string,
76
+ type: LayoutAnimationType,
65
77
  yogaValues: LayoutAnimationsValues,
66
78
  config: LayoutAnimationFunction
67
79
  ) => void;
@@ -1,6 +1,7 @@
1
1
  export { BaseAnimationBuilder } from './BaseAnimationBuilder';
2
2
  export { ComplexAnimationBuilder } from './ComplexAnimationBuilder';
3
3
  export { Keyframe } from './Keyframe';
4
+ export { LayoutAnimationType } from './commonTypes';
4
5
  export type {
5
6
  LayoutAnimation,
6
7
  AnimationFunction,
@@ -1,21 +1,25 @@
1
- import { runOnUI } from '../core';
2
1
  import { withStyleAnimation } from '../animation/styleAnimation';
3
2
  import { SharedValue } from '../commonTypes';
4
3
  import { makeUIMutable } from '../mutables';
5
4
  import {
6
5
  LayoutAnimationFunction,
6
+ LayoutAnimationType,
7
7
  LayoutAnimationsValues,
8
8
  } from './animationBuilder';
9
+ import { runOnUIImmediately } from '../threads';
9
10
 
10
11
  const TAG_OFFSET = 1e9;
11
12
 
12
13
  function startObservingProgress(
13
14
  tag: number,
14
- sharedValue: SharedValue<number>
15
+ sharedValue: SharedValue<number>,
16
+ animationType: LayoutAnimationType
15
17
  ): void {
16
18
  'worklet';
19
+ const isSharedTransition =
20
+ animationType === LayoutAnimationType.SHARED_ELEMENT_TRANSITION;
17
21
  sharedValue.addListener(tag + TAG_OFFSET, () => {
18
- _notifyAboutProgress(tag, sharedValue.value);
22
+ _notifyAboutProgress(tag, sharedValue.value, isSharedTransition);
19
23
  });
20
24
  }
21
25
 
@@ -38,16 +42,16 @@ function createLayoutAnimationManager() {
38
42
  return {
39
43
  start(
40
44
  tag: number,
41
- type: string,
45
+ type: LayoutAnimationType,
42
46
  yogaValues: LayoutAnimationsValues,
43
47
  config: LayoutAnimationFunction
44
48
  ) {
45
49
  const style = config(yogaValues);
46
50
  let currentAnimation = style.animations;
47
51
 
48
- if (type === 'entering') {
52
+ if (type === LayoutAnimationType.ENTERING) {
49
53
  enteringAnimationForTag.set(tag, currentAnimation);
50
- } else if (type === 'layout') {
54
+ } else if (type === LayoutAnimationType.LAYOUT) {
51
55
  // When layout animation is requested, but entering is still running, we merge
52
56
  // new layout animation targets into the ongoing animation
53
57
  const enteringAnimation = enteringAnimationForTag.get(tag);
@@ -72,20 +76,24 @@ function createLayoutAnimationManager() {
72
76
  if (finished) {
73
77
  enteringAnimationForTag.delete(tag);
74
78
  mutableValuesForTag.delete(tag);
75
- const shouldRemoveView = type === 'exiting';
79
+ const shouldRemoveView = type === LayoutAnimationType.EXITING;
76
80
  stopObservingProgress(tag, value, finished, shouldRemoveView);
77
81
  }
78
82
  style.callback &&
79
83
  style.callback(finished === undefined ? false : finished);
80
84
  };
81
85
 
82
- startObservingProgress(tag, value);
86
+ startObservingProgress(tag, value, type);
83
87
  value.value = animation;
84
88
  },
89
+ stop(tag: number) {
90
+ const value = mutableValuesForTag.get(tag);
91
+ stopObservingProgress(tag, value, true, true);
92
+ },
85
93
  };
86
94
  }
87
95
 
88
- runOnUI(() => {
96
+ runOnUIImmediately(() => {
89
97
  'worklet';
90
98
  global.LayoutAnimationsManager = createLayoutAnimationManager();
91
99
  })();