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
@@ -9,6 +9,7 @@
9
9
  #include <jsi/jsi.h>
10
10
 
11
11
  #include <memory>
12
+ #include <string>
12
13
  #include <utility>
13
14
 
14
15
  #if __has_include(<reacthermes/HermesExecutorFactory.h>)
@@ -41,6 +42,11 @@ class HermesExecutorRuntimeAdapter
41
42
  thread_->quitSynchronous();
42
43
  }
43
44
 
45
+ #if REACT_NATIVE_MINOR_VERSION >= 71
46
+ facebook::hermes::HermesRuntime &getRuntime() override {
47
+ return hermesRuntime_;
48
+ }
49
+ #else
44
50
  facebook::jsi::Runtime &getRuntime() override {
45
51
  return hermesRuntime_;
46
52
  }
@@ -48,6 +54,7 @@ class HermesExecutorRuntimeAdapter
48
54
  facebook::hermes::debugger::Debugger &getDebugger() override {
49
55
  return hermesRuntime_.getDebugger();
50
56
  }
57
+ #endif // REACT_NATIVE_MINOR_VERSION
51
58
 
52
59
  // This is not empty in the original implementation, but we decided to tickle
53
60
  // the runtime by running a small piece of code on every frame as using this
@@ -72,20 +79,62 @@ ReanimatedHermesRuntime::ReanimatedHermesRuntime(
72
79
  #if HERMES_ENABLE_DEBUGGER
73
80
  auto adapter =
74
81
  std::make_unique<HermesExecutorRuntimeAdapter>(*runtime_, jsQueue);
82
+ #if REACT_NATIVE_MINOR_VERSION >= 71
83
+ debugToken_ = facebook::hermes::inspector::chrome::enableDebugging(
84
+ std::move(adapter), "Reanimated Runtime");
85
+ #else
75
86
  facebook::hermes::inspector::chrome::enableDebugging(
76
87
  std::move(adapter), "Reanimated Runtime");
88
+ #endif // REACT_NATIVE_MINOR_VERSION
77
89
  #else
78
90
  // This is required by iOS, because there is an assertion in the destructor
79
91
  // that the thread was indeed `quit` before
80
92
  jsQueue->quitSynchronous();
81
93
  #endif
94
+
95
+ #ifdef DEBUG
96
+ facebook::hermes::HermesRuntime *wrappedRuntime = runtime_.get();
97
+ jsi::Value evalWithSourceMap = jsi::Function::createFromHostFunction(
98
+ *runtime_,
99
+ jsi::PropNameID::forAscii(*runtime_, "evalWithSourceMap"),
100
+ 3,
101
+ [wrappedRuntime](
102
+ jsi::Runtime &rt,
103
+ const jsi::Value &thisValue,
104
+ const jsi::Value *args,
105
+ size_t count) -> jsi::Value {
106
+ auto code = std::make_shared<const jsi::StringBuffer>(
107
+ args[0].asString(rt).utf8(rt));
108
+ std::string sourceURL;
109
+ if (count > 1 && args[1].isString()) {
110
+ sourceURL = args[1].asString(rt).utf8(rt);
111
+ }
112
+ std::shared_ptr<const jsi::Buffer> sourceMap;
113
+ if (count > 2 && args[2].isString()) {
114
+ sourceMap = std::make_shared<const jsi::StringBuffer>(
115
+ args[2].asString(rt).utf8(rt));
116
+ }
117
+ #if REACT_NATIVE_MINOR_VERSION >= 65
118
+ return wrappedRuntime->evaluateJavaScriptWithSourceMap(
119
+ code, sourceMap, sourceURL);
120
+ #else
121
+ return wrappedRuntime->evaluateJavaScript(code, sourceURL);
122
+ #endif
123
+ });
124
+ runtime_->global().setProperty(
125
+ *runtime_, "evalWithSourceMap", evalWithSourceMap);
126
+ #endif // DEBUG
82
127
  }
83
128
 
