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
@@ -0,0 +1,23 @@
1
+ {
2
+ "devDependencies": {
3
+ "@react-native/eslint-config": "^0.72.1",
4
+ "@types/node": "^18.15.11",
5
+ "esbuild": "^0.17.11",
6
+ "eslint": "^8.35.0",
7
+ "prettier": "^2.5.1",
8
+ "tsc-watch": "^6.0.0",
9
+ "typescript": "^4.1.3"
10
+ },
11
+ "license": "MIT",
12
+ "readmeFilename": "README.md",
13
+ "scripts": {
14
+ "prepare": "yarn generate",
15
+ "generate": "yarn tsc && yarn bundle && yarn clean",
16
+ "clean": "rm -f lib/*",
17
+ "bundle": "esbuild ./lib/plugin.js --bundle --external:@babel --external:convert-source-map --external:fs --external:'../../package.json' --log-level=warning --platform=node --sourcemap=linked --outfile=build/plugin.js",
18
+ "format": "prettier --write --list-different **/*.ts",
19
+ "watch": "tsc-watch --onSuccess \"yarn bundle\"",
20
+ "lint": "eslint --max-warnings=0 --ext .ts .",
21
+ "type:check": "tsc --noEmit"
22
+ }
23
+ }
@@ -0,0 +1,213 @@
1
+ import {
2
+ BabelFileResult,
3
+ NodePath,
4
+ transformSync,
5
+ PluginItem,
6
+ } from '@babel/core';
7
+ import generate from '@babel/generator';
8
+ import {
9
+ ObjectMethod,
10
+ isObjectMethod,
11
+ FunctionDeclaration,
12
+ FunctionExpression,
13
+ ArrowFunctionExpression,
14
+ identifier,
15
+ Identifier,
16
+ objectProperty,
17
+ isArrowFunctionExpression,
18
+ variableDeclaration,
19
+ variableDeclarator,
20
+ isBlockStatement,
21
+ functionExpression,
22
+ isFunctionDeclaration,
23
+ VariableDeclaration,
24
+ ExpressionStatement,
25
+ isProgram,
26
+ memberExpression,
27
+ File as BabelFile,
28
+ objectPattern,
29
+ thisExpression,
30
+ isExpression,
31
+ isExpressionStatement,
32
+ } from '@babel/types';
33
+ import * as fs from 'fs';
34
+ import * as convertSourceMap from 'convert-source-map';
35
+ import { strict as assert } from 'assert';
36
+ import { isRelease } from './utils';
37
+
38
+ export function buildWorkletString(
39
+ fun: BabelFile,
40
+ closureVariables: Array<Identifier>,
41
+ name: string,
42
+ inputMap: BabelFileResult['map']
43
+ ): Array<string | null | undefined> {
44
+ const draftExpression = (fun.program.body.find((obj) =>
45
+ isFunctionDeclaration(obj)
46
+ ) ||
47
+ fun.program.body.find((obj) => isExpressionStatement(obj)) ||
48
+ undefined) as FunctionDeclaration | ExpressionStatement | undefined;
49
+
50
+ assert(draftExpression, "'draftExpression' is undefined");
51
+
52
+ const expression = isFunctionDeclaration(draftExpression)
53
+ ? draftExpression
54
+ : draftExpression.expression;
55
+
56
+ assert(
57
+ 'params' in expression,
58
+ "'params' property is undefined in 'expression'"
59
+ );
60
+ assert(
61
+ isBlockStatement(expression.body),
62
+ "'expression.body' is not a 'BlockStatement'"
63
+ );
64
+
65
+ const workletFunction = functionExpression(
66
+ identifier(name),
67
+ expression.params,
68
+ expression.body
69
+ );
70
+
71
+ const code = generate(workletFunction).code;
72
+
73
+ assert(inputMap, "'inputMap' is undefined");
74
+
75
+ const includeSourceMap = shouldGenerateSourceMap();
76
+
77
+ if (includeSourceMap) {
78
+ // Clear contents array (should be empty anyways)
79
+ inputMap.sourcesContent = [];
80
+ // Include source contents in source map, because Flipper/iframe is not
81
+ // allowed to read files from disk.
82
+ for (const sourceFile of inputMap.sources) {
83
+ inputMap.sourcesContent.push(
84
+ fs.readFileSync(sourceFile).toString('utf-8')
85
+ );
86
+ }
87
+ }
88
+
89
+ const transformed = transformSync(code, {
90
+ plugins: [prependClosureVariablesIfNecessary(closureVariables)],
91
+ compact: !includeSourceMap,
92
+ sourceMaps: includeSourceMap,
93
+ inputSourceMap: inputMap,
94
+ ast: false,
95
+ babelrc: false,
96
+ configFile: false,
97
+ comments: false,
98
+ });
99
+
100
+ assert(transformed, "'transformed' is null");
101
+
102
+ let sourceMap;
103
+ if (includeSourceMap) {
104
+ sourceMap = convertSourceMap.fromObject(transformed.map).toObject();
105
+ // sourcesContent field contains a full source code of the file which contains the worklet
106
+ // and is not needed by the source map interpreter in order to symbolicate a stack trace.
107
+ // Therefore, we remove it to reduce the bandwith and avoid sending it potentially multiple times
108
+ // in files that contain multiple worklets. Along with sourcesContent.
109
+ delete sourceMap.sourcesContent;
110
+ }
111
+
112
+ return [transformed.code, JSON.stringify(sourceMap)];
113
+ }
114
+
115
+ function shouldGenerateSourceMap() {
116
+ if (isRelease()) {
117
+ return false;
118
+ }
119
+
120
+ // We want to detect this, so we can disable source maps (because they break
121
+ // snapshot tests with jest).
122
+ if (process.env.REANIMATED_JEST_DISABLE_SOURCEMAP === 'jest') {
123
+ return false;
124
+ }
125
+
126
+ return true;
127
+ }
128
+
129
+ function prependClosure(
130
+ path: NodePath<
131
+ | FunctionDeclaration
132
+ | FunctionExpression
133
+ | ArrowFunctionExpression
134
+ | ObjectMethod
135
+ >,
136
+ closureVariables: Array<Identifier>,
137
+ closureDeclaration: VariableDeclaration
138
+ ) {
139
+ if (closureVariables.length === 0 || !isProgram(path.parent)) {
140
+ return;
141
+ }
142
+
143
+ if (!isExpression(path.node.body)) {
144
+ path.node.body.body.unshift(closureDeclaration);
145
+ }
146
+ }
147
+
148
+ function prependRecursiveDeclaration(
149
+ path: NodePath<
150
+ | FunctionDeclaration
151
+ | FunctionExpression
152
+ | ArrowFunctionExpression
153
+ | ObjectMethod
154
+ >
155
+ ) {
156
+ if (
157
+ isProgram(path.parent) &&
158
+ !isArrowFunctionExpression(path.node) &&
159
+ !isObjectMethod(path.node) &&
160
+ path.node.id &&
161
+ path.scope.parent
162
+ ) {
163
+ const hasRecursiveCalls =
164
+ path.scope.parent.bindings[path.node.id.name]?.references > 0;
165
+ if (hasRecursiveCalls) {
166
+ path.node.body.body.unshift(
167
+ variableDeclaration('const', [
168
+ variableDeclarator(
169
+ identifier(path.node.id.name),
170
+ memberExpression(thisExpression(), identifier('_recur'))
171
+ ),
172
+ ])
173
+ );
174
+ }
175
+ }
176
+ }
177
+
178
+ function prependClosureVariablesIfNecessary(
179
+ closureVariables: Array<Identifier>
180
+ ): PluginItem {
181
+ const closureDeclaration = variableDeclaration('const', [
182
+ variableDeclarator(
183
+ objectPattern(
184
+ closureVariables.map((variable) =>
185
+ objectProperty(
186
+ identifier(variable.name),
187
+ identifier(variable.name),
188
+ false,
189
+ true
190
+ )
191
+ )
192
+ ),
193
+ memberExpression(thisExpression(), identifier('_closure'))
194
+ ),
195
+ ]);
196
+
197
+ return {
198
+ visitor: {
199
+ 'FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ObjectMethod':
200
+ (
201
+ path: NodePath<
202
+ | FunctionDeclaration
203
+ | FunctionExpression
204
+ | ArrowFunctionExpression
205
+ | ObjectMethod
206
+ >
207
+ ) => {
208
+ prependClosure(path, closureVariables, closureDeclaration);
209
+ prependRecursiveDeclaration(path);
210
+ },
211
+ },
212
+ };
213
+ }
@@ -0,0 +1,60 @@
1
+ export const globals = new Set([
2
+ 'this',
3
+ 'console',
4
+ 'performance',
5
+ 'Date',
6
+ 'Array',
7
+ 'ArrayBuffer',
8
+ 'Int8Array',
9
+ 'Int16Array',
10
+ 'Int32Array',
11
+ 'Uint8Array',
12
+ 'Uint8ClampedArray',
13
+ 'Uint16Array',
14
+ 'Uint32Array',
15
+ 'Float32Array',
16
+ 'Float64Array',
17
+ 'HermesInternal',
18
+ 'JSON',
19
+ 'Math',
20
+ 'Number',
21
+ 'Object',
22
+ 'String',
23
+ 'Symbol',
24
+ 'undefined',
25
+ 'null',
26
+ 'UIManager',
27
+ 'requestAnimationFrame',
28
+ 'setImmediate',
29
+ 'queueMicrotask',
30
+ '_WORKLET',
31
+ 'arguments',
32
+ 'Boolean',
33
+ 'parseInt',
34
+ 'parseFloat',
35
+ 'Map',
36
+ 'WeakMap',
37
+ 'Proxy',
38
+ 'WeakRef',
39
+ 'Set',
40
+ '_log',
41
+ '_scheduleOnJS',
42
+ '_makeShareableClone',
43
+ '_updateDataSynchronously',
44
+ 'eval',
45
+ '_updatePropsPaper',
46
+ '_updatePropsFabric',
47
+ '_removeShadowNodeFromRegistry',
48
+ 'RegExp',
49
+ 'Error',
50
+ '__ErrorUtils',
51
+ 'global',
52
+ '_measure',
53
+ '_scrollTo',
54
+ '_dispatchCommand',
55
+ '_setGestureState',
56
+ 'isNaN',
57
+ 'LayoutAnimationRepository',
58
+ '_notifyAboutProgress',
59
+ '_notifyAboutEnd',
60
+ ]);
@@ -0,0 +1,37 @@
1
+ import { NodePath } from '@babel/core';
2
+ import {
3
+ DirectiveLiteral,
4
+ expressionStatement,
5
+ assignmentExpression,
6
+ memberExpression,
7
+ identifier,
8
+ stringLiteral,
9
+ FunctionDeclaration,
10
+ } from '@babel/types';
11
+
12
+ export function injectVersion(path: NodePath<DirectiveLiteral>) {
13
+ // We want to inject plugin's version only once,
14
+ // hence we have a Directive Literal line in Reanimated code.
15
+ // See src/reanimated2/platform-specific/checkPluginVersion.ts
16
+ // to see the details of this implementation.
17
+ if (path.node.value !== 'inject Reanimated Babel plugin version') {
18
+ return;
19
+ }
20
+ const injectedName = '_REANIMATED_VERSION_BABEL_PLUGIN';
21
+ const versionString = require('../../package.json').version;
22
+ const pluginVersionNode = expressionStatement(
23
+ assignmentExpression(
24
+ '=',
25
+ memberExpression(identifier('global'), identifier(injectedName)),
26
+ stringLiteral(versionString)
27
+ )
28
+ );
29
+
30
+ // Function that contains injection directive literal is a FunctionDeclaration.
31
+ const functionParent = (
32
+ path.getFunctionParent() as NodePath<FunctionDeclaration>
33
+ ).node;
34
+ // DirectiveLiteral is in property of its function parent 'directives' hence we cannot just replace it.
35
+ functionParent.body.directives = [];
36
+ functionParent.body.body.unshift(pluginVersionNode);
37
+ }
@@ -0,0 +1,375 @@
1
+ import { NodePath, transformSync, traverse } from '@babel/core';
2
+ import generate from '@babel/generator';
3
+ import {
4
+ ObjectMethod,
5
+ isObjectMethod,
6
+ FunctionDeclaration,
7
+ FunctionExpression,
8
+ ArrowFunctionExpression,
9
+ identifier,
10
+ Identifier,
11
+ objectProperty,
12
+ variableDeclaration,
13
+ variableDeclarator,
14
+ cloneNode,
15
+ isBlockStatement,
16
+ functionExpression,
17
+ objectExpression,
18
+ stringLiteral,
19
+ isFunctionDeclaration,
20
+ VariableDeclaration,
21
+ ExpressionStatement,
22
+ ReturnStatement,
23
+ isProgram,
24
+ isObjectProperty,
25
+ isMemberExpression,
26
+ isObjectExpression,
27
+ expressionStatement,
28
+ assignmentExpression,
29
+ memberExpression,
30
+ numericLiteral,
31
+ arrayExpression,
32
+ newExpression,
33
+ returnStatement,
34
+ blockStatement,
35
+ isFunctionExpression,
36
+ isIdentifier,
37
+ File as BabelFile,
38
+ } from '@babel/types';
39
+ import { ReanimatedPluginPass } from './types';
40
+ import { isRelease } from './utils';
41
+ import { strict as assert } from 'assert';
42
+ import { globals } from './commonObjects';
43
+ import { relative } from 'path';
44
+ import { buildWorkletString } from './buildWorkletString';
45
+
46
+ const version = require('../../package.json').version;
47
+
48
+ export function makeWorklet(
49
+ fun: NodePath<
50
+ | FunctionDeclaration
51
+ | FunctionExpression
52
+ | ObjectMethod
53
+ | ArrowFunctionExpression
54
+ >,
55
+ state: ReanimatedPluginPass
56
+ ): FunctionExpression {
57
+ // Returns a new FunctionExpression which is a workletized version of provided
58
+ // FunctionDeclaration, FunctionExpression, ArrowFunctionExpression or ObjectMethod.
59
+
60
+ const functionName = makeWorkletName(fun);
61
+
62
+ // remove 'worklet'; directive before generating string
63
+ fun.traverse({
64
+ DirectiveLiteral(path) {
65
+ if (path.node.value === 'worklet' && path.getFunctionParent() === fun) {
66
+ path.parentPath.remove();
67
+ }
68
+ },
69
+ });
70
+
71
+ // We use copy because some of the plugins don't update bindings and
72
+ // some even break them
73
+ assert(state.file.opts.filename, "'state.file.opts.filename' is undefined");
74
+
75
+ const codeObject = generate(fun.node, {
76
+ sourceMaps: true,
77
+ sourceFileName: state.file.opts.filename,
78
+ });
79
+
80
+ // We need to add a newline at the end, because there could potentially be a
81
+ // comment after the function that gets included here, and then the closing
82
+ // bracket would become part of the comment thus resulting in an error, since
83
+ // there is a missing closing bracket.
84
+ codeObject.code =
85
+ '(' + (isObjectMethod(fun) ? 'function ' : '') + codeObject.code + '\n)';
86
+
87
+ const transformed = transformSync(codeObject.code, {
88
+ filename: state.file.opts.filename,
89
+ presets: ['@babel/preset-typescript'],
90
+ plugins: [
91
+ '@babel/plugin-transform-shorthand-properties',
92
+ '@babel/plugin-transform-arrow-functions',
93
+ '@babel/plugin-proposal-optional-chaining',
94
+ '@babel/plugin-proposal-nullish-coalescing-operator',
95
+ ['@babel/plugin-transform-template-literals', { loose: true }],
96
+ ],
97
+ ast: true,
98
+ babelrc: false,
99
+ configFile: false,
100
+ inputSourceMap: codeObject.map,
101
+ });
102
+
103
+ assert(transformed, "'transformed' is undefined");
104
+ assert(transformed.ast, "'transformed.ast' is undefined");
105
+
106
+ const variables = makeArrayFromCapturedBindings(transformed.ast, fun);
107
+
108
+ const privateFunctionId = identifier('_f');
109
+ const clone = cloneNode(fun.node);
110
+ const funExpression = isBlockStatement(clone.body)
111
+ ? functionExpression(null, clone.params, clone.body)
112
+ : clone;
113
+
114
+ const [funString, sourceMapString] = buildWorkletString(
115
+ transformed.ast,
116
+ variables,
117
+ functionName,
118
+ transformed.map
119
+ );
120
+ assert(funString, "'funString' is undefined");
121
+ const workletHash = hash(funString);
122
+
123
+ let location = state.file.opts.filename;
124
+ if (state.opts.relativeSourceLocation) {
125
+ location = relative(state.cwd, location);
126
+ }
127
+
128
+ let lineOffset = 1;
129
+ if (variables.length > 0) {
130
+ // When worklet captures some variables, we append closure destructing at
131
+ // the beginning of the function body. This effectively results in line
132
+ // numbers shifting by the number of captured variables (size of the
133
+ // closure) + 2 (for the opening and closing brackets of the destruct
134
+ // statement)
135
+ lineOffset -= variables.length + 2;
136
+ }
137
+
138
+ const pathForStringDefinitions = fun.parentPath.isProgram()
139
+ ? fun
140
+ : fun.findParent((path) => isProgram(path.parentPath));
141
+ assert(pathForStringDefinitions, "'pathForStringDefinitions' is null");
142
+ assert(
143
+ pathForStringDefinitions.parentPath,
144
+ "'pathForStringDefinitions.parentPath' is null"
145
+ );
146
+
147
+ const initDataId =
148
+ pathForStringDefinitions.parentPath.scope.generateUidIdentifier(
149
+ `worklet_${workletHash}_init_data`
150
+ );
151
+
152
+ const initDataObjectExpression = objectExpression([
153
+ objectProperty(identifier('code'), stringLiteral(funString)),
154
+ objectProperty(identifier('location'), stringLiteral(location)),
155
+ ]);
156
+
157
+ if (sourceMapString) {
158
+ initDataObjectExpression.properties.push(
159
+ objectProperty(identifier('sourceMap'), stringLiteral(sourceMapString))
160
+ );
161
+ }
162
+
163
+ pathForStringDefinitions.insertBefore(
164
+ variableDeclaration('const', [
165
+ variableDeclarator(initDataId, initDataObjectExpression),
166
+ ])
167
+ );
168
+
169
+ assert(
170
+ !isFunctionDeclaration(funExpression),
171
+ "'funExpression' is a 'FunctionDeclaration'"
172
+ );
173
+ assert(
174
+ !isObjectMethod(funExpression),
175
+ "'funExpression' is an 'ObjectMethod'"
176
+ );
177
+
178
+ const statements: Array<
179
+ VariableDeclaration | ExpressionStatement | ReturnStatement
180
+ > = [
181
+ variableDeclaration('const', [
182
+ variableDeclarator(privateFunctionId, funExpression),
183
+ ]),
184
+ expressionStatement(
185
+ assignmentExpression(
186
+ '=',
187
+ memberExpression(privateFunctionId, identifier('_closure'), false),
188
+ objectExpression(
189
+ variables.map((variable) =>
190
+ objectProperty(identifier(variable.name), variable, false, true)
191
+ )
192
+ )
193
+ )
194
+ ),
195
+ expressionStatement(
196
+ assignmentExpression(
197
+ '=',
198
+ memberExpression(privateFunctionId, identifier('__initData'), false),
199
+ initDataId
200
+ )
201
+ ),
202
+ expressionStatement(
203
+ assignmentExpression(
204
+ '=',
205
+ memberExpression(privateFunctionId, identifier('__workletHash'), false),
206
+ numericLiteral(workletHash)
207
+ )
208
+ ),
209
+ ];
210
+
211
+ if (!isRelease()) {
212
+ statements.unshift(
213
+ variableDeclaration('const', [
214
+ variableDeclarator(
215
+ identifier('_e'),
216
+ arrayExpression([
217
+ newExpression(
218
+ memberExpression(identifier('global'), identifier('Error')),
219
+ []
220
+ ),
221
+ numericLiteral(lineOffset),
222
+ numericLiteral(-27), // the placement of opening bracket after Exception in line that defined '_e' variable
223
+ ])
224
+ ),
225
+ ])
226
+ );
227
+ statements.push(
228
+ expressionStatement(
229
+ assignmentExpression(
230
+ '=',
231
+ memberExpression(
232
+ privateFunctionId,
233
+ identifier('__stackDetails'),
234
+ false
235
+ ),
236
+ identifier('_e')
237
+ )
238
+ )
239
+ );
240
+ if (shouldInjectVersion()) {
241
+ statements.push(
242
+ expressionStatement(
243
+ assignmentExpression(
244
+ '=',
245
+ memberExpression(privateFunctionId, identifier('__version'), false),
246
+ stringLiteral(version)
247
+ )
248
+ )
249
+ );
250
+ }
251
+ }
252
+
253
+ statements.push(returnStatement(privateFunctionId));
254
+
255
+ const newFun = functionExpression(undefined, [], blockStatement(statements));
256
+
257
+ return newFun;
258
+ }
259
+
260
+ function shouldInjectVersion() {
261
+ // We don't inject version in release since cache is reset there anyway
262
+ if (isRelease()) {
263
+ return false;
264
+ }
265
+
266
+ // We don't want to pollute tests with current version number so we disable it
267
+ // for all tests (except one)
268
+ if (process.env.REANIMATED_JEST_DISABLE_VERSION === 'jest') {
269
+ return false;
270
+ }
271
+
272
+ return true;
273
+ }
274
+
275
+ function hash(str: string) {
276
+ let i = str.length;
277
+ let hash1 = 5381;
278
+ let hash2 = 52711;
279
+
280
+ while (i--) {
281
+ const char = str.charCodeAt(i);
282
+ // eslint-disable-next-line no-bitwise
283
+ hash1 = (hash1 * 33) ^ char;
284
+ // eslint-disable-next-line no-bitwise
285
+ hash2 = (hash2 * 33) ^ char;
286
+ }
287
+
288
+ // eslint-disable-next-line no-bitwise
289
+ return (hash1 >>> 0) * 4096 + (hash2 >>> 0);
290
+ }
291
+
292
+ function makeWorkletName(
293
+ fun: NodePath<
294
+ | FunctionDeclaration
295
+ | FunctionExpression
296
+ | ObjectMethod
297
+ | ArrowFunctionExpression
298
+ >
299
+ ) {
300
+ if (isObjectMethod(fun.node) && 'name' in fun.node.key) {
301
+ return fun.node.key.name;
302
+ }
303
+ if (isFunctionDeclaration(fun.node) && fun.node.id) {
304
+ return fun.node.id.name;
305
+ }
306
+ if (isFunctionExpression(fun.node) && isIdentifier(fun.node.id)) {
307
+ return fun.node.id.name;
308
+ }
309
+ return 'anonymous'; // fallback for ArrowFunctionExpression and unnamed FunctionExpression
310
+ }
311
+
312
+ function makeArrayFromCapturedBindings(
313
+ ast: BabelFile,
314
+ fun: NodePath<
315
+ | FunctionDeclaration
316
+ | FunctionExpression
317
+ | ObjectMethod
318
+ | ArrowFunctionExpression
319
+ >
320
+ ) {
321
+ const closure = new Map<string, Identifier>();
322
+
323
+ // this traversal looks for variables to capture
324
+ traverse(ast, {
325
+ Identifier(path) {
326
+ // we only capture variables that were declared outside of the scope
327
+ if (!path.isReferencedIdentifier()) {
328
+ return;
329
+ }
330
+ const name = path.node.name;
331
+ // if the function is named and was added to globals we don't want to add it to closure
332
+ // hence we check if identifier has that name
333
+ if (globals.has(name)) {
334
+ return;
335
+ }
336
+ if (
337
+ 'id' in fun.node &&
338
+ fun.node.id &&
339
+ fun.node.id.name === name // we don't want to capture function's own name
340
+ ) {
341
+ return;
342
+ }
343
+
344
+ const parentNode = path.parent;
345
+
346
+ if (
347
+ isMemberExpression(parentNode) &&
348
+ parentNode.property === path.node &&
349
+ !parentNode.computed
350
+ ) {
351
+ return;
352
+ }
353
+
354
+ if (
355
+ isObjectProperty(parentNode) &&
356
+ isObjectExpression(path.parentPath.parent) &&
357
+ path.node !== parentNode.value
358
+ ) {
359
+ return;
360
+ }
361
+
362
+ let currentScope = path.scope;
363
+
364
+ while (currentScope != null) {
365
+ if (currentScope.bindings[name] != null) {
366
+ return;
367
+ }
368
+ currentScope = currentScope.parent;
369
+ }
370
+ closure.set(name, path.node);
371
+ },
372
+ });
373
+
374
+ return Array.from(closure.values());
375
+ }