react-native-reanimated 3.0.0-rc.8 → 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 (339) 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 +122 -121
  10. package/Common/cpp/NativeModules/NativeReanimatedModule.h +21 -14
  11. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +15 -7
  12. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.h +8 -4
  13. package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.cpp +50 -1
  14. package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.h +10 -1
  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 +11 -63
  19. package/Common/cpp/SharedItems/Shareables.h +113 -93
  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 +67 -247
  27. package/Common/cpp/Tools/RuntimeDecorator.h +2 -3
  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 +31 -5
  62. package/ios/LayoutReanimation/REAAnimationsManager.m +265 -77
  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 +67 -60
  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 +18 -35
  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/component/FlatList.js +19 -3
  97. package/lib/commonjs/reanimated2/component/FlatList.js.map +1 -1
  98. package/lib/commonjs/reanimated2/core.js +34 -83
  99. package/lib/commonjs/reanimated2/core.js.map +1 -1
  100. package/lib/commonjs/reanimated2/errors.js +66 -0
  101. package/lib/commonjs/reanimated2/errors.js.map +1 -0
  102. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js +2 -2
  103. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
  104. package/lib/commonjs/reanimated2/globals.d.js.map +1 -1
  105. package/lib/commonjs/reanimated2/hook/index.js +0 -6
  106. package/lib/commonjs/reanimated2/hook/index.js.map +1 -1
  107. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js +5 -2
  108. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  109. package/lib/commonjs/reanimated2/hook/useAnimatedReaction.js +13 -1
  110. package/lib/commonjs/reanimated2/hook/useAnimatedReaction.js.map +1 -1
  111. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js +1 -1
  112. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js.map +1 -1
  113. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js +89 -16
  114. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  115. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js +43 -50
  116. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  117. package/lib/commonjs/reanimated2/hook/useDerivedValue.js +13 -1
  118. package/lib/commonjs/reanimated2/hook/useDerivedValue.js.map +1 -1
  119. package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js +2 -2
  120. package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js.map +1 -1
  121. package/lib/commonjs/reanimated2/hook/utils.js +18 -65
  122. package/lib/commonjs/reanimated2/hook/utils.js.map +1 -1
  123. package/lib/commonjs/reanimated2/index.js +13 -0
  124. package/lib/commonjs/reanimated2/index.js.map +1 -1
  125. package/lib/commonjs/reanimated2/initializers.js +196 -0
  126. package/lib/commonjs/reanimated2/initializers.js.map +1 -0
  127. package/lib/commonjs/reanimated2/interpolateColor.js +96 -19
  128. package/lib/commonjs/reanimated2/interpolateColor.js.map +1 -1
  129. package/lib/commonjs/reanimated2/jestUtils.js +1 -1
  130. package/lib/commonjs/reanimated2/jestUtils.js.map +1 -1
  131. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js +101 -16
  132. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  133. package/lib/commonjs/reanimated2/js-reanimated/Mapper.js +22 -0
  134. package/lib/commonjs/reanimated2/js-reanimated/Mapper.js.map +1 -1
  135. package/lib/commonjs/reanimated2/js-reanimated/WebSensor.js +2 -0
  136. package/lib/commonjs/reanimated2/js-reanimated/WebSensor.js.map +1 -0
  137. package/lib/commonjs/reanimated2/js-reanimated/commonTypes.js.map +1 -1
  138. package/lib/commonjs/reanimated2/js-reanimated/global.js +4 -9
  139. package/lib/commonjs/reanimated2/js-reanimated/global.js.map +1 -1
  140. package/lib/commonjs/reanimated2/js-reanimated/index.js +0 -1
  141. package/lib/commonjs/reanimated2/js-reanimated/index.js.map +1 -1
  142. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +11 -0
  143. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  144. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js +8 -0
  145. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  146. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js +16 -12
  147. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
  148. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +16 -23
  149. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
  150. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -14
  151. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
  152. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -14
  153. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
  154. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Slide.js +8 -15
  155. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
  156. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +16 -23
  157. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
  158. package/lib/commonjs/reanimated2/layoutReanimation/index.js +13 -0
  159. package/lib/commonjs/reanimated2/layoutReanimation/index.js.map +1 -1
  160. package/lib/commonjs/reanimated2/layoutReanimation/sharedTransitions/index.js +94 -0
  161. package/lib/commonjs/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -0
  162. package/lib/commonjs/reanimated2/mappers.js +18 -6
  163. package/lib/commonjs/reanimated2/mappers.js.map +1 -1
  164. package/lib/commonjs/reanimated2/mock.js +45 -0
  165. package/lib/commonjs/reanimated2/mock.js.map +1 -1
  166. package/lib/commonjs/reanimated2/mutables.js +4 -2
  167. package/lib/commonjs/reanimated2/mutables.js.map +1 -1
  168. package/lib/commonjs/reanimated2/platform-specific/checkVersion.js +42 -0
  169. package/lib/commonjs/reanimated2/platform-specific/checkVersion.js.map +1 -0
  170. package/lib/commonjs/reanimated2/platform-specific/checkVersion.web.js +15 -0
  171. package/lib/commonjs/reanimated2/platform-specific/checkVersion.web.js.map +1 -0
  172. package/lib/commonjs/reanimated2/pluginUtils.js +11 -0
  173. package/lib/commonjs/reanimated2/pluginUtils.js.map +1 -0
  174. package/lib/commonjs/reanimated2/shareables.js +38 -11
  175. package/lib/commonjs/reanimated2/shareables.js.map +1 -1
  176. package/lib/commonjs/reanimated2/threads.js +114 -4
  177. package/lib/commonjs/reanimated2/threads.js.map +1 -1
  178. package/lib/commonjs/reanimated2/utils.js +7 -0
  179. package/lib/commonjs/reanimated2/utils.js.map +1 -1
  180. package/lib/commonjs/reanimated2/valueSetter.js +1 -3
  181. package/lib/commonjs/reanimated2/valueSetter.js.map +1 -1
  182. package/lib/module/createAnimatedComponent.js +229 -29
  183. package/lib/module/createAnimatedComponent.js.map +1 -1
  184. package/lib/module/reanimated2/Colors.js +35 -19
  185. package/lib/module/reanimated2/Colors.js.map +1 -1
  186. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js +18 -34
  187. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  188. package/lib/module/reanimated2/animation/styleAnimation.js +5 -1
  189. package/lib/module/reanimated2/animation/styleAnimation.js.map +1 -1
  190. package/lib/module/reanimated2/animation/util.js +17 -16
  191. package/lib/module/reanimated2/animation/util.js.map +1 -1
  192. package/lib/module/reanimated2/commonTypes.js +29 -0
  193. package/lib/module/reanimated2/commonTypes.js.map +1 -1
  194. package/lib/module/reanimated2/component/FlatList.js +18 -4
  195. package/lib/module/reanimated2/component/FlatList.js.map +1 -1
  196. package/lib/module/reanimated2/core.js +30 -76
  197. package/lib/module/reanimated2/core.js.map +1 -1
  198. package/lib/module/reanimated2/errors.js +58 -0
  199. package/lib/module/reanimated2/errors.js.map +1 -0
  200. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js +2 -2
  201. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
  202. package/lib/module/reanimated2/globals.d.js.map +1 -1
  203. package/lib/module/reanimated2/hook/index.js +1 -1
  204. package/lib/module/reanimated2/hook/index.js.map +1 -1
  205. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js +5 -2
  206. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  207. package/lib/module/reanimated2/hook/useAnimatedReaction.js +12 -1
  208. package/lib/module/reanimated2/hook/useAnimatedReaction.js.map +1 -1
  209. package/lib/module/reanimated2/hook/useAnimatedRef.js +2 -2
  210. package/lib/module/reanimated2/hook/useAnimatedRef.js.map +1 -1
  211. package/lib/module/reanimated2/hook/useAnimatedSensor.js +88 -13
  212. package/lib/module/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  213. package/lib/module/reanimated2/hook/useAnimatedStyle.js +45 -52
  214. package/lib/module/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  215. package/lib/module/reanimated2/hook/useDerivedValue.js +12 -1
  216. package/lib/module/reanimated2/hook/useDerivedValue.js.map +1 -1
  217. package/lib/module/reanimated2/hook/useScrollViewOffset.js +2 -2
  218. package/lib/module/reanimated2/hook/useScrollViewOffset.js.map +1 -1
  219. package/lib/module/reanimated2/hook/utils.js +17 -60
  220. package/lib/module/reanimated2/hook/utils.js.map +1 -1
  221. package/lib/module/reanimated2/index.js +1 -0
  222. package/lib/module/reanimated2/index.js.map +1 -1
  223. package/lib/module/reanimated2/initializers.js +182 -0
  224. package/lib/module/reanimated2/initializers.js.map +1 -0
  225. package/lib/module/reanimated2/interpolateColor.js +96 -19
  226. package/lib/module/reanimated2/interpolateColor.js.map +1 -1
  227. package/lib/module/reanimated2/jestUtils.js +1 -1
  228. package/lib/module/reanimated2/jestUtils.js.map +1 -1
  229. package/lib/module/reanimated2/js-reanimated/JSReanimated.js +101 -16
  230. package/lib/module/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  231. package/lib/module/reanimated2/js-reanimated/Mapper.js +21 -0
  232. package/lib/module/reanimated2/js-reanimated/Mapper.js.map +1 -1
  233. package/lib/module/reanimated2/js-reanimated/WebSensor.js +2 -0
  234. package/lib/module/reanimated2/js-reanimated/WebSensor.js.map +1 -0
  235. package/lib/module/reanimated2/js-reanimated/commonTypes.js.map +1 -1
  236. package/lib/module/reanimated2/js-reanimated/global.js +4 -9
  237. package/lib/module/reanimated2/js-reanimated/global.js.map +1 -1
  238. package/lib/module/reanimated2/js-reanimated/index.js +0 -1
  239. package/lib/module/reanimated2/js-reanimated/index.js.map +1 -1
  240. package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +9 -1
  241. package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  242. package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js +1 -0
  243. package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  244. package/lib/module/reanimated2/layoutReanimation/animationsManager.js +15 -10
  245. package/lib/module/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
  246. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +16 -21
  247. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
  248. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -12
  249. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
  250. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -12
  251. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
  252. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js +8 -13
  253. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
  254. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +16 -21
  255. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
  256. package/lib/module/reanimated2/layoutReanimation/index.js +1 -0
  257. package/lib/module/reanimated2/layoutReanimation/index.js.map +1 -1
  258. package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js +82 -0
  259. package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -0
  260. package/lib/module/reanimated2/mappers.js +16 -6
  261. package/lib/module/reanimated2/mappers.js.map +1 -1
  262. package/lib/module/reanimated2/mock.js +45 -0
  263. package/lib/module/reanimated2/mock.js.map +1 -1
  264. package/lib/module/reanimated2/mutables.js +4 -2
  265. package/lib/module/reanimated2/mutables.js.map +1 -1
  266. package/lib/module/reanimated2/platform-specific/checkVersion.js +35 -0
  267. package/lib/module/reanimated2/platform-specific/checkVersion.js.map +1 -0
  268. package/lib/module/reanimated2/platform-specific/checkVersion.web.js +8 -0
  269. package/lib/module/reanimated2/platform-specific/checkVersion.web.js.map +1 -0
  270. package/lib/module/reanimated2/pluginUtils.js +4 -0
  271. package/lib/module/reanimated2/pluginUtils.js.map +1 -0
  272. package/lib/module/reanimated2/shareables.js +38 -9
  273. package/lib/module/reanimated2/shareables.js.map +1 -1
  274. package/lib/module/reanimated2/threads.js +105 -4
  275. package/lib/module/reanimated2/threads.js.map +1 -1
  276. package/lib/module/reanimated2/utils.js +5 -0
  277. package/lib/module/reanimated2/utils.js.map +1 -1
  278. package/lib/module/reanimated2/valueSetter.js +1 -2
  279. package/lib/module/reanimated2/valueSetter.js.map +1 -1
  280. package/package.json +9 -8
  281. package/{plugin.js → plugin/index.js} +173 -228
  282. package/react-native-reanimated.d.ts +57 -10
  283. package/scripts/reanimated_utils.rb +15 -2
  284. package/src/createAnimatedComponent.tsx +238 -28
  285. package/src/reanimated2/Colors.ts +38 -11
  286. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +63 -41
  287. package/src/reanimated2/animation/styleAnimation.ts +8 -1
  288. package/src/reanimated2/animation/util.ts +29 -16
  289. package/src/reanimated2/commonTypes.ts +28 -1
  290. package/src/reanimated2/component/FlatList.tsx +30 -5
  291. package/src/reanimated2/core.ts +45 -75
  292. package/src/reanimated2/errors.ts +57 -0
  293. package/src/reanimated2/frameCallback/FrameCallbackRegistryUI.ts +2 -2
  294. package/src/reanimated2/globals.d.ts +34 -18
  295. package/src/reanimated2/hook/index.ts +1 -1
  296. package/src/reanimated2/hook/useAnimatedKeyboard.ts +10 -4
  297. package/src/reanimated2/hook/useAnimatedReaction.ts +12 -5
  298. package/src/reanimated2/hook/useAnimatedRef.ts +1 -4
  299. package/src/reanimated2/hook/useAnimatedSensor.ts +88 -11
  300. package/src/reanimated2/hook/useAnimatedStyle.ts +43 -45
  301. package/src/reanimated2/hook/useDerivedValue.ts +8 -1
  302. package/src/reanimated2/hook/useScrollViewOffset.ts +2 -2
  303. package/src/reanimated2/hook/utils.ts +15 -61
  304. package/src/reanimated2/index.ts +1 -0
  305. package/src/reanimated2/initializers.ts +184 -0
  306. package/src/reanimated2/interpolateColor.ts +104 -20
  307. package/src/reanimated2/jestUtils.ts +1 -1
  308. package/src/reanimated2/js-reanimated/JSReanimated.ts +105 -18
  309. package/src/reanimated2/js-reanimated/Mapper.ts +32 -0
  310. package/src/reanimated2/js-reanimated/WebSensor.ts +34 -0
  311. package/src/reanimated2/js-reanimated/commonTypes.ts +0 -1
  312. package/src/reanimated2/js-reanimated/global.ts +4 -8
  313. package/src/reanimated2/js-reanimated/index.ts +0 -1
  314. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +13 -1
  315. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +1 -0
  316. package/src/reanimated2/layoutReanimation/animationsManager.ts +17 -12
  317. package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +16 -19
  318. package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +14 -11
  319. package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +21 -11
  320. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +32 -11
  321. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +36 -19
  322. package/src/reanimated2/layoutReanimation/index.ts +1 -0
  323. package/src/reanimated2/layoutReanimation/sharedTransitions/index.ts +87 -0
  324. package/src/reanimated2/mappers.ts +17 -6
  325. package/src/reanimated2/mock.ts +128 -0
  326. package/src/reanimated2/mutables.ts +2 -0
  327. package/src/reanimated2/platform-specific/checkVersion.ts +39 -0
  328. package/src/reanimated2/platform-specific/checkVersion.web.ts +6 -0
  329. package/src/reanimated2/pluginUtils.ts +8 -0
  330. package/src/reanimated2/shareables.ts +47 -11
  331. package/src/reanimated2/threads.ts +103 -1
  332. package/src/reanimated2/utils.ts +6 -0
  333. package/src/reanimated2/valueSetter.ts +1 -2
  334. package/lib/commonjs/reanimated2/time.js +0 -55
  335. package/lib/commonjs/reanimated2/time.js.map +0 -1
  336. package/lib/module/reanimated2/time.js +0 -37
  337. package/lib/module/reanimated2/time.js.map +0 -1
  338. package/src/reanimated2/time.ts +0 -30
  339. /package/android/src/{main/java → reactNativeVersionPatch/ReanimatedUIManager/70}/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +0 -0