84
129
  ReanimatedHermesRuntime::~ReanimatedHermesRuntime() {
85
130
  #if HERMES_ENABLE_DEBUGGER
86
131
  // We have to disable debugging before the runtime is destroyed.
132
+ #if REACT_NATIVE_MINOR_VERSION >= 71
133
+ facebook::hermes::inspector::chrome::disableDebugging(debugToken_);
134
+ #else
87
135
  facebook::hermes::inspector::chrome::disableDebugging(*runtime_);
88
- #endif
136
+ #endif // REACT_NATIVE_MINOR_VERSION
137
+ #endif // HERMES_ENABLE_DEBUGGER
89
138
  }
90
139
 
91
140
  } // namespace reanimated
@@ -25,6 +25,10 @@
25
25
  #include <hermes/hermes.h>
26
26
  #endif
27
27
 
28
+ #if REACT_NATIVE_MINOR_VERSION >= 71
29
+ #include <hermes/inspector/chrome/Registration.h>
30
+ #endif
31
+
28
32
  namespace reanimated {
29
33
 
30
34
  using namespace facebook;
@@ -116,8 +120,13 @@ class ReanimatedHermesRuntime
116
120
  ~ReanimatedHermesRuntime();
117
121
 
118
122
  private:
119
- std::shared_ptr<facebook::hermes::HermesRuntime> runtime_;
123
+ std::unique_ptr<facebook::hermes::HermesRuntime> runtime_;
120
124
  ReanimatedReentrancyCheck reentrancyCheck_;
125
+ #if HERMES_ENABLE_DEBUGGER
126
+ #if REACT_NATIVE_MINOR_VERSION >= 71
127
+ facebook::hermes::inspector::chrome::DebugSessionToken debugToken_;
128
+ #endif // REACT_NATIVE_MINOR_VERSION >= 71
129
+ #endif // HERMES_ENABLE_DEBUGGER
121
130
  };
122
131
 
123
132
  } // namespace reanimated
@@ -11,8 +11,12 @@
11
11
  #elif JS_RUNTIME_V8
12
12
  #include <v8runtime/V8RuntimeFactory.h>
13
13
  #else
14
+ #if REACT_NATIVE_MINOR_VERSION >= 71
15
+ #include <jsc/JSCRuntime.h>
16
+ #else
14
17
  #include <jsi/JSCRuntime.h>
15
- #endif
18
+ #endif // REACT_NATIVE_MINOR_VERSION
19
+ #endif // JS_RUNTIME
16
20
 
