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
package/plugin/index.js CHANGED
@@ -1,807 +1 @@
1
- 'use strict';
2
- const generate = require('@babel/generator').default;
3
- const hash = require('string-hash-64');
4
- const traverse = require('@babel/traverse').default;
5
- const { transformSync } = require('@babel/core');
6
- const fs = require('fs');
7
- const convertSourceMap = require('convert-source-map');
8
- /**
9
- * holds a map of function names as keys and array of argument indexes as values which should be automatically workletized(they have to be functions)(starting from 0)
10
- */
11
- const functionArgsToWorkletize = new Map([
12
- ['useFrameCallback', [0]],
13
- ['useAnimatedStyle', [0]],
14
- ['useAnimatedProps', [0]],
15
- ['createAnimatedPropAdapter', [0]],
16
- ['useDerivedValue', [0]],
17
- ['useAnimatedScrollHandler', [0]],
18
- ['useAnimatedReaction', [0, 1]],
19
- ['useWorkletCallback', [0]],
20
- // animations' callbacks
21
- ['withTiming', [2]],
22
- ['withSpring', [2]],
23
- ['withDecay', [1]],
24
- ['withRepeat', [3]],
25
- ]);
26
-
27
- const objectHooks = new Set([
28
- 'useAnimatedGestureHandler',
29
- 'useAnimatedScrollHandler',
30
- ]);
31
-
32
- const globals = new Set([
33
- 'this',
34
- 'console',
35
- 'performance',
36
- 'Date',
37
- 'Array',
38
- 'ArrayBuffer',
39
- 'Int8Array',
40
- 'Int16Array',
41
- 'Int32Array',
42
- 'Uint8Array',
43
- 'Uint8ClampedArray',
44
- 'Uint16Array',
45
- 'Uint32Array',
46
- 'Float32Array',
47
- 'Float64Array',
48
- 'Date',
49
- 'HermesInternal',
50
- 'JSON',
51
- 'Math',
52
- 'Number',
53
- 'Object',
54
- 'String',
55
- 'Symbol',
56
- 'undefined',
57
- 'null',
58
- 'UIManager',
59
- 'requestAnimationFrame',
60
- 'setImmediate',
61
- '_WORKLET',
62
- 'arguments',
63
- 'Boolean',
64
- 'parseInt',
65
- 'parseFloat',
66
- 'Map',
67
- 'WeakMap',
68
- 'WeakRef',
69
- 'Set',
70
- '_log',
71
- '_scheduleOnJS',
72
- '_makeShareableClone',
73
- '_updateDataSynchronously',
74
- 'eval',
75
- '_updatePropsPaper',
76
- '_updatePropsFabric',
77
- '_removeShadowNodeFromRegistry',
78
- 'RegExp',
79
- 'Error',
80
- 'ErrorUtils',
81
- 'global',
82
- '_measure',
83
- '_scrollTo',
84
- '_dispatchCommand',
85
- '_setGestureState',
86
- '_getCurrentTime',
87
- 'isNaN',
88
- 'LayoutAnimationRepository',
89
- '_notifyAboutProgress',
90
- '_notifyAboutEnd',
91
- ]);
92
-
93
- const gestureHandlerGestureObjects = new Set([
94
- // from https://github.com/software-mansion/react-native-gesture-handler/blob/new-api/src/handlers/gestures/gestureObjects.ts
95
- 'Tap',
96
- 'Pan',
97
- 'Pinch',
98
- 'Rotation',
99
- 'Fling',
100
- 'LongPress',
101
- 'ForceTouch',
102
- 'Native',
103
- 'Manual',
104
- 'Race',
105
- 'Simultaneous',
106
- 'Exclusive',
107
- ]);
108
-
109
- const gestureHandlerBuilderMethods = new Set([
110
- 'onBegin',
111
- 'onStart',
112
- 'onEnd',
113
- 'onFinalize',
114
- 'onUpdate',
115
- 'onChange',
116
- 'onTouchesDown',
117
- 'onTouchesMove',
118
- 'onTouchesUp',
119
- 'onTouchesCancelled',
120
- ]);
121
-
122
- function isRelease() {
123
- return ['production', 'release'].includes(process.env.BABEL_ENV);
124
- }
125
-
126
- function shouldGenerateSourceMap() {
127
- if (isRelease()) {
128
- return false;
129
- }
130
-
131
- if (process.env.REANIMATED_PLUGIN_TESTS === 'jest') {
132
- // We want to detect this, so we can disable source maps (because they break
133
- // snapshot tests with jest).
134
- return false;
135
- }
136
-
137
- return true;
138
- }
139
-
140
- function buildWorkletString(t, fun, closureVariables, name, inputMap) {
141
- function prependClosureVariablesIfNecessary() {
142
- const closureDeclaration = t.variableDeclaration('const', [
143
- t.variableDeclarator(
144
- t.objectPattern(
145
- closureVariables.map((variable) =>
146
- t.objectProperty(
147
- t.identifier(variable.name),
148
- t.identifier(variable.name),
149
- false,
150
- true
151
- )
152
- )
153
- ),
154
- t.memberExpression(t.thisExpression(), t.identifier('_closure'))
155
- ),
156
- ]);
157
-
158
- function prependClosure(path) {
159
- if (closureVariables.length === 0 || path.parent.type !== 'Program') {
160
- return;
161
- }
162
-
163
- path.node.body.body.unshift(closureDeclaration);
164
- }
165
-
166
- function prepandRecursiveDeclaration(path) {
167
- if (path.parent.type === 'Program' && path.node.id && path.scope.parent) {
168
- const hasRecursiveCalls =
169
- path.scope.parent.bindings[path.node.id.name]?.references > 0;
170
- if (hasRecursiveCalls) {
171
- path.node.body.body.unshift(
172
- t.variableDeclaration('const', [
173
- t.variableDeclarator(
174
- t.identifier(path.node.id.name),
175
- t.memberExpression(t.thisExpression(), t.identifier('_recur'))
176
- ),
177
- ])
178
- );
179
- }
180
- }
181
- }
182
-
183
- return {
184
- visitor: {
185
- 'FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ObjectMethod':
186
- (path) => {
187
- prependClosure(path);
188
- prepandRecursiveDeclaration(path);
189
- },
190
- },
191
- };
192
- }
193
-
194
- const expression =
195
- fun.program.body.find(({ type }) => type === 'FunctionDeclaration') ||
196
- fun.program.body.find(({ type }) => type === 'ExpressionStatement')
197
- .expression;
198
-
199
- const workletFunction = t.functionExpression(
200
- t.identifier(name),
201
- expression.params,
202
- expression.body
203
- );
204
-
205
- const code = generate(workletFunction).code;
206
-
207
- const includeSourceMap = shouldGenerateSourceMap();
208
-
209
- if (includeSourceMap) {
210
- // Clear contents array (should be empty anyways)
211
- inputMap.sourcesContent = [];
212
- // Include source contents in source map, because Flipper/iframe is not
213
- // allowed to read files from disk.
214
- for (const sourceFile of inputMap.sources) {
215
- inputMap.sourcesContent.push(
216
- fs.readFileSync(sourceFile).toString('utf-8')
217
- );
218
- }
219
- }
220
-
221
- const transformed = transformSync(code, {
222
- plugins: [prependClosureVariablesIfNecessary()],
223
- compact: !includeSourceMap,
224
- sourceMaps: includeSourceMap,
225
- inputSourceMap: inputMap,
226
- ast: false,
227
- babelrc: false,
228
- configFile: false,
229
- comments: false,
230
- });
231
-
232
- let sourceMap;
233
- if (includeSourceMap) {
234
- sourceMap = convertSourceMap.fromObject(transformed.map).toObject();
235
- // sourcesContent field contains a full source code of the file which contains the worklet
236
- // and is not needed by the source map interpreter in order to symbolicate a stack trace.
237
- // Therefore, we remove it to reduce the bandwith and avoid sending it potentially multiple times
238
- // in files that contain multiple worklets. Along with sourcesContent.
239
- delete sourceMap.sourcesContent;
240
- }
241
-
242
- return [transformed.code, JSON.stringify(sourceMap)];
243
- }
244
-
245
- function makeWorkletName(t, fun) {
246
- if (t.isObjectMethod(fun)) {
247
- return fun.node.key.name;
248
- }
249
- if (t.isFunctionDeclaration(fun)) {
250
- return fun.node.id.name;
251
- }
252
- if (t.isFunctionExpression(fun) && t.isIdentifier(fun.node.id)) {
253
- return fun.node.id.name;
254
- }
255
- return 'anonymous'; // fallback for ArrowFunctionExpression and unnamed FunctionExpression
256
- }
257
-
258
- function makeWorklet(t, fun, state) {
259
- // Returns a new FunctionExpression which is a workletized version of provided
260
- // FunctionDeclaration, FunctionExpression, ArrowFunctionExpression or ObjectMethod.
261
-
262
- const functionName = makeWorkletName(t, fun);
263
-
264
- const closure = new Map();
265
-
266
- // remove 'worklet'; directive before generating string
267
- fun.traverse({
268
- DirectiveLiteral(path) {
269
- if (path.node.value === 'worklet' && path.getFunctionParent() === fun) {
270
- path.parentPath.remove();
271
- }
272
- },
273
- });
274
-
275
- // We use copy because some of the plugins don't update bindings and
276
- // some even break them
277
-
278
- const codeObject = generate(fun.node, {
279
- sourceMaps: true,
280
- sourceFileName: state.file.opts.filename,
281
- });
282
-
283
- // We need to add a newline at the end, because there could potentially be a
284
- // comment after the function that gets included here, and then the closing
285
- // bracket would become part of the comment thus resulting in an error, since
286
- // there is a missing closing bracket.
287
- const code =
288
- '(' + (t.isObjectMethod(fun) ? 'function ' : '') + codeObject.code + '\n)';
289
-
290
- const transformed = transformSync(code, {
291
- filename: state.file.opts.filename,
292
- presets: ['@babel/preset-typescript'],
293
- plugins: [
294
- '@babel/plugin-transform-shorthand-properties',
295
- '@babel/plugin-transform-arrow-functions',
296
- '@babel/plugin-proposal-optional-chaining',
297
- '@babel/plugin-proposal-nullish-coalescing-operator',
298
- ['@babel/plugin-transform-template-literals', { loose: true }],
299
- ],
300
- ast: true,
301
- babelrc: false,
302
- configFile: false,
303
- inputSourceMap: codeObject.map,
304
- });
305
-
306
- traverse(transformed.ast, {
307
- ReferencedIdentifier(path) {
308
- const name = path.node.name;
309
- if (globals.has(name) || (fun.node.id && fun.node.id.name === name)) {
310
- return;
311
- }
312
-
313
- const parentNode = path.parent;
314
-
315
- if (
316
- parentNode.type === 'MemberExpression' &&
317
- parentNode.property === path.node &&
318
- !parentNode.computed
319
- ) {
320
- return;
321
- }
322
-
323
- if (
324
- parentNode.type === 'ObjectProperty' &&
325
- path.parentPath.parent.type === 'ObjectExpression' &&
326
- path.node !== parentNode.value
327
- ) {
328
- return;
329
- }
330
-
331
- let currentScope = path.scope;
332
-
333
- while (currentScope != null) {
334
- if (currentScope.bindings[name] != null) {
335
- return;
336
- }
337
- currentScope = currentScope.parent;
338
- }
339
- closure.set(name, path.node);
340
- },
341
- });
342
-
343
- const variables = Array.from(closure.values());
344
-
345
- const privateFunctionId = t.identifier('_f');
346
- const clone = t.cloneNode(fun.node);
347
- let funExpression;
348
- if (clone.body.type === 'BlockStatement') {
349
- funExpression = t.functionExpression(null, clone.params, clone.body);
350
- } else {
351
- funExpression = clone;
352
- }
353
-
354
- const [funString, sourceMapString] = buildWorkletString(
355
- t,
356
- transformed.ast,
357
- variables,
358
- functionName,
359
- transformed.map
360
- );
361
- const workletHash = hash(funString);
362
-
363
- let location = state.file.opts.filename;
364
- if (state.opts && state.opts.relativeSourceLocation) {
365
- const path = require('path');
366
- location = path.relative(state.cwd, location);
367
- }
368
-
369
- let lineOffset = 1;
370
- if (closure.size > 0) {
371
- // When worklet captures some variables, we append closure destructing at
372
- // the beginning of the function body. This effectively results in line
373
- // numbers shifting by the number of captured variables (size of the
374
- // closure) + 2 (for the opening and closing brackets of the destruct
375
- // statement)
376
- lineOffset -= closure.size + 2;
377
- }
378
-
379
- const pathForStringDefinitions = fun.parentPath.isProgram()
380
- ? fun
381
- : fun.findParent((path) => path.parentPath.isProgram());
382
-
383
- const initDataId =
384
- pathForStringDefinitions.parentPath.scope.generateUidIdentifier(
385
- `worklet_${workletHash}_init_data`
386
- );
387
-
388
- const initDataObjectExpression = t.objectExpression([
389
- t.objectProperty(t.identifier('code'), t.stringLiteral(funString)),
390
- t.objectProperty(t.identifier('location'), t.stringLiteral(location)),
391
- ]);
392
-
393
- if (sourceMapString) {
394
- initDataObjectExpression.properties.push(
395
- t.objectProperty(
396
- t.identifier('sourceMap'),
397
- t.stringLiteral(sourceMapString)
398
- )
399
- );
400
- }
401
-
402
- pathForStringDefinitions.insertBefore(
403
- t.variableDeclaration('const', [
404
- t.variableDeclarator(initDataId, initDataObjectExpression),
405
- ])
406
- );
407
-
408
- const statements = [
409
- t.variableDeclaration('const', [
410
- t.variableDeclarator(privateFunctionId, funExpression),
411
- ]),
412
- t.expressionStatement(
413
- t.assignmentExpression(
414
- '=',
415
- t.memberExpression(privateFunctionId, t.identifier('_closure'), false),
416
- t.objectExpression(
417
- variables.map((variable) =>
418
- t.objectProperty(t.identifier(variable.name), variable, false, true)
419
- )
420
- )
421
- )
422
- ),
423
- t.expressionStatement(
424
- t.assignmentExpression(
425
- '=',
426
- t.memberExpression(
427
- privateFunctionId,
428
- t.identifier('__initData'),
429
- false
430
- ),
431
- initDataId
432
- )
433
- ),
434
- t.expressionStatement(
435
- t.assignmentExpression(
436
- '=',
437
- t.memberExpression(
438
- privateFunctionId,
439
- t.identifier('__workletHash'),
440
- false
441
- ),
442
- t.numericLiteral(workletHash)
443
- )
444
- ),
445
- ];
446
-
447
- if (!isRelease()) {
448
- statements.unshift(
449
- t.variableDeclaration('const', [
450
- t.variableDeclarator(
451
- t.identifier('_e'),
452
- t.arrayExpression([
453
- t.newExpression(t.identifier('Error'), []),
454
- t.numericLiteral(lineOffset),
455
- t.numericLiteral(-20), // the placement of opening bracket after Exception in line that defined '_e' variable
456
- ])
457
- ),
458
- ])
459
- );
460
- statements.push(
461
- t.expressionStatement(
462
- t.assignmentExpression(
463
- '=',
464
- t.memberExpression(
465
- privateFunctionId,
466
- t.identifier('__stackDetails'),
467
- false
468
- ),
469
- t.identifier('_e')
470
- )
471
- )
472
- );
473
- }
474
-
475
- statements.push(t.returnStatement(privateFunctionId));
476
-
477
- const newFun = t.functionExpression(fun.id, [], t.blockStatement(statements));
478
-
479
- return newFun;
480
- }
481
-
482
- function processWorkletFunction(t, fun, state) {
483
- // Replaces FunctionDeclaration, FunctionExpression or ArrowFunctionExpression
484
- // with a workletized version of itself.
485
-
486
- if (!t.isFunctionParent(fun)) {
487
- return;
488
- }
489
-
490
- const newFun = makeWorklet(t, fun, state);
491
-
492
- const replacement = t.callExpression(newFun, []);
493
-
494
- // we check if function needs to be assigned to variable declaration.
495
- // This is needed if function definition directly in a scope. Some other ways
496
- // where function definition can be used is for example with variable declaration:
497
- // const ggg = function foo() { }
498
- // ^ in such a case we don't need to define variable for the function
499
- const needDeclaration =
500
- t.isScopable(fun.parent) || t.isExportNamedDeclaration(fun.parent);
501
- fun.replaceWith(
502
- fun.node.id && needDeclaration
503
- ? t.variableDeclaration('const', [
504
- t.variableDeclarator(fun.node.id, replacement),
505
- ])
506
- : replacement
507
- );
508
- }
509
-
510
- function processWorkletObjectMethod(t, path, state) {
511
- // Replaces ObjectMethod with a workletized version of itself.
512
-
513
- if (!t.isFunctionParent(path)) {
514
- return;
515
- }
516
-
517
- const newFun = makeWorklet(t, path, state);
518
-
519
- const replacement = t.objectProperty(
520
- t.identifier(path.node.key.name),
521
- t.callExpression(newFun, [])
522
- );
523
-
524
- path.replaceWith(replacement);
525
- }
526
-
527
- function processIfWorkletNode(t, fun, state) {
528
- fun.traverse({
529
- DirectiveLiteral(path) {
530
- const value = path.node.value;
531
- if (value === 'worklet' && path.getFunctionParent() === fun) {
532
- // make sure "worklet" is listed among directives for the fun
533
- // this is necessary as because of some bug, babel will attempt to
534
- // process replaced function if it is nested inside another function
535
- const directives = fun.node.body.directives;
536
- if (
537
- directives &&
538
- directives.length > 0 &&
539
- directives.some(
540
- (directive) =>
541
- t.isDirectiveLiteral(directive.value) &&
542
- directive.value.value === 'worklet'
543
- )
544
- ) {
545
- processWorkletFunction(t, fun, state);
546
- }
547
- }
548
- },
549
- });
550
- }
551
-
552
- function processIfGestureHandlerEventCallbackFunctionNode(t, fun, state) {
553
- // Auto-workletizes React Native Gesture Handler callback functions.
554
- // Detects `Gesture.Tap().onEnd(<fun>)` or similar, but skips `something.onEnd(<fun>)`.
555
- // Supports method chaining as well, e.g. `Gesture.Tap().onStart(<fun1>).onUpdate(<fun2>).onEnd(<fun3>)`.
556
-
557
- // Example #1: `Gesture.Tap().onEnd(<fun>)`
558
- /*
559
- CallExpression(
560
- callee: MemberExpression(
561
- object: CallExpression(
562
- callee: MemberExpression(
563
- object: Identifier('Gesture')
564
- property: Identifier('Tap')
565
- )
566
- )
567
- property: Identifier('onEnd')
568
- )
569
- arguments: [fun]
570
- )
571
- */
572
-
573
- // Example #2: `Gesture.Tap().onStart(<fun1>).onUpdate(<fun2>).onEnd(<fun3>)`
574
- /*
575
- CallExpression(
576
- callee: MemberExpression(
577
- object: CallExpression(
578
- callee: MemberExpression(
579
- object: CallExpression(
580
- callee: MemberExpression(
581
- object: CallExpression(
582
- callee: MemberExpression(
583
- object: Identifier('Gesture')
584
- property: Identifier('Tap')
585
- )
586
- )
587
- property: Identifier('onStart')
588
- )
589
- arguments: [fun1]
590
- )
591
- property: Identifier('onUpdate')
592
- )
593
- arguments: [fun2]
594
- )
595
- property: Identifier('onEnd')
596
- )
597
- arguments: [fun3]
598
- )
599
- */
600
-
601
- if (
602
- t.isCallExpression(fun.parent) &&
603
- isGestureObjectEventCallbackMethod(t, fun.parent.callee)
604
- ) {
605
- processWorkletFunction(t, fun, state);
606
- }
607
- }
608
-
609
- function isGestureObjectEventCallbackMethod(t, node) {
610
- // Checks if node matches the pattern `Gesture.Foo()[*].onBar`
611
- // where `[*]` represents any number of method calls.
612
- return (
613
- t.isMemberExpression(node) &&
614
- t.isIdentifier(node.property) &&
615
- gestureHandlerBuilderMethods.has(node.property.name) &&
616
- containsGestureObject(t, node.object)
617
- );
618
- }
619
-
620
- function containsGestureObject(t, node) {
621
- // Checks if node matches the pattern `Gesture.Foo()[*]`
622
- // where `[*]` represents any number of chained method calls, like `.something(42)`.
623
-
624
- // direct call
625
- if (isGestureObject(t, node)) {
626
- return true;
627
- }
628
-
629
- // method chaining
630
- if (
631
- t.isCallExpression(node) &&
632
- t.isMemberExpression(node.callee) &&
633
- containsGestureObject(t, node.callee.object)
634
- ) {
635
- return true;
636
- }
637
-
638
- return false;
639
- }
640
-
641
- function isGestureObject(t, node) {
642
- // Checks if node matches `Gesture.Tap()` or similar.
643
- /*
644
- node: CallExpression(
645
- callee: MemberExpression(
646
- object: Identifier('Gesture')
647
- property: Identifier('Tap')
648
- )
649
- )
650
- */
651
- return (
652
- t.isCallExpression(node) &&
653
- t.isMemberExpression(node.callee) &&
654
- t.isIdentifier(node.callee.object) &&
655
- node.callee.object.name === 'Gesture' &&
656
- t.isIdentifier(node.callee.property) &&
657
- gestureHandlerGestureObjects.has(node.callee.property.name)
658
- );
659
- }
660
-
661
- function processWorklets(t, path, state) {
662
- const callee =
663
- path.node.callee.type === 'SequenceExpression'
664
- ? path.node.callee.expressions[path.node.callee.expressions.length - 1]
665
- : path.node.callee;
666
-
667
- const name =
668
- callee.type === 'MemberExpression' ? callee.property.name : callee.name;
669
-
670
- if (
671
- objectHooks.has(name) &&
672
- path.get('arguments.0').type === 'ObjectExpression'
673
- ) {
674
- const properties = path.get('arguments.0.properties');
675
- for (const property of properties) {
676
- if (t.isObjectMethod(property)) {
677
- processWorkletObjectMethod(t, property, state);
678
- } else {
679
- const value = property.get('value');
680
- processWorkletFunction(t, value, state);
681
- }
682
- }
683
- } else {
684
- const indexes = functionArgsToWorkletize.get(name);
685
- if (Array.isArray(indexes)) {
686
- indexes.forEach((index) => {
687
- processWorkletFunction(t, path.get(`arguments.${index}`), state);
688
- });
689
- }
690
- }
691
- }
692
-
693
- function generateInlineStylesWarning(t, memberExpression) {
694
- // replaces `sharedvalue.value` with `(()=>{console.warn(require('react-native-reanimated').getUseOfValueInStyleWarning());return sharedvalue.value;})()`
695
- return t.callExpression(
696
- t.arrowFunctionExpression(
697
- [],
698
- t.blockStatement([
699
- t.expressionStatement(
700
- t.callExpression(
701
- t.memberExpression(t.identifier('console'), t.identifier('warn')),
702
- [
703
- t.callExpression(
704
- t.memberExpression(
705
- t.callExpression(t.identifier('require'), [
706
- t.stringLiteral('react-native-reanimated'),
707
- ]),
708
- t.identifier('getUseOfValueInStyleWarning')
709
- ),
710
- []
711
- ),
712
- ]
713
- )
714
- ),
715
- t.returnStatement(memberExpression.node),
716
- ])
717
- ),
718
- []
719
- );
720
- }
721
-
722
- function processPropertyValueForInlineStylesWarning(t, path) {
723
- // if it's something like object.value then raise a warning
724
- if (t.isMemberExpression(path)) {
725
- if (path.get('property').node.name === 'value') {
726
- path.replaceWith(generateInlineStylesWarning(t, path));
727
- }
728
- }
729
- }
730
-
731
- function processTransformPropertyForInlineStylesWarning(t, path) {
732
- if (t.isArrayExpression(path)) {
733
- const elements = path.get('elements');
734
- for (const element of elements) {
735
- if (t.isObjectExpression(element)) {
736
- processStyleObjectForInlineStylesWarning(t, element);
737
- }
738
- }
739
- }
740
- }
741
-
742
- function processStyleObjectForInlineStylesWarning(t, path) {
743
- const properties = path.get('properties');
744
- for (const property of properties) {
745
- const value = property.get('value');
746
- if (t.isProperty(property)) {
747
- if (property.get('key').node.name === 'transform') {
748
- processTransformPropertyForInlineStylesWarning(t, value);
749
- } else {
750
- processPropertyValueForInlineStylesWarning(t, value);
751
- }
752
- }
753
- }
754
- }
755
-
756
- function processInlineStylesWarning(t, path, state) {
757
- if (isRelease()) return;
758
- if (state.opts.disableInlineStylesWarning) return;
759
- if (path.get('name').node.name !== 'style') return;
760
- if (!t.isJSXExpressionContainer(path.get('value'))) return;
761
-
762
- const expression = path.get('value').get('expression');
763
- // style={[{...}, {...}]}
764
- if (t.isArrayExpression(expression)) {
765
- const elements = expression.get('elements');
766
- for (const element of elements) {
767
- if (t.isObjectExpression(element)) {
768
- processStyleObjectForInlineStylesWarning(t, element);
769
- }
770
- }
771
- }
772
- // style={{...}}
773
- else if (t.isObjectExpression(expression)) {
774
- processStyleObjectForInlineStylesWarning(t, expression);
775
- }
776
- }
777
-
778
- module.exports = function ({ types: t }) {
779
- return {
780
- pre() {
781
- // allows adding custom globals such as host-functions
782
- if (this.opts != null && Array.isArray(this.opts.globals)) {
783
- this.opts.globals.forEach((name) => {
784
- globals.add(name);
785
- });
786
- }
787
- },
788
- visitor: {
789
- CallExpression: {
790
- enter(path, state) {
791
- processWorklets(t, path, state);
792
- },
793
- },
794
- 'FunctionDeclaration|FunctionExpression|ArrowFunctionExpression': {
795
- enter(path, state) {
796
- processIfWorkletNode(t, path, state);
797
- processIfGestureHandlerEventCallbackFunctionNode(t, path, state);
798
- },
799
- },
800
- JSXAttribute: {
801
- enter(path, state) {
802
- processInlineStylesWarning(t, path, state);
803
- },
804
- },
805
- },
806
- };
807
- };
1
+ module.exports = require('./build/plugin.js');