react-native-reanimated 3.0.2 → 3.1.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 (473) hide show
  1. package/Common/cpp/Fabric/FabricUtils.h +1 -1
  2. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +38 -27
  3. package/Common/cpp/SharedItems/Shareables.h +22 -0
  4. package/Common/cpp/Tools/PlatformDepMethodsHolder.h +2 -0
  5. package/Common/cpp/Tools/RuntimeDecorator.cpp +4 -1
  6. package/Common/cpp/Tools/RuntimeDecorator.h +2 -1
  7. package/Common/cpp/Tools/SingleInstanceChecker.h +14 -2
  8. package/RNReanimated.podspec +5 -2
  9. package/android/CMakeLists.txt +4 -0
  10. package/android/build.gradle +18 -10
  11. package/android/src/main/cpp/NativeProxy.cpp +316 -337
  12. package/android/src/main/cpp/NativeProxy.h +53 -11
  13. package/android/src/main/java/com/swmansion/reanimated/NativeMethodsHelper.java +7 -12
  14. package/android/src/main/java/com/swmansion/reanimated/NodesManager.java +11 -8
  15. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/NativeProxyCommon.java +21 -14
  16. package/android/src/paper/java/com/swmansion/reanimated/NativeProxy.java +0 -3
  17. package/ios/Fabric/REAInitializerRCTFabricSurface.mm +1 -0
  18. package/ios/REANodesManager.h +1 -0
  19. package/ios/REANodesManager.mm +30 -4
  20. package/ios/keyboardObserver/REAKeyboardEventObserver.m +51 -130
  21. package/ios/native/NativeMethods.mm +1 -1
  22. package/ios/native/NativeProxy.mm +4 -1
  23. package/ios/native/REAIOSErrorHandler.mm +1 -1
  24. package/ios/native/REAIOSLogger.mm +1 -1
  25. package/ios/native/REAIOSScheduler.mm +1 -1
  26. package/ios/native/REAInitializer.mm +1 -1
  27. package/ios/native/REAMessageThread.mm +2 -2
  28. package/lib/commonjs/Animated.js +0 -8
  29. package/lib/commonjs/Animated.js.map +1 -1
  30. package/lib/commonjs/ConfigHelper.js +8 -19
  31. package/lib/commonjs/ConfigHelper.js.map +1 -1
  32. package/lib/commonjs/createAnimatedComponent.js +20 -158
  33. package/lib/commonjs/createAnimatedComponent.js.map +1 -1
  34. package/lib/commonjs/index.js +0 -9
  35. package/lib/commonjs/index.js.map +1 -1
  36. package/lib/commonjs/index.web.js +0 -7
  37. package/lib/commonjs/index.web.js.map +1 -1
  38. package/lib/commonjs/reanimated2/Bezier.js +14 -34
  39. package/lib/commonjs/reanimated2/Bezier.js.map +1 -1
  40. package/lib/commonjs/reanimated2/Colors.js +60 -132
  41. package/lib/commonjs/reanimated2/Colors.js.map +1 -1
  42. package/lib/commonjs/reanimated2/Easing.js +81 -34
  43. package/lib/commonjs/reanimated2/Easing.js.map +1 -1
  44. package/lib/commonjs/reanimated2/NativeMethods.js +8 -20
  45. package/lib/commonjs/reanimated2/NativeMethods.js.map +1 -1
  46. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js +5 -31
  47. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  48. package/lib/commonjs/reanimated2/NativeReanimated/index.js +0 -7
  49. package/lib/commonjs/reanimated2/NativeReanimated/index.js.map +1 -1
  50. package/lib/commonjs/reanimated2/PlatformChecker.js +0 -6
  51. package/lib/commonjs/reanimated2/PlatformChecker.js.map +1 -1
  52. package/lib/commonjs/reanimated2/PropAdapters.js +10 -12
  53. package/lib/commonjs/reanimated2/PropAdapters.js.map +1 -1
  54. package/lib/commonjs/reanimated2/UpdateProps.js +3 -12
  55. package/lib/commonjs/reanimated2/UpdateProps.js.map +1 -1
  56. package/lib/commonjs/reanimated2/ViewDescriptorsSet.js +0 -10
  57. package/lib/commonjs/reanimated2/ViewDescriptorsSet.js.map +1 -1
  58. package/lib/commonjs/reanimated2/WorkletEventHandler.js +5 -22
  59. package/lib/commonjs/reanimated2/WorkletEventHandler.js.map +1 -1
  60. package/lib/commonjs/reanimated2/animation/decay.js +7 -18
  61. package/lib/commonjs/reanimated2/animation/decay.js.map +1 -1
  62. package/lib/commonjs/reanimated2/animation/delay.js +0 -11
  63. package/lib/commonjs/reanimated2/animation/delay.js.map +1 -1
  64. package/lib/commonjs/reanimated2/animation/index.js +0 -8
  65. package/lib/commonjs/reanimated2/animation/index.js.map +1 -1
  66. package/lib/commonjs/reanimated2/animation/repeat.js +6 -22
  67. package/lib/commonjs/reanimated2/animation/repeat.js.map +1 -1
  68. package/lib/commonjs/reanimated2/animation/sequence.js +3 -20
  69. package/lib/commonjs/reanimated2/animation/sequence.js.map +1 -1
  70. package/lib/commonjs/reanimated2/animation/spring.js +11 -23
  71. package/lib/commonjs/reanimated2/animation/spring.js.map +1 -1
  72. package/lib/commonjs/reanimated2/animation/styleAnimation.js +3 -35
  73. package/lib/commonjs/reanimated2/animation/styleAnimation.js.map +1 -1
  74. package/lib/commonjs/reanimated2/animation/timing.js +0 -11
  75. package/lib/commonjs/reanimated2/animation/timing.js.map +1 -1
  76. package/lib/commonjs/reanimated2/animation/util.js +11 -41
  77. package/lib/commonjs/reanimated2/animation/util.js.map +1 -1
  78. package/lib/commonjs/reanimated2/commonTypes.js +16 -23
  79. package/lib/commonjs/reanimated2/commonTypes.js.map +1 -1
  80. package/lib/commonjs/reanimated2/component/FlatList.js +0 -16
  81. package/lib/commonjs/reanimated2/component/FlatList.js.map +1 -1
  82. package/lib/commonjs/reanimated2/component/Image.js +0 -4
  83. package/lib/commonjs/reanimated2/component/Image.js.map +1 -1
  84. package/lib/commonjs/reanimated2/component/ScrollView.js +0 -4
  85. package/lib/commonjs/reanimated2/component/ScrollView.js.map +1 -1
  86. package/lib/commonjs/reanimated2/component/Text.js +0 -4
  87. package/lib/commonjs/reanimated2/component/Text.js.map +1 -1
  88. package/lib/commonjs/reanimated2/component/View.js +0 -4
  89. package/lib/commonjs/reanimated2/component/View.js.map +1 -1
  90. package/lib/commonjs/reanimated2/core.js +6 -48
  91. package/lib/commonjs/reanimated2/core.js.map +1 -1
  92. package/lib/commonjs/reanimated2/errors.js +3 -14
  93. package/lib/commonjs/reanimated2/errors.js.map +1 -1
  94. package/lib/commonjs/reanimated2/fabricUtils.js +3 -5
  95. package/lib/commonjs/reanimated2/fabricUtils.js.map +1 -1
  96. package/lib/commonjs/reanimated2/fabricUtils.web.js +1 -3
  97. package/lib/commonjs/reanimated2/fabricUtils.web.js.map +1 -1
  98. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryJS.js +3 -12
  99. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryJS.js.map +1 -1
  100. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js +13 -17
  101. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
  102. package/lib/commonjs/reanimated2/globals.d.js.map +1 -1
  103. package/lib/commonjs/reanimated2/hook/Hooks.js +0 -5
  104. package/lib/commonjs/reanimated2/hook/Hooks.js.map +1 -1
  105. package/lib/commonjs/reanimated2/hook/commonTypes.js.map +1 -1
  106. package/lib/commonjs/reanimated2/hook/index.js +0 -12
  107. package/lib/commonjs/reanimated2/hook/index.js.map +1 -1
  108. package/lib/commonjs/reanimated2/hook/useAnimatedGestureHandler.js +4 -17
  109. package/lib/commonjs/reanimated2/hook/useAnimatedGestureHandler.js.map +1 -1
  110. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js +2 -9
  111. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  112. package/lib/commonjs/reanimated2/hook/useAnimatedReaction.js +1 -11
  113. package/lib/commonjs/reanimated2/hook/useAnimatedReaction.js.map +1 -1
  114. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js +0 -12
  115. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js.map +1 -1
  116. package/lib/commonjs/reanimated2/hook/useAnimatedScrollHandler.js +2 -9
  117. package/lib/commonjs/reanimated2/hook/useAnimatedScrollHandler.js.map +1 -1
  118. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js +8 -23
  119. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  120. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js +13 -71
  121. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  122. package/lib/commonjs/reanimated2/hook/useDerivedValue.js +4 -13
  123. package/lib/commonjs/reanimated2/hook/useDerivedValue.js.map +1 -1
  124. package/lib/commonjs/reanimated2/hook/useFrameCallback.js +0 -5
  125. package/lib/commonjs/reanimated2/hook/useFrameCallback.js.map +1 -1
  126. package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js +0 -7
  127. package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js.map +1 -1
  128. package/lib/commonjs/reanimated2/hook/useSharedValue.js +2 -7
  129. package/lib/commonjs/reanimated2/hook/useSharedValue.js.map +1 -1
  130. package/lib/commonjs/reanimated2/hook/utils.js +8 -39
  131. package/lib/commonjs/reanimated2/hook/utils.js.map +1 -1
  132. package/lib/commonjs/reanimated2/index.js +0 -26
  133. package/lib/commonjs/reanimated2/index.js.map +1 -1
  134. package/lib/commonjs/reanimated2/initializers.js +21 -43
  135. package/lib/commonjs/reanimated2/initializers.js.map +1 -1
  136. package/lib/commonjs/reanimated2/interpolateColor.js +6 -43
  137. package/lib/commonjs/reanimated2/interpolateColor.js.map +1 -1
  138. package/lib/commonjs/reanimated2/interpolation.js +14 -29
  139. package/lib/commonjs/reanimated2/interpolation.js.map +1 -1
  140. package/lib/commonjs/reanimated2/jestUtils.js +11 -44
  141. package/lib/commonjs/reanimated2/jestUtils.js.map +1 -1
  142. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js +15 -39
  143. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  144. package/lib/commonjs/reanimated2/js-reanimated/Mapper.js +9 -28
  145. package/lib/commonjs/reanimated2/js-reanimated/Mapper.js.map +1 -1
  146. package/lib/commonjs/reanimated2/js-reanimated/MapperRegistry.js +7 -37
  147. package/lib/commonjs/reanimated2/js-reanimated/MapperRegistry.js.map +1 -1
  148. package/lib/commonjs/reanimated2/js-reanimated/MutableValue.js +5 -18
  149. package/lib/commonjs/reanimated2/js-reanimated/MutableValue.js.map +1 -1
  150. package/lib/commonjs/reanimated2/js-reanimated/global.js +2 -9
  151. package/lib/commonjs/reanimated2/js-reanimated/global.js.map +1 -1
  152. package/lib/commonjs/reanimated2/js-reanimated/index.js +3 -14
  153. package/lib/commonjs/reanimated2/js-reanimated/index.js.map +1 -1
  154. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js +7 -26
  155. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js.map +1 -1
  156. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +3 -49
  157. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js.map +1 -1
  158. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/Keyframe.js +7 -43
  159. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/Keyframe.js.map +1 -1
  160. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +4 -5
  161. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  162. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js +0 -4
  163. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  164. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js +4 -23
  165. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
  166. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +3 -74
  167. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
  168. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Fade.js +3 -53
  169. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Fade.js.map +1 -1
  170. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Flip.js +3 -63
  171. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Flip.js.map +1 -1
  172. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +7 -26
  173. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
  174. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +3 -13
  175. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js.map +1 -1
  176. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Roll.js +3 -23
  177. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
  178. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +3 -43
  179. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Rotate.js.map +1 -1
  180. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Slide.js +3 -43
  181. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
  182. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +3 -23
  183. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Stretch.js.map +1 -1
  184. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +3 -83
  185. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
  186. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/index.js +0 -20
  187. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/index.js.map +1 -1
  188. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +3 -22
  189. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js.map +1 -1
  190. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +5 -29
  191. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js.map +1 -1
  192. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +3 -9
  193. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js.map +1 -1
  194. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +5 -11
  195. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js.map +1 -1
  196. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +3 -8
  197. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js.map +1 -1
  198. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +3 -12
  199. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js.map +1 -1
  200. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/index.js +0 -12
  201. package/lib/commonjs/reanimated2/layoutReanimation/defaultTransitions/index.js.map +1 -1
  202. package/lib/commonjs/reanimated2/layoutReanimation/index.js +0 -9
  203. package/lib/commonjs/reanimated2/layoutReanimation/index.js.map +1 -1
  204. package/lib/commonjs/reanimated2/layoutReanimation/sharedTransitions/index.js +3 -17
  205. package/lib/commonjs/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -1
  206. package/lib/commonjs/reanimated2/mappers.js +26 -32
  207. package/lib/commonjs/reanimated2/mappers.js.map +1 -1
  208. package/lib/commonjs/reanimated2/mock.js +5 -15
  209. package/lib/commonjs/reanimated2/mock.js.map +1 -1
  210. package/lib/commonjs/reanimated2/mutables.js +2 -28
  211. package/lib/commonjs/reanimated2/mutables.js.map +1 -1
  212. package/lib/commonjs/reanimated2/platform-specific/RNRenderer.js +0 -2
  213. package/lib/commonjs/reanimated2/platform-specific/RNRenderer.js.map +1 -1
  214. package/lib/commonjs/reanimated2/platform-specific/RNRenderer.web.js.map +1 -1
  215. package/lib/commonjs/reanimated2/platform-specific/checkCppVersion.js +31 -0
  216. package/lib/commonjs/reanimated2/platform-specific/checkCppVersion.js.map +1 -0
  217. package/lib/commonjs/reanimated2/platform-specific/checkVersion.web.js +0 -2
  218. package/lib/commonjs/reanimated2/platform-specific/checkVersion.web.js.map +1 -1
  219. package/lib/commonjs/reanimated2/platform-specific/jsVersion.js +14 -0
  220. package/lib/commonjs/reanimated2/platform-specific/jsVersion.js.map +1 -0
  221. package/lib/commonjs/reanimated2/pluginUtils.js +0 -1
  222. package/lib/commonjs/reanimated2/pluginUtils.js.map +1 -1
  223. package/lib/commonjs/reanimated2/shareables.js +92 -49
  224. package/lib/commonjs/reanimated2/shareables.js.map +1 -1
  225. package/lib/commonjs/reanimated2/threads.js +42 -46
  226. package/lib/commonjs/reanimated2/threads.js.map +1 -1
  227. package/lib/commonjs/reanimated2/utils.js +0 -5
  228. package/lib/commonjs/reanimated2/utils.js.map +1 -1
  229. package/lib/commonjs/reanimated2/valueSetter.js +6 -21
  230. package/lib/commonjs/reanimated2/valueSetter.js.map +1 -1
  231. package/lib/commonjs/setAndForwardRef.js +3 -3
  232. package/lib/commonjs/setAndForwardRef.js.map +1 -1
  233. package/lib/module/Animated.js.map +1 -1
  234. package/lib/module/ConfigHelper.js +9 -15
  235. package/lib/module/ConfigHelper.js.map +1 -1
  236. package/lib/module/createAnimatedComponent.js +20 -139
  237. package/lib/module/createAnimatedComponent.js.map +1 -1
  238. package/lib/module/index.js +0 -2
  239. package/lib/module/index.js.map +1 -1
  240. package/lib/module/index.web.js.map +1 -1
  241. package/lib/module/reanimated2/Bezier.js +14 -33
  242. package/lib/module/reanimated2/Bezier.js.map +1 -1
  243. package/lib/module/reanimated2/Colors.js +59 -109
  244. package/lib/module/reanimated2/Colors.js.map +1 -1
  245. package/lib/module/reanimated2/Easing.js +37 -33
  246. package/lib/module/reanimated2/Easing.js.map +1 -1
  247. package/lib/module/reanimated2/NativeMethods.js +8 -15
  248. package/lib/module/reanimated2/NativeMethods.js.map +1 -1
  249. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js +5 -27
  250. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  251. package/lib/module/reanimated2/NativeReanimated/index.js +0 -2
  252. package/lib/module/reanimated2/NativeReanimated/index.js.map +1 -1
  253. package/lib/module/reanimated2/PlatformChecker.js.map +1 -1
  254. package/lib/module/reanimated2/PropAdapters.js +12 -10
  255. package/lib/module/reanimated2/PropAdapters.js.map +1 -1
  256. package/lib/module/reanimated2/UpdateProps.js +3 -5
  257. package/lib/module/reanimated2/UpdateProps.js.map +1 -1
  258. package/lib/module/reanimated2/ViewDescriptorsSet.js +0 -6
  259. package/lib/module/reanimated2/ViewDescriptorsSet.js.map +1 -1
  260. package/lib/module/reanimated2/WorkletEventHandler.js +5 -18
  261. package/lib/module/reanimated2/WorkletEventHandler.js.map +1 -1
  262. package/lib/module/reanimated2/animation/decay.js +7 -15
  263. package/lib/module/reanimated2/animation/decay.js.map +1 -1
  264. package/lib/module/reanimated2/animation/delay.js +0 -9
  265. package/lib/module/reanimated2/animation/delay.js.map +1 -1
  266. package/lib/module/reanimated2/animation/index.js.map +1 -1
  267. package/lib/module/reanimated2/animation/repeat.js +6 -20
  268. package/lib/module/reanimated2/animation/repeat.js.map +1 -1
  269. package/lib/module/reanimated2/animation/sequence.js +3 -18
  270. package/lib/module/reanimated2/animation/sequence.js.map +1 -1
  271. package/lib/module/reanimated2/animation/spring.js +11 -21
  272. package/lib/module/reanimated2/animation/spring.js.map +1 -1
  273. package/lib/module/reanimated2/animation/styleAnimation.js +7 -31
  274. package/lib/module/reanimated2/animation/styleAnimation.js.map +1 -1
  275. package/lib/module/reanimated2/animation/timing.js +0 -8
  276. package/lib/module/reanimated2/animation/timing.js.map +1 -1
  277. package/lib/module/reanimated2/animation/util.js +10 -33
  278. package/lib/module/reanimated2/animation/util.js.map +1 -1
  279. package/lib/module/reanimated2/commonTypes.js +12 -19
  280. package/lib/module/reanimated2/commonTypes.js.map +1 -1
  281. package/lib/module/reanimated2/component/FlatList.js +0 -4
  282. package/lib/module/reanimated2/component/FlatList.js.map +1 -1
  283. package/lib/module/reanimated2/component/Image.js.map +1 -1
  284. package/lib/module/reanimated2/component/ScrollView.js.map +1 -1
  285. package/lib/module/reanimated2/component/Text.js.map +1 -1
  286. package/lib/module/reanimated2/component/View.js.map +1 -1
  287. package/lib/module/reanimated2/core.js +6 -22
  288. package/lib/module/reanimated2/core.js.map +1 -1
  289. package/lib/module/reanimated2/errors.js +3 -13
  290. package/lib/module/reanimated2/errors.js.map +1 -1
  291. package/lib/module/reanimated2/fabricUtils.js +3 -3
  292. package/lib/module/reanimated2/fabricUtils.js.map +1 -1
  293. package/lib/module/reanimated2/fabricUtils.web.js +1 -1
  294. package/lib/module/reanimated2/fabricUtils.web.js.map +1 -1
  295. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryJS.js +3 -8
  296. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryJS.js.map +1 -1
  297. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js +13 -15
  298. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
  299. package/lib/module/reanimated2/globals.d.js.map +1 -1
  300. package/lib/module/reanimated2/hook/Hooks.js +3 -2
  301. package/lib/module/reanimated2/hook/Hooks.js.map +1 -1
  302. package/lib/module/reanimated2/hook/commonTypes.js.map +1 -1
  303. package/lib/module/reanimated2/hook/index.js.map +1 -1
  304. package/lib/module/reanimated2/hook/useAnimatedGestureHandler.js +3 -14
  305. package/lib/module/reanimated2/hook/useAnimatedGestureHandler.js.map +1 -1
  306. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js +2 -5
  307. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  308. package/lib/module/reanimated2/hook/useAnimatedReaction.js +1 -7
  309. package/lib/module/reanimated2/hook/useAnimatedReaction.js.map +1 -1
  310. package/lib/module/reanimated2/hook/useAnimatedRef.js +0 -6
  311. package/lib/module/reanimated2/hook/useAnimatedRef.js.map +1 -1
  312. package/lib/module/reanimated2/hook/useAnimatedScrollHandler.js +2 -7
  313. package/lib/module/reanimated2/hook/useAnimatedScrollHandler.js.map +1 -1
  314. package/lib/module/reanimated2/hook/useAnimatedSensor.js +9 -20
  315. package/lib/module/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  316. package/lib/module/reanimated2/hook/useAnimatedStyle.js +13 -59
  317. package/lib/module/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  318. package/lib/module/reanimated2/hook/useDerivedValue.js +4 -8
  319. package/lib/module/reanimated2/hook/useDerivedValue.js.map +1 -1
  320. package/lib/module/reanimated2/hook/useFrameCallback.js.map +1 -1
  321. package/lib/module/reanimated2/hook/useScrollViewOffset.js +0 -1
  322. package/lib/module/reanimated2/hook/useScrollViewOffset.js.map +1 -1
  323. package/lib/module/reanimated2/hook/useSharedValue.js +2 -3
  324. package/lib/module/reanimated2/hook/useSharedValue.js.map +1 -1
  325. package/lib/module/reanimated2/hook/utils.js +8 -21
  326. package/lib/module/reanimated2/hook/utils.js.map +1 -1
  327. package/lib/module/reanimated2/index.js.map +1 -1
  328. package/lib/module/reanimated2/initializers.js +23 -37
  329. package/lib/module/reanimated2/initializers.js.map +1 -1
  330. package/lib/module/reanimated2/interpolateColor.js +5 -34
  331. package/lib/module/reanimated2/interpolateColor.js.map +1 -1
  332. package/lib/module/reanimated2/interpolation.js +13 -28
  333. package/lib/module/reanimated2/interpolation.js.map +1 -1
  334. package/lib/module/reanimated2/jestUtils.js +11 -35
  335. package/lib/module/reanimated2/jestUtils.js.map +1 -1
  336. package/lib/module/reanimated2/js-reanimated/JSReanimated.js +15 -35
  337. package/lib/module/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  338. package/lib/module/reanimated2/js-reanimated/Mapper.js +9 -23
  339. package/lib/module/reanimated2/js-reanimated/Mapper.js.map +1 -1
  340. package/lib/module/reanimated2/js-reanimated/MapperRegistry.js +7 -35
  341. package/lib/module/reanimated2/js-reanimated/MapperRegistry.js.map +1 -1
  342. package/lib/module/reanimated2/js-reanimated/MutableValue.js +5 -16
  343. package/lib/module/reanimated2/js-reanimated/MutableValue.js.map +1 -1
  344. package/lib/module/reanimated2/js-reanimated/global.js +2 -6
  345. package/lib/module/reanimated2/js-reanimated/global.js.map +1 -1
  346. package/lib/module/reanimated2/js-reanimated/index.js +3 -9
  347. package/lib/module/reanimated2/js-reanimated/index.js.map +1 -1
  348. package/lib/module/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js +7 -23
  349. package/lib/module/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js.map +1 -1
  350. package/lib/module/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +3 -45
  351. package/lib/module/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js.map +1 -1
  352. package/lib/module/reanimated2/layoutReanimation/animationBuilder/Keyframe.js +7 -39
  353. package/lib/module/reanimated2/layoutReanimation/animationBuilder/Keyframe.js.map +1 -1
  354. package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +3 -3
  355. package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  356. package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  357. package/lib/module/reanimated2/layoutReanimation/animationsManager.js +4 -19
  358. package/lib/module/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
  359. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +3 -52
  360. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
  361. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Fade.js +3 -32
  362. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Fade.js.map +1 -1
  363. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Flip.js +3 -38
  364. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Flip.js.map +1 -1
  365. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +7 -16
  366. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
  367. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +3 -8
  368. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js.map +1 -1
  369. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js +3 -14
  370. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
  371. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +3 -26
  372. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Rotate.js.map +1 -1
  373. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js +3 -26
  374. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
  375. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +3 -14
  376. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Stretch.js.map +1 -1
  377. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +3 -50
  378. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
  379. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/index.js.map +1 -1
  380. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +3 -17
  381. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js.map +1 -1
  382. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +5 -23
  383. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js.map +1 -1
  384. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +3 -5
  385. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js.map +1 -1
  386. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +5 -6
  387. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js.map +1 -1
  388. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +3 -5
  389. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js.map +1 -1
  390. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +3 -8
  391. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js.map +1 -1
  392. package/lib/module/reanimated2/layoutReanimation/defaultTransitions/index.js.map +1 -1
  393. package/lib/module/reanimated2/layoutReanimation/index.js.map +1 -1
  394. package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js +3 -13
  395. package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -1
  396. package/lib/module/reanimated2/mappers.js +26 -25
  397. package/lib/module/reanimated2/mappers.js.map +1 -1
  398. package/lib/module/reanimated2/mock.js +5 -15
  399. package/lib/module/reanimated2/mock.js.map +1 -1
  400. package/lib/module/reanimated2/mutables.js +2 -19
  401. package/lib/module/reanimated2/mutables.js.map +1 -1
  402. package/lib/module/reanimated2/platform-specific/RNRenderer.js.map +1 -1
  403. package/lib/module/reanimated2/platform-specific/RNRenderer.web.js.map +1 -1
  404. package/lib/module/reanimated2/platform-specific/checkCppVersion.js +24 -0
  405. package/lib/module/reanimated2/platform-specific/checkCppVersion.js.map +1 -0
  406. package/lib/module/reanimated2/platform-specific/checkVersion.web.js +0 -1
  407. package/lib/module/reanimated2/platform-specific/checkVersion.web.js.map +1 -1
  408. package/lib/module/reanimated2/platform-specific/jsVersion.js +7 -0
  409. package/lib/module/reanimated2/platform-specific/jsVersion.js.map +1 -0
  410. package/lib/module/reanimated2/pluginUtils.js.map +1 -1
  411. package/lib/module/reanimated2/shareables.js +96 -44
  412. package/lib/module/reanimated2/shareables.js.map +1 -1
  413. package/lib/module/reanimated2/threads.js +39 -33
  414. package/lib/module/reanimated2/threads.js.map +1 -1
  415. package/lib/module/reanimated2/utils.js +0 -3
  416. package/lib/module/reanimated2/utils.js.map +1 -1
  417. package/lib/module/reanimated2/valueSetter.js +6 -19
  418. package/lib/module/reanimated2/valueSetter.js.map +1 -1
  419. package/lib/module/setAndForwardRef.js +3 -2
  420. package/lib/module/setAndForwardRef.js.map +1 -1
  421. package/package.json +46 -40
  422. package/plugin/.eslintrc.js +7 -0
  423. package/plugin/README.md +241 -0
  424. package/plugin/build/plugin.js +714 -0
  425. package/plugin/build/plugin.js.map +7 -0
  426. package/plugin/index.js +1 -807
  427. package/plugin/package.json +23 -0
  428. package/plugin/src/buildWorkletString.ts +213 -0
  429. package/plugin/src/commonObjects.ts +60 -0
  430. package/plugin/src/injectVersion.ts +37 -0
  431. package/plugin/src/makeWorklet.ts +375 -0
  432. package/plugin/src/plugin.ts +49 -0
  433. package/plugin/src/processForCalleesWorklets.ts +106 -0
  434. package/plugin/src/processIfGestureHandlerEventCallbackFunctionNode.ts +156 -0
  435. package/plugin/src/processIfWorkletFunction.ts +55 -0
  436. package/plugin/src/processIfWorkletNode.ts +44 -0
  437. package/plugin/src/processInlineStylesWarning.ts +129 -0
  438. package/plugin/src/processWorkletObjectMethod.ts +31 -0
  439. package/plugin/src/types.ts +15 -0
  440. package/plugin/src/utils.ts +6 -0
  441. package/plugin/tsconfig.json +15 -0
  442. package/plugin/yarn.lock +2193 -0
  443. package/react-native-reanimated.d.ts +1 -0
  444. package/scripts/reanimated_utils.rb +2 -2
  445. package/src/createAnimatedComponent.tsx +2 -3
  446. package/src/reanimated2/Easing.ts +19 -0
  447. package/src/reanimated2/NativeMethods.ts +9 -4
  448. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +2 -2
  449. package/src/reanimated2/UpdateProps.ts +2 -2
  450. package/src/reanimated2/animation/decay.ts +7 -1
  451. package/src/reanimated2/animation/styleAnimation.ts +5 -1
  452. package/src/reanimated2/core.ts +4 -4
  453. package/src/reanimated2/errors.ts +1 -0
  454. package/src/reanimated2/frameCallback/FrameCallbackRegistryUI.ts +12 -4
  455. package/src/reanimated2/globals.d.ts +71 -112
  456. package/src/reanimated2/hook/commonTypes.ts +1 -1
  457. package/src/reanimated2/hook/useAnimatedReaction.ts +2 -2
  458. package/src/reanimated2/hook/useAnimatedSensor.ts +2 -2
  459. package/src/reanimated2/initializers.ts +11 -8
  460. package/src/reanimated2/jestUtils.ts +0 -1
  461. package/src/reanimated2/js-reanimated/JSReanimated.ts +5 -1
  462. package/src/reanimated2/js-reanimated/index.ts +1 -1
  463. package/src/reanimated2/mappers.ts +26 -4
  464. package/src/reanimated2/mock.ts +1 -0
  465. package/src/reanimated2/platform-specific/checkCppVersion.ts +29 -0
  466. package/src/reanimated2/platform-specific/jsVersion.ts +6 -0
  467. package/src/reanimated2/shareables.ts +107 -8
  468. package/src/reanimated2/threads.ts +36 -17
  469. package/lib/commonjs/reanimated2/platform-specific/checkVersion.js +0 -42
  470. package/lib/commonjs/reanimated2/platform-specific/checkVersion.js.map +0 -1
  471. package/lib/module/reanimated2/platform-specific/checkVersion.js +0 -35
  472. package/lib/module/reanimated2/platform-specific/checkVersion.js.map +0 -1
  473. package/src/reanimated2/platform-specific/checkVersion.ts +0 -39
