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
@@ -1,7 +1,15 @@
1
1
  import { NativeModules } from 'react-native';
2
- import { ShareableRef, ShareableSyncDataHolderRef } from '../commonTypes';
3
- import { LayoutAnimationFunction } from '../layoutReanimation';
4
- import { version as jsVersion } from '../../../package.json';
2
+ import {
3
+ ShareableRef,
4
+ ShareableSyncDataHolderRef,
5
+ Value3D,
6
+ ValueRotation,
7
+ } from '../commonTypes';
8
+ import {
9
+ LayoutAnimationFunction,
10
+ LayoutAnimationType,
11
+ } from '../layoutReanimation';
12
+ import { checkVersion } from '../platform-specific/checkVersion';
5
13
 
6
14
  export class NativeReanimated {
7
15
  native: boolean;
@@ -15,44 +23,40 @@ export class NativeReanimated {
15
23
  this.InnerNativeModule = global.__reanimatedModuleProxy;
16
24
  this.native = native;
17
25
  if (native) {
18
- this.checkVersion();
19
- }
20
- }
21
-
22
- checkVersion(): void {
23
- const cppVersion = global._REANIMATED_VERSION_CPP;
24
- const ok = (() => {
25
- if (
26
- jsVersion.match(/^\d+\.\d+\.\d+$/) &&
27
- cppVersion.match(/^\d+\.\d+\.\d+$/)
28
- ) {
29
- // x.y.z, compare only major and minor, skip patch
30
- const [jsMajor, jsMinor] = jsVersion.split('.');
31
- const [cppMajor, cppMinor] = cppVersion.split('.');
32
- return jsMajor === cppMajor && jsMinor === cppMinor;
33
- } else {
34
- // alpha, beta or rc, compare everything
35
- return jsVersion === cppVersion;
26
+ if (this.InnerNativeModule === undefined) {
27
+ console.error(
28
+ `[Reanimated] The native part of Reanimated doesn't seem to be initialized. This could be caused by\n\
29
+ - not rebuilding the app after installing or upgrading Reanimated\n\
30
+ - trying to run Reanimated on an unsupported platform\n\
31
+ - running in a brownfield app without manually initializing the native library`
32
+ );
33
+ return;
36
34
  }
37
- })();
38
- if (!ok) {
39
- console.error(
40
- `[Reanimated] Mismatch between JavaScript part and native part of Reanimated (${jsVersion} vs. ${cppVersion}). Did you forget to re-build the app after upgrading react-native-reanimated? If you use Expo Go, you must downgrade to ${cppVersion} which is bundled into Expo SDK.`
41
- );
42
- // TODO: detect Expo managed workflow
35
+ checkVersion();
43
36
  }
44
37
  }
45
38
 
46
- getTimestamp(): number {
47
- throw new Error('stub implementation, used on the web only');
48
- }
49
-
50
- installCoreFunctions(valueUnpacker: <T>(value: T) => T): void {
51
- return this.InnerNativeModule.installCoreFunctions(valueUnpacker);
39
+ installCoreFunctions(
40
+ callGuard: <T extends Array<any>, U>(
41
+ fn: (...args: T) => U,
42
+ ...args: T
43
+ ) => void,
44
+ valueUnpacker: <T>(value: T) => T
45
+ ): void {
46
+ return this.InnerNativeModule.installCoreFunctions(
47
+ callGuard,
48
+ valueUnpacker
49
+ );
52
50
  }
53
51
 
54
- makeShareableClone<T>(value: T): ShareableRef<T> {
55
- return this.InnerNativeModule.makeShareableClone(value);
52
+ makeShareableClone<T>(
53
+ value: T,
54
+ shouldPersistRemote: boolean
55
+ ): ShareableRef<T> {
56
+ return this.InnerNativeModule.makeShareableClone(
57
+ value,
58
+ shouldPersistRemote
59
+ );
56
60
  }
57
61
 
58
62
  makeSynchronizedDataHolder<T>(
@@ -79,9 +83,15 @@ export class NativeReanimated {
79
83
  registerSensor<T>(
80
84
  sensorType: number,
81
85
  interval: number,
82
- handler: ShareableRef<T>
86
+ iosReferenceFrame: number,
87
+ handler: ShareableRef<T> | ((data: Value3D | ValueRotation) => void)
83
88
  ) {
84
- return this.InnerNativeModule.registerSensor(sensorType, interval, handler);
89
+ return this.InnerNativeModule.registerSensor(
90
+ sensorType,
91
+ interval,
92
+ iosReferenceFrame,
93
+ handler
94
+ );
85
95
  }
86
96
 
87
97
  unregisterSensor(sensorId: number) {
@@ -109,10 +119,16 @@ export class NativeReanimated {
109
119
 
110
120
  configureLayoutAnimation(
111
121
  viewTag: number,
112
- type: string,
122
+ type: LayoutAnimationType,
123
+ sharedTransitionTag: string,
113
124
  config: ShareableRef<Keyframe | LayoutAnimationFunction>
114
125
  ) {
115
- this.InnerNativeModule.configureLayoutAnimation(viewTag, type, config);
126
+ this.InnerNativeModule.configureLayoutAnimation(
127
+ viewTag,
128
+ type,
129
+ sharedTransitionTag,
130
+ config
131
+ );
116
132
  }
117
133
 
118
134
  enableLayoutAnimations(flag: boolean): void {
@@ -123,8 +139,14 @@ export class NativeReanimated {
123
139
  this.InnerNativeModule.configureProps(uiProps, nativeProps);
124
140
  }
125
141
 
126
- subscribeForKeyboardEvents(handler: ShareableRef<number>): number {
127
- return this.InnerNativeModule.subscribeForKeyboardEvents(handler);
142
+ subscribeForKeyboardEvents(
143
+ handler: ShareableRef<number>,
144
+ isStatusBarTranslucent: boolean
145
+ ): number {
146
+ return this.InnerNativeModule.subscribeForKeyboardEvents(
147
+ handler,
148
+ isStatusBarTranslucent
149
+ );
128
150
  }
129
151
 
130
152
  unsubscribeFromKeyboardEvents(listenerId: number): void {
@@ -46,7 +46,7 @@ export function setPath<T>(
46
46
  for (let i = 0; i < keys.length - 1; i++) {
47
47
  // creates entry if there isn't one
48
48
  currObj = currObj as { [key: string]: NestedObjectValues<T> };
49
- if (!currObj[keys[i]]) {
49
+ if (!(keys[i] in currObj)) {
50
50
  // if next key is a number create an array
51
51
  if (typeof keys[i + 1] === 'number') {
52
52
  currObj[keys[i]] = [];
@@ -178,6 +178,13 @@ export function withStyleAnimation(
178
178
  if (prevAnimation && !prevVal) {
179
179
  prevVal = prevAnimation.current;
180
180
  }
181
+ if (prevVal === undefined) {
182
+ console.warn(
183
+ `Initial values for animation are missing for property ${currentEntry.path.join(
184
+ '.'
185
+ )}`
186
+ );
187
+ }
181
188
  setPath(animation.current, currentEntry.path, prevVal);
182
189
  let currentAnimation: AnimationObject;
183
190
  if (
@@ -7,7 +7,14 @@ import {
7
7
  StyleLayoutAnimation,
8
8
  } from './commonTypes';
9
9
  /* global _WORKLET */
10
- import { ParsedColorArray, convertToHSVA, isColor, toRGBA } from '../Colors';
10
+ import {
11
+ ParsedColorArray,
12
+ isColor,
13
+ convertToRGBA,
14
+ rgbaArrayToRGBAColor,
15
+ toGammaSpace,
16
+ toLinearSpace,
17
+ } from '../Colors';
11
18
 
12
19
  import {
13
20
  AnimatedStyle,
@@ -126,55 +133,59 @@ function decorateAnimation<T extends AnimationObject | StyleLayoutAnimation>(
126
133
  return res;
127
134
  };
128
135
 
129
- const tab = ['H', 'S', 'V', 'A'];
136
+ const tab = ['R', 'G', 'B', 'A'];
130
137
  const colorOnStart = (
131
138
  animation: Animation<AnimationObject>,
132
139
  value: string | number,
133
140
  timestamp: Timestamp,
134
141
  previousAnimation: Animation<AnimationObject>
135
142
  ): void => {
136
- let HSVAValue: ParsedColorArray;
137
- let HSVACurrent: ParsedColorArray;
138
- let HSVAToValue: ParsedColorArray;
143
+ let RGBAValue: ParsedColorArray;
144
+ let RGBACurrent: ParsedColorArray;
145
+ let RGBAToValue: ParsedColorArray;
139
146
  const res: Array<number> = [];
140
147
  if (isColor(value)) {
141
- HSVACurrent = convertToHSVA(animation.current);
142
- HSVAValue = convertToHSVA(value);
148
+ RGBACurrent = toLinearSpace(convertToRGBA(animation.current));
149
+ RGBAValue = toLinearSpace(convertToRGBA(value));
143
150
  if (animation.toValue) {
144
- HSVAToValue = convertToHSVA(animation.toValue);
151
+ RGBAToValue = toLinearSpace(convertToRGBA(animation.toValue));
145
152
  }
146
153
  }
147
154
  tab.forEach((i, index) => {
148
155
  animation[i] = Object.assign({}, animationCopy);
149
- animation[i].current = HSVACurrent[index];
150
- animation[i].toValue = HSVAToValue ? HSVAToValue[index] : undefined;
156
+ animation[i].current = RGBACurrent[index];
157
+ animation[i].toValue = RGBAToValue ? RGBAToValue[index] : undefined;
151
158
  animation[i].onStart(
152
159
  animation[i],
153
- HSVAValue[index],
160
+ RGBAValue[index],
154
161
  timestamp,
155
162
  previousAnimation ? previousAnimation[i] : undefined
156
163
  );
157
164
  res.push(animation[i].current);
158
165
  });
159
166
 
160
- animation.current = toRGBA(res as ParsedColorArray);
167
+ animation.current = rgbaArrayToRGBAColor(
168
+ toGammaSpace(res as ParsedColorArray)
169
+ );
161
170
  };
162
171
 
163
172
  const colorOnFrame = (
164
173
  animation: Animation<AnimationObject>,
165
174
  timestamp: Timestamp
166
175
  ): boolean => {
167
- const HSVACurrent = convertToHSVA(animation.current);
176
+ const RGBACurrent = toLinearSpace(convertToRGBA(animation.current));
168
177
  const res: Array<number> = [];
169
178
  let finished = true;
170
179
  tab.forEach((i, index) => {
171
- animation[i].current = HSVACurrent[index];
180
+ animation[i].current = RGBACurrent[index];
172
181
  // @ts-ignore: disable-next-line
173
182
  finished &= animation[i].onFrame(animation[i], timestamp);
174
183
  res.push(animation[i].current);
175
184
  });
176
185
 
177
- animation.current = toRGBA(res as ParsedColorArray);
186
+ animation.current = rgbaArrayToRGBAColor(
187
+ toGammaSpace(res as ParsedColorArray)
188
+ );
178
189
  return finished;
179
190
  };
180
191
 
@@ -247,6 +258,8 @@ type AnimationToDecoration<T extends AnimationObject | StyleLayoutAnimation> =
247
258
  ? NextAnimation<SequenceAnimation>
248
259
  : AnimatableValue | T;
249
260
 
261
+ const IS_NATIVE = NativeReanimatedModule.native;
262
+
250
263
  export function defineAnimation<
251
264
  T extends AnimationObject | StyleLayoutAnimation
252
265
  >(starting: AnimationToDecoration<T>, factory: () => T): T {
@@ -261,7 +274,7 @@ export function defineAnimation<
261
274
  return animation;
262
275
  };
263
276
 
264
- if (_WORKLET || !NativeReanimatedModule.native) {
277
+ if (_WORKLET || !IS_NATIVE) {
265
278
  return create();
266
279
  }
267
280
  // @ts-ignore: eslint-disable-line
@@ -79,7 +79,6 @@ export type Context = Record<string, unknown>;
79
79
  export interface WorkletFunction {
80
80
  _closure?: Context;
81
81
  __workletHash?: number;
82
- __optimalization?: number;
83
82
  }
84
83
 
85
84
  export interface BasicWorkletFunction<T> extends WorkletFunction {
@@ -145,6 +144,21 @@ export interface Animation<T extends AnimationObject> extends AnimationObject {
145
144
  ) => void;
146
145
  }
147
146
 
147
+ export enum SensorType {
148
+ ACCELEROMETER = 1,
149
+ GYROSCOPE = 2,
150
+ GRAVITY = 3,
151
+ MAGNETIC_FIELD = 4,
152
+ ROTATION = 5,
153
+ }
154
+ export enum IOSReferenceFrame {
155
+ XArbitraryZVertical,
156
+ XArbitraryCorrectedZVertical,
157
+ XMagneticNorthZVertical,
158
+ XTrueNorthZVertical,
159
+ Auto,
160
+ }
161
+
148
162
  export interface NumericAnimation {
149
163
  current?: number;
150
164
  }
@@ -160,6 +174,7 @@ export type Value3D = {
160
174
  x: number;
161
175
  y: number;
162
176
  z: number;
177
+ interfaceOrientation: InterfaceOrientation;
163
178
  };
164
179
 
165
180
  export type ValueRotation = {
@@ -170,8 +185,16 @@ export type ValueRotation = {
170
185
  yaw: number;
171
186
  pitch: number;
172
187
  roll: number;
188
+ interfaceOrientation: InterfaceOrientation;
173
189
  };
174
190
 
191
+ export enum InterfaceOrientation {
192
+ ROTATION_0 = 0,
193
+ ROTATION_90 = 90,
194
+ ROTATION_180 = 180,
195
+ ROTATION_270 = 270,
196
+ }
197
+
175
198
  export type ShadowNodeWrapper = object;
176
199
 
177
200
  export enum KeyboardState {
@@ -195,3 +218,7 @@ export interface MeasuredDimensions {
195
218
  pageX: number;
196
219
  pageY: number;
197
220
  }
221
+
222
+ export interface AnimatedKeyboardOptions {
223
+ isStatusBarTranslucentAndroid?: boolean;
224
+ }
@@ -1,8 +1,14 @@
1
1
  import React, { ForwardedRef, forwardRef } from 'react';
2
- import { FlatList, FlatListProps, LayoutChangeEvent } from 'react-native';
2
+ import {
3
+ FlatList,
4
+ FlatListProps,
5
+ LayoutChangeEvent,
6
+ StyleSheet,
7
+ } from 'react-native';
3
8
  import ReanimatedView from './View';
4
9
  import createAnimatedComponent from '../../createAnimatedComponent';
5
10
  import { ILayoutAnimationBuilder } from '../layoutReanimation/animationBuilder/commonTypes';
11
+ import { StyleProps } from '../commonTypes';
6
12
 
7
13
  const AnimatedFlatList = createAnimatedComponent(FlatList as any) as any;
8
14
 
@@ -10,12 +16,20 @@ interface AnimatedFlatListProps {
10
16
  onLayout: (event: LayoutChangeEvent) => void;
11
17
  // implicit `children` prop has been removed in @types/react^18.0.0
12
18
  children: React.ReactNode;
19
+ inverted?: boolean;
20
+ horizontal?: boolean;
13
21
  }
14
22
 
15
- const createCellRenderer = (itemLayoutAnimation?: ILayoutAnimationBuilder) => {
23
+ const createCellRenderer = (
24
+ itemLayoutAnimation?: ILayoutAnimationBuilder,
25
+ cellStyle?: StyleProps
26
+ ) => {
16
27
  const cellRenderer = (props: AnimatedFlatListProps) => {
17
28
  return (
18
- <ReanimatedView layout={itemLayoutAnimation} onLayout={props.onLayout}>
29
+ <ReanimatedView
30
+ layout={itemLayoutAnimation}
31
+ onLayout={props.onLayout}
32
+ style={cellStyle}>
19
33
  {props.children}
20
34
  </ReanimatedView>
21
35
  );
@@ -34,9 +48,15 @@ const ReanimatedFlatlist: ReanimatedFlatListFC = forwardRef(
34
48
  (props: ReanimatedFlatListProps<any>, ref: ForwardedRef<FlatList>) => {
35
49
  const { itemLayoutAnimation, ...restProps } = props;
36
50
 
51
+ const cellStyle = restProps?.inverted
52
+ ? restProps?.horizontal
53
+ ? styles.horizontallyInverted
54
+ : styles.verticallyInverted
55
+ : undefined;
56
+
37
57
  const cellRenderer = React.useMemo(
38
- () => createCellRenderer(itemLayoutAnimation),
39
- []
58
+ () => createCellRenderer(itemLayoutAnimation, cellStyle),
59
+ [cellStyle]
40
60
  );
41
61
 
42
62
  return (
@@ -49,4 +69,9 @@ const ReanimatedFlatlist: ReanimatedFlatListFC = forwardRef(
49
69
  }
50
70
  );
51
71
 
72
+ const styles = StyleSheet.create({
73
+ verticallyInverted: { transform: [{ scaleY: -1 }] },
74
+ horizontallyInverted: { transform: [{ scaleX: -1 }] },
75
+ });
76
+
52
77
  export default ReanimatedFlatlist;
@@ -1,29 +1,28 @@
1
- /* global _setGlobalConsole */
2
1
  import NativeReanimatedModule from './NativeReanimated';
3
2
  import { nativeShouldBeMock, shouldBeUseWeb, isWeb } from './PlatformChecker';
4
- import { BasicWorkletFunction, Value3D, ValueRotation } from './commonTypes';
3
+ import {
4
+ AnimatedKeyboardOptions,
5
+ BasicWorkletFunction,
6
+ Value3D,
7
+ ValueRotation,
8
+ } from './commonTypes';
5
9
  import {
6
10
  makeShareableCloneRecursive,
7
11
  makeShareable as makeShareableUnwrapped,
8
12
  } from './shareables';
9
- import { runOnUI, runOnJS } from './threads';
10
13
  import { startMapper as startMapperUnwrapped } from './mappers';
11
14
  import {
12
15
  makeMutable as makeMutableUnwrapped,
13
16
  makeRemote as makeRemoteUnwrapped,
14
17
  } from './mutables';
15
- import { LayoutAnimationFunction } from './layoutReanimation';
18
+ import {
19
+ LayoutAnimationFunction,
20
+ LayoutAnimationType,
21
+ } from './layoutReanimation';
22
+ import { initializeUIRuntime } from './initializers';
16
23
 
17
24
  export { stopMapper } from './mappers';
18
25
  export { runOnJS, runOnUI } from './threads';
19
- export { getTimestamp } from './time';
20
-
21
- if (global._setGlobalConsole === undefined) {
22
- // it can happen when Reanimated plugin wasn't added, but the user uses the only API from version 1
23
- global._setGlobalConsole = () => {
24
- // noop
25
- };
26
- }
27
26
 
28
27
  export type ReanimatedConsole = Pick<
29
28
  Console,
@@ -114,56 +113,20 @@ export function getViewProp<T>(viewTag: string, propName: string): Promise<T> {
114
113
  });
115
114
  }
116
115
 
117
- function valueUnpacker(objectToUnpack: any, category?: string): any {
118
- 'worklet';
119
- let workletsCache = global.__workletsCache;
120
- let handleCache = global.__handleCache;
121
- if (workletsCache === undefined) {
122
- // init
123
- workletsCache = global.__workletsCache = new Map();
124
- handleCache = global.__handleCache = new WeakMap();
125
- }
126
- if (objectToUnpack.__workletHash) {
127
- let workletFun = workletsCache.get(objectToUnpack.__workletHash);
128
- if (workletFun === undefined) {
129
- // eslint-disable-next-line no-eval
130
- workletFun = eval('(' + objectToUnpack.asString + '\n)') as (
131
- ...args: any[]
132
- ) => any;
133
- workletsCache.set(objectToUnpack.__workletHash, workletFun);
134
- }
135
- const functionInstance = workletFun.bind(objectToUnpack);
136
- objectToUnpack._recur = functionInstance;
137
- return functionInstance;
138
- } else if (objectToUnpack.__init) {
139
- let value = handleCache!.get(objectToUnpack);
140
- if (value === undefined) {
141
- value = objectToUnpack.__init();
142
- handleCache!.set(objectToUnpack, value);
143
- }
144
- return value;
145
- } else if (category === 'RemoteFunction') {
146
- const fun = () => {
147
- throw new Error(`Tried to synchronously call a non-worklet function on the UI thread.
148
-
149
- Possible solutions are:
150
- a) If you want to synchronously execute this method, mark it as a worklet
151
- b) If you want to execute this function on the JS thread, wrap it using \`runOnJS\``);
152
- };
153
- fun.__remoteFunction = objectToUnpack;
154
- return fun;
155
- } else {
156
- throw new Error('data type not recognized by unpack method');
157
- }
158
- }
159
-
160
116
  export function registerEventHandler<T>(
161
117
  eventHash: string,
162
118
  eventHandler: (event: T) => void
163
119
  ): string {
120
+ function handleAndFlushImmediates(eventTimestamp: number, event: T) {
121
+ 'worklet';
122
+ global.__frameTimestamp = eventTimestamp;
123
+ eventHandler(event);
124
+ global.__flushAnimationFrame(eventTimestamp);
125
+ global.__frameTimestamp = undefined;
126
+ }
164
127
  return NativeReanimatedModule.registerEventHandler(
165
128
  eventHash,
166
- makeShareableCloneRecursive(eventHandler)
129
+ makeShareableCloneRecursive(handleAndFlushImmediates)
167
130
  );
168
131
  }
169
132
 
@@ -172,10 +135,22 @@ export function unregisterEventHandler(id: string): void {
172
135
  }
173
136
 
174
137
  export function subscribeForKeyboardEvents(
175
- eventHandler: (state: number, height: number) => void
138
+ eventHandler: (state: number, height: number) => void,
139
+ options: AnimatedKeyboardOptions
176
140
  ): number {
141
+ // TODO: this should really go with the same code path as other events, that is
142
+ // via registerEventHandler. For now we are copying the code from there.
143
+ function handleAndFlushImmediates(state: number, height: number) {
144
+ 'worklet';
145
+ const now = performance.now();
146
+ global.__frameTimestamp = now;
147
+ eventHandler(state, height);
148
+ global.__flushAnimationFrame(now);
149
+ global.__frameTimestamp = undefined;
150
+ }
177
151
  return NativeReanimatedModule.subscribeForKeyboardEvents(
178
- makeShareableCloneRecursive(eventHandler)
152
+ makeShareableCloneRecursive(handleAndFlushImmediates),
153
+ options.isStatusBarTranslucentAndroid ?? false
179
154
  );
180
155
  }
181
156
 
@@ -186,11 +161,16 @@ export function unsubscribeFromKeyboardEvents(listenerId: number): void {
186
161
  export function registerSensor(
187
162
  sensorType: number,
188
163
  interval: number,
189
- eventHandler: (data: Value3D | ValueRotation) => void
164
+ iosReferenceFrame: number,
165
+ eventHandler: (
166
+ data: Value3D | ValueRotation,
167
+ orientationDegrees: number
168
+ ) => void
190
169
  ): number {
191
170
  return NativeReanimatedModule.registerSensor(
192
171
  sensorType,
193
172
  interval,
173
+ iosReferenceFrame,
194
174
  makeShareableCloneRecursive(eventHandler)
195
175
  );
196
176
  }
@@ -199,21 +179,9 @@ export function unregisterSensor(listenerId: number): void {
199
179
  return NativeReanimatedModule.unregisterSensor(listenerId);
200
180
  }
201
181
 
202
- NativeReanimatedModule.installCoreFunctions(valueUnpacker);
203
-
182
+ // initialize UI runtime if applicable
204
183
  if (!isWeb() && isConfigured()) {
205
- const capturableConsole = console;
206
- runOnUI(() => {
207
- 'worklet';
208
- const console = {
209
- debug: runOnJS(capturableConsole.debug),
210
- log: runOnJS(capturableConsole.log),
211
- warn: runOnJS(capturableConsole.warn),
212
- error: runOnJS(capturableConsole.error),
213
- info: runOnJS(capturableConsole.info),
214
- };
215
- _setGlobalConsole(console);
216
- })();
184
+ initializeUIRuntime();
217
185
  }
218
186
 
219
187
  type FeaturesConfig = {
@@ -247,12 +215,14 @@ export function enableLayoutAnimations(
247
215
 
248
216
  export function configureLayoutAnimations(
249
217
  viewTag: number,
250
- type: string,
251
- config: LayoutAnimationFunction | Keyframe
218
+ type: LayoutAnimationType,
219
+ config: LayoutAnimationFunction | Keyframe,
220
+ sharedTransitionTag = ''
252
221
  ): void {
253
222
  NativeReanimatedModule.configureLayoutAnimation(
254
223
  viewTag,
255
224
  type,
225
+ sharedTransitionTag,
256
226
  makeShareableCloneRecursive(config)
257
227
  );
258
228
  }
@@ -0,0 +1,57 @@
1
+ type StackDetails = [Error, number, number];
2
+
3
+ const _workletStackDetails = new Map<number, StackDetails>();
4
+
5
+ export function registerWorkletStackDetails(
6
+ hash: number,
7
+ stackDetails: StackDetails
8
+ ) {
9
+ _workletStackDetails.set(hash, stackDetails);
10
+ }
11
+
12
+ function getBundleOffset(error: Error): [string, number, number] {
13
+ const frame = error.stack?.split('\n')?.[0];
14
+ if (frame) {
15
+ const parsedFrame = /@([^@]+):(\d+):(\d+)/.exec(frame);
16
+ if (parsedFrame) {
17
+ const [, file, line, col] = parsedFrame;
18
+ return [file, Number(line), Number(col)];
19
+ }
20
+ }
21
+ return ['unknown', 0, 0];
22
+ }
23
+
24
+ function processStack(stack: string): string {
25
+ const workletStackEntries = stack.match(/worklet_(\d+):(\d+):(\d+)/g);
26
+ let result = stack;
27
+ workletStackEntries?.forEach((match) => {
28
+ const [, hash, origLine, origCol] = match.split(/:|_/).map(Number);
29
+ const errorDetails = _workletStackDetails.get(hash);
30
+ if (!errorDetails) {
31
+ return;
32
+ }
33
+ const [error, lineOffset, colOffset] = errorDetails;
34
+ const [bundleFile, bundleLine, bundleCol] = getBundleOffset(error);
35
+ const line = origLine + bundleLine + lineOffset;
36
+ const col = origCol + bundleCol + colOffset;
37
+
38
+ result = result.replace(match, `${bundleFile}:${line}:${col}`);
39
+ });
40
+ return result;
41
+ }
42
+
43
+ export function reportFatalErrorOnJS({
44
+ message,
45
+ stack,
46
+ }: {
47
+ message: string;
48
+ stack?: string;
49
+ }) {
50
+ const error = new Error();
51
+ error.message = message;
52
+ error.stack = stack ? processStack(stack) : undefined;
53
+ error.name = 'ReanimatedError';
54
+ // @ts-ignore React Native's ErrorUtils implementation extends the Error type with jsEngine field
55
+ error.jsEngine = 'reanimated';
56
+ global.ErrorUtils.reportFatalError(error);
57
+ }
@@ -1,4 +1,4 @@
1
- import { runOnUI } from '../core';
1
+ import { runOnUIImmediately } from '../threads';
2
2
 
3
3
  type CallbackDetails = {
4
4
  callback: (frameInfo: FrameInfo) => void;
@@ -24,7 +24,7 @@ export interface FrameCallbackRegistryUI {
24
24
  manageStateFrameCallback: (callbackId: number, state: boolean) => void;
25
25
  }
26
26
 
27
- export const prepareUIRegistry = runOnUI(() => {
27
+ export const prepareUIRegistry = runOnUIImmediately(() => {
28
28
  'worklet';
29
29
 
30
30
  const frameCallbackRegistry: FrameCallbackRegistryUI = {