@@ -14,11 +14,7 @@ AnimatedSensorModule::AnimatedSensorModule(
14
14
  platformDepMethodsHolder.unregisterSensor) {}
15
15
 
16
16
  AnimatedSensorModule::~AnimatedSensorModule() {
17
- // It is called during app reload because app reload doesn't call hooks
18
- // unmounting
19
- for (auto sensorId : sensorsIds_) {
20
- platformUnregisterSensorFunction_(sensorId);
21
- }
17
+ assert(sensorsIds_.empty());
22
18
  }
23
19
 
24
20
  jsi::Value AnimatedSensorModule::registerSensor(
@@ -26,19 +22,32 @@ jsi::Value AnimatedSensorModule::registerSensor(
26
22
  const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
27
23
  const jsi::Value &sensorTypeValue,
28
24
  const jsi::Value &interval,
25
+ const jsi::Value &iosReferenceFrame,
29
26
  const jsi::Value &sensorDataHandler) {
30
27
  SensorType sensorType = static_cast<SensorType>(sensorTypeValue.asNumber());
31
28
 
32
29
  auto shareableHandler = extractShareableOrThrow(rt, sensorDataHandler);
33
- auto uiRuntime = runtimeHelper->uiRuntime();
34
30
 
35
31
  int sensorId = platformRegisterSensorFunction_(
36
- sensorType, interval.asNumber(), [=](double newValues[]) {
37
- jsi::Runtime &rt = *uiRuntime;
38
- auto handler =
39
- shareableHandler->getJSValue(rt).asObject(rt).asFunction(rt);
32
+ sensorType,
33
+ interval.asNumber(),
34
+ iosReferenceFrame.asNumber(),
35
+ [sensorType,
36
+ shareableHandler,
37
+ weakRuntimeHelper = std::weak_ptr<JSRuntimeHelper>(runtimeHelper)](
38
+ double newValues[], int orientationDegrees) {
39
+ auto runtimeHelper = weakRuntimeHelper.lock();
40
+ if (runtimeHelper == nullptr || runtimeHelper->uiRuntimeDestroyed) {
41
+ return;
42
+ }
43
+
44
+ auto &rt = *runtimeHelper->uiRuntime();
45
+ auto handler = shareableHandler->getJSValue(rt);
40
46
  if (sensorType == SensorType::ROTATION_VECTOR) {
41
47
  jsi::Object value(rt);
48
+ // TODO: timestamp should be provided by the platform implementation
49
+ // such that the native side has a chance of providing a true event
50
+ // timestamp
42
51
  value.setProperty(rt, "qx", newValues[0]);
43
52
  value.setProperty(rt, "qy", newValues[1]);
44
53
  value.setProperty(rt, "qz", newValues[2]);
@@ -46,13 +55,15 @@ jsi::Value AnimatedSensorModule::registerSensor(
46
55
  value.setProperty(rt, "yaw", newValues[4]);
47
56
  value.setProperty(rt, "pitch", newValues[5]);
48
57
  value.setProperty(rt, "roll", newValues[6]);
49
- handler.call(rt, value);
58
+ value.setProperty(rt, "interfaceOrientation", orientationDegrees);
59
+ runtimeHelper->runOnUIGuarded(handler, value);
50
60
  } else {
51
61
  jsi::Object value(rt);
52
62
  value.setProperty(rt, "x", newValues[0]);
53
63
  value.setProperty(rt, "y", newValues[1]);
54
64
  value.setProperty(rt, "z", newValues[2]);
55
- handler.call(rt, value);
65
+ value.setProperty(rt, "interfaceOrientation", orientationDegrees);
66
+ runtimeHelper->runOnUIGuarded(handler, value);
56
67
  }
57
68
  });
58
69
  if (sensorId != -1) {
@@ -67,4 +78,11 @@ void AnimatedSensorModule::unregisterSensor(const jsi::Value &sensorId) {
67
78
  platformUnregisterSensorFunction_(sensorId.asNumber());
68
79
  }
69
80
 
81
+ void AnimatedSensorModule::unregisterAllSensors() {
82
+ for (auto sensorId : sensorsIds_) {
83
+ platformUnregisterSensorFunction_(sensorId);
84
+ }
85
+ sensorsIds_.clear();
86
+ }
87
+
70
88
  } // namespace reanimated
@@ -35,8 +35,10 @@ class AnimatedSensorModule {
35
35
  const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
36
36
  const jsi::Value &sensorType,
37
37
  const jsi::Value &interval,
38
+ const jsi::Value &iosReferenceFrame,
38
39
  const jsi::Value &sensorDataContainer);
39
40
  void unregisterSensor(const jsi::Value &sensorId);
41
+ void unregisterAllSensors();
40
42
  };
41
43
 
42
44
  } // namespace reanimated
@@ -1,12 +1,8 @@
1
1
  #ifdef RCT_NEW_ARCH_ENABLED
2
2
 
3
- #if REACT_NATIVE_MINOR_VERSION < 69
4
- #error \
5
- "Reanimated 3 does not support React Native 0.68.x when Fabric is enabled. Please upgrade to React Native 0.69.0 or newer if you want to use Reanimated with the new architecture."
6
- #endif
7
-
8
3
  #include "FabricUtils.h"
9
4
 
5
+ #include <react/renderer/debug/SystraceSection.h>
10
6
  #include <react/renderer/uimanager/UIManagerBinding.h>
11
7
 
12
8
  using namespace facebook::react;
@@ -22,110 +18,10 @@ RuntimeExecutor getRuntimeExecutorFromBinding(Binding *binding) {
22
18
  }
23
19
  #endif
24
20
 
25
- inline static const UIManagerPublic *getUIManagerPublic(
26
- const UIManager *uiManager) {
27
- return reinterpret_cast<const UIManagerPublic *>(uiManager);
28
- }
29
-
30
21
  std::shared_ptr<const ContextContainer> getContextContainerFromUIManager(
31
22
  const UIManager *uiManager) {
32
- return getUIManagerPublic(uiManager)->contextContainer_;
33
- }
34
-
35
- inline static UIManagerDelegate *getDelegateFromUIManager(
36
- const UIManager *uiManager) {
37
- return getUIManagerPublic(uiManager)->delegate_;
38
- }
39
-
40
- void UIManager_dispatchCommand(
41
- const std::shared_ptr<UIManager> &uiManager,
42
- const ShadowNode::Shared &shadowNode,
43
- std::string const &commandName,
44
- folly::dynamic const &args) {
45
- auto delegate_ = getDelegateFromUIManager(&*uiManager);
46
-
47
- // copied from UIManager.cpp
48
- if (delegate_) {
49
- delegate_->uiManagerDidDispatchCommand(shadowNode, commandName, args);
50
- }
51
- }
52
-
53
- LayoutMetrics UIManager_getRelativeLayoutMetrics(
54
- const std::shared_ptr<UIManager> &uiManager,
55
- ShadowNode const &shadowNode,
56
- ShadowNode const *ancestorShadowNode,
57
- LayoutableShadowNode::LayoutInspectingPolicy policy) {
58
- // based on implementation from UIManager.cpp
59
- const auto &shadowTreeRegistry = uiManager->getShadowTreeRegistry();
60
-
61
- // We might store here an owning pointer to `ancestorShadowNode` to ensure
62
- // that the node is not deallocated during method execution lifetime.
63
- auto owningAncestorShadowNode = ShadowNode::Shared{};
64
-
65
- if (!ancestorShadowNode) {
66
- shadowTreeRegistry.visit(
67
- shadowNode.getSurfaceId(), [&](ShadowTree const &shadowTree) {
68
- owningAncestorShadowNode =
69
- shadowTree.getCurrentRevision().rootShadowNode;
70
- ancestorShadowNode = owningAncestorShadowNode.get();
71
- });
72
- } else {
73
- // It is possible for JavaScript (or other callers) to have a reference
74
- // to a previous version of ShadowNodes, but we enforce that
75
- // metrics are only calculated on most recently committed versions.
76
- owningAncestorShadowNode =
77
- uiManager->getNewestCloneOfShadowNode(*ancestorShadowNode);
78
- ancestorShadowNode = owningAncestorShadowNode.get();
79
- }
80
-
81
- auto layoutableAncestorShadowNode =
82
- traitCast<LayoutableShadowNode const *>(ancestorShadowNode);
83
-
84
- if (!layoutableAncestorShadowNode) {
85
- return EmptyLayoutMetrics;
86
- }
87
-
88
- return LayoutableShadowNode::computeRelativeLayoutMetrics(
89
- shadowNode.getFamily(), *layoutableAncestorShadowNode, policy);
90
- }
91
-
92
- ShadowNode::Shared UIManager_cloneNode(
93
- const UIManager *uiManager,
94
- const ShadowNode::Shared &shadowNode,
95
- const ShadowNode::SharedListOfShared &children,
96
- const RawProps *rawProps) {
97
- auto delegate_ = getDelegateFromUIManager(uiManager);
98
- auto contextContainer_ = getContextContainerFromUIManager(uiManager);
99
-
100
- // copied from UIManager.cpp
101
- PropsParserContext propsParserContext{
102
- shadowNode->getFamily().getSurfaceId(), *contextContainer_.get()};
103
-
104
- auto &componentDescriptor = shadowNode->getComponentDescriptor();
105
- auto clonedShadowNode = componentDescriptor.cloneShadowNode(
106
- *shadowNode,
107
- {
108
- /* .props = */
109
- rawProps ? componentDescriptor.cloneProps(
110
- propsParserContext, shadowNode->getProps(), *rawProps)
111
- : ShadowNodeFragment::propsPlaceholder(),
112
- /* .children = */ children,
113
- });
114
-
115
- if (delegate_) {
116
- delegate_->uiManagerDidCloneShadowNode(
117
- *shadowNode.get(), *clonedShadowNode);
118
- }
119
-
120
- return clonedShadowNode;
121
- }
122
-
123
- void UIManager_appendChild(
124
- const ShadowNode::Shared &parentShadowNode,
125
- const ShadowNode::Shared &childShadowNode) {
126
- // copied from UIManager.cpp
127
- auto &componentDescriptor = parentShadowNode->getComponentDescriptor();
128
- componentDescriptor.appendChild(parentShadowNode, childShadowNode);
23
+ return reinterpret_cast<const UIManagerPublic *>(uiManager)
24
+ ->contextContainer_;
129
25
  }
130
26
 
131
27
  } // namespace reanimated
@@ -2,15 +2,16 @@
2
2
  #ifdef RCT_NEW_ARCH_ENABLED
3
3
 
4
4
  #ifdef ANDROID
5
- #include <Binding.h>
6
5
  #include <fbjni/fbjni.h>
6
+ #include <react/fabric/Binding.h>
7
7
  #endif
8
8
  #include <react/renderer/uimanager/UIManager.h>
9
9
 
10
10
  #include <memory>
11
11
  #include <string>
12
12
 
13
- using namespace facebook::react;
13
+ using namespace facebook;
14
+ using namespace react;
14
15
 
15
16
  namespace reanimated {
16
17
 
@@ -52,28 +53,6 @@ RuntimeExecutor getRuntimeExecutorFromBinding(Binding *binding);
52
53
  std::shared_ptr<const ContextContainer> getContextContainerFromUIManager(
53
54
  const UIManager *uiManager);
54
55
 
55
- void UIManager_dispatchCommand(
56
- const std::shared_ptr<UIManager> &uiManager,
57
- const ShadowNode::Shared &shadowNode,
58
- std::string const &commandName,
59
- folly::dynamic const &args);
60
-
61
- LayoutMetrics UIManager_getRelativeLayoutMetrics(
62
- const std::shared_ptr<UIManager> &uiManager,
63
- ShadowNode const &shadowNode,
64
- ShadowNode const *ancestorShadowNode,
65
- LayoutableShadowNode::LayoutInspectingPolicy policy);
66
-
67
- ShadowNode::Shared UIManager_cloneNode(
68
- const UIManager *uiManager,
69
- const ShadowNode::Shared &shadowNode,
70
- const ShadowNode::SharedListOfShared &children = nullptr,
71
- const RawProps *rawProps = nullptr);
72
-
73
- void UIManager_appendChild(
74
- const ShadowNode::Shared &parentShadowNode,
75
- const ShadowNode::Shared &childShadowNode);
76
-
77
56
  } // namespace reanimated
78
57
 
79
58
  #endif // RCT_NEW_ARCH_ENABLED
@@ -4,6 +4,8 @@
4
4
  #include "FabricUtils.h"
5
5
  #include "NewestShadowNodesRegistry.h"
6
6
 
7
+ #include <react/renderer/debug/SystraceSection.h>
8
+
7
9
  #include <utility>
8
10
 
9
11
  using namespace facebook;
@@ -51,7 +53,7 @@ ReanimatedUIManagerBinding::ReanimatedUIManagerBinding(
51
53
  RuntimeExecutor runtimeExecutor,
52
54
  std::unique_ptr<EventHandler const> eventHandler,
53
55
  std::shared_ptr<NewestShadowNodesRegistry> newestShadowNodesRegistry)
54
- : UIManagerBinding(uiManager, runtimeExecutor),
56
+ : UIManagerBinding(uiManager),
55
57
  uiManager_(std::move(uiManager)),
56
58
  newestShadowNodesRegistry_(newestShadowNodesRegistry) {
57
59
  if (eventHandler != nullptr) {
@@ -62,25 +64,44 @@ ReanimatedUIManagerBinding::ReanimatedUIManagerBinding(
62
64
 
63
65
  ReanimatedUIManagerBinding::~ReanimatedUIManagerBinding() {}
64
66
 
65
- static inline ShadowNode::Shared cloneNode(
67
+ static inline ShadowNode::Shared cloneNodeUsingNewest(
66
68
  UIManager *uiManager,
67
69
  NewestShadowNodesRegistry *newestShadowNodesRegistry,
68
- const ShadowNode::Shared &shadowNode,
69
- const ShadowNode::SharedListOfShared &children = nullptr,
70
- const RawProps *rawProps = nullptr) {
70
+ ShadowNode const &shadowNode,
71
+ ShadowNode::SharedListOfShared const &children = nullptr,
72
+ RawProps const *rawProps = nullptr) {
71
73
  {
72
74
  auto lock = newestShadowNodesRegistry->createLock();
73
- auto newest = newestShadowNodesRegistry->get(shadowNode->getTag());
75
+ auto newest = newestShadowNodesRegistry->get(shadowNode.getTag());
74
76
  if (newest != nullptr) {
75
77
  // ShadowNode managed by Reanimated, use newest ShadowNode from registry
76
- auto clone = UIManager_cloneNode(uiManager, newest, children, rawProps);
78
+ auto clone = uiManager->cloneNode(*newest, children, rawProps);
77
79
  newestShadowNodesRegistry->update(clone);
78
80
  return clone;
79
81
  }
80
82
  } // release lock since we don't need registry anymore
81
83
 
82
84
  // ShadowNode not managed by Reanimated (yet?)
83
- return UIManager_cloneNode(uiManager, shadowNode, children, rawProps);
85
+ return uiManager->cloneNode(shadowNode, children, rawProps);
86
+ }
87
+
88
+ static inline void appendChildUsingNewest(
89
+ UIManager *uiManager,
90
+ NewestShadowNodesRegistry *newestShadowNodesRegistry,
91
+ const ShadowNode::Shared &parentShadowNode,
92
+ const ShadowNode::Shared &childShadowNode) {
93
+ {
94
+ auto lock = newestShadowNodesRegistry->createLock();
95
+ auto newestChildShadowNode =
96
+ newestShadowNodesRegistry->get(childShadowNode->getTag());
97
+ if (newestChildShadowNode != nullptr) {
98
+ uiManager->appendChild(parentShadowNode, newestChildShadowNode);
99
+ return;
100
+ }
101
+ } // release lock since we don't need registry anymore
102
+
103
+ // child ShadowNode not managed by Reanimated (yet?)
104
+ uiManager->appendChild(parentShadowNode, childShadowNode);
84
105
  }
85
106
 
86
107
  jsi::Value ReanimatedUIManagerBinding::get(
@@ -94,6 +115,7 @@ jsi::Value ReanimatedUIManagerBinding::get(
94
115
 
95
116
  // based on implementation from UIManagerBinding.cpp
96
117
  auto methodName = name.utf8(runtime);
118
+ SystraceSection s("ReanimatedUIManagerBinding::get", "name", methodName);
97
119
  UIManager *uiManager = uiManager_.get();
98
120
  NewestShadowNodesRegistry *newestShadowNodesRegistry =
99
121
  newestShadowNodesRegistry_.get();
@@ -106,15 +128,15 @@ jsi::Value ReanimatedUIManagerBinding::get(
106
128
  1,
107
129
  [uiManager, newestShadowNodesRegistry](
108
130
  jsi::Runtime &runtime,
109
- jsi::Value const &thisValue,
131
+ jsi::Value const & /*thisValue*/,
110
132
  jsi::Value const *arguments,
111
- size_t count) noexcept -> jsi::Value {
133
+ size_t /*count*/) noexcept -> jsi::Value {
112
134
  return valueFromShadowNode(
113
135
  runtime,
114
- cloneNode(
136
+ cloneNodeUsingNewest(
115
137
  uiManager,
116
138
  newestShadowNodesRegistry,
117
- shadowNodeFromValue(runtime, arguments[0])));
139
+ *shadowNodeFromValue(runtime, arguments[0])));
118
140
  });
119
141
  }
120
142
 
@@ -126,15 +148,15 @@ jsi::Value ReanimatedUIManagerBinding::get(
126
148
  1,
127
149
  [uiManager, newestShadowNodesRegistry](
128
150
  jsi::Runtime &runtime,
129
- jsi::Value const &thisValue,
151
+ jsi::Value const & /*thisValue*/,
130
152
  jsi::Value const *arguments,
131
- size_t count) noexcept -> jsi::Value {
153
+ size_t /*count*/) noexcept -> jsi::Value {
132
154
  return valueFromShadowNode(
133
155
  runtime,
134
- cloneNode(
156
+ cloneNodeUsingNewest(
135
157
  uiManager,
136
158
  newestShadowNodesRegistry,
137
- shadowNodeFromValue(runtime, arguments[0]),
159
+ *shadowNodeFromValue(runtime, arguments[0]),
138
160
  ShadowNode::emptySharedShadowNodeSharedList()));
139
161
  });
140
162
  }
@@ -147,16 +169,16 @@ jsi::Value ReanimatedUIManagerBinding::get(
147
169
  2,
148
170
  [uiManager, newestShadowNodesRegistry](
149
171
  jsi::Runtime &runtime,
150
- jsi::Value const &thisValue,
172
+ jsi::Value const & /*thisValue*/,
151
173
  jsi::Value const *arguments,
152
- size_t count) noexcept -> jsi::Value {
174
+ size_t /*count*/) noexcept -> jsi::Value {
153
175
  auto const &rawProps = RawProps(runtime, arguments[1]);
154
176
  return valueFromShadowNode(
155
177
  runtime,
156
- cloneNode(
178
+ cloneNodeUsingNewest(
157
179
  uiManager,
158
180
  newestShadowNodesRegistry,
159
- shadowNodeFromValue(runtime, arguments[0]),
181
+ *shadowNodeFromValue(runtime, arguments[0]),
160
182
  nullptr,
161
183
  &rawProps));
162
184
  });
@@ -170,16 +192,16 @@ jsi::Value ReanimatedUIManagerBinding::get(
170
192
  2,
171
193
  [uiManager, newestShadowNodesRegistry](
172
194
  jsi::Runtime &runtime,
173
- jsi::Value const &thisValue,
195
+ jsi::Value const & /*thisValue*/,
174
196
  jsi::Value const *arguments,
175
- size_t count) noexcept -> jsi::Value {
197
+ size_t /*count*/) noexcept -> jsi::Value {
176
198
  auto const &rawProps = RawProps(runtime, arguments[1]);
177
199
  return valueFromShadowNode(
178
200
  runtime,
179
- cloneNode(
201
+ cloneNodeUsingNewest(
180
202
  uiManager,
181
203
  newestShadowNodesRegistry,
182
- shadowNodeFromValue(runtime, arguments[0]),
204
+ *shadowNodeFromValue(runtime, arguments[0]),
183
205
  ShadowNode::emptySharedShadowNodeSharedList(),
184
206
  &rawProps));
185
207
  });
@@ -190,21 +212,16 @@ jsi::Value ReanimatedUIManagerBinding::get(
190
212
  runtime,
191
213
  name,
192
214
  2,
193
- [newestShadowNodesRegistry](
215
+ [uiManager, newestShadowNodesRegistry](
194
216
  jsi::Runtime &runtime,
195
- jsi::Value const &thisValue,
217
+ jsi::Value const & /*thisValue*/,
196
218
  jsi::Value const *arguments,
197
- size_t count) noexcept -> jsi::Value {
198
- auto parent = shadowNodeFromValue(runtime, arguments[0]);
199
- auto child = shadowNodeFromValue(runtime, arguments[1]);
200
- {
201
- auto lock = newestShadowNodesRegistry->createLock();
202
- auto newest = newestShadowNodesRegistry->get(child->getTag());
203
- if (newest != nullptr) {
204
- child = newest;
205
- }
206
- }
207
- UIManager_appendChild(parent, child);
219
+ size_t /*count*/) noexcept -> jsi::Value {
220
+ appendChildUsingNewest(
221
+ uiManager,
222
+ newestShadowNodesRegistry,
223
+ shadowNodeFromValue(runtime, arguments[0]),
224
+ shadowNodeFromValue(runtime, arguments[1]));
208
225
  return jsi::Value::undefined();
209
226
  });
210
227
  }
@@ -0,0 +1,8 @@
1
+ #pragma once
2
+
3
+ typedef enum LayoutAnimationType {
4
+ ENTERING = 1,
5
+ EXITING = 2,
6
+ LAYOUT = 3,
7
+ SHARED_ELEMENT_TRANSITION = 4
8
+ } LayoutAnimationType;
@@ -1,4 +1,5 @@
1
1
  #include "LayoutAnimationsManager.h"
2
+ #include "CollectionUtils.h"
2
3
  #include "Shareables.h"
3
4
 
4
5
  #include <utility>
@@ -7,30 +8,22 @@ namespace reanimated {
7
8
 
8
9
  void LayoutAnimationsManager::configureAnimation(
9
10
  int tag,
10
- const std::string &type,
11
+ LayoutAnimationType type,
12
+ const std::string &sharedTransitionTag,
11
13
  std::shared_ptr<Shareable> config) {
12
14
  auto lock = std::unique_lock<std::mutex>(animationsMutex_);
13
- if (type == "entering") {
14
- enteringAnimations_[tag] = config;
15
- } else if (type == "exiting") {
16
- exitingAnimations_[tag] = config;
17
- } else if (type == "layout") {
18
- layoutAnimations_[tag] = config;
15
+ getConfigsForType(type)[tag] = config;
16
+ if (type == SHARED_ELEMENT_TRANSITION) {
17
+ sharedTransitionGroups_[sharedTransitionTag].push_back(tag);
18
+ viewTagToSharedTag_[tag] = sharedTransitionTag;
19
19
  }
20
20
  }
21
21
 
22
22
  bool LayoutAnimationsManager::hasLayoutAnimation(
23
23
  int tag,
24
- const std::string &type) {
24
+ LayoutAnimationType type) {
25
25
  auto lock = std::unique_lock<std::mutex>(animationsMutex_);
26
- if (type == "entering") {
27
- return enteringAnimations_.find(tag) != enteringAnimations_.end();
28
- } else if (type == "exiting") {
29
- return exitingAnimations_.find(tag) != exitingAnimations_.end();
30
- } else if (type == "layout") {
31
- return layoutAnimations_.find(tag) != layoutAnimations_.end();
32
- }
33
- return false;
26
+ return collection::contains(getConfigsForType(type), tag);
34
27
  }
35
28
 
36
29
  void LayoutAnimationsManager::clearLayoutAnimationConfig(int tag) {
@@ -38,25 +31,30 @@ void LayoutAnimationsManager::clearLayoutAnimationConfig(int tag) {
38
31
  enteringAnimations_.erase(tag);
39
32
  exitingAnimations_.erase(tag);
40
33
  layoutAnimations_.erase(tag);
34
+
35
+ sharedTransitionAnimations_.erase(tag);
36
+ auto const &groupName = viewTagToSharedTag_[tag];
37
+ auto &group = sharedTransitionGroups_[groupName];
38
+ auto position = std::find(group.begin(), group.end(), tag);
39
+ if (position != group.end()) {
40
+ group.erase(position);
41
+ }
42
+ if (group.size() == 0) {
43
+ sharedTransitionGroups_.erase(groupName);
44
+ }
45
+ viewTagToSharedTag_.erase(tag);
41
46
  }
42
47
 
43
48
  void LayoutAnimationsManager::startLayoutAnimation(
44
49
  jsi::Runtime &rt,
45
50
  int tag,
46
- const std::string &type,
51
+ LayoutAnimationType type,
47
52
  const jsi::Object &values) {
48
53
  std::shared_ptr<Shareable> config, viewShareable;
49
54
  {
50
55
  auto lock = std::unique_lock<std::mutex>(animationsMutex_);
51
- if (type == "entering") {
52
- config = enteringAnimations_[tag];
53
- } else if (type == "exiting") {
54
- config = exitingAnimations_[tag];
55
- } else if (type == "layout") {
56
- config = layoutAnimations_[tag];
57
- }
56
+ config = getConfigsForType(type)[tag];
58
57
  }
59
-
60
58
  // TODO: cache the following!!
61
59
  jsi::Value layoutAnimationRepositoryAsValue =
62
60
  rt.global()
@@ -68,9 +66,66 @@ void LayoutAnimationsManager::startLayoutAnimation(
68
66
  startAnimationForTag.call(
69
67
  rt,
70
68
  jsi::Value(tag),
71
- jsi::String::createFromAscii(rt, type),
69
+ jsi::Value(static_cast<int>(type)),
72
70
  values,
73
71
  config->getJSValue(rt));
74
72
  }
75
73
 
74
+ void LayoutAnimationsManager::cancelLayoutAnimation(
75
+ jsi::Runtime &rt,
76
+ int tag,
77
+ LayoutAnimationType type,
78
+ bool cancelled = true,
79
+ bool removeView = true) {
80
+ jsi::Value layoutAnimationRepositoryAsValue =
81
+ rt.global()
82
+ .getPropertyAsObject(rt, "global")
83
+ .getProperty(rt, "LayoutAnimationsManager");
84
+ jsi::Function cancelLayoutAnimation =
85
+ layoutAnimationRepositoryAsValue.getObject(rt).getPropertyAsFunction(
86
+ rt, "stop");
87
+ std::shared_ptr<Shareable> config;
88
+ {
89
+ auto lock = std::unique_lock<std::mutex>(animationsMutex_);
90
+ config = sharedTransitionAnimations_[tag];
91
+ }
92
+ if (config != nullptr) {
93
+ cancelLayoutAnimation.call(
94
+ rt, jsi::Value(tag), config->getJSValue(rt), cancelled, removeView);
95
+ }
96
+ }
97
+
98
+ /*
99
+ The top screen on the stack triggers the animation, so we need to find
100
+ the sibling view registered in the past. This method finds view
101
+ registered in the same transition group (with the same transition tag)
102
+ which has been added to that group directly before the one that we
103
+ provide as an argument.
104
+ */
105
+ int LayoutAnimationsManager::findPrecedingViewTagForTransition(int tag) {
106
+ auto const &groupName = viewTagToSharedTag_[tag];
107
+ auto const &group = sharedTransitionGroups_[groupName];
108
+ auto position = std::find(group.begin(), group.end(), tag);
109
+ if (position != group.end() && position != group.begin()) {
110
+ return *std::prev(position);
111
+ }
112
+ return -1;
113
+ }
114
+
115
+ std::unordered_map<int, std::shared_ptr<Shareable>>
116
+ &LayoutAnimationsManager::getConfigsForType(LayoutAnimationType type) {
117
+ switch (type) {
118
+ case ENTERING:
119
+ return enteringAnimations_;
120
+ case EXITING:
121
+ return exitingAnimations_;
122
+ case LAYOUT:
123
+ return layoutAnimations_;
124
+ case SHARED_ELEMENT_TRANSITION:
125
+ return sharedTransitionAnimations_;
126
+ default:
127
+ assert(false);
128
+ }
129
+ }
130
+
76
131
  } // namespace reanimated
@@ -1,6 +1,7 @@
1
1
  #pragma once
2
2
 
3
3
  #include "ErrorHandler.h"
4
+ #include "LayoutAnimationType.h"
4
5
  #include "Shareables.h"
5
6
 
6
7
  #include <jsi/jsi.h>
@@ -10,6 +11,7 @@
10
11
  #include <mutex>
11
12
  #include <string>
12
13
  #include <unordered_map>
14
+ #include <vector>
13
15
 
14
16
  namespace reanimated {
15
17
 
@@ -19,20 +21,35 @@ class LayoutAnimationsManager {
19
21
  public:
20
22
  void configureAnimation(
21
23
  int tag,
22
- const std::string &type,
24
+ LayoutAnimationType type,
25
+ const std::string &sharedTransitionTag,
23
26
  std::shared_ptr<Shareable> config);
24
- bool hasLayoutAnimation(int tag, const std::string &type);
27
+ bool hasLayoutAnimation(int tag, LayoutAnimationType type);
25
28
  void startLayoutAnimation(
26
29
  jsi::Runtime &rt,
27
30
  int tag,
28
- const std::string &type,
31
+ LayoutAnimationType type,
29
32
  const jsi::Object &values);
30
33
  void clearLayoutAnimationConfig(int tag);
34
+ void cancelLayoutAnimation(
35
+ jsi::Runtime &rt,
36
+ int tag,
37
+ LayoutAnimationType type,
38
+ bool cancelled /* = true */,
39
+ bool removeView /* = true */);
40
+ int findPrecedingViewTagForTransition(int tag);
31
41
 
32
42
  private:
43
+ std::unordered_map<int, std::shared_ptr<Shareable>> &getConfigsForType(
44
+ LayoutAnimationType type);
45
+
33
46
  std::unordered_map<int, std::shared_ptr<Shareable>> enteringAnimations_;
34
47
  std::unordered_map<int, std::shared_ptr<Shareable>> exitingAnimations_;
35
48
  std::unordered_map<int, std::shared_ptr<Shareable>> layoutAnimations_;
49
+ std::unordered_map<int, std::shared_ptr<Shareable>>
50
+ sharedTransitionAnimations_;
51
+ std::unordered_map<std::string, std::vector<int>> sharedTransitionGroups_;
52
+ std::unordered_map<int, std::string> viewTagToSharedTag_;
36
53
  mutable std::mutex
37
54
  animationsMutex_; // Protects `enteringAnimations_`, `exitingAnimations_`,
38
55
  // `layoutAnimations_` and `viewSharedValues_`.