@@ -1,20 +1,18 @@
1
1
  import NativeReanimatedModule from './NativeReanimated';
2
2
  import { shouldBeUseWeb } from './PlatformChecker';
3
- import { registerWorkletStackDetails } from './errors'; // for web/chrome debugger/jest environments this file provides a stub implementation
3
+ import { registerWorkletStackDetails } from './errors';
4
+ import { jsVersion } from './platform-specific/jsVersion';
5
+
6
+ // for web/chrome debugger/jest environments this file provides a stub implementation
4
7
  // where no shareable references are used. Instead, the objects themselves are used
5
8
  // instead of shareable references, because of the fact that we don't have to deal with
6
9
  // runnning the code on separate VMs.
7
-
8
10
  const USE_STUB_IMPLEMENTATION = shouldBeUseWeb();
9
-
10
- const _shareableCache = new WeakMap(); // the below symbol is used to represent a mapping from the value to itself
11
+ const _shareableCache = new WeakMap();
12
+ // the below symbol is used to represent a mapping from the value to itself
11
13
  // this is used to allow for a converted shareable to be passed to makeShareableClone
12
-
13
-
14
14
  const _shareableFlag = Symbol('shareable flag');
15
-
16
15
  const MAGIC_KEY = 'REANIMATED_MAGIC_KEY';
17
-
18
16
  function isHostObject(value) {
19
17
  // We could use JSI to determine whether an object is a host object, however
20
18
  // the below workaround works well and is way faster than an additional JSI call.
@@ -22,37 +20,89 @@ function isHostObject(value) {
22
20
  // and hence return true for all `in` checks regardless of the key we ask for.
23
21
  return MAGIC_KEY in value;
24
22
  }
25
-
26
23
  export function registerShareableMapping(shareable, shareableRef) {
27
24
  if (USE_STUB_IMPLEMENTATION) {
28
25
  return;
29
26
  }
30
-
31
27
  _shareableCache.set(shareable, shareableRef || _shareableFlag);
32
28
  }
29
+ function isPlainJSObject(object) {
30
+ return Object.getPrototypeOf(object) === Object.prototype;
31
+ }
32
+
33
+ // The below object is used as a replacement for objects that cannot be transferred
34
+ // as shareable values. In makeShareableCloneRecursive we detect if an object is of
35
+ // a plain Object.prototype and only allow such objects to be transferred. This lets
36
+ // us avoid all sorts of react internals from leaking into the UI runtime. To make it
37
+ // possible to catch errors when someone actually tries to access such object on the UI
38
+ // runtime, we use the below Proxy object which is instantiated on the UI runtime and
39
+ // throws whenever someone tries to access its fields.
40
+ const INACCESSIBLE_OBJECT = {
41
+ __init: () => {
42
+ 'worklet';
43
+
44
+ return new Proxy({}, {
45
+ get: (_, prop) => {
46
+ if (prop === '_isReanimatedSharedValue') {
47
+ // not very happy about this check here, but we need to allow for
48
+ // "inaccessible" objects to be tested with isSharedValue check
49
+ // as it is being used in the mappers when extracing inputs recursively.
50
+ // Apparently we can't check if a key exists there as HostObjects always
51
+ // return true for such tests, so the only possibility for us is to
52
+ // actually access that key and see if it is set to true. We therefore
53
+ // need to allow for this key to be accessed here.
54
+ return false;
55
+ }
56
+ throw new Error(`Trying to access property \`${prop}\` of an object which cannot be sent to the UI runtime.`);
57
+ },
58
+ set: () => {
59
+ throw new Error('Trying to write to an object which cannot be sent to the UI runtime.');
60
+ }
61
+ });
62
+ }
63
+ };
64
+ const DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD = 30;
65
+ // Below variable stores object that we process in makeShareableCloneRecursive at the specified depth.
66
+ // We use it to check if later on the function reenters with the same object
67
+ let processedObjectAtThresholdDepth;
68
+
69
+ // We only want to show mismatch error once so we use this flag to track it
70
+ let didShowPluginVersionMismatchError = false;
33
71
  export function makeShareableCloneRecursive(value) {
34
72
  let shouldPersistRemote = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
35
-
73
+ let depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
36
74
  if (USE_STUB_IMPLEMENTATION) {
37
75
  return value;
38
- } // This one actually may be worth to be moved to c++, we also need similar logic to run on the UI thread
39
-
40
-
76
+ }
77
+ if (depth >= DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {
78
+ // if we reach certain recursion depth we suspect that we are dealing with a cyclic object.
79
+ // this type of objects are not supported and cannot be trasferred as shareable, so we
80
+ // implement a simple detection mechanism that remembers the value at a given depth and
81
+ // tests whether we try reenter this method later on with the same value. If that happens
82
+ // we throw an appropriate error.
83
+ if (depth === DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {
84
+ processedObjectAtThresholdDepth = value;
85
+ } else if (value === processedObjectAtThresholdDepth) {
86
+ throw new Error('Trying to convert a cyclic object to a shareable. This is not supported.');
87
+ }
88
+ } else {
89
+ processedObjectAtThresholdDepth = undefined;
90
+ }
91
+ // This one actually may be worth to be moved to c++, we also need similar logic to run on the UI thread
41
92
  const type = typeof value;
42
-
43
- if ((type === 'object' || type === 'function') && value !== null) {
93
+ const isTypeObject = type === 'object';
94
+ const isTypeFunction = type === 'function';
95
+ if ((isTypeObject || isTypeFunction) && value !== null) {
44
96
  const cached = _shareableCache.get(value);
45
-
46
97
  if (cached === _shareableFlag) {
47
98
  return value;
48
99
  } else if (cached !== undefined) {
49
100
  return cached;
50
101
  } else {
51
102
  let toAdapt;
52
-
53
103
  if (Array.isArray(value)) {
54
- toAdapt = value.map(element => makeShareableCloneRecursive(element));
55
- } else if (type === 'function' && value.__workletHash === undefined) {
104
+ toAdapt = value.map(element => makeShareableCloneRecursive(element, shouldPersistRemote, depth + 1));
105
+ } else if (isTypeFunction && value.__workletHash === undefined) {
56
106
  // this is a remote function
57
107
  toAdapt = value;
58
108
  } else if (isHostObject(value)) {
@@ -60,30 +110,46 @@ export function makeShareableCloneRecursive(value) {
60
110
  // then recreate new host object wrapping the same instance on the UI thread.
61
111
  // there is no point of iterating over keys as we do for regular objects.
62
112
  toAdapt = value;
63
- } else {
113
+ } else if (isPlainJSObject(value) || isTypeFunction) {
64
114
  toAdapt = {};
65
-
66
115
  if (value.__workletHash !== undefined) {
67
116
  // we are converting a worklet
68
117
  if (__DEV__) {
118
+ if (
119
+ // We don't want this error to be logged more than once.
120
+ !didShowPluginVersionMismatchError && value.__version !== jsVersion) {
121
+ didShowPluginVersionMismatchError = true;
122
+ console.error(`[Reanimated] Mismatch between JavaScript code version and Reanimated Babel plugin version (${jsVersion} vs. ${value.__version}). Please clear your Metro bundler cache with \`yarn start --reset-cache\`,
123
+ \`npm start -- --reset-cache\` or \`expo start -c\` and run the app again.`);
124
+ }
69
125
  registerWorkletStackDetails(value.__workletHash, value.__stackDetails);
70
126
  delete value.__stackDetails;
71
- } // to save on transferring static __initData field of worklet structure
127
+ }
128
+ // to save on transferring static __initData field of worklet structure
72
129
  // we request shareable value to persist its UI counterpart. This means
73
130
  // that the __initData field that contains long strings represeting the
74
131
  // worklet code, source map, and location, will always be
75
- // serialized/deserialized once.
76
-
77
-
132
+ // serialized/deserialized once. We don't increase depth when calling
133
+ // this method as these objects have one level anyways.
78
134
  toAdapt.__initData = makeShareableCloneRecursive(value.__initData, true);
79
135
  delete value.__initData;
80
136
  }
81
-
82
137
  for (const [key, element] of Object.entries(value)) {
83
- toAdapt[key] = makeShareableCloneRecursive(element);
138
+ toAdapt[key] = makeShareableCloneRecursive(element, shouldPersistRemote, depth + 1);
84
139
  }
140
+ } else {
141
+ // This is reached for object types that are not of plain Object.prototype.
142
+ // We don't support such objects from being transferred as shareables to
143
+ // the UI runtime and hence we replace them with "inaccessible object"
144
+ // which is implemented as a Proxy object that throws on any attempt
145
+ // of accessing its fields. We argue that such objects can sometimes leak
146
+ // as attributes of objects being captured by worklets but should never
147
+ // be used on the UI runtime regardless. If they are being accessed, the user
148
+ // will get an appropriate error message.
149
+ const inaccessibleObject = makeShareableCloneRecursive(INACCESSIBLE_OBJECT);
150
+ _shareableCache.set(value, inaccessibleObject);
151
+ return inaccessibleObject;
85
152
  }
86
-
87
153
  if (__DEV__) {
88
154
  // we freeze objects that are transformed to shareable. This should help
89
155
  // detect issues when someone modifies data after it's been converted to
@@ -93,17 +159,12 @@ export function makeShareableCloneRecursive(value) {
93
159
  // to be mutable they should use shared values instead.
94
160
  Object.freeze(value);
95
161
  }
96
-
97
162
  const adopted = NativeReanimatedModule.makeShareableClone(toAdapt, shouldPersistRemote);
98
-
99
163
  _shareableCache.set(value, adopted);
100
-
101
164
  _shareableCache.set(adopted, _shareableFlag);
102
-
103
165
  return adopted;
104
166
  }
105
167
  }
106
-
107
168
  return NativeReanimatedModule.makeShareableClone(value, shouldPersistRemote);
108
169
  }
109
170
  export function makeShareableCloneOnUIRecursive(value) {
@@ -114,41 +175,32 @@ export function makeShareableCloneOnUIRecursive(value) {
114
175
  // see more details in the comment where USE_STUB_IMPLEMENTATION is defined.
115
176
  return value;
116
177
  }
117
-
118
178
  function cloneRecursive(value) {
119
179
  const type = typeof value;
120
-
121
180
  if ((type === 'object' || type === 'function') && value !== null) {
122
181
  let toAdapt;
123
-
124
182
  if (Array.isArray(value)) {
125
183
  toAdapt = value.map(element => cloneRecursive(element));
126
- } else {
184
+ } else if (value !== undefined) {
127
185
  toAdapt = {};
128
-
129
186
  for (const [key, element] of Object.entries(value)) {
130
187
  toAdapt[key] = cloneRecursive(element);
131
188
  }
132
189
  }
133
-
134
190
  if (__DEV__) {
135
191
  // See the reasoning behind freezing in the other comment above.
136
192
  Object.freeze(value);
137
193
  }
138
-
139
194
  return _makeShareableClone(toAdapt);
140
195
  }
141
-
142
196
  return _makeShareableClone(value);
143
197
  }
144
-
145
198
  return cloneRecursive(value);
146
199
  }
147
200
  export function makeShareable(value) {
148
201
  if (USE_STUB_IMPLEMENTATION) {
149
202
  return value;
150
203
  }
151
-
152
204
  const handle = makeShareableCloneRecursive({
153
205
  __init: () => {
154
206
  'worklet';
@@ -1 +1 @@
1
- {"version":3,"names":["NativeReanimatedModule","shouldBeUseWeb","registerWorkletStackDetails","USE_STUB_IMPLEMENTATION","_shareableCache","WeakMap","_shareableFlag","Symbol","MAGIC_KEY","isHostObject","value","registerShareableMapping","shareable","shareableRef","set","makeShareableCloneRecursive","shouldPersistRemote","type","cached","get","undefined","toAdapt","Array","isArray","map","element","__workletHash","__DEV__","__stackDetails","__initData","key","Object","entries","freeze","adopted","makeShareableClone","makeShareableCloneOnUIRecursive","cloneRecursive","_makeShareableClone","makeShareable","handle","__init"],"sources":["shareables.ts"],"sourcesContent":["import NativeReanimatedModule from './NativeReanimated';\nimport { ShareableRef } from './commonTypes';\nimport { shouldBeUseWeb } from './PlatformChecker';\nimport { registerWorkletStackDetails } from './errors';\n\n// for web/chrome debugger/jest environments this file provides a stub implementation\n// where no shareable references are used. Instead, the objects themselves are used\n// instead of shareable references, because of the fact that we don't have to deal with\n// runnning the code on separate VMs.\nconst USE_STUB_IMPLEMENTATION = shouldBeUseWeb();\n\nconst _shareableCache = new WeakMap<\n Record<string, unknown>,\n ShareableRef<any> | symbol\n>();\n// the below symbol is used to represent a mapping from the value to itself\n// this is used to allow for a converted shareable to be passed to makeShareableClone\nconst _shareableFlag = Symbol('shareable flag');\n\nconst MAGIC_KEY = 'REANIMATED_MAGIC_KEY';\n\nfunction isHostObject(value: any): boolean {\n // We could use JSI to determine whether an object is a host object, however\n // the below workaround works well and is way faster than an additional JSI call.\n // We use the fact that host objects have broken implementation of `hasOwnProperty`\n // and hence return true for all `in` checks regardless of the key we ask for.\n return MAGIC_KEY in value;\n}\n\nexport function registerShareableMapping(\n shareable: any,\n shareableRef?: ShareableRef<any>\n): void {\n if (USE_STUB_IMPLEMENTATION) {\n return;\n }\n _shareableCache.set(shareable, shareableRef || _shareableFlag);\n}\n\nexport function makeShareableCloneRecursive<T>(\n value: any,\n shouldPersistRemote = false\n): ShareableRef<T> {\n if (USE_STUB_IMPLEMENTATION) {\n return value;\n }\n // This one actually may be worth to be moved to c++, we also need similar logic to run on the UI thread\n const type = typeof value;\n if ((type === 'object' || type === 'function') && value !== null) {\n const cached = _shareableCache.get(value);\n if (cached === _shareableFlag) {\n return value;\n } else if (cached !== undefined) {\n return cached as ShareableRef<T>;\n } else {\n let toAdapt: any;\n if (Array.isArray(value)) {\n toAdapt = value.map((element) => makeShareableCloneRecursive(element));\n } else if (type === 'function' && value.__workletHash === undefined) {\n // this is a remote function\n toAdapt = value;\n } else if (isHostObject(value)) {\n // for host objects we pass the reference to the object as shareable and\n // then recreate new host object wrapping the same instance on the UI thread.\n // there is no point of iterating over keys as we do for regular objects.\n toAdapt = value;\n } else {\n toAdapt = {};\n if (value.__workletHash !== undefined) {\n // we are converting a worklet\n if (__DEV__) {\n registerWorkletStackDetails(\n value.__workletHash,\n value.__stackDetails\n );\n delete value.__stackDetails;\n }\n // to save on transferring static __initData field of worklet structure\n // we request shareable value to persist its UI counterpart. This means\n // that the __initData field that contains long strings represeting the\n // worklet code, source map, and location, will always be\n // serialized/deserialized once.\n toAdapt.__initData = makeShareableCloneRecursive(\n value.__initData,\n true\n );\n delete value.__initData;\n }\n\n for (const [key, element] of Object.entries(value)) {\n toAdapt[key] = makeShareableCloneRecursive(element);\n }\n }\n if (__DEV__) {\n // we freeze objects that are transformed to shareable. This should help\n // detect issues when someone modifies data after it's been converted to\n // shareable. Meaning that they may be doing a faulty assumption in their\n // code expecting that the updates are going to automatically populate to\n // the object sent to the UI thread. If the user really wants some objects\n // to be mutable they should use shared values instead.\n Object.freeze(value);\n }\n const adopted = NativeReanimatedModule.makeShareableClone(\n toAdapt,\n shouldPersistRemote\n );\n _shareableCache.set(value, adopted);\n _shareableCache.set(adopted, _shareableFlag);\n return adopted;\n }\n }\n return NativeReanimatedModule.makeShareableClone(value, shouldPersistRemote);\n}\n\nexport function makeShareableCloneOnUIRecursive<T>(value: T): ShareableRef<T> {\n 'worklet';\n if (USE_STUB_IMPLEMENTATION) {\n // @ts-ignore web is an interesting place where we don't run a secondary VM on the UI thread\n // see more details in the comment where USE_STUB_IMPLEMENTATION is defined.\n return value;\n }\n function cloneRecursive<T>(value: T): ShareableRef<T> {\n const type = typeof value;\n if ((type === 'object' || type === 'function') && value !== null) {\n let toAdapt: any;\n if (Array.isArray(value)) {\n toAdapt = value.map((element) => cloneRecursive(element));\n } else {\n toAdapt = {};\n for (const [key, element] of Object.entries(value)) {\n toAdapt[key] = cloneRecursive(element);\n }\n }\n if (__DEV__) {\n // See the reasoning behind freezing in the other comment above.\n Object.freeze(value);\n }\n return _makeShareableClone(toAdapt);\n }\n return _makeShareableClone(value);\n }\n return cloneRecursive(value);\n}\n\nexport function makeShareable<T>(value: T): T {\n if (USE_STUB_IMPLEMENTATION) {\n return value;\n }\n const handle = makeShareableCloneRecursive({\n __init: () => {\n 'worklet';\n return value;\n },\n });\n registerShareableMapping(value, handle);\n return value;\n}\n"],"mappings":"AAAA,OAAOA,sBAAP,MAAmC,oBAAnC;AAEA,SAASC,cAAT,QAA+B,mBAA/B;AACA,SAASC,2BAAT,QAA4C,UAA5C,C,CAEA;AACA;AACA;AACA;;AACA,MAAMC,uBAAuB,GAAGF,cAAc,EAA9C;;AAEA,MAAMG,eAAe,GAAG,IAAIC,OAAJ,EAAxB,C,CAIA;AACA;;;AACA,MAAMC,cAAc,GAAGC,MAAM,CAAC,gBAAD,CAA7B;;AAEA,MAAMC,SAAS,GAAG,sBAAlB;;AAEA,SAASC,YAAT,CAAsBC,KAAtB,EAA2C;EACzC;EACA;EACA;EACA;EACA,OAAOF,SAAS,IAAIE,KAApB;AACD;;AAED,OAAO,SAASC,wBAA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AWC,OAAD,IAAaY,cAAc,CAACZ,OAAD,CAArC,CAAV;MACD,CAFD,MAEO;QACLJ,OAAO,GAAG,EAAV;;QACA,KAAK,MAAM,CAACS,GAAD,EAAML,OAAN,CAAX,IAA6BM,MAAM,CAACC,OAAP,CAAetB,KAAf,CAA7B,EAAoD;UAClDW,OAAO,CAACS,GAAD,CAAP,GAAeO,cAAc,CAACZ,OAAD,CAA7B;QACD;MACF;;MACD,IAAIE,OAAJ,EAAa;QACX;QACAI,MAAM,CAACE,MAAP,CAAcvB,KAAd;MACD;;MACD,OAAO4B,mBAAmB,CAACjB,OAAD,CAA1B;IACD;;IACD,OAAOiB,mBAAmB,CAAC5B,KAAD,CAA1B;EACD;;EACD,OAAO2B,cAAc,CAAC3B,KAAD,CAArB;AACD;AAED,OAAO,SAAS6B,aAAT,CAA0B7B,KAA1B,EAAuC;EAC5C,IAAIP,uBAAJ,EAA6B;IAC3B,OAAOO,KAAP;EACD;;EACD,MAAM8B,MAAM,GAAGzB,2BAA2B,CAAC;IACzC0B,MAAM,EAAE,MAAM;MACZ;;MACA,OAAO/B,KAAP;IACD;EAJwC,CAAD,CAA1C;EAMAC,wBAAwB,CAACD,KAAD,EAAQ8B,MAAR,CAAxB;EACA,OAAO9B,KAAP;AACD"}
1
+ {"version":3,"names":["NativeReanimatedModule","shouldBeUseWeb","registerWorkletStackDetails","jsVersion","USE_STUB_IMPLEMENTATION","_shareableCache","WeakMap","_shareableFlag","Symbol","MAGIC_KEY","isHostObject","value","registerShareableMapping","shareable","shareableRef","set","isPlainJSObject","object","Object","getPrototypeOf","prototype","INACCESSIBLE_OBJECT","__init","Proxy","get","_","prop","Error","DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD","processedObjectAtThresholdDepth","didShowPluginVersionMismatchError","makeShareableCloneRecursive","shouldPersistRemote","arguments","length","undefined","depth","type","isTypeObject","isTypeFunction","cached","toAdapt","Array","isArray","map","element","__workletHash","__DEV__","__version","console","error","__stackDetails","__initData","key","entries","inaccessibleObject","freeze","adopted","makeShareableClone","makeShareableCloneOnUIRecursive","cloneRecursive","_makeShareableClone","makeShareable","handle"],"sources":["shareables.ts"],"sourcesContent":["import NativeReanimatedModule from './NativeReanimated';\nimport { ShareableRef } from './commonTypes';\nimport { shouldBeUseWeb } from './PlatformChecker';\nimport { registerWorkletStackDetails } from './errors';\nimport { jsVersion } from './platform-specific/jsVersion';\n\n// for web/chrome debugger/jest environments this file provides a stub implementation\n// where no shareable references are used. Instead, the objects themselves are used\n// instead of shareable references, because of the fact that we don't have to deal with\n// runnning the code on separate VMs.\nconst USE_STUB_IMPLEMENTATION = shouldBeUseWeb();\n\nconst _shareableCache = new WeakMap<\n Record<string, unknown>,\n ShareableRef<any> | symbol\n>();\n// the below symbol is used to represent a mapping from the value to itself\n// this is used to allow for a converted shareable to be passed to makeShareableClone\nconst _shareableFlag = Symbol('shareable flag');\n\nconst MAGIC_KEY = 'REANIMATED_MAGIC_KEY';\n\nfunction isHostObject(value: any): boolean {\n // We could use JSI to determine whether an object is a host object, however\n // the below workaround works well and is way faster than an additional JSI call.\n // We use the fact that host objects have broken implementation of `hasOwnProperty`\n // and hence return true for all `in` checks regardless of the key we ask for.\n return MAGIC_KEY in value;\n}\n\nexport function registerShareableMapping(\n shareable: any,\n shareableRef?: ShareableRef<any>\n): void {\n if (USE_STUB_IMPLEMENTATION) {\n return;\n }\n _shareableCache.set(shareable, shareableRef || _shareableFlag);\n}\n\nfunction isPlainJSObject(object: object) {\n return Object.getPrototypeOf(object) === Object.prototype;\n}\n\n// The below object is used as a replacement for objects that cannot be transferred\n// as shareable values. In makeShareableCloneRecursive we detect if an object is of\n// a plain Object.prototype and only allow such objects to be transferred. This lets\n// us avoid all sorts of react internals from leaking into the UI runtime. To make it\n// possible to catch errors when someone actually tries to access such object on the UI\n// runtime, we use the below Proxy object which is instantiated on the UI runtime and\n// throws whenever someone tries to access its fields.\nconst INACCESSIBLE_OBJECT = {\n __init: () => {\n 'worklet';\n return new Proxy(\n {},\n {\n get: (_: any, prop: string) => {\n if (prop === '_isReanimatedSharedValue') {\n // not very happy about this check here, but we need to allow for\n // \"inaccessible\" objects to be tested with isSharedValue check\n // as it is being used in the mappers when extracing inputs recursively.\n // Apparently we can't check if a key exists there as HostObjects always\n // return true for such tests, so the only possibility for us is to\n // actually access that key and see if it is set to true. We therefore\n // need to allow for this key to be accessed here.\n return false;\n }\n throw new Error(\n `Trying to access property \\`${prop}\\` of an object which cannot be sent to the UI runtime.`\n );\n },\n set: () => {\n throw new Error(\n 'Trying to write to an object which cannot be sent to the UI runtime.'\n );\n },\n }\n );\n },\n};\n\nconst DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD = 30;\n// Below variable stores object that we process in makeShareableCloneRecursive at the specified depth.\n// We use it to check if later on the function reenters with the same object\nlet processedObjectAtThresholdDepth: any;\n\n// We only want to show mismatch error once so we use this flag to track it\nlet didShowPluginVersionMismatchError = false;\n\nexport function makeShareableCloneRecursive<T>(\n value: any,\n shouldPersistRemote = false,\n depth = 0\n): ShareableRef<T> {\n if (USE_STUB_IMPLEMENTATION) {\n return value;\n }\n if (depth >= DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {\n // if we reach certain recursion depth we suspect that we are dealing with a cyclic object.\n // this type of objects are not supported and cannot be trasferred as shareable, so we\n // implement a simple detection mechanism that remembers the value at a given depth and\n // tests whether we try reenter this method later on with the same value. If that happens\n // we throw an appropriate error.\n if (depth === DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {\n processedObjectAtThresholdDepth = value;\n } else if (value === processedObjectAtThresholdDepth) {\n throw new Error(\n 'Trying to convert a cyclic object to a shareable. This is not supported.'\n );\n }\n } else {\n processedObjectAtThresholdDepth = undefined;\n }\n // This one actually may be worth to be moved to c++, we also need similar logic to run on the UI thread\n const type = typeof value;\n const isTypeObject = type === 'object';\n const isTypeFunction = type === 'function';\n if ((isTypeObject || isTypeFunction) && value !== null) {\n const cached = _shareableCache.get(value);\n if (cached === _shareableFlag) {\n return value;\n } else if (cached !== undefined) {\n return cached as ShareableRef<T>;\n } else {\n let toAdapt: any;\n if (Array.isArray(value)) {\n toAdapt = value.map((element) =>\n makeShareableCloneRecursive(element, shouldPersistRemote, depth + 1)\n );\n } else if (isTypeFunction && value.__workletHash === undefined) {\n // this is a remote function\n toAdapt = value;\n } else if (isHostObject(value)) {\n // for host objects we pass the reference to the object as shareable and\n // then recreate new host object wrapping the same instance on the UI thread.\n // there is no point of iterating over keys as we do for regular objects.\n toAdapt = value;\n } else if (isPlainJSObject(value) || isTypeFunction) {\n toAdapt = {};\n if (value.__workletHash !== undefined) {\n // we are converting a worklet\n if (__DEV__) {\n if (\n // We don't want this error to be logged more than once.\n !didShowPluginVersionMismatchError &&\n value.__version !== jsVersion\n ) {\n didShowPluginVersionMismatchError = true;\n console.error(`[Reanimated] Mismatch between JavaScript code version and Reanimated Babel plugin version (${jsVersion} vs. ${value.__version}). Please clear your Metro bundler cache with \\`yarn start --reset-cache\\`,\n \\`npm start -- --reset-cache\\` or \\`expo start -c\\` and run the app again.`);\n }\n registerWorkletStackDetails(\n value.__workletHash,\n value.__stackDetails\n );\n delete value.__stackDetails;\n }\n // to save on transferring static __initData field of worklet structure\n // we request shareable value to persist its UI counterpart. This means\n // that the __initData field that contains long strings represeting the\n // worklet code, source map, and location, will always be\n // serialized/deserialized once. We don't increase depth when calling\n // this method as these objects have one level anyways.\n toAdapt.__initData = makeShareableCloneRecursive(\n value.__initData,\n true\n );\n delete value.__initData;\n }\n\n for (const [key, element] of Object.entries(value)) {\n toAdapt[key] = makeShareableCloneRecursive(\n element,\n shouldPersistRemote,\n depth + 1\n );\n }\n } else {\n // This is reached for object types that are not of plain Object.prototype.\n // We don't support such objects from being transferred as shareables to\n // the UI runtime and hence we replace them with \"inaccessible object\"\n // which is implemented as a Proxy object that throws on any attempt\n // of accessing its fields. We argue that such objects can sometimes leak\n // as attributes of objects being captured by worklets but should never\n // be used on the UI runtime regardless. If they are being accessed, the user\n // will get an appropriate error message.\n const inaccessibleObject =\n makeShareableCloneRecursive<T>(INACCESSIBLE_OBJECT);\n _shareableCache.set(value, inaccessibleObject);\n return inaccessibleObject;\n }\n if (__DEV__) {\n // we freeze objects that are transformed to shareable. This should help\n // detect issues when someone modifies data after it's been converted to\n // shareable. Meaning that they may be doing a faulty assumption in their\n // code expecting that the updates are going to automatically populate to\n // the object sent to the UI thread. If the user really wants some objects\n // to be mutable they should use shared values instead.\n Object.freeze(value);\n }\n const adopted = NativeReanimatedModule.makeShareableClone(\n toAdapt,\n shouldPersistRemote\n );\n _shareableCache.set(value, adopted);\n _shareableCache.set(adopted, _shareableFlag);\n return adopted;\n }\n }\n return NativeReanimatedModule.makeShareableClone(value, shouldPersistRemote);\n}\n\nexport function makeShareableCloneOnUIRecursive<T>(value: T): ShareableRef<T> {\n 'worklet';\n if (USE_STUB_IMPLEMENTATION) {\n // @ts-ignore web is an interesting place where we don't run a secondary VM on the UI thread\n // see more details in the comment where USE_STUB_IMPLEMENTATION is defined.\n return value;\n }\n function cloneRecursive<T>(value: T): ShareableRef<T> {\n const type = typeof value;\n if ((type === 'object' || type === 'function') && value !== null) {\n let toAdapt: any;\n if (Array.isArray(value)) {\n toAdapt = value.map((element) => cloneRecursive(element));\n } else if (value !== undefined) {\n toAdapt = {};\n for (const [key, element] of Object.entries(value)) {\n toAdapt[key] = cloneRecursive(element);\n }\n }\n if (__DEV__) {\n // See the reasoning behind freezing in the other comment above.\n Object.freeze(value);\n }\n return _makeShareableClone(toAdapt);\n }\n return _makeShareableClone(value);\n }\n return cloneRecursive(value);\n}\n\nexport function makeShareable<T>(value: T): T {\n if (USE_STUB_IMPLEMENTATION) {\n return value;\n }\n const handle = makeShareableCloneRecursive({\n __init: () => {\n 'worklet';\n return value;\n },\n });\n registerShareableMapping(value, handle);\n return value;\n}\n"],"mappings":"AAAA,OAAOA,sBAAsB,MAAM,oBAAoB;AAEvD,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,2BAA2B,QAA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ACA,IAAIE,OAAO,EAAE;QACX;QACA7B,MAAM,CAACsC,MAAM,CAAC7C,KAAK,CAAC;MACtB;MACA,OAAOkD,mBAAmB,CAACpB,OAAO,CAAC;IACrC;IACA,OAAOoB,mBAAmB,CAAClD,KAAK,CAAC;EACnC;EACA,OAAOiD,cAAc,CAACjD,KAAK,CAAC;AAC9B;AAEA,OAAO,SAASmD,aAAaA,CAAInD,KAAQ,EAAK;EAC5C,IAAIP,uBAAuB,EAAE;IAC3B,OAAOO,KAAK;EACd;EACA,MAAMoD,MAAM,GAAGhC,2BAA2B,CAAC;IACzCT,MAAM,EAAEA,CAAA,KAAM;MACZ,SAAS;;MACT,OAAOX,KAAK;IACd;EACF,CAAC,CAAC;EACFC,wBAAwB,CAACD,KAAK,EAAEoD,MAAM,CAAC;EACvC,OAAOpD,KAAK;AACd"}
@@ -4,52 +4,58 @@ import { makeShareableCloneOnUIRecursive, makeShareableCloneRecursive } from './
4
4
  const IS_JEST = isJest();
5
5
  const IS_WEB = shouldBeUseWeb();
6
6
  let _runOnUIQueue = [];
7
- export function setupSetImmediate() {
7
+ export function setupMicrotasks() {
8
8
  'worklet';
9
9
 
10
- let immediateCallbacks = []; // @ts-ignore – typescript expects this to conform to NodeJS definition and expects the return value to be NodeJS.Immediate which is an object and not a number
10
+ let microtasksQueue = [];
11
+ let isExecutingMicrotasksQueue = false;
11
12
 
12
- global.setImmediate = callback => {
13
- immediateCallbacks.push(callback);
13
+ // @ts-ignore – typescript expects this to conform to NodeJS definition and expects the return value to be NodeJS.Immediate which is an object and not a number
14
+ global.queueMicrotask = callback => {
15
+ microtasksQueue.push(callback);
14
16
  return -1;
15
17
  };
16
-
17
- global.__flushImmediates = () => {
18
- for (let index = 0; index < immediateCallbacks.length; index += 1) {
19
- // we use classic 'for' loop because the size of the currentTasks array may change while executing some of the callbacks due to setImmediate calls
20
- immediateCallbacks[index]();
18
+ global.__callMicrotasks = () => {
19
+ if (isExecutingMicrotasksQueue) {
20
+ return;
21
+ }
22
+ try {
23
+ isExecutingMicrotasksQueue = true;
24
+ for (let index = 0; index < microtasksQueue.length; index += 1) {
25
+ // we use classic 'for' loop because the size of the currentTasks array may change while executing some of the callbacks due to queueMicrotask calls
26
+ microtasksQueue[index]();
27
+ }
28
+ microtasksQueue = [];
29
+ global._maybeFlushUIUpdatesQueue();
30
+ } finally {
31
+ isExecutingMicrotasksQueue = false;
21
32
  }
22
-
23
- immediateCallbacks = [];
24
33
  };
25
34
  }
26
-
27
- function flushImmediatesOnUIThread() {
35
+ function callMicrotasksOnUIThread() {
28
36
  'worklet';
29
37
 
30
- global.__flushImmediates();
38
+ global.__callMicrotasks();
31
39
  }
40
+ export const callMicrotasks = shouldBeUseWeb() ? () => {
41
+ // on web flushing is a noop as immediates are handled by the browser
42
+ } : callMicrotasksOnUIThread;
32
43
 
33
- export const flushImmediates = shouldBeUseWeb() ? () => {// on web flushing is a noop as immediates are handled by the browser
34
- } : flushImmediatesOnUIThread;
35
44
  /**
36
45
  * Schedule a worklet to execute on the UI runtime. This method does not schedule the work immediately but instead
37
- * waits for other worklets to be scheduled within the same JS loop. It uses setImmediate to schedule all the worklets
46
+ * waits for other worklets to be scheduled within the same JS loop. It uses queueMicrotask to schedule all the worklets
38
47
  * at once making sure they will run within the same frame boundaries on the UI thread.
39
48
  */
40
-
41
49
  export function runOnUI(worklet) {
42
50
  if (__DEV__ && !IS_WEB && worklet.__workletHash === undefined) {
43
51
  throw new Error('runOnUI() can only be used on worklets');
44
52
  }
45
-
46
53
  return function () {
47
54
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
48
55
  args[_key] = arguments[_key];
49
56
  }
50
-
51
57
  if (IS_JEST) {
52
- // Mocking time in Jest is tricky as both requestAnimationFrame and setImmediate
58
+ // Mocking time in Jest is tricky as both requestAnimationFrame and queueMicrotask
53
59
  // callbacks run on the same queue and can be interleaved. There is no way
54
60
  // to flush particular queue in Jest and the only control over mocked timers
55
61
  // is by using jest.advanceTimersByTime() method which advances all types
@@ -65,11 +71,18 @@ export function runOnUI(worklet) {
65
71
  }));
66
72
  return;
67
73
  }
68
-
74
+ if (__DEV__) {
75
+ // in DEV mode we call shareable conversion here because in case the object
76
+ // can't be converted, we will get a meaningful stack-trace as opposed to the
77
+ // situation when conversion is only done via microtask queue. This does not
78
+ // make the app particularily less efficient as converted objects are cached
79
+ // and for a given worklet the conversion only happens once.
80
+ makeShareableCloneRecursive(worklet);
81
+ makeShareableCloneRecursive(args);
82
+ }
69
83
  _runOnUIQueue.push([worklet, args]);
70
-
71
84
  if (_runOnUIQueue.length === 1) {
72
- setImmediate(() => {
85
+ queueMicrotask(() => {
73
86
  const queue = _runOnUIQueue;
74
87
  _runOnUIQueue = [];
75
88
  NativeReanimatedModule.scheduleOnUI(makeShareableCloneRecursive(() => {
@@ -79,26 +92,24 @@ export function runOnUI(worklet) {
79
92
  let [worklet, args] = _ref;
80
93
  worklet(...args);
81
94
  });
82
- flushImmediates();
95
+ callMicrotasks();
83
96
  }));
84
97
  });
85
98
  }
86
99
  };
87
100
  }
101
+
88
102
  /**
89
103
  * Schedule a worklet to execute on the UI runtime skipping batching mechanism.
90
104
  */
91
-
92
105
  export function runOnUIImmediately(worklet) {
93
106
  if (__DEV__ && !IS_WEB && worklet.__workletHash === undefined) {
94
107
  throw new Error('runOnUI() can only be used on worklets');
95
108
  }
96
-
97
109
  return function () {
98
110
  for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
99
111
  args[_key2] = arguments[_key2];
100
112
  }
101
-
102
113
  NativeReanimatedModule.scheduleOnUI(makeShareableCloneRecursive(() => {
103
114
  'worklet';
104
115
 
@@ -106,7 +117,6 @@ export function runOnUIImmediately(worklet) {
106
117
  }));
107
118
  };
108
119
  }
109
-
110
120
  if (__DEV__) {
111
121
  try {
112
122
  runOnUI(() => {
@@ -116,7 +126,6 @@ if (__DEV__) {
116
126
  throw new Error('Failed to create a worklet. Did you forget to add Reanimated Babel plugin in babel.config.js? See installation docs at https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation#babel-plugin.');
117
127
  }
118
128
  }
119
-
120
129
  export function runOnJS(fun) {
121
130
  'worklet';
122
131
 
@@ -127,16 +136,13 @@ export function runOnJS(fun) {
127
136
  // reference to the original remote function in the `__remoteFunction` property.
128
137
  fun = fun.__remoteFunction;
129
138
  }
130
-
131
139
  if (!_WORKLET) {
132
140
  return fun;
133
141
  }
134
-
135
142
  return function () {
136
143
  for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
137
144
  args[_key3] = arguments[_key3];
138
145
  }
139
-
140
146
  _scheduleOnJS(fun, args.length > 0 ? makeShareableCloneOnUIRecursive(args) : undefined);
141
147
  };
142
148
  }
@@ -1 +1 @@
1
- {"version":3,"names":["NativeReanimatedModule","isJest","shouldBeUseWeb","makeShareableCloneOnUIRecursive","makeShareableCloneRecursive","IS_JEST","IS_WEB","_runOnUIQueue","setupSetImmediate","immediateCallbacks","global","setImmediate","callback","push","__flushImmediates","index","length","flushImmediatesOnUIThread","flushImmediates","runOnUI","worklet","__DEV__","__workletHash","undefined","Error","args","scheduleOnUI","queue","forEach","runOnUIImmediately","e","runOnJS","fun","__remoteFunction","_WORKLET","_scheduleOnJS"],"sources":["threads.ts"],"sourcesContent":["import NativeReanimatedModule from './NativeReanimated';\nimport { isJest, shouldBeUseWeb } from './PlatformChecker';\nimport { ComplexWorkletFunction } from './commonTypes';\nimport {\n makeShareableCloneOnUIRecursive,\n makeShareableCloneRecursive,\n} from './shareables';\n\nconst IS_JEST = isJest();\nconst IS_WEB = shouldBeUseWeb();\n\nlet _runOnUIQueue: Array<[ComplexWorkletFunction<any[], any>, any[]]> = [];\n\nexport function setupSetImmediate() {\n 'worklet';\n\n let immediateCallbacks: Array<() => void> = [];\n\n // @ts-ignore – typescript expects this to conform to NodeJS definition and expects the return value to be NodeJS.Immediate which is an object and not a number\n global.setImmediate = (callback: () => void): number => {\n immediateCallbacks.push(callback);\n return -1;\n };\n\n global.__flushImmediates = () => {\n for (let index = 0; index < immediateCallbacks.length; index += 1) {\n // we use classic 'for' loop because the size of the currentTasks array may change while executing some of the callbacks due to setImmediate calls\n immediateCallbacks[index]();\n }\n immediateCallbacks = [];\n };\n}\n\nfunction flushImmediatesOnUIThread() {\n 'worklet';\n global.__flushImmediates();\n}\n\nexport const flushImmediates = shouldBeUseWeb()\n ? () => {\n // on web flushing is a noop as immediates are handled by the browser\n }\n : flushImmediatesOnUIThread;\n\n/**\n * Schedule a worklet to execute on the UI runtime. This method does not schedule the work immediately but instead\n * waits for other worklets to be scheduled within the same JS loop. It uses setImmediate to schedule all the worklets\n * at once making sure they will run within the same frame boundaries on the UI thread.\n */\nexport function runOnUI<A extends any[], R>(\n worklet: ComplexWorkletFunction<A, R>\n): (...args: A) => void {\n if (__DEV__ && !IS_WEB && worklet.__workletHash === undefined) {\n throw new Error('runOnUI() can only be used on worklets');\n }\n return (...args) => {\n if (IS_JEST) {\n // Mocking time in Jest is tricky as both requestAnimationFrame and setImmediate\n // callbacks run on the same queue and can be interleaved. There is no way\n // to flush particular queue in Jest and the only control over mocked timers\n // is by using jest.advanceTimersByTime() method which advances all types\n // of timers including immediate and animation callbacks. Ideally we'd like\n // to have some way here to schedule work along with React updates, but\n // that's not possible, and hence in Jest environment instead of using scheduling\n // mechanism we just schedule the work ommiting the queue. This is ok for the\n // uses that we currently have but may not be ok for future tests that we write.\n NativeReanimatedModule.scheduleOnUI(\n makeShareableCloneRecursive(() => {\n 'worklet';\n worklet(...args);\n })\n );\n return;\n }\n _runOnUIQueue.push([worklet, args]);\n if (_runOnUIQueue.length === 1) {\n setImmediate(() => {\n const queue = _runOnUIQueue;\n _runOnUIQueue = [];\n NativeReanimatedModule.scheduleOnUI(\n makeShareableCloneRecursive(() => {\n 'worklet';\n queue.forEach(([worklet, args]) => {\n worklet(...args);\n });\n flushImmediates();\n })\n );\n });\n }\n };\n}\n\n/**\n * Schedule a worklet to execute on the UI runtime skipping batching mechanism.\n */\nexport function runOnUIImmediately<A extends any[], R>(\n worklet: ComplexWorkletFunction<A, R>\n): (...args: A) => void {\n if (__DEV__ && !IS_WEB && worklet.__workletHash === undefined) {\n throw new Error('runOnUI() can only be used on worklets');\n }\n return (...args) => {\n NativeReanimatedModule.scheduleOnUI(\n makeShareableCloneRecursive(() => {\n 'worklet';\n worklet(...args);\n })\n );\n };\n}\n\nif (__DEV__) {\n try {\n runOnUI(() => {\n 'worklet';\n });\n } catch (e) {\n throw new Error(\n 'Failed to create a worklet. Did you forget to add Reanimated Babel plugin in babel.config.js? See installation docs at https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation#babel-plugin.'\n );\n }\n}\n\nexport function runOnJS<A extends any[], R>(\n fun: ComplexWorkletFunction<A, R>\n): (...args: A) => void {\n 'worklet';\n if (fun.__remoteFunction) {\n // in development mode the function provided as `fun` throws an error message\n // such that when someone accidently calls it directly on the UI runtime, they\n // see that they should use `runOnJS` instead. To facilitate that we purt the\n // reference to the original remote function in the `__remoteFunction` property.\n fun = fun.__remoteFunction;\n }\n if (!_WORKLET) {\n return fun;\n }\n return (...args) => {\n _scheduleOnJS(\n fun,\n args.length > 0 ? makeShareableCloneOnUIRecursive(args) : undefined\n );\n };\n}\n"],"mappings":"AAAA,OAAOA,sBAAP,MAAmC,oBAAnC;AACA,SAASC,MAAT,EAAiBC,cAAjB,QAAuC,mBAAvC;AAEA,SACEC,+BADF,EAEEC,2BAFF,QAGO,cAHP;AAKA,MAAMC,OAAO,GAAGJ,MAAM,EAAtB;AACA,MAAMK,MAAM,GAAGJ,cAAc,EAA7B;AAEA,IAAIK,aAAiE,GAAG,EAAxE;AAEA,OAAO,SAASC,iBAAT,GAA6B;EAClC;;EAEA,IAAIC,kBAAqC,GAAG,EAA5C,CAHkC,CAKlC;;EACAC,MAAM,CAACC,YAAP,GAAuBC,QAAD,IAAkC;IACtDH,kBAAkB,CAACI,IAAnB,CAAwBD,QAAxB;IACA,OAAO,CAAC,C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oB;YACjCL,OAAO,CAAC,GAAGK,IAAJ,CAAP;UACD,CAFD;UAGAP,eAAe;QAChB,CAN0B,CAD7B;MASD,CAZW,CAAZ;IAaD;EACF,CAnCD;AAoCD;AAED;AACA;AACA;;AACA,OAAO,SAASW,kBAAT,CACLT,OADK,EAEiB;EACtB,IAAIC,OAAO,IAAI,CAACf,MAAZ,IAAsBc,OAAO,CAACE,aAAR,KAA0BC,SAApD,EAA+D;IAC7D,MAAM,IAAIC,KAAJ,CAAU,wCAAV,CAAN;EACD;;EACD,OAAO,YAAa;IAAA,mCAATC,IAAS;MAATA,IAAS;IAAA;;IAClBzB,sBAAsB,CAAC0B,YAAvB,CACEtB,2BAA2B,CAAC,MAAM;MAChC;;MACAgB,OAAO,CAAC,GAAGK,IAAJ,CAAP;IACD,CAH0B,CAD7B;EAMD,CAPD;AAQD;;AAED,IAAIJ,OAAJ,EAAa;EACX,IAAI;IACFF,OAAO,CAAC,MAAM;MACZ;IACD,CAFM,CAAP;EAGD,CAJD,CAIE,OAAOW,CAAP,EAAU;IACV,MAAM,IAAIN,KAAJ,CACJ,wNADI,CAAN;EAGD;AACF;;AAED,OAAO,SAASO,OAAT,CACLC,GADK,EAEiB;EACtB;;EACA,IAAIA,GAAG,CAACC,gBAAR,EAA0B;IACxB;IACA;IACA;IACA;IACAD,GAAG,GAAGA,GAAG,CAACC,gBAAV;EACD;;EACD,IAAI,CAACC,QAAL,EAAe;IACb,OAAOF,GAAP;EACD;;EACD,OAAO,YAAa;IAAA,mCAATP,IAAS;MAATA,IAAS;IAAA;;IAClBU,aAAa,CACXH,GADW,EAEXP,IAAI,CAACT,MAAL,GAAc,CAAd,GAAkBb,+BAA+B,CAACsB,IAAD,CAAjD,GAA0DF,SAF/C,CAAb;EAID,CALD;AAMD"}
1
+ {"version":3,"names":["NativeReanimatedModule","isJest","shouldBeUseWeb","makeShareableCloneOnUIRecursive","makeShareableCloneRecursive","IS_JEST","IS_WEB","_runOnUIQueue","setupMicrotasks","microtasksQueue","isExecutingMicrotasksQueue","global","queueMicrotask","callback","push","__callMicrotasks","index","length","_maybeFlushUIUpdatesQueue","callMicrotasksOnUIThread","callMicrotasks","runOnUI","worklet","__DEV__","__workletHash","undefined","Error","_len","arguments","args","Array","_key","scheduleOnUI","queue","forEach","_ref","runOnUIImmediately","_len2","_key2","e","runOnJS","fun","__remoteFunction","_WORKLET","_len3","_key3","_scheduleOnJS"],"sources":["threads.ts"],"sourcesContent":["import NativeReanimatedModule from './NativeReanimated';\nimport { isJest, shouldBeUseWeb } from './PlatformChecker';\nimport { ComplexWorkletFunction } from './commonTypes';\nimport {\n makeShareableCloneOnUIRecursive,\n makeShareableCloneRecursive,\n} from './shareables';\n\nconst IS_JEST = isJest();\nconst IS_WEB = shouldBeUseWeb();\n\nlet _runOnUIQueue: Array<[ComplexWorkletFunction<any[], any>, any[]]> = [];\n\nexport function setupMicrotasks() {\n 'worklet';\n\n let microtasksQueue: Array<() => void> = [];\n let isExecutingMicrotasksQueue = false;\n\n // @ts-ignore – typescript expects this to conform to NodeJS definition and expects the return value to be NodeJS.Immediate which is an object and not a number\n global.queueMicrotask = (callback: () => void): number => {\n microtasksQueue.push(callback);\n return -1;\n };\n\n global.__callMicrotasks = () => {\n if (isExecutingMicrotasksQueue) {\n return;\n }\n try {\n isExecutingMicrotasksQueue = true;\n for (let index = 0; index < microtasksQueue.length; index += 1) {\n // we use classic 'for' loop because the size of the currentTasks array may change while executing some of the callbacks due to queueMicrotask calls\n microtasksQueue[index]();\n }\n microtasksQueue = [];\n global._maybeFlushUIUpdatesQueue();\n } finally {\n isExecutingMicrotasksQueue = false;\n }\n };\n}\n\nfunction callMicrotasksOnUIThread() {\n 'worklet';\n global.__callMicrotasks();\n}\n\nexport const callMicrotasks = shouldBeUseWeb()\n ? () => {\n // on web flushing is a noop as immediates are handled by the browser\n }\n : callMicrotasksOnUIThread;\n\n/**\n * Schedule a worklet to execute on the UI runtime. This method does not schedule the work immediately but instead\n * waits for other worklets to be scheduled within the same JS loop. It uses queueMicrotask to schedule all the worklets\n * at once making sure they will run within the same frame boundaries on the UI thread.\n */\nexport function runOnUI<A extends any[], R>(\n worklet: ComplexWorkletFunction<A, R>\n): (...args: A) => void {\n if (__DEV__ && !IS_WEB && worklet.__workletHash === undefined) {\n throw new Error('runOnUI() can only be used on worklets');\n }\n return (...args) => {\n if (IS_JEST) {\n // Mocking time in Jest is tricky as both requestAnimationFrame and queueMicrotask\n // callbacks run on the same queue and can be interleaved. There is no way\n // to flush particular queue in Jest and the only control over mocked timers\n // is by using jest.advanceTimersByTime() method which advances all types\n // of timers including immediate and animation callbacks. Ideally we'd like\n // to have some way here to schedule work along with React updates, but\n // that's not possible, and hence in Jest environment instead of using scheduling\n // mechanism we just schedule the work ommiting the queue. This is ok for the\n // uses that we currently have but may not be ok for future tests that we write.\n NativeReanimatedModule.scheduleOnUI(\n makeShareableCloneRecursive(() => {\n 'worklet';\n worklet(...args);\n })\n );\n return;\n }\n if (__DEV__) {\n // in DEV mode we call shareable conversion here because in case the object\n // can't be converted, we will get a meaningful stack-trace as opposed to the\n // situation when conversion is only done via microtask queue. This does not\n // make the app particularily less efficient as converted objects are cached\n // and for a given worklet the conversion only happens once.\n makeShareableCloneRecursive(worklet);\n makeShareableCloneRecursive(args);\n }\n _runOnUIQueue.push([worklet, args]);\n if (_runOnUIQueue.length === 1) {\n queueMicrotask(() => {\n const queue = _runOnUIQueue;\n _runOnUIQueue = [];\n NativeReanimatedModule.scheduleOnUI(\n makeShareableCloneRecursive(() => {\n 'worklet';\n queue.forEach(([worklet, args]) => {\n worklet(...args);\n });\n callMicrotasks();\n })\n );\n });\n }\n };\n}\n\n/**\n * Schedule a worklet to execute on the UI runtime skipping batching mechanism.\n */\nexport function runOnUIImmediately<A extends any[], R>(\n worklet: ComplexWorkletFunction<A, R>\n): (...args: A) => void {\n if (__DEV__ && !IS_WEB && worklet.__workletHash === undefined) {\n throw new Error('runOnUI() can only be used on worklets');\n }\n return (...args) => {\n NativeReanimatedModule.scheduleOnUI(\n makeShareableCloneRecursive(() => {\n 'worklet';\n worklet(...args);\n })\n );\n };\n}\n\nif (__DEV__) {\n try {\n runOnUI(() => {\n 'worklet';\n });\n } catch (e) {\n throw new Error(\n 'Failed to create a worklet. Did you forget to add Reanimated Babel plugin in babel.config.js? See installation docs at https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation#babel-plugin.'\n );\n }\n}\n\nexport function runOnJS<A extends any[], R>(\n fun: ComplexWorkletFunction<A, R>\n): (...args: A) => void {\n 'worklet';\n if (fun.__remoteFunction) {\n // in development mode the function provided as `fun` throws an error message\n // such that when someone accidently calls it directly on the UI runtime, they\n // see that they should use `runOnJS` instead. To facilitate that we purt the\n // reference to the original remote function in the `__remoteFunction` property.\n fun = fun.__remoteFunction;\n }\n if (!_WORKLET) {\n return fun;\n }\n return (...args) => {\n _scheduleOnJS(\n fun,\n args.length > 0 ? makeShareableCloneOnUIRecursive(args) : undefined\n );\n };\n}\n"],"mappings":"AAAA,OAAOA,sBAAsB,MAAM,oBAAoB;AACvD,SAASC,MAAM,EAAEC,cAAc,QAAQ,mBAAmB;AAE1D,SACEC,+BAA+B,EAC/BC,2BAA2B,QACtB,cAAc;AAErB,MAAMC,OAAO,GAAGJ,MAAM,EAAE;AACxB,MAAMK,MAAM,GAAGJ,cAAc,EAAE;AAE/B,IAAIK,aAAiE,GAAG,EAAE;AAE1E,OAAO,SAASC,eAAeA,CAAA,EAAG;EAChC,SAAS;;EAET,IAAIC,eAAkC,GAAG,EAAE;EAC3C,IAAIC,0BAA0B,GAAG,KAAK;;EAEtC;EACAC,MAAM,CAACC,cAAc,GAAIC,QAAoB,IAAa;IACxDJ,eAAe,CAACK,IAAI,CAACD,QAAQ,CAAC;IAC9B,OAAO,CAAC,CAAC;EACX,CAAC;EAEDF,MAAM,CAACI,gBAAgB,GAAG,MAAM;IAC9B,IAAIL,0BAA0B,EAAE;MAC9B;IACF;IACA,IAAI;MACFA,0BAA0B,GAAG,IAAI;MAC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;EACH;AACF;AAEA,OAAO,SAASc,OAAOA,CACrBC,GAAiC,EACX;EACtB,SAAS;;EACT,IAAIA,GAAG,CAACC,gBAAgB,EAAE;IACxB;IACA;IACA;IACA;IACAD,GAAG,GAAGA,GAAG,CAACC,gBAAgB;EAC5B;EACA,IAAI,CAACC,QAAQ,EAAE;IACb,OAAOF,GAAG;EACZ;EACA,OAAO,YAAa;IAAA,SAAAG,KAAA,GAAAhB,SAAA,CAAAX,MAAA,EAATY,IAAI,OAAAC,KAAA,CAAAc,KAAA,GAAAC,KAAA,MAAAA,KAAA,GAAAD,KAAA,EAAAC,KAAA;MAAJhB,IAAI,CAAAgB,KAAA,IAAAjB,SAAA,CAAAiB,KAAA;IAAA;IACbC,aAAa,CACXL,GAAG,EACHZ,IAAI,CAACZ,MAAM,GAAG,CAAC,GAAGd,+BAA+B,CAAC0B,IAAI,CAAC,GAAGJ,SAAS,CACpE;EACH,CAAC;AACH"}
@@ -1,5 +1,4 @@
1
1
  import { measure } from './NativeMethods';
2
-
3
2
  /**
4
3
  * Given an absolute position and a component ref, returns the relative
5
4
  * position in the component's local coordinate space.
@@ -8,11 +7,9 @@ export function getRelativeCoords(parentRef, absoluteX, absoluteY) {
8
7
  'worklet';
9
8
 
10
9
  const parentCoords = measure(parentRef);
11
-
12
10
  if (parentCoords === null) {
13
11
  return null;
14
12
  }
15
-
16
13
  return {
17
14
  x: absoluteX - parentCoords.x,
18
15
  y: absoluteY - parentCoords.y
@@ -1 +1 @@
1
- {"version":3,"names":["measure","getRelativeCoords","parentRef","absoluteX","absoluteY","parentCoords","x","y","isSharedValue","value","_isReanimatedSharedValue"],"sources":["utils.ts"],"sourcesContent":["import { Component } from 'react';\nimport { measure } from './NativeMethods';\nimport { RefObjectFunction } from './hook/commonTypes';\nimport { SharedValue } from './commonTypes';\n\nexport interface ComponentCoords {\n x: number;\n y: number;\n}\n\n/**\n * Given an absolute position and a component ref, returns the relative\n * position in the component's local coordinate space.\n */\nexport function getRelativeCoords(\n parentRef: RefObjectFunction<Component>,\n absoluteX: number,\n absoluteY: number\n): ComponentCoords | null {\n 'worklet';\n const parentCoords = measure(parentRef);\n if (parentCoords === null) {\n return null;\n }\n return {\n x: absoluteX - parentCoords.x,\n y: absoluteY - parentCoords.y,\n };\n}\n\nexport function isSharedValue<T>(value: any): value is SharedValue<T> {\n 'worklet';\n return value?._isReanimatedSharedValue === true;\n}\n"],"mappings":"AACA,SAASA,OAAT,QAAwB,iBAAxB;;AASA;AACA;AACA;AACA;AACA,OAAO,SAASC,iBAAT,CACLC,SADK,EAELC,SAFK,EAGLC,SAHK,EAImB;EACxB;;EACA,MAAMC,YAAY,GAAGL,OAAO,CAACE,SAAD,CAA5B;;EACA,IAAIG,YAAY,KAAK,IAArB,EAA2B;IACzB,OAAO,IAAP;EACD;;EACD,OAAO;IACLC,CAAC,EAAEH,SAAS,GAAGE,YAAY,CAACC,CADvB;IAELC,CAAC,EAAEH,SAAS,GAAGC,YAAY,CAACE;EAFvB,CAAP;AAID;AAED,OAAO,SAASC,aAAT,CAA0BC,KAA1B,EAA+D;EACpE;;EACA,OAAO,CAAAA,KAAK,SAAL,IAAAA,KAAK,WAAL,YAAAA,KAAK,CAAEC,wBAAP,MAAoC,IAA3C;AACD"}
1
+ {"version":3,"names":["measure","getRelativeCoords","parentRef","absoluteX","absoluteY","parentCoords","x","y","isSharedValue","value","_isReanimatedSharedValue"],"sources":["utils.ts"],"sourcesContent":["import { Component } from 'react';\nimport { measure } from './NativeMethods';\nimport { RefObjectFunction } from './hook/commonTypes';\nimport { SharedValue } from './commonTypes';\n\nexport interface ComponentCoords {\n x: number;\n y: number;\n}\n\n/**\n * Given an absolute position and a component ref, returns the relative\n * position in the component's local coordinate space.\n */\nexport function getRelativeCoords(\n parentRef: RefObjectFunction<Component>,\n absoluteX: number,\n absoluteY: number\n): ComponentCoords | null {\n 'worklet';\n const parentCoords = measure(parentRef);\n if (parentCoords === null) {\n return null;\n }\n return {\n x: absoluteX - parentCoords.x,\n y: absoluteY - parentCoords.y,\n };\n}\n\nexport function isSharedValue<T>(value: any): value is SharedValue<T> {\n 'worklet';\n return value?._isReanimatedSharedValue === true;\n}\n"],"mappings":"AACA,SAASA,OAAO,QAAQ,iBAAiB;AASzC;AACA;AACA;AACA;AACA,OAAO,SAASC,iBAAiBA,CAC/BC,SAAuC,EACvCC,SAAiB,EACjBC,SAAiB,EACO;EACxB,SAAS;;EACT,MAAMC,YAAY,GAAGL,OAAO,CAACE,SAAS,CAAC;EACvC,IAAIG,YAAY,KAAK,IAAI,EAAE;IACzB,OAAO,IAAI;EACb;EACA,OAAO;IACLC,CAAC,EAAEH,SAAS,GAAGE,YAAY,CAACC,CAAC;IAC7BC,CAAC,EAAEH,SAAS,GAAGC,YAAY,CAACE;EAC9B,CAAC;AACH;AAEA,OAAO,SAASC,aAAaA,CAAIC,KAAU,EAA2B;EACpE,SAAS;;EACT,OAAO,CAAAA,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEC,wBAAwB,MAAK,IAAI;AACjD"}
@@ -3,53 +3,41 @@ export function valueSetter(sv, value) {
3
3
  'worklet';
4
4
 
5
5
  const previousAnimation = sv._animation;
6
-
7
6
  if (previousAnimation) {
8
7
  previousAnimation.cancelled = true;
9
8
  sv._animation = null;
10
9
  }
11
-
12
10
  if (typeof value === 'function' || value !== null && typeof value === 'object' && value.onFrame !== undefined) {
13
- const animation = typeof value === 'function' ? value() : value; // prevent setting again to the same value
11
+ const animation = typeof value === 'function' ? value() : value;
12
+ // prevent setting again to the same value
14
13
  // and triggering the mappers that treat this value as an input
15
14
  // this happens when the animation's target value(stored in animation.current until animation.onStart is called) is set to the same value as a current one(this._value)
16
15
  // built in animations that are not higher order(withTiming, withSpring) hold target value in .current
17
-
18
16
  if (sv._value === animation.current && !animation.isHigherOrder) {
19
17
  animation.callback && animation.callback(true);
20
18
  return;
21
- } // animated set
22
-
23
-
19
+ }
20
+ // animated set
24
21
  const initializeAnimation = timestamp => {
25
22
  animation.onStart(animation, sv.value, timestamp, previousAnimation);
26
23
  };
27
-
28
24
  const currentTimestamp = global.__frameTimestamp || performance.now();
29
25
  initializeAnimation(currentTimestamp);
30
-
31
26
  const step = timestamp => {
32
27
  if (animation.cancelled) {
33
- animation.callback && animation.callback(false
34
- /* finished */
35
- );
28
+ animation.callback && animation.callback(false /* finished */);
36
29
  return;
37
30
  }
38
-
39
31
  const finished = animation.onFrame(animation, timestamp);
40
32
  animation.finished = true;
41
33
  animation.timestamp = timestamp;
42
34
  sv._value = animation.current;
43
-
44
35
  if (finished) {
45
- animation.callback && animation.callback(true
46
- /* finished */
47
- );
36
+ animation.callback && animation.callback(true /* finished */);
48
37
  } else {
49
38
  requestAnimationFrame(step);
50
39
  }
51
40
  };
52
-
53
41
  sv._animation = animation;
54
42
  step(currentTimestamp);
55
43
  } else {
@@ -58,7 +46,6 @@ export function valueSetter(sv, value) {
58
46
  if (sv._value === value) {
59
47
  return;
60
48
  }
61
-
62
49
  sv._value = value;
63
50
  }
64
51
  }