17
21
  namespace reanimated {
18
22
 
@@ -10,7 +10,7 @@ void EventHandlerRegistry::registerEventHandler(
10
10
  eventHandlers[eventHandler->id] = eventHandler;
11
11
  }
12
12
 
13
- void EventHandlerRegistry::unregisterEventHandler(unsigned long id) {
13
+ void EventHandlerRegistry::unregisterEventHandler(uint64_t id) {
14
14
  const std::lock_guard<std::mutex> lock(instanceMutex);
15
15
  auto handlerIt = eventHandlers.find(id);
16
16
  if (handlerIt != eventHandlers.end()) {
@@ -24,13 +24,9 @@ void EventHandlerRegistry::unregisterEventHandler(unsigned long id) {
24
24
 
25
25
  void EventHandlerRegistry::processEvent(
26
26
  jsi::Runtime &rt,
27
- std::string eventName,
28
- #ifdef RCT_NEW_ARCH_ENABLED
29
- jsi::Value &eventPayload
30
- #else
31
- std::string eventPayload
32
- #endif
33
- /**/) {
27
+ double eventTimestamp,
28
+ const std::string &eventName,
29
+ const jsi::Value &eventPayload) {
34
30
  std::vector<std::shared_ptr<WorkletEventHandler>> handlersForEvent;
35
31
  {
36
32
  const std::lock_guard<std::mutex> lock(instanceMutex);
@@ -41,38 +37,16 @@ void EventHandlerRegistry::processEvent(
41
37
  }
42
38
  }
43
39
  }
44
- #ifdef RCT_NEW_ARCH_ENABLED
45
- eventPayload.asObject(rt).setProperty(
46
- rt, "eventName", jsi::String::createFromUtf8(rt, eventName));
47
- for (auto handler : handlersForEvent) {
48
- handler->process(rt, eventPayload);
49
- }
50
- #else
51
- // We receive here a JS Map with JSON as a value of NativeMap key
52
- // { NativeMap: { "jsonProp": "json value" } }
53
- // So we need to extract only JSON part
54
- std::string delimimter = "NativeMap:";
55
- auto positionToSplit = eventPayload.find(delimimter) + delimimter.size();
56
- auto lastBracketCharactedPosition = eventPayload.size() - positionToSplit - 1;
57
- auto eventJSON =
58
- eventPayload.substr(positionToSplit, lastBracketCharactedPosition);
59
40
 
60
- if (eventJSON.compare(std::string("null")) == 0) {
61
- return;
62
- }
63
-
64
- auto eventObject = jsi::Value::createFromJsonUtf8(
65
- rt, reinterpret_cast<uint8_t *>(&eventJSON[0]), eventJSON.size());
66
-
67
- eventObject.asObject(rt).setProperty(
41
+ eventPayload.asObject(rt).setProperty(
68
42
  rt, "eventName", jsi::String::createFromUtf8(rt, eventName));
69
43
  for (auto handler : handlersForEvent) {
70
- handler->process(rt, eventObject);
44
+ handler->process(eventTimestamp, eventPayload);
71
45
  }
72
- #endif
73
46
  }
74
47
 
75
- bool EventHandlerRegistry::isAnyHandlerWaitingForEvent(std::string eventName) {
48
+ bool EventHandlerRegistry::isAnyHandlerWaitingForEvent(
49
+ const std::string &eventName) {
76
50
  const std::lock_guard<std::mutex> lock(instanceMutex);
77
51
  auto it = eventMappings.find(eventName);
78
52
  return (it != eventMappings.end()) && (!(it->second).empty());
@@ -18,28 +18,22 @@ class WorkletEventHandler;
18
18
  class EventHandlerRegistry {
19
19
  std::map<
20
20
  std::string,
21
- std::unordered_map<unsigned long, std::shared_ptr<WorkletEventHandler>>>
21
+ std::unordered_map<uint64_t, std::shared_ptr<WorkletEventHandler>>>
22
22
  eventMappings;
23
- std::map<unsigned long, std::shared_ptr<WorkletEventHandler>> eventHandlers;
23
+ std::map<uint64_t, std::shared_ptr<WorkletEventHandler>> eventHandlers;
24
24
  std::mutex instanceMutex;
25
25
 
26
26
  public:
27
27
  void registerEventHandler(std::shared_ptr<WorkletEventHandler> eventHandler);
28
- void unregisterEventHandler(unsigned long id);
28
+ void unregisterEventHandler(uint64_t id);
29
29
 
30
- #ifdef RCT_NEW_ARCH_ENABLED
31
30
  void processEvent(
32
31
  jsi::Runtime &rt,
33
- std::string eventName,
34
- jsi::Value &eventPayload);
35
- #else
36
- void processEvent(
37
- jsi::Runtime &rt,
38
- std::string eventName,
39
- std::string eventPayload);
40
- #endif
32
+ double eventTimestamp,
33
+ const std::string &eventName,
34
+ const jsi::Value &eventPayload);
41
35
 
42
- bool isAnyHandlerWaitingForEvent(std::string eventName);
36
+ bool isAnyHandlerWaitingForEvent(const std::string &eventName);
43
37
  };
44
38
 
45
39
  } // namespace reanimated
@@ -11,9 +11,13 @@ CoreFunction::CoreFunction(
11
11
  jsi::Runtime &rt = *runtimeHelper->rnRuntime();
12
12
  auto workletObject = workletValue.asObject(rt);
13
13
  rnFunction_ = std::make_unique<jsi::Function>(workletObject.asFunction(rt));
14
- functionBody_ =
15
- workletObject.getProperty(rt, "asString").asString(rt).utf8(rt);
16
- location_ = workletObject.getProperty(rt, "__location").asString(rt).utf8(rt);
14
+ functionBody_ = workletObject.getPropertyAsObject(rt, "__initData")
15
+ .getProperty(rt, "code")
16
+ .asString(rt)
17
+ .utf8(rt);
18
+ location_ = "worklet_" +
19
+ std::to_string(static_cast<uint64_t>(
20
+ workletObject.getProperty(rt, "__workletHash").getNumber()));
17
21
  }
18
22
 
19
23
  std::unique_ptr<jsi::Function> &CoreFunction::getFunction(jsi::Runtime &rt) {
@@ -57,61 +61,8 @@ std::shared_ptr<Shareable> extractShareableOrThrow(
57
61
 
58
62
  Shareable::~Shareable() {}
59
63
 
60
- #if HAS_JS_WEAK_OBJECTS
61
-
62
- jsi::Value RetainingShareable::getJSValue(jsi::Runtime &rt) {
63
- jsi::Value value;
64
- if (runtimeHelper_->isRNRuntime(rt)) {
65
- // TODO: it is suboptimal to generate new object every time getJS is called
66
- // on host runtime – the objects we are generating already exists and we
67
- // should possibly just grab a hold of such object and use it here instead
68
- // of creating a new JS representation. As far as I understand the only
69
- // case where it can be realistically called this way is when a shared
70
- // value is created and then accessed on the same runtime
71
- return toJSValue(rt);
72
- } else if (remoteValue_ == nullptr) {
73
- value = toJSValue(rt);
74
- remoteValue_ = std::make_unique<jsi::WeakObject>(rt, value.asObject(rt));
75
- } else {
76
- value = remoteValue_->lock(rt);
77
- if (value.isUndefined()) {
78
- value = toJSValue(rt);
79
- remoteValue_ = std::make_unique<jsi::WeakObject>(rt, value.asObject(rt));
80
- }
81
- }
82
- return value;
83
- }
84
-
85
- RetainingShareable::~RetainingShareable() {
86
- if (runtimeHelper_->uiRuntimeDestroyed) {
87
- // The below use of unique_ptr.release prevents the smart pointer from
88
- // calling the destructor of the kept object. This effectively results in
89
- // leaking some memory. We do this on purpose, as sometimes we would keep
90
- // references to JSI objects past the lifetime of its runtime (e.g., shared
91
- // values references from the RN VM holds reference to JSI objects on the
92
- // UI runtime). When the UI runtime is terminated, the orphaned JSI objects
93
- // would crash the app when their destructors are called, because they
94
- // call into a memory that's managed by the terminated runtime. We accept
95
- // the tradeoff of leaking memory here, as it has a limited impact. This
96
- // scenario can only occur when the React instance is torn down which
97
- // happens in development mode during app reloads, or in production when the
98
- // app is being shut down gracefully by the system. An alternative solution
99
- // would require us to keep track of all JSI values that are in use which
100
- // would require additional data structure and compute spent on bookkeeping
101
- // that only for the sake of destroying the values in time before the
102
- // runtime is terminated. Note that the underlying memory that jsi::Value
103
- // refers to is managed by the VM and gets freed along with the runtime.
104
- remoteValue_.release();
105
- }
106
- }
107
-
108
- #endif // HAS_JS_WEAK_OBJECTS
109
-
110
- ShareableArray::ShareableArray(
111
- const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
112
- jsi::Runtime &rt,
113
- const jsi::Array &array)
114
- : RetainingShareable(runtimeHelper, rt, ArrayType) {
64
+ ShareableArray::ShareableArray(jsi::Runtime &rt, const jsi::Array &array)
65
+ : Shareable(ArrayType) {
115
66
  auto size = array.size(rt);
116
67
  data_.reserve(size);
117
68
  for (size_t i = 0; i < size; i++) {
@@ -119,11 +70,8 @@ ShareableArray::ShareableArray(
119
70
  }
120
71
  }
121
72
 
122
- ShareableObject::ShareableObject(
123
- const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
124
- jsi::Runtime &rt,
125
- const jsi::Object &object)
126
- : RetainingShareable(runtimeHelper, rt, ObjectType) {
73
+ ShareableObject::ShareableObject(jsi::Runtime &rt, const jsi::Object &object)
74
+ : Shareable(ObjectType) {
127
75
  auto propertyNames = object.getPropertyNames(rt);
128
76
  auto size = propertyNames.size(rt);
129
77
  data_.reserve(size);
@@ -6,21 +6,37 @@
6
6
  #include <utility>
7
7
  #include <vector>
8
8
 
9
- #ifdef RCT_NEW_ARCH_ENABLED
10
- #include <react/renderer/uimanager/primitives.h>
11
- #endif
12
-
13
9
  #include "ReanimatedRuntime.h"
14
10
  #include "RuntimeManager.h"
15
11
  #include "Scheduler.h"
16
12
 
17
- #define HAS_JS_WEAK_OBJECTS JS_RUNTIME_HERMES
18
-
19
13
  using namespace facebook;
20
14
 
21
15
  namespace reanimated {
22
16
 
23
- class CoreFunction;
17
+ class JSRuntimeHelper;
18
+
19
+ // Core functions are not allowed to capture outside variables, otherwise they'd
20
+ // try to access _closure variable which is something we want to avoid for
21
+ // simplicity reasons.
22
+ class CoreFunction {
23
+ private:
24
+ std::unique_ptr<jsi::Function> rnFunction_;
25
+ std::unique_ptr<jsi::Function> uiFunction_;
26
+ std::string functionBody_;
27
+ std::string location_;
28
+ JSRuntimeHelper
29
+ *runtimeHelper_; // runtime helper holds core function references, so we
30
+ // use normal pointer here to avoid ref cycles.
31
+ std::unique_ptr<jsi::Function> &getFunction(jsi::Runtime &rt);
32
+
33
+ public:
34
+ CoreFunction(JSRuntimeHelper *runtimeHelper, const jsi::Value &workletObject);
35
+ template <typename... Args>
36
+ jsi::Value call(jsi::Runtime &rt, Args &&...args) {
37
+ return getFunction(rt)->call(rt, args...);
38
+ }
39
+ };
24
40
 
25
41
  class JSRuntimeHelper {
26
42
  private:
@@ -35,8 +51,9 @@ class JSRuntimeHelper {
35
51
  const std::shared_ptr<Scheduler> &scheduler)
36
52
  : rnRuntime_(rnRuntime), uiRuntime_(uiRuntime), scheduler_(scheduler) {}
37
53
 
38
- volatile bool uiRuntimeDestroyed;
39
- std::shared_ptr<CoreFunction> valueUnpacker;
54
+ volatile bool uiRuntimeDestroyed = false;
55
+ std::unique_ptr<CoreFunction> callGuard;
56
+ std::unique_ptr<CoreFunction> valueUnpacker;
40
57
 
41
58
  inline jsi::Runtime *uiRuntime() const {
42
59
  return uiRuntime_;
@@ -61,27 +78,19 @@ class JSRuntimeHelper {
61
78
  void scheduleOnJS(std::function<void()> job) {
62
79
  scheduler_->scheduleOnJS(job);
63
80
  }
64
- };
65
-
66
- // Core functions are not allowed to capture outside variables, otherwise they'd
67
- // try to access _closure variable which is something we want to avoid for
68
- // simplicity reasons.
69
- class CoreFunction {
70
- private:
71
- std::unique_ptr<jsi::Function> rnFunction_;
72
- std::unique_ptr<jsi::Function> uiFunction_;
73
- std::string functionBody_;
74
- std::string location_;
75
- JSRuntimeHelper
76
- *runtimeHelper_; // runtime helper holds core function references, so we
77
- // use normal pointer here to avoid ref cycles.
78
- std::unique_ptr<jsi::Function> &getFunction(jsi::Runtime &rt);
79
81
 
80
- public:
81
- CoreFunction(JSRuntimeHelper *runtimeHelper, const jsi::Value &workletObject);
82
82
  template <typename... Args>
83
- jsi::Value call(jsi::Runtime &rt, Args &&...args) {
84
- return getFunction(rt)->call(rt, args...);
83
+ inline void runOnUIGuarded(const jsi::Value &function, Args &&...args) {
84
+ // We only use callGuard in debug mode, otherwise we call the provided
85
+ // function directly. CallGuard provides a way of capturing exceptions in
86
+ // JavaScript and propagating them to the main React Native thread such that
87
+ // they can be presented using RN's LogBox.
88
+ jsi::Runtime &rt = *uiRuntime_;
89
+ #ifdef DEBUG
90
+ callGuard->call(rt, function, args...);
91
+ #else
92
+ function.asObject(rt).asFunction(rt).call(rt, args...);
93
+ #endif
85
94
  }
86
95
  };
87
96
 
@@ -106,9 +115,7 @@ class Shareable {
106
115
  RemoteFunctionType,
107
116
  HandleType,
108
117
  SynchronizedDataHolder,
109
- #ifdef RCT_NEW_ARCH_ENABLED
110
- ShadowNode,
111
- #endif
118
+ HostObjectType,
112
119
  };
113
120
 
114
121
  explicit Shareable(ValueType valueType) : valueType_(valueType) {}
@@ -126,34 +133,57 @@ class Shareable {
126
133
  ValueType valueType_;
127
134
  };
128
135
 
129
- class RetainingShareable : public Shareable {
130
- protected:
131
- std::shared_ptr<JSRuntimeHelper> runtimeHelper_;
132
-
133
- #if HAS_JS_WEAK_OBJECTS
134
-
136
+ template <typename BaseClass>
137
+ class RetainingShareable : virtual public BaseClass {
135
138
  private:
136
- std::unique_ptr<jsi::WeakObject> remoteValue_;
137
-
138
- public:
139
- jsi::Value getJSValue(jsi::Runtime &rt) final;
140
-
141
- RetainingShareable(
142
- const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
143
- jsi::Runtime &rt,
144
- ValueType valueType)
145
- : Shareable(valueType), runtimeHelper_(runtimeHelper) {}
146
-
147
- ~RetainingShareable();
148
- #else
139
+ std::shared_ptr<JSRuntimeHelper> runtimeHelper_;
140
+ std::unique_ptr<jsi::Value> remoteValue_;
149
141
 
150
142
  public:
143
+ template <typename... Args>
151
144
  RetainingShareable(
152
145
  const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
153
- jsi::Runtime &rt,
154
- ValueType valueType)
155
- : Shareable(valueType), runtimeHelper_(runtimeHelper) {}
156
- #endif
146
+ Args &&...args)
147
+ : BaseClass(std::forward<Args>(args)...), runtimeHelper_(runtimeHelper) {}
148
+ jsi::Value getJSValue(jsi::Runtime &rt) {
149
+ if (runtimeHelper_->isRNRuntime(rt)) {
150
+ // TODO: it is suboptimal to generate new object every time getJS is
151
+ // called on host runtime – the objects we are generating already exists
152
+ // and we should possibly just grab a hold of such object and use it here
153
+ // instead of creating a new JS representation. As far as I understand the
154
+ // only case where it can be realistically called this way is when a
155
+ // shared value is created and then accessed on the same runtime
156
+ return BaseClass::toJSValue(rt);
157
+ } else if (remoteValue_ == nullptr) {
158
+ auto value = BaseClass::toJSValue(rt);
159
+ remoteValue_ = std::make_unique<jsi::Value>(rt, value);
160
+ return value;
161
+ }
162
+ return jsi::Value(rt, *remoteValue_);
163
+ }
164
+ ~RetainingShareable() {
165
+ if (runtimeHelper_->uiRuntimeDestroyed) {
166
+ // The below use of unique_ptr.release prevents the smart pointer from
167
+ // calling the destructor of the kept object. This effectively results in
168
+ // leaking some memory. We do this on purpose, as sometimes we would keep
169
+ // references to JSI objects past the lifetime of its runtime (e.g.,
170
+ // shared values references from the RN VM holds reference to JSI objects
171
+ // on the UI runtime). When the UI runtime is terminated, the orphaned JSI
172
+ // objects would crash the app when their destructors are called, because
173
+ // they call into a memory that's managed by the terminated runtime. We
174
+ // accept the tradeoff of leaking memory here, as it has a limited impact.
175
+ // This scenario can only occur when the React instance is torn down which
176
+ // happens in development mode during app reloads, or in production when
177
+ // the app is being shut down gracefully by the system. An alternative
178
+ // solution would require us to keep track of all JSI values that are in
179
+ // use which would require additional data structure and compute spent on
180
+ // bookkeeping that only for the sake of destroying the values in time
181
+ // before the runtime is terminated. Note that the underlying memory that
182
+ // jsi::Value refers to is managed by the VM and gets freed along with the
183
+ // runtime.
184
+ remoteValue_.release();
185
+ }
186
+ }
157
187
  };
158
188
 
159
189
  class ShareableJSRef : public jsi::HostObject {
@@ -195,12 +225,9 @@ std::shared_ptr<T> extractShareableOrThrow(
195
225
  return res;
196
226
  }
197
227
 
198
- class ShareableArray : public RetainingShareable {
228
+ class ShareableArray : public Shareable {
199
229
  public:
200
- ShareableArray(
201
- const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
202
- jsi::Runtime &rt,
203
- const jsi::Array &array);
230
+ ShareableArray(jsi::Runtime &rt, const jsi::Array &array);
204
231
 
205
232
  jsi::Value toJSValue(jsi::Runtime &rt) override {
206
233
  auto size = data_.size();
@@ -215,12 +242,9 @@ class ShareableArray : public RetainingShareable {
215
242
  std::vector<std::shared_ptr<Shareable>> data_;
216
243
  };
217
244
 
218
- class ShareableObject : public RetainingShareable {
245
+ class ShareableObject : public Shareable {
219
246
  public:
220
- ShareableObject(
221
- const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
222
- jsi::Runtime &rt,
223
- const jsi::Object &object);
247
+ ShareableObject(jsi::Runtime &rt, const jsi::Object &object);
224
248
  jsi::Value toJSValue(jsi::Runtime &rt) override {
225
249
  auto obj = jsi::Object(rt);
226
250
  for (size_t i = 0, size = data_.size(); i < size; i++) {
@@ -234,34 +258,31 @@ class ShareableObject : public RetainingShareable {
234
258
  std::vector<std::pair<std::string, std::shared_ptr<Shareable>>> data_;
235
259
  };
236
260
 
237
- #ifdef RCT_NEW_ARCH_ENABLED
238
- class ShareableShadowNodeWrapper : public Shareable {
239
- private:
240
- react::ShadowNode::Shared shadowNode_;
241
-
261
+ class ShareableHostObject : public Shareable {
242
262
  public:
243
- ShareableShadowNodeWrapper(
263
+ ShareableHostObject(
244
264
  const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
245
265
  jsi::Runtime &rt,
246
- const jsi::Object &wrapperObject)
247
- : Shareable(ShadowNode) {
248
- shadowNode_ =
249
- wrapperObject.getHostObject<ShadowNodeWrapper>(rt)->shadowNode;
250
- }
266
+ const std::shared_ptr<jsi::HostObject> &hostObject)
267
+ : Shareable(HostObjectType), hostObject_(hostObject) {}
251
268
  jsi::Value toJSValue(jsi::Runtime &rt) override {
252
- return jsi::Object::createFromHostObject(
253
- rt, std::make_shared<ShadowNodeWrapper>(shadowNode_));
269
+ return jsi::Object::createFromHostObject(rt, hostObject_);
254
270
  }
271
+
272
+ protected:
273
+ std::shared_ptr<jsi::HostObject> hostObject_;
255
274
  };
256
- #endif
257
275
 
258
276
  class ShareableWorklet : public ShareableObject {
277
+ private:
278
+ std::shared_ptr<JSRuntimeHelper> runtimeHelper_;
279
+
259
280
  public:
260
281
  ShareableWorklet(
261
282
  const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
262
283
  jsi::Runtime &rt,
263
284
  const jsi::Object &worklet)
264
- : ShareableObject(runtimeHelper, rt, worklet) {
285
+ : ShareableObject(rt, worklet), runtimeHelper_(runtimeHelper) {
265
286
  valueType_ = WorkletType;
266
287
  }
267
288
  jsi::Value toJSValue(jsi::Runtime &rt) override {
@@ -271,18 +292,20 @@ class ShareableWorklet : public ShareableObject {
271
292
  };
272
293
 
273
294
  class ShareableRemoteFunction
274
- : public RetainingShareable,
295
+ : public Shareable,
275
296
  public std::enable_shared_from_this<ShareableRemoteFunction> {
276
297
  private:
277
298
  jsi::Function function_;
299
+ std::shared_ptr<JSRuntimeHelper> runtimeHelper_;
278
300
 
279
301
  public:
280
302
  ShareableRemoteFunction(
281
303
  const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
282
304
  jsi::Runtime &rt,
283
305
  jsi::Function &&function)
284
- : RetainingShareable(runtimeHelper, rt, RemoteFunctionType),
285
- function_(std::move(function)) {}
306
+ : Shareable(RemoteFunctionType),
307
+ function_(std::move(function)),
308
+ runtimeHelper_(runtimeHelper) {}
286
309
  jsi::Value toJSValue(jsi::Runtime &rt) override {
287
310
  if (runtimeHelper_->isUIRuntime(rt)) {
288
311
  #ifdef DEBUG
@@ -311,8 +334,7 @@ class ShareableHandle : public Shareable {
311
334
  jsi::Runtime &rt,
312
335
  const jsi::Object &initializerObject)
313
336
  : Shareable(HandleType), runtimeHelper_(runtimeHelper) {
314
- initializer_ =
315
- std::make_unique<ShareableObject>(runtimeHelper, rt, initializerObject);
337
+ initializer_ = std::make_unique<ShareableObject>(rt, initializerObject);
316
338
  }
317
339
  ~ShareableHandle() {
318
340
  if (runtimeHelper_->uiRuntimeDestroyed) {
@@ -357,7 +379,7 @@ class ShareableSynchronizedDataHolder
357
379
  std::shared_ptr<Shareable> data_;
358
380
  std::shared_ptr<jsi::Value> uiValue_;
359
381
  std::shared_ptr<jsi::Value> rnValue_;
360
- std::mutex dataAccessLock_;
382
+ std::mutex dataAccessMutex_; // Protects `data_`.
361
383
 
362
384
  public:
363
385
  ShareableSynchronizedDataHolder(
@@ -369,7 +391,7 @@ class ShareableSynchronizedDataHolder
369
391
  data_(extractShareableOrThrow(rt, initialValue)) {}
370
392
 
371
393
  jsi::Value get(jsi::Runtime &rt) {
372
- std::unique_lock<std::mutex> read_lock(dataAccessLock_);
394
+ std::unique_lock<std::mutex> read_lock(dataAccessMutex_);
373
395
  if (runtimeHelper_->isUIRuntime(rt)) {
374
396
  if (uiValue_ == nullptr) {
375
397
  auto value = data_->getJSValue(rt);
@@ -390,7 +412,7 @@ class ShareableSynchronizedDataHolder
390
412
  }
391
413
 
392
414
  void set(jsi::Runtime &rt, const jsi::Value &data) {
393
- std::unique_lock<std::mutex> write_lock(dataAccessLock_);
415
+ std::unique_lock<std::mutex> write_lock(dataAccessMutex_);
394
416
  data_ = extractShareableOrThrow(rt, data);
395
417
  uiValue_.reset();
396
418
  rnValue_.reset();
@@ -403,16 +425,14 @@ class ShareableSynchronizedDataHolder
403
425
 
404
426
  class ShareableString : public Shareable {
405
427
  public:
406
- ShareableString(jsi::Runtime &rt, const jsi::String &string)
407
- : Shareable(StringType) {
408
- data = string.utf8(rt);
409
- }
428
+ explicit ShareableString(const std::string &string)
429
+ : Shareable(StringType), data_(string) {}
410
430
  jsi::Value toJSValue(jsi::Runtime &rt) override {
411
- return jsi::String::createFromUtf8(rt, data);
431
+ return jsi::String::createFromUtf8(rt, data_);
412
432
  }
413
433
 
414
434
  protected:
415
- std::string data;
435
+ std::string data_;
416
436
  };
417
437
 
418
438
  class ShareableScalar : public Shareable {