react-native-reanimated 3.0.0-rc.9 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (329) hide show
  1. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +30 -12
  2. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.h +2 -0
  3. package/Common/cpp/Fabric/FabricUtils.cpp +3 -107
  4. package/Common/cpp/Fabric/FabricUtils.h +3 -24
  5. package/Common/cpp/Fabric/ReanimatedUIManagerBinding.cpp +54 -37
  6. package/Common/cpp/LayoutAnimations/LayoutAnimationType.h +8 -0
  7. package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.cpp +81 -26
  8. package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.h +20 -3
  9. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +105 -109
  10. package/Common/cpp/NativeModules/NativeReanimatedModule.h +19 -12
  11. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +15 -7
  12. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.h +6 -2
  13. package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.cpp +20 -1
  14. package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.h +9 -0
  15. package/Common/cpp/ReanimatedRuntime/ReanimatedRuntime.cpp +5 -1
  16. package/Common/cpp/Registries/EventHandlerRegistry.cpp +8 -34
  17. package/Common/cpp/Registries/EventHandlerRegistry.h +7 -13
  18. package/Common/cpp/SharedItems/Shareables.cpp +9 -63
  19. package/Common/cpp/SharedItems/Shareables.h +77 -72
  20. package/Common/cpp/Tools/CollectionUtils.h +14 -0
  21. package/Common/cpp/Tools/JsiUtils.cpp +26 -0
  22. package/Common/cpp/Tools/JsiUtils.h +176 -0
  23. package/Common/cpp/Tools/PlatformDepMethodsHolder.h +5 -5
  24. package/Common/cpp/Tools/ReanimatedVersion.cpp +17 -0
  25. package/Common/cpp/Tools/ReanimatedVersion.h +11 -0
  26. package/Common/cpp/Tools/RuntimeDecorator.cpp +49 -230
  27. package/Common/cpp/Tools/RuntimeDecorator.h +0 -2
  28. package/Common/cpp/Tools/WorkletEventHandler.cpp +3 -2
  29. package/Common/cpp/Tools/WorkletEventHandler.h +14 -6
  30. package/RNReanimated.podspec +2 -1
  31. package/android/CMakeLists.txt +188 -181
  32. package/android/build.gradle +362 -311
  33. package/android/proguard-rules.pro +2 -0
  34. package/android/src/fabric/java/com/swmansion/reanimated/NativeProxy.java +63 -295
  35. package/android/src/main/cpp/LayoutAnimations.cpp +35 -5
  36. package/android/src/main/cpp/LayoutAnimations.h +23 -6
  37. package/android/src/main/cpp/NativeProxy.cpp +143 -98
  38. package/android/src/main/cpp/NativeProxy.h +22 -28
  39. package/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java +5 -4
  40. package/android/src/main/java/com/swmansion/reanimated/Utils.java +7 -1
  41. package/android/src/main/java/com/swmansion/reanimated/keyboardObserver/ReanimatedKeyboardEventListener.java +10 -3
  42. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java +218 -35
  43. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/LayoutAnimations.java +43 -17
  44. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/NativeMethodsHolder.java +6 -2
  45. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/SharedElement.java +19 -0
  46. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/SharedTransitionManager.java +610 -0
  47. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/Snapshot.java +93 -23
  48. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/AnimationFrameCallback.java +19 -0
  49. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/EventHandler.java +35 -0
  50. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/KeyboardEventDataUpdater.java +16 -0
  51. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/NativeProxyCommon.java +206 -0
  52. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/SensorSetter.java +17 -0
  53. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensor.java +9 -3
  54. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorContainer.java +3 -4
  55. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.java +31 -7
  56. package/android/src/paper/java/com/swmansion/reanimated/NativeProxy.java +90 -307
  57. package/android/src/reactNativeVersionPatch/ReanimatedUIManager/70/com/swmansion/reanimated/ReanimatedUIManagerFactory.java +16 -0
  58. package/android/src/reactNativeVersionPatch/ReanimatedUIManager/latest/com/swmansion/reanimated/ReanimatedUIManagerFactory.java +63 -0
  59. package/android/src/reactNativeVersionPatch/ReanimatedUIManager/latest/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +271 -0
  60. package/android/src/reactNativeVersionPatch/nativeHierarchyManager/latest/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +76 -20
  61. package/ios/LayoutReanimation/REAAnimationsManager.h +28 -4
  62. package/ios/LayoutReanimation/REAAnimationsManager.m +216 -61
  63. package/ios/LayoutReanimation/REAFrame.h +10 -0
  64. package/ios/LayoutReanimation/REAFrame.m +15 -0
  65. package/ios/LayoutReanimation/REAScreensHelper.h +19 -0
  66. package/ios/LayoutReanimation/REAScreensHelper.m +106 -0
  67. package/ios/LayoutReanimation/REASharedElement.h +15 -0
  68. package/ios/LayoutReanimation/REASharedElement.m +16 -0
  69. package/ios/LayoutReanimation/REASharedTransitionManager.h +17 -0
  70. package/ios/LayoutReanimation/REASharedTransitionManager.m +632 -0
  71. package/ios/LayoutReanimation/REASnapshot.h +1 -0
  72. package/ios/LayoutReanimation/REASnapshot.m +96 -11
  73. package/ios/LayoutReanimation/REAUIManager.mm +64 -17
  74. package/ios/REAModule.mm +2 -7
  75. package/ios/REANodesManager.mm +1 -21
  76. package/ios/keyboardObserver/REAKeyboardEventObserver.m +72 -36
  77. package/ios/native/NativeProxy.mm +75 -114
  78. package/ios/native/REAInitializer.mm +2 -7
  79. package/ios/native/REAJSIUtils.h +60 -2
  80. package/ios/sensor/ReanimatedSensor.h +6 -2
  81. package/ios/sensor/ReanimatedSensor.m +43 -7
  82. package/ios/sensor/ReanimatedSensorContainer.h +4 -1
  83. package/ios/sensor/ReanimatedSensorContainer.m +8 -2
  84. package/lib/commonjs/createAnimatedComponent.js +232 -28
  85. package/lib/commonjs/createAnimatedComponent.js.map +1 -1
  86. package/lib/commonjs/reanimated2/Colors.js +43 -22
  87. package/lib/commonjs/reanimated2/Colors.js.map +1 -1
  88. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js +16 -33
  89. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  90. package/lib/commonjs/reanimated2/animation/styleAnimation.js +5 -1
  91. package/lib/commonjs/reanimated2/animation/styleAnimation.js.map +1 -1
  92. package/lib/commonjs/reanimated2/animation/util.js +17 -15
  93. package/lib/commonjs/reanimated2/animation/util.js.map +1 -1
  94. package/lib/commonjs/reanimated2/commonTypes.js +33 -1
  95. package/lib/commonjs/reanimated2/commonTypes.js.map +1 -1
  96. package/lib/commonjs/reanimated2/core.js +33 -14
  97. package/lib/commonjs/reanimated2/core.js.map +1 -1
  98. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js +2 -2
  99. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
  100. package/lib/commonjs/reanimated2/globals.d.js.map +1 -1
  101. package/lib/commonjs/reanimated2/hook/index.js +0 -6
  102. package/lib/commonjs/reanimated2/hook/index.js.map +1 -1
  103. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js +5 -2
  104. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  105. package/lib/commonjs/reanimated2/hook/useAnimatedReaction.js +13 -1
  106. package/lib/commonjs/reanimated2/hook/useAnimatedReaction.js.map +1 -1
  107. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js +1 -1
  108. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js.map +1 -1
  109. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js +89 -16
  110. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  111. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js +43 -40
  112. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  113. package/lib/commonjs/reanimated2/hook/useDerivedValue.js +13 -1
  114. package/lib/commonjs/reanimated2/hook/useDerivedValue.js.map +1 -1
  115. package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js +2 -2
  116. package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js.map +1 -1
  117. package/lib/commonjs/reanimated2/hook/utils.js +18 -65
  118. package/lib/commonjs/reanimated2/hook/utils.js.map +1 -1
  119. package/lib/commonjs/reanimated2/index.js +13 -0
  120. package/lib/commonjs/reanimated2/index.js.map +1 -1
  121. package/lib/commonjs/reanimated2/initializers.js +71 -32
  122. package/lib/commonjs/reanimated2/initializers.js.map +1 -1
  123. package/lib/commonjs/reanimated2/interpolateColor.js +96 -19
  124. package/lib/commonjs/reanimated2/interpolateColor.js.map +1 -1
  125. package/lib/commonjs/reanimated2/jestUtils.js +1 -1
  126. package/lib/commonjs/reanimated2/jestUtils.js.map +1 -1
  127. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js +103 -13
  128. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  129. package/lib/commonjs/reanimated2/js-reanimated/Mapper.js +22 -0
  130. package/lib/commonjs/reanimated2/js-reanimated/Mapper.js.map +1 -1
  131. package/lib/commonjs/reanimated2/js-reanimated/WebSensor.js +2 -0
  132. package/lib/commonjs/reanimated2/js-reanimated/WebSensor.js.map +1 -0
  133. package/lib/commonjs/reanimated2/js-reanimated/commonTypes.js.map +1 -1
  134. package/lib/commonjs/reanimated2/js-reanimated/global.js +0 -2
  135. package/lib/commonjs/reanimated2/js-reanimated/global.js.map +1 -1
  136. package/lib/commonjs/reanimated2/js-reanimated/index.js +0 -1
  137. package/lib/commonjs/reanimated2/js-reanimated/index.js.map +1 -1
  138. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +11 -0
  139. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  140. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js +8 -0
  141. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  142. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js +17 -9
  143. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
  144. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +16 -23
  145. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
  146. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -14
  147. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
  148. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -14
  149. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
  150. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Slide.js +8 -15
  151. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
  152. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +16 -23
  153. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
  154. package/lib/commonjs/reanimated2/layoutReanimation/index.js +13 -0
  155. package/lib/commonjs/reanimated2/layoutReanimation/index.js.map +1 -1
  156. package/lib/commonjs/reanimated2/layoutReanimation/sharedTransitions/index.js +94 -0
  157. package/lib/commonjs/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -0
  158. package/lib/commonjs/reanimated2/mappers.js +18 -6
  159. package/lib/commonjs/reanimated2/mappers.js.map +1 -1
  160. package/lib/commonjs/reanimated2/mock.js +20 -1
  161. package/lib/commonjs/reanimated2/mock.js.map +1 -1
  162. package/lib/commonjs/reanimated2/mutables.js +4 -2
  163. package/lib/commonjs/reanimated2/mutables.js.map +1 -1
  164. package/lib/commonjs/reanimated2/platform-specific/checkVersion.js +42 -0
  165. package/lib/commonjs/reanimated2/platform-specific/checkVersion.js.map +1 -0
  166. package/lib/commonjs/reanimated2/platform-specific/checkVersion.web.js +15 -0
  167. package/lib/commonjs/reanimated2/platform-specific/checkVersion.web.js.map +1 -0
  168. package/lib/commonjs/reanimated2/pluginUtils.js +11 -0
  169. package/lib/commonjs/reanimated2/pluginUtils.js.map +1 -0
  170. package/lib/commonjs/reanimated2/shareables.js +36 -15
  171. package/lib/commonjs/reanimated2/shareables.js.map +1 -1
  172. package/lib/commonjs/reanimated2/threads.js +114 -4
  173. package/lib/commonjs/reanimated2/threads.js.map +1 -1
  174. package/lib/commonjs/reanimated2/utils.js +7 -0
  175. package/lib/commonjs/reanimated2/utils.js.map +1 -1
  176. package/lib/commonjs/reanimated2/valueSetter.js +1 -3
  177. package/lib/commonjs/reanimated2/valueSetter.js.map +1 -1
  178. package/lib/module/createAnimatedComponent.js +229 -29
  179. package/lib/module/createAnimatedComponent.js.map +1 -1
  180. package/lib/module/reanimated2/Colors.js +35 -19
  181. package/lib/module/reanimated2/Colors.js.map +1 -1
  182. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js +16 -32
  183. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  184. package/lib/module/reanimated2/animation/styleAnimation.js +5 -1
  185. package/lib/module/reanimated2/animation/styleAnimation.js.map +1 -1
  186. package/lib/module/reanimated2/animation/util.js +17 -16
  187. package/lib/module/reanimated2/animation/util.js.map +1 -1
  188. package/lib/module/reanimated2/commonTypes.js +29 -0
  189. package/lib/module/reanimated2/commonTypes.js.map +1 -1
  190. package/lib/module/reanimated2/core.js +32 -7
  191. package/lib/module/reanimated2/core.js.map +1 -1
  192. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js +2 -2
  193. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
  194. package/lib/module/reanimated2/globals.d.js.map +1 -1
  195. package/lib/module/reanimated2/hook/index.js +1 -1
  196. package/lib/module/reanimated2/hook/index.js.map +1 -1
  197. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js +5 -2
  198. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  199. package/lib/module/reanimated2/hook/useAnimatedReaction.js +12 -1
  200. package/lib/module/reanimated2/hook/useAnimatedReaction.js.map +1 -1
  201. package/lib/module/reanimated2/hook/useAnimatedRef.js +2 -2
  202. package/lib/module/reanimated2/hook/useAnimatedRef.js.map +1 -1
  203. package/lib/module/reanimated2/hook/useAnimatedSensor.js +88 -13
  204. package/lib/module/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  205. package/lib/module/reanimated2/hook/useAnimatedStyle.js +46 -43
  206. package/lib/module/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  207. package/lib/module/reanimated2/hook/useDerivedValue.js +12 -1
  208. package/lib/module/reanimated2/hook/useDerivedValue.js.map +1 -1
  209. package/lib/module/reanimated2/hook/useScrollViewOffset.js +2 -2
  210. package/lib/module/reanimated2/hook/useScrollViewOffset.js.map +1 -1
  211. package/lib/module/reanimated2/hook/utils.js +17 -60
  212. package/lib/module/reanimated2/hook/utils.js.map +1 -1
  213. package/lib/module/reanimated2/index.js +1 -0
  214. package/lib/module/reanimated2/index.js.map +1 -1
  215. package/lib/module/reanimated2/initializers.js +72 -33
  216. package/lib/module/reanimated2/initializers.js.map +1 -1
  217. package/lib/module/reanimated2/interpolateColor.js +96 -19
  218. package/lib/module/reanimated2/interpolateColor.js.map +1 -1
  219. package/lib/module/reanimated2/jestUtils.js +1 -1
  220. package/lib/module/reanimated2/jestUtils.js.map +1 -1
  221. package/lib/module/reanimated2/js-reanimated/JSReanimated.js +103 -13
  222. package/lib/module/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  223. package/lib/module/reanimated2/js-reanimated/Mapper.js +21 -0
  224. package/lib/module/reanimated2/js-reanimated/Mapper.js.map +1 -1
  225. package/lib/module/reanimated2/js-reanimated/WebSensor.js +2 -0
  226. package/lib/module/reanimated2/js-reanimated/WebSensor.js.map +1 -0
  227. package/lib/module/reanimated2/js-reanimated/commonTypes.js.map +1 -1
  228. package/lib/module/reanimated2/js-reanimated/global.js +0 -2
  229. package/lib/module/reanimated2/js-reanimated/global.js.map +1 -1
  230. package/lib/module/reanimated2/js-reanimated/index.js +0 -1
  231. package/lib/module/reanimated2/js-reanimated/index.js.map +1 -1
  232. package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +9 -1
  233. package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  234. package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js +1 -0
  235. package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  236. package/lib/module/reanimated2/layoutReanimation/animationsManager.js +15 -8
  237. package/lib/module/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
  238. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +16 -21
  239. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
  240. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -12
  241. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
  242. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -12
  243. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
  244. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js +8 -13
  245. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
  246. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +16 -21
  247. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
  248. package/lib/module/reanimated2/layoutReanimation/index.js +1 -0
  249. package/lib/module/reanimated2/layoutReanimation/index.js.map +1 -1
  250. package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js +82 -0
  251. package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -0
  252. package/lib/module/reanimated2/mappers.js +16 -6
  253. package/lib/module/reanimated2/mappers.js.map +1 -1
  254. package/lib/module/reanimated2/mock.js +20 -1
  255. package/lib/module/reanimated2/mock.js.map +1 -1
  256. package/lib/module/reanimated2/mutables.js +4 -2
  257. package/lib/module/reanimated2/mutables.js.map +1 -1
  258. package/lib/module/reanimated2/platform-specific/checkVersion.js +35 -0
  259. package/lib/module/reanimated2/platform-specific/checkVersion.js.map +1 -0
  260. package/lib/module/reanimated2/platform-specific/checkVersion.web.js +8 -0
  261. package/lib/module/reanimated2/platform-specific/checkVersion.web.js.map +1 -0
  262. package/lib/module/reanimated2/pluginUtils.js +4 -0
  263. package/lib/module/reanimated2/pluginUtils.js.map +1 -0
  264. package/lib/module/reanimated2/shareables.js +36 -12
  265. package/lib/module/reanimated2/shareables.js.map +1 -1
  266. package/lib/module/reanimated2/threads.js +105 -4
  267. package/lib/module/reanimated2/threads.js.map +1 -1
  268. package/lib/module/reanimated2/utils.js +5 -0
  269. package/lib/module/reanimated2/utils.js.map +1 -1
  270. package/lib/module/reanimated2/valueSetter.js +1 -2
  271. package/lib/module/reanimated2/valueSetter.js.map +1 -1
  272. package/package.json +10 -10
  273. package/{plugin.js → plugin/index.js} +128 -249
  274. package/react-native-reanimated.d.ts +57 -10
  275. package/scripts/reanimated_utils.rb +15 -2
  276. package/src/createAnimatedComponent.tsx +238 -28
  277. package/src/reanimated2/Colors.ts +38 -11
  278. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +52 -39
  279. package/src/reanimated2/animation/styleAnimation.ts +8 -1
  280. package/src/reanimated2/animation/util.ts +29 -16
  281. package/src/reanimated2/commonTypes.ts +28 -1
  282. package/src/reanimated2/core.ts +42 -9
  283. package/src/reanimated2/frameCallback/FrameCallbackRegistryUI.ts +2 -2
  284. package/src/reanimated2/globals.d.ts +12 -15
  285. package/src/reanimated2/hook/index.ts +1 -1
  286. package/src/reanimated2/hook/useAnimatedKeyboard.ts +10 -4
  287. package/src/reanimated2/hook/useAnimatedReaction.ts +12 -5
  288. package/src/reanimated2/hook/useAnimatedRef.ts +1 -4
  289. package/src/reanimated2/hook/useAnimatedSensor.ts +88 -11
  290. package/src/reanimated2/hook/useAnimatedStyle.ts +44 -36
  291. package/src/reanimated2/hook/useDerivedValue.ts +8 -1
  292. package/src/reanimated2/hook/useScrollViewOffset.ts +2 -2
  293. package/src/reanimated2/hook/utils.ts +15 -61
  294. package/src/reanimated2/index.ts +1 -0
  295. package/src/reanimated2/initializers.ts +76 -35
  296. package/src/reanimated2/interpolateColor.ts +104 -20
  297. package/src/reanimated2/jestUtils.ts +1 -1
  298. package/src/reanimated2/js-reanimated/JSReanimated.ts +98 -15
  299. package/src/reanimated2/js-reanimated/Mapper.ts +32 -0
  300. package/src/reanimated2/js-reanimated/WebSensor.ts +34 -0
  301. package/src/reanimated2/js-reanimated/commonTypes.ts +0 -1
  302. package/src/reanimated2/js-reanimated/global.ts +0 -1
  303. package/src/reanimated2/js-reanimated/index.ts +0 -1
  304. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +13 -1
  305. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +1 -0
  306. package/src/reanimated2/layoutReanimation/animationsManager.ts +17 -9
  307. package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +16 -19
  308. package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +14 -11
  309. package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +21 -11
  310. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +32 -11
  311. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +36 -19
  312. package/src/reanimated2/layoutReanimation/index.ts +1 -0
  313. package/src/reanimated2/layoutReanimation/sharedTransitions/index.ts +87 -0
  314. package/src/reanimated2/mappers.ts +17 -6
  315. package/src/reanimated2/mock.ts +24 -1
  316. package/src/reanimated2/mutables.ts +2 -0
  317. package/src/reanimated2/platform-specific/checkVersion.ts +39 -0
  318. package/src/reanimated2/platform-specific/checkVersion.web.ts +6 -0
  319. package/src/reanimated2/pluginUtils.ts +8 -0
  320. package/src/reanimated2/shareables.ts +45 -16
  321. package/src/reanimated2/threads.ts +103 -1
  322. package/src/reanimated2/utils.ts +6 -0
  323. package/src/reanimated2/valueSetter.ts +1 -2
  324. package/lib/commonjs/reanimated2/time.js +0 -55
  325. package/lib/commonjs/reanimated2/time.js.map +0 -1
  326. package/lib/module/reanimated2/time.js +0 -37
  327. package/lib/module/reanimated2/time.js.map +0 -1
  328. package/src/reanimated2/time.ts +0 -30
  329. /package/android/src/{main/java → reactNativeVersionPatch/ReanimatedUIManager/70}/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +0 -0
@@ -6,12 +6,10 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.areDependenciesEqual = areDependenciesEqual;
7
7
  exports.buildDependencies = buildDependencies;
8
8
  exports.buildWorkletsHash = buildWorkletsHash;
9
- exports.canApplyOptimalisation = canApplyOptimalisation;
10
- exports.getStyleWithoutAnimations = getStyleWithoutAnimations;
11
9
  exports.hasColorProps = hasColorProps;
12
10
  exports.isAnimated = isAnimated;
13
11
  exports.parseColors = parseColors;
14
- exports.styleDiff = styleDiff;
12
+ exports.shallowEqual = shallowEqual;
15
13
  exports.useEvent = useEvent;
16
14
  exports.useHandler = useHandler;
17
15
  exports.validateAnimatedStyles = void 0;
@@ -153,84 +151,39 @@ function parseColors(updates) {
153
151
  }
154
152
  }
155
153
 
156
- function canApplyOptimalisation(upadterFn) {
157
- const FUNCTIONLESS_FLAG = 0b00000001;
158
- const STATEMENTLESS_FLAG = 0b00000010; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
159
-
160
- const optimalization = upadterFn.__optimalization;
161
- return optimalization & FUNCTIONLESS_FLAG && optimalization & STATEMENTLESS_FLAG;
162
- }
163
-
164
154
  function isAnimated(prop) {
165
155
  'worklet';
166
156
 
167
- const propsToCheck = [prop];
168
-
169
- while (propsToCheck.length > 0) {
170
- const currentProp = propsToCheck.pop();
171
-
172
- if (Array.isArray(currentProp)) {
173
- for (const item of currentProp) {
174
- propsToCheck.push(item);
175
- }
176
- } else if ((currentProp === null || currentProp === void 0 ? void 0 : currentProp.onFrame) !== undefined) {
157
+ if (Array.isArray(prop)) {
158
+ return prop.some(isAnimated);
159
+ } else if (typeof prop === 'object') {
160
+ if (prop.onFrame !== undefined) {
177
161
  return true;
178
- } else if (typeof currentProp === 'object') {
179
- for (const item of Object.values(currentProp)) {
180
- propsToCheck.push(item);
181
- }
182
- } // if none of the above, it's not the animated prop, check next one
183
-
184
- } // when none of the props were animated return false
185
-
186
-
187
- return false;
188
- }
189
-
190
- function styleDiff(oldStyle, newStyle) {
191
- 'worklet';
192
-
193
- const diff = {};
194
-
195
- for (const key in oldStyle) {
196
- if (newStyle[key] === undefined) {
197
- diff[key] = null;
162
+ } else {
163
+ return Object.values(prop).some(isAnimated);
198
164
  }
199
165
  }
200
166
 
201
- for (const key in newStyle) {
202
- const value = newStyle[key];
203
- const oldValue = oldStyle[key];
204
-
205
- if (isAnimated(value)) {
206
- // do nothing
207
- continue;
208
- }
209
-
210
- if (oldValue !== value) {
211
- diff[key] = value;
212
- }
213
- }
214
-
215
- return diff;
167
+ return false;
216
168
  }
217
169
 
218
- function getStyleWithoutAnimations(newStyle) {
170
+ function shallowEqual(a, b) {
219
171
  'worklet';
220
172
 
221
- const diff = {};
173
+ const aKeys = Object.keys(a);
174
+ const bKeys = Object.keys(b);
222
175
 
223
- for (const key in newStyle) {
224
- const value = newStyle[key];
176
+ if (aKeys.length !== bKeys.length) {
177
+ return false;
178
+ }
225
179
 
226
- if (isAnimated(value)) {
227
- continue;
180
+ for (let i = 0; i < aKeys.length; i++) {
181
+ if (a[aKeys[i]] !== b[aKeys[i]]) {
182
+ return false;
228
183
  }
229
-
230
- diff[key] = value;
231
184
  }
232
185
 
233
- return diff;
186
+ return true;
234
187
  }
235
188
 
236
189
  const validateAnimatedStyles = styles => {
@@ -1 +1 @@
1
- {"version":3,"names":["useEvent","handler","eventNames","rebuild","initRef","useRef","current","WorkletEventHandler","updateWorklet","useHandler","handlers","dependencies","context","makeRemote","savedDependencies","useEffect","buildDependencies","doDependenciesDiffer","areDependenciesEqual","useWeb","isWeb","isJest","buildWorkletsHash","Object","values","reduce","acc","worklet","__workletHash","toString","handlersList","filter","undefined","map","workletHash","closure","_closure","push","nextDeps","prevDeps","is","x","y","objectIs","areHookInputsEqual","length","i","hasColorProps","updates","colorPropsSet","Set","colorProps","key","has","parseColors","indexOf","processedColor","processColor","canApplyOptimalisation","upadterFn","FUNCTIONLESS_FLAG","STATEMENTLESS_FLAG","optimalization","__optimalization","isAnimated","prop","propsToCheck","currentProp","pop","Array","isArray","item","onFrame","styleDiff","oldStyle","newStyle","diff","value","oldValue","getStyleWithoutAnimations","validateAnimatedStyles","styles","Error"],"sources":["utils.ts"],"sourcesContent":["import { MutableRefObject, useEffect, useRef } from 'react';\nimport { processColor } from '../Colors';\nimport {\n AnimatedStyle,\n Context,\n NativeEvent,\n NestedObjectValues,\n StyleProps,\n WorkletFunction,\n AnimationObject,\n} from '../commonTypes';\nimport { makeRemote } from '../core';\nimport { isWeb, isJest } from '../PlatformChecker';\nimport { colorProps } from '../UpdateProps';\nimport WorkletEventHandler from '../WorkletEventHandler';\nimport { ContextWithDependencies, DependencyList } from './commonTypes';\n\ninterface Handler<T, TContext extends Context> extends WorkletFunction {\n (event: T, context: TContext): void;\n}\n\ninterface Handlers<T, TContext extends Context> {\n [key: string]: Handler<T, TContext> | undefined;\n}\n\nexport interface UseHandlerContext<TContext extends Context> {\n context: TContext;\n doDependenciesDiffer: boolean;\n useWeb: boolean;\n}\n\nexport function useEvent<T extends NativeEvent<T>>(\n handler: (event: T) => void,\n eventNames: string[] = [],\n rebuild = false\n): MutableRefObject<WorkletEventHandler<T> | null> {\n const initRef = useRef<WorkletEventHandler<T> | null>(null);\n if (initRef.current === null) {\n initRef.current = new WorkletEventHandler(handler, eventNames);\n } else if (rebuild) {\n initRef.current.updateWorklet(handler);\n }\n\n return initRef;\n}\n\nexport function useHandler<T, TContext extends Context>(\n handlers: Handlers<T, TContext>,\n dependencies?: DependencyList\n): UseHandlerContext<TContext> {\n const initRef = useRef<ContextWithDependencies<TContext> | null>(null);\n if (initRef.current === null) {\n initRef.current = {\n context: makeRemote<TContext>({} as TContext),\n savedDependencies: [],\n };\n }\n\n useEffect(() => {\n return () => {\n initRef.current = null;\n };\n }, []);\n\n const { context, savedDependencies } = initRef.current;\n\n dependencies = buildDependencies(dependencies, handlers);\n\n const doDependenciesDiffer = !areDependenciesEqual(\n dependencies,\n savedDependencies\n );\n initRef.current.savedDependencies = dependencies;\n const useWeb = isWeb() || isJest();\n\n return { context, doDependenciesDiffer, useWeb };\n}\n\n// builds one big hash from multiple worklets' hashes\nexport function buildWorkletsHash(\n handlers: Record<string, WorkletFunction> | Array<WorkletFunction>\n): string {\n return Object.values(handlers).reduce(\n (acc: string, worklet: WorkletFunction) =>\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n acc + worklet.__workletHash!.toString(),\n ''\n );\n}\n\n// builds dependencies array for gesture handlers\nexport function buildDependencies(\n dependencies: DependencyList,\n handlers: Record<string, WorkletFunction | undefined>\n): Array<unknown> {\n const handlersList: WorkletFunction[] = Object.values(handlers).filter(\n (handler) => handler !== undefined\n ) as WorkletFunction[];\n if (!dependencies) {\n dependencies = handlersList.map((handler) => {\n return {\n workletHash: handler.__workletHash,\n closure: handler._closure,\n };\n });\n } else {\n dependencies.push(buildWorkletsHash(handlersList));\n }\n return dependencies;\n}\n\n// this is supposed to work as useEffect comparison\nexport function areDependenciesEqual(\n nextDeps: DependencyList,\n prevDeps: DependencyList\n): boolean {\n function is(x: number, y: number) {\n /* eslint-disable no-self-compare */\n return (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y);\n /* eslint-enable no-self-compare */\n }\n const objectIs: (nextDeps: unknown, prevDeps: unknown) => boolean =\n typeof Object.is === 'function' ? Object.is : is;\n\n function areHookInputsEqual(\n nextDeps: DependencyList,\n prevDeps: DependencyList\n ): boolean {\n if (!nextDeps || !prevDeps || prevDeps.length !== nextDeps.length) {\n return false;\n }\n for (let i = 0; i < prevDeps.length; ++i) {\n if (!objectIs(nextDeps[i], prevDeps[i])) {\n return false;\n }\n }\n return true;\n }\n\n return areHookInputsEqual(nextDeps, prevDeps);\n}\n\nexport function hasColorProps(updates: AnimatedStyle): boolean {\n const colorPropsSet = new Set(colorProps);\n for (const key in updates) {\n if (colorPropsSet.has(key)) {\n return true;\n }\n }\n return false;\n}\n\nexport function parseColors(updates: AnimatedStyle): void {\n 'worklet';\n for (const key in updates) {\n if (colorProps.indexOf(key) !== -1) {\n // value could be an animation in which case processColor will recognize it and will return undefined\n // -> in such a case we don't want to override style of that key\n const processedColor = processColor(updates[key]);\n if (processedColor !== undefined) {\n updates[key] = processedColor;\n }\n }\n }\n}\n\nexport function canApplyOptimalisation(upadterFn: WorkletFunction): number {\n const FUNCTIONLESS_FLAG = 0b00000001;\n const STATEMENTLESS_FLAG = 0b00000010;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const optimalization = upadterFn.__optimalization!;\n return (\n optimalization & FUNCTIONLESS_FLAG && optimalization & STATEMENTLESS_FLAG\n );\n}\n\nexport function isAnimated(prop: NestedObjectValues<AnimationObject>): boolean {\n 'worklet';\n const propsToCheck: NestedObjectValues<AnimationObject>[] = [prop];\n while (propsToCheck.length > 0) {\n const currentProp: NestedObjectValues<AnimationObject> =\n propsToCheck.pop() as NestedObjectValues<AnimationObject>;\n if (Array.isArray(currentProp)) {\n for (const item of currentProp) {\n propsToCheck.push(item);\n }\n } else if (currentProp?.onFrame !== undefined) {\n return true;\n } else if (typeof currentProp === 'object') {\n for (const item of Object.values(currentProp)) {\n propsToCheck.push(item);\n }\n }\n // if none of the above, it's not the animated prop, check next one\n }\n\n // when none of the props were animated return false\n return false;\n}\n\nexport function styleDiff<T extends AnimatedStyle>(\n oldStyle: AnimatedStyle,\n newStyle: AnimatedStyle\n): Partial<T> {\n 'worklet';\n const diff: any = {};\n for (const key in oldStyle) {\n if (newStyle[key] === undefined) {\n diff[key] = null;\n }\n }\n for (const key in newStyle) {\n const value = newStyle[key];\n const oldValue = oldStyle[key];\n\n if (isAnimated(value)) {\n // do nothing\n continue;\n }\n if (oldValue !== value) {\n diff[key] = value;\n }\n }\n return diff;\n}\n\nexport function getStyleWithoutAnimations(newStyle: AnimatedStyle): StyleProps {\n 'worklet';\n const diff: StyleProps = {};\n\n for (const key in newStyle) {\n const value = newStyle[key];\n if (isAnimated(value)) {\n continue;\n }\n diff[key] = value;\n }\n return diff;\n}\n\nexport const validateAnimatedStyles = (styles: AnimatedStyle): void => {\n 'worklet';\n if (typeof styles !== 'object') {\n throw new Error(\n `useAnimatedStyle has to return an object, found ${typeof styles} instead`\n );\n } else if (Array.isArray(styles)) {\n throw new Error(\n 'useAnimatedStyle has to return an object and cannot return static styles combined with dynamic ones. Please do merging where a component receives props.'\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAUA;;AACA;;AACA;;AACA;;;;AAiBO,SAASA,QAAT,CACLC,OADK,EAI4C;EAAA,IAFjDC,UAEiD,uEAF1B,EAE0B;EAAA,IADjDC,OACiD,uEADvC,KACuC;EACjD,MAAMC,OAAO,GAAG,IAAAC,aAAA,EAAsC,IAAtC,CAAhB;;EACA,IAAID,OAAO,CAACE,OAAR,KAAoB,IAAxB,EAA8B;IAC5BF,OAAO,CAACE,OAAR,GAAkB,IAAIC,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EAEA,KAAK,MAAMxB,GAAX,IAAkBuB,QAAlB,EAA4B;IAC1B,MAAME,KAAK,GAAGF,QAAQ,CAACvB,GAAD,CAAtB;;IACA,IAAIY,UAAU,CAACa,KAAD,CAAd,EAAuB;MACrB;IACD;;IACDD,IAAI,CAACxB,GAAD,CAAJ,GAAYyB,KAAZ;EACD;;EACD,OAAOD,IAAP;AACD;;AAEM,MAAMI,sBAAsB,GAAIC,MAAD,IAAiC;EACrE;;EACA,IAAI,OAAOA,MAAP,KAAkB,QAAtB,EAAgC;IAC9B,MAAM,IAAIC,KAAJ,CACH,mDAAkD,OAAOD,MAAO,UAD7D,CAAN;EAGD,CAJD,MAIO,IAAIZ,KAAK,CAACC,OAAN,CAAcW,MAAd,CAAJ,EAA2B;IAChC,MAAM,IAAIC,KAAJ,CACJ,0JADI,CAAN;EAGD;AACF,CAXM"}
1
+ {"version":3,"names":["useEvent","handler","eventNames","rebuild","initRef","useRef","current","WorkletEventHandler","updateWorklet","useHandler","handlers","dependencies","context","makeRemote","savedDependencies","useEffect","buildDependencies","doDependenciesDiffer","areDependenciesEqual","useWeb","isWeb","isJest","buildWorkletsHash","Object","values","reduce","acc","worklet","__workletHash","toString","handlersList","filter","undefined","map","workletHash","closure","_closure","push","nextDeps","prevDeps","is","x","y","objectIs","areHookInputsEqual","length","i","hasColorProps","updates","colorPropsSet","Set","colorProps","key","has","parseColors","indexOf","processedColor","processColor","isAnimated","prop","Array","isArray","some","onFrame","shallowEqual","a","b","aKeys","keys","bKeys","validateAnimatedStyles","styles","Error"],"sources":["utils.ts"],"sourcesContent":["import { MutableRefObject, useEffect, useRef } from 'react';\nimport { processColor } from '../Colors';\nimport {\n AnimatedStyle,\n Context,\n NativeEvent,\n NestedObjectValues,\n WorkletFunction,\n AnimationObject,\n} from '../commonTypes';\nimport { makeRemote } from '../core';\nimport { isWeb, isJest } from '../PlatformChecker';\nimport { colorProps } from '../UpdateProps';\nimport WorkletEventHandler from '../WorkletEventHandler';\nimport { ContextWithDependencies, DependencyList } from './commonTypes';\n\ninterface Handler<T, TContext extends Context> extends WorkletFunction {\n (event: T, context: TContext): void;\n}\n\ninterface Handlers<T, TContext extends Context> {\n [key: string]: Handler<T, TContext> | undefined;\n}\n\nexport interface UseHandlerContext<TContext extends Context> {\n context: TContext;\n doDependenciesDiffer: boolean;\n useWeb: boolean;\n}\n\nexport function useEvent<T extends NativeEvent<T>>(\n handler: (event: T) => void,\n eventNames: string[] = [],\n rebuild = false\n): MutableRefObject<WorkletEventHandler<T> | null> {\n const initRef = useRef<WorkletEventHandler<T> | null>(null);\n if (initRef.current === null) {\n initRef.current = new WorkletEventHandler(handler, eventNames);\n } else if (rebuild) {\n initRef.current.updateWorklet(handler);\n }\n\n return initRef;\n}\n\nexport function useHandler<T, TContext extends Context>(\n handlers: Handlers<T, TContext>,\n dependencies?: DependencyList\n): UseHandlerContext<TContext> {\n const initRef = useRef<ContextWithDependencies<TContext> | null>(null);\n if (initRef.current === null) {\n initRef.current = {\n context: makeRemote<TContext>({} as TContext),\n savedDependencies: [],\n };\n }\n\n useEffect(() => {\n return () => {\n initRef.current = null;\n };\n }, []);\n\n const { context, savedDependencies } = initRef.current;\n\n dependencies = buildDependencies(dependencies, handlers);\n\n const doDependenciesDiffer = !areDependenciesEqual(\n dependencies,\n savedDependencies\n );\n initRef.current.savedDependencies = dependencies;\n const useWeb = isWeb() || isJest();\n\n return { context, doDependenciesDiffer, useWeb };\n}\n\n// builds one big hash from multiple worklets' hashes\nexport function buildWorkletsHash(\n handlers: Record<string, WorkletFunction> | Array<WorkletFunction>\n): string {\n return Object.values(handlers).reduce(\n (acc: string, worklet: WorkletFunction) =>\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n acc + worklet.__workletHash!.toString(),\n ''\n );\n}\n\n// builds dependencies array for gesture handlers\nexport function buildDependencies(\n dependencies: DependencyList,\n handlers: Record<string, WorkletFunction | undefined>\n): Array<unknown> {\n const handlersList: WorkletFunction[] = Object.values(handlers).filter(\n (handler) => handler !== undefined\n ) as WorkletFunction[];\n if (!dependencies) {\n dependencies = handlersList.map((handler) => {\n return {\n workletHash: handler.__workletHash,\n closure: handler._closure,\n };\n });\n } else {\n dependencies.push(buildWorkletsHash(handlersList));\n }\n return dependencies;\n}\n\n// this is supposed to work as useEffect comparison\nexport function areDependenciesEqual(\n nextDeps: DependencyList,\n prevDeps: DependencyList\n): boolean {\n function is(x: number, y: number) {\n /* eslint-disable no-self-compare */\n return (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y);\n /* eslint-enable no-self-compare */\n }\n const objectIs: (nextDeps: unknown, prevDeps: unknown) => boolean =\n typeof Object.is === 'function' ? Object.is : is;\n\n function areHookInputsEqual(\n nextDeps: DependencyList,\n prevDeps: DependencyList\n ): boolean {\n if (!nextDeps || !prevDeps || prevDeps.length !== nextDeps.length) {\n return false;\n }\n for (let i = 0; i < prevDeps.length; ++i) {\n if (!objectIs(nextDeps[i], prevDeps[i])) {\n return false;\n }\n }\n return true;\n }\n\n return areHookInputsEqual(nextDeps, prevDeps);\n}\n\nexport function hasColorProps(updates: AnimatedStyle): boolean {\n const colorPropsSet = new Set(colorProps);\n for (const key in updates) {\n if (colorPropsSet.has(key)) {\n return true;\n }\n }\n return false;\n}\n\nexport function parseColors(updates: AnimatedStyle): void {\n 'worklet';\n for (const key in updates) {\n if (colorProps.indexOf(key) !== -1) {\n // value could be an animation in which case processColor will recognize it and will return undefined\n // -> in such a case we don't want to override style of that key\n const processedColor = processColor(updates[key]);\n if (processedColor !== undefined) {\n updates[key] = processedColor;\n }\n }\n }\n}\n\nexport function isAnimated(prop: NestedObjectValues<AnimationObject>): boolean {\n 'worklet';\n if (Array.isArray(prop)) {\n return prop.some(isAnimated);\n } else if (typeof prop === 'object') {\n if (prop.onFrame !== undefined) {\n return true;\n } else {\n return Object.values(prop).some(isAnimated);\n }\n }\n return false;\n}\n\nexport function shallowEqual(a: any, b: any) {\n 'worklet';\n const aKeys = Object.keys(a);\n const bKeys = Object.keys(b);\n if (aKeys.length !== bKeys.length) {\n return false;\n }\n for (let i = 0; i < aKeys.length; i++) {\n if (a[aKeys[i]] !== b[aKeys[i]]) {\n return false;\n }\n }\n return true;\n}\n\nexport const validateAnimatedStyles = (styles: AnimatedStyle): void => {\n 'worklet';\n if (typeof styles !== 'object') {\n throw new Error(\n `useAnimatedStyle has to return an object, found ${typeof styles} instead`\n );\n } else if (Array.isArray(styles)) {\n throw new Error(\n 'useAnimatedStyle has to return an object and cannot return static styles combined with dynamic ones. Please do merging where a component receives props.'\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;;AACA;;AASA;;AACA;;AACA;;AACA;;;;AAiBO,SAASA,QAAT,CACLC,OADK,EAI4C;EAAA,IAFjDC,UAEiD,uEAF1B,EAE0B;EAAA,IADjDC,OACiD,uEADvC,KACuC;EACjD,MAAMC,OAAO,GAAG,IAAAC,aAAA,EAAsC,IAAtC,CAAhB;;EACA,IAAID,OAAO,CAACE,OAAR,KAAoB,IAAxB,EAA8B;IAC5BF,OAAO,CAACE,OAAR,GAAkB,IAAIC,4BAAJ,CAAwBN,OAAxB,EAAiCC,UAAjC,CAAlB;EACD,CAFD,MAEO,IAAIC,OAAJ,EAAa;IAClBC,OAAO,CAACE,OAAR,CAAgBE,aAAhB,CAA8BP,OAA9B;EACD;;EAED,OAAOG,OAAP;AACD;;AAEM,SAASK,UAAT,CACLC,QADK,EAELC,YAFK,EAGwB;EAC7B,MAAMP,OAAO,GAAG,IAAAC,aAAA,EAAiD,IAAjD,CAAhB;;EACA,IAAID,OAAO,CAACE,OAAR,KAAoB,IAAxB,EAA8B;IAC5BF,OAAO,CAACE,OAAR,GAAkB;MAChBM,OAAO,EAAE,IAAAC,gBAAA,EAAqB,EAArB,CADO;MAEhBC,iBAAiB,EAAE;IAFH,CAAlB;EAID;;EAED,IAAAC,gBAAA,EAAU,MAAM;IACd,OAAO,MAAM;MACXX,OAAO,CAACE,OAAR,GAAkB,IAAlB;IACD,CA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BAAsB,GAAIC,MAAD,IAAiC;EACrE;;EACA,IAAI,OAAOA,MAAP,KAAkB,QAAtB,EAAgC;IAC9B,MAAM,IAAIC,KAAJ,CACH,mDAAkD,OAAOD,MAAO,UAD7D,CAAN;EAGD,CAJD,MAIO,IAAIX,KAAK,CAACC,OAAN,CAAcU,MAAd,CAAJ,EAA2B;IAChC,MAAM,IAAIC,KAAJ,CACJ,0JADI,CAAN;EAGD;AACF,CAXM"}
@@ -159,4 +159,17 @@ Object.keys(_commonTypes).forEach(function (key) {
159
159
  }
160
160
  });
161
161
  });
162
+
163
+ var _pluginUtils = require("./pluginUtils");
164
+
165
+ Object.keys(_pluginUtils).forEach(function (key) {
166
+ if (key === "default" || key === "__esModule") return;
167
+ if (key in exports && exports[key] === _pluginUtils[key]) return;
168
+ Object.defineProperty(exports, key, {
169
+ enumerable: true,
170
+ get: function () {
171
+ return _pluginUtils[key];
172
+ }
173
+ });
174
+ });
162
175
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from './core';\nexport * from './hook';\nexport * from './animation';\nexport * from './interpolation';\nexport * from './interpolateColor';\nexport * from './Easing';\nexport * from './NativeMethods';\nexport * from './Colors';\nexport * from './PropAdapters';\nexport * from './layoutReanimation';\nexport * from './utils';\nexport * from './commonTypes';\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from './core';\nexport * from './hook';\nexport * from './animation';\nexport * from './interpolation';\nexport * from './interpolateColor';\nexport * from './Easing';\nexport * from './NativeMethods';\nexport * from './Colors';\nexport * from './PropAdapters';\nexport * from './layoutReanimation';\nexport * from './utils';\nexport * from './commonTypes';\nexport * from './pluginUtils';\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
@@ -46,29 +46,33 @@ function valueUnpacker(objectToUnpack, category) {
46
46
  handleCache = global.__handleCache = new WeakMap();
47
47
  }
48
48
 
49
- if (objectToUnpack.__workletHash) {
50
- let workletFun = workletsCache.get(objectToUnpack.__workletHash);
49
+ const workletHash = objectToUnpack.__workletHash;
50
+
51
+ if (workletHash !== undefined) {
52
+ let workletFun = workletsCache.get(workletHash);
51
53
 
52
54
  if (workletFun === undefined) {
55
+ const initData = objectToUnpack.__initData;
56
+
53
57
  if (global.evalWithSourceMap) {
54
58
  // if the runtime (hermes only for now) supports loading source maps
55
59
  // we want to use the proper filename for the location as it guarantees
56
60
  // that debugger understands and loads the source code of the file where
57
61
  // the worklet is defined.
58
- workletFun = global.evalWithSourceMap('(' + objectToUnpack.asString + '\n)', objectToUnpack.__location, objectToUnpack.__sourceMap);
62
+ workletFun = global.evalWithSourceMap('(' + initData.code + '\n)', initData.location, initData.sourceMap);
59
63
  } else if (global.evalWithSourceUrl) {
60
64
  // if the runtime doesn't support loading source maps, in dev mode we
61
65
  // can pass source url when evaluating the worklet. Now, instead of using
62
66
  // the actual file location we use worklet hash, as it the allows us to
63
67
  // properly symbolicate traces (see errors.ts for details)
64
- workletFun = global.evalWithSourceUrl('(' + objectToUnpack.asString + '\n)', `worklet_${objectToUnpack.__workletHash}`);
68
+ workletFun = global.evalWithSourceUrl('(' + initData.code + '\n)', `worklet_${workletHash}`);
65
69
  } else {
66
70
  // in release we use the regular eval to save on JSI calls
67
71
  // eslint-disable-next-line no-eval
68
- workletFun = eval('(' + objectToUnpack.asString + '\n)');
72
+ workletFun = eval('(' + initData.code + '\n)');
69
73
  }
70
74
 
71
- workletsCache.set(objectToUnpack.__workletHash, workletFun);
75
+ workletsCache.set(workletHash, workletFun);
72
76
  }
73
77
 
74
78
  const functionInstance = workletFun.bind(objectToUnpack);
@@ -99,12 +103,70 @@ Possible solutions are:
99
103
  }
100
104
  }
101
105
 
106
+ function setupRequestAnimationFrame() {
107
+ 'worklet'; // Jest mocks requestAnimationFrame API and it does not like if that mock gets overridden
108
+ // so we avoid doing requestAnimationFrame batching in Jest environment.
109
+
110
+ const nativeRequestAnimationFrame = global.requestAnimationFrame;
111
+ let animationFrameCallbacks = [];
112
+ let lastNativeAnimationFrameTimestamp = -1;
113
+
114
+ global.__flushAnimationFrame = frameTimestamp => {
115
+ const currentCallbacks = animationFrameCallbacks;
116
+ animationFrameCallbacks = [];
117
+ currentCallbacks.forEach(f => f(frameTimestamp));
118
+ (0, _threads.flushImmediates)();
119
+ };
120
+
121
+ global.requestAnimationFrame = callback => {
122
+ animationFrameCallbacks.push(callback);
123
+
124
+ if (animationFrameCallbacks.length === 1) {
125
+ // We schedule native requestAnimationFrame only when the first callback
126
+ // is added and then use it to execute all the enqueued callbacks. Once
127
+ // the callbacks are run, we clear the array.
128
+ nativeRequestAnimationFrame(timestamp => {
129
+ if (lastNativeAnimationFrameTimestamp >= timestamp) {
130
+ // Make sure we only execute the callbacks once for a given frame
131
+ return;
132
+ }
133
+
134
+ lastNativeAnimationFrameTimestamp = timestamp;
135
+ global.__frameTimestamp = timestamp;
136
+
137
+ global.__flushAnimationFrame(timestamp);
138
+
139
+ global.__frameTimestamp = undefined;
140
+ });
141
+ } // Reanimated currently does not support cancelling calbacks requested with
142
+ // requestAnimationFrame. We return -1 as identifier which isn't in line
143
+ // with the spec but it should give users better clue in case they actually
144
+ // attempt to store the value returned from rAF and use it for cancelling.
145
+
146
+
147
+ return -1;
148
+ };
149
+ }
150
+
102
151
  function initializeUIRuntime() {
103
152
  _NativeReanimated.default.installCoreFunctions(callGuardDEV, valueUnpacker);
104
153
 
105
154
  const IS_JEST = (0, _PlatformChecker.isJest)();
155
+
156
+ if (IS_JEST) {
157
+ // requestAnimationFrame react-native jest's setup is incorrect as it polyfills
158
+ // the method directly using setTimeout, therefore the callback doesn't get the
159
+ // expected timestamp as the only argument: https://github.com/facebook/react-native/blob/main/jest/setup.js#L28
160
+ // We override this setup here to make sure that callbacks get the proper timestamps
161
+ // when executed. For non-jest environments we define requestAnimationFrame in setupRequestAnimationFrame
162
+ // @ts-ignore TypeScript uses Node definition for rAF, setTimeout, etc which returns a Timeout object rather than a number
163
+ global.requestAnimationFrame = callback => {
164
+ return setTimeout(() => callback(performance.now()), 0);
165
+ };
166
+ }
167
+
106
168
  const capturableConsole = console;
107
- (0, _threads.runOnUI)(() => {
169
+ (0, _threads.runOnUIImmediately)(() => {
108
170
  'worklet'; // setup error handler
109
171
 
110
172
  global.ErrorUtils = {
@@ -126,31 +188,8 @@ function initializeUIRuntime() {
126
188
  };
127
189
 
128
190
  if (!IS_JEST) {
129
- // Jest mocks requestAnimationFrame API and it does not like if that mock gets overridden
130
- // so we avoid doing requestAnimationFrame batching in Jest environment.
131
- const nativeRequestAnimationFrame = global.requestAnimationFrame;
132
- let callbacks = [];
133
-
134
- global.requestAnimationFrame = callback => {
135
- callbacks.push(callback);
136
-
137
- if (callbacks.length === 1) {
138
- // We schedule native requestAnimationFrame only when the first callback
139
- // is added and then use it to execute all the enqueued callbacks. Once
140
- // the callbacks are run, we clear the array.
141
- nativeRequestAnimationFrame(timestamp => {
142
- const currentCallbacks = callbacks;
143
- callbacks = [];
144
- currentCallbacks.forEach(f => f(timestamp));
145
- });
146
- } // Reanimated currently does not support cancelling calbacks requested with
147
- // requestAnimationFrame. We return -1 as identifier which isn't in line
148
- // with the spec but it should give users better clue in case they actually
149
- // attempt to store the value returned from rAF and use it for cancelling.
150
-
151
-
152
- return -1;
153
- };
191
+ (0, _threads.setupSetImmediate)();
192
+ setupRequestAnimationFrame();
154
193
  }
155
194
  })();
156
195
  }
@@ -1 +1 @@
1
- {"version":3,"names":["callGuardDEV","fn","args","e","global","ErrorUtils","reportFatalError","valueUnpacker","objectToUnpack","category","workletsCache","__workletsCache","handleCache","__handleCache","undefined","Map","WeakMap","__workletHash","workletFun","get","evalWithSourceMap","asString","__location","__sourceMap","evalWithSourceUrl","eval","set","functionInstance","bind","_recur","__init","value","fun","Error","__remoteFunction","initializeUIRuntime","NativeReanimatedModule","installCoreFunctions","IS_JEST","isJest","capturableConsole","console","runOnUI","error","runOnJS","reportFatalErrorOnJS","message","stack","debug","log","warn","info","nativeRequestAnimationFrame","requestAnimationFrame","callbacks","callback","push","length","timestamp","currentCallbacks","forEach","f"],"sources":["initializers.ts"],"sourcesContent":["import { reportFatalErrorOnJS } from './errors';\nimport NativeReanimatedModule from './NativeReanimated';\nimport { isJest } from './PlatformChecker';\nimport { runOnUI, runOnJS } from './threads';\n\n// callGuard is only used with debug builds\nfunction callGuardDEV<T extends Array<any>, U>(\n fn: (...args: T) => U,\n ...args: T\n): void {\n 'worklet';\n try {\n fn(...args);\n } catch (e) {\n if (global.ErrorUtils) {\n global.ErrorUtils.reportFatalError(e as Error);\n } else {\n throw e;\n }\n }\n}\n\nfunction valueUnpacker(objectToUnpack: any, category?: string): any {\n 'worklet';\n let workletsCache = global.__workletsCache;\n let handleCache = global.__handleCache;\n if (workletsCache === undefined) {\n // init\n workletsCache = global.__workletsCache = new Map();\n handleCache = global.__handleCache = new WeakMap();\n }\n if (objectToUnpack.__workletHash) {\n let workletFun = workletsCache.get(objectToUnpack.__workletHash);\n if (workletFun === undefined) {\n if (global.evalWithSourceMap) {\n // if the runtime (hermes only for now) supports loading source maps\n // we want to use the proper filename for the location as it guarantees\n // that debugger understands and loads the source code of the file where\n // the worklet is defined.\n workletFun = global.evalWithSourceMap(\n '(' + objectToUnpack.asString + '\\n)',\n objectToUnpack.__location,\n objectToUnpack.__sourceMap\n ) as (...args: any[]) => any;\n } else if (global.evalWithSourceUrl) {\n // if the runtime doesn't support loading source maps, in dev mode we\n // can pass source url when evaluating the worklet. Now, instead of using\n // the actual file location we use worklet hash, as it the allows us to\n // properly symbolicate traces (see errors.ts for details)\n workletFun = global.evalWithSourceUrl(\n '(' + objectToUnpack.asString + '\\n)',\n `worklet_${objectToUnpack.__workletHash}`\n ) as (...args: any[]) => any;\n } else {\n // in release we use the regular eval to save on JSI calls\n // eslint-disable-next-line no-eval\n workletFun = eval('(' + objectToUnpack.asString + '\\n)') as (\n ...args: any[]\n ) => any;\n }\n workletsCache.set(objectToUnpack.__workletHash, workletFun);\n }\n const functionInstance = workletFun.bind(objectToUnpack);\n objectToUnpack._recur = functionInstance;\n return functionInstance;\n } else if (objectToUnpack.__init) {\n let value = handleCache!.get(objectToUnpack);\n if (value === undefined) {\n value = objectToUnpack.__init();\n handleCache!.set(objectToUnpack, value);\n }\n return value;\n } else if (category === 'RemoteFunction') {\n const fun = () => {\n throw new Error(`Tried to synchronously call a non-worklet function on the UI thread.\n\nPossible solutions are:\n a) If you want to synchronously execute this method, mark it as a worklet\n b) If you want to execute this function on the JS thread, wrap it using \\`runOnJS\\``);\n };\n fun.__remoteFunction = objectToUnpack;\n return fun;\n } else {\n throw new Error('data type not recognized by unpack method');\n }\n}\n\nexport function initializeUIRuntime() {\n NativeReanimatedModule.installCoreFunctions(callGuardDEV, valueUnpacker);\n\n const IS_JEST = isJest();\n\n const capturableConsole = console;\n runOnUI(() => {\n 'worklet';\n // setup error handler\n global.ErrorUtils = {\n reportFatalError: (error: Error) => {\n runOnJS(reportFatalErrorOnJS)({\n message: error.message,\n stack: error.stack,\n });\n },\n };\n\n // setup console\n // @ts-ignore TypeScript doesn't like that there are missing methods in console object, but we don't provide all the methods for the UI runtime console version\n global.console = {\n debug: runOnJS(capturableConsole.debug),\n log: runOnJS(capturableConsole.log),\n warn: runOnJS(capturableConsole.warn),\n error: runOnJS(capturableConsole.error),\n info: runOnJS(capturableConsole.info),\n };\n\n if (!IS_JEST) {\n // Jest mocks requestAnimationFrame API and it does not like if that mock gets overridden\n // so we avoid doing requestAnimationFrame batching in Jest environment.\n const nativeRequestAnimationFrame = global.requestAnimationFrame;\n let callbacks: Array<(time: number) => void> = [];\n global.requestAnimationFrame = (\n callback: (timestamp: number) => void\n ): number => {\n callbacks.push(callback);\n if (callbacks.length === 1) {\n // We schedule native requestAnimationFrame only when the first callback\n // is added and then use it to execute all the enqueued callbacks. Once\n // the callbacks are run, we clear the array.\n nativeRequestAnimationFrame((timestamp) => {\n const currentCallbacks = callbacks;\n callbacks = [];\n currentCallbacks.forEach((f) => f(timestamp));\n });\n }\n // Reanimated currently does not support cancelling calbacks requested with\n // requestAnimationFrame. We return -1 as identifier which isn't in line\n // with the spec but it should give users better clue in case they actually\n // attempt to store the value returned from rAF and use it for cancelling.\n return -1;\n };\n }\n })();\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;;;AAEA;AACA,SAASA,YAAT,CACEC,EADF,EAGQ;EACN;;EADM,kCADHC,IACG;IADHA,IACG;EAAA;;EAEN,IAAI;IACFD,EAAE,CAAC,GAAGC,IAAJ,CAAF;EACD,CAFD,CAEE,OAAOC,CAAP,EAAU;IACV,IAAIC,MAAM,CAACC,UAAX,EAAuB;MACrBD,MAAM,CAACC,UAAP,CAAkBC,gBAAlB,CAAmCH,CAAnC;IACD,CAFD,MAEO;MACL,MAAMA,CAAN;IACD;EACF;AACF;;AAED,SAASI,aAAT,CAAuBC,cAAvB,EAA4CC,QAA5C,EAAoE;EAClE;;EACA,IAAIC,aAAa,GAAGN,MAAM,CAACO,eAA3B;EACA,IAAIC,WAAW,GAAGR,MAAM,CAACS,aAAzB;;EACA,IAAIH,aAAa,KAAKI,SAAtB,EAAiC;IAC/B;IACAJ,aAAa,GAAGN,MAAM,CAACO,eAAP,GAAyB,IAAII,GAAJ,EAAzC;IACAH,WAAW,GAAGR,MAAM,CAACS,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BAA3C;MACA,IAAIC,SAAwC,GAAG,EAA/C;;MACAlD,MAAM,CAACiD,qBAAP,GACEE,QAD6B,IAElB;QACXD,SAAS,CAACE,IAAV,CAAeD,QAAf;;QACA,IAAID,SAAS,CAACG,MAAV,KAAqB,CAAzB,EAA4B;UAC1B;UACA;UACA;UACAL,2BAA2B,CAAEM,SAAD,IAAe;YACzC,MAAMC,gBAAgB,GAAGL,SAAzB;YACAA,SAAS,GAAG,EAAZ;YACAK,gBAAgB,CAACC,OAAjB,CAA0BC,CAAD,IAAOA,CAAC,CAACH,SAAD,CAAjC;UACD,CAJ0B,CAA3B;QAKD,CAXU,CAYX;QACA;QACA;QACA;;;QACA,OAAO,CAAC,CAAR;MACD,CAnBD;IAoBD;EACF,CAhDD;AAiDD"}
1
+ {"version":3,"names":["callGuardDEV","fn","args","e","global","ErrorUtils","reportFatalError","valueUnpacker","objectToUnpack","category","workletsCache","__workletsCache","handleCache","__handleCache","undefined","Map","WeakMap","workletHash","__workletHash","workletFun","get","initData","__initData","evalWithSourceMap","code","location","sourceMap","evalWithSourceUrl","eval","set","functionInstance","bind","_recur","__init","value","fun","Error","__remoteFunction","setupRequestAnimationFrame","nativeRequestAnimationFrame","requestAnimationFrame","animationFrameCallbacks","lastNativeAnimationFrameTimestamp","__flushAnimationFrame","frameTimestamp","currentCallbacks","forEach","f","flushImmediates","callback","push","length","timestamp","__frameTimestamp","initializeUIRuntime","NativeReanimatedModule","installCoreFunctions","IS_JEST","isJest","setTimeout","performance","now","capturableConsole","console","runOnUIImmediately","error","runOnJS","reportFatalErrorOnJS","message","stack","debug","log","warn","info","setupSetImmediate"],"sources":["initializers.ts"],"sourcesContent":["import { reportFatalErrorOnJS } from './errors';\nimport NativeReanimatedModule from './NativeReanimated';\nimport { isJest } from './PlatformChecker';\nimport {\n runOnJS,\n setupSetImmediate,\n flushImmediates,\n runOnUIImmediately,\n} from './threads';\n\n// callGuard is only used with debug builds\nfunction callGuardDEV<T extends Array<any>, U>(\n fn: (...args: T) => U,\n ...args: T\n): void {\n 'worklet';\n try {\n fn(...args);\n } catch (e) {\n if (global.ErrorUtils) {\n global.ErrorUtils.reportFatalError(e as Error);\n } else {\n throw e;\n }\n }\n}\n\nfunction valueUnpacker(objectToUnpack: any, category?: string): any {\n 'worklet';\n let workletsCache = global.__workletsCache;\n let handleCache = global.__handleCache;\n if (workletsCache === undefined) {\n // init\n workletsCache = global.__workletsCache = new Map();\n handleCache = global.__handleCache = new WeakMap();\n }\n const workletHash = objectToUnpack.__workletHash;\n if (workletHash !== undefined) {\n let workletFun = workletsCache.get(workletHash);\n if (workletFun === undefined) {\n const initData = objectToUnpack.__initData;\n if (global.evalWithSourceMap) {\n // if the runtime (hermes only for now) supports loading source maps\n // we want to use the proper filename for the location as it guarantees\n // that debugger understands and loads the source code of the file where\n // the worklet is defined.\n workletFun = global.evalWithSourceMap(\n '(' + initData.code + '\\n)',\n initData.location,\n initData.sourceMap\n ) as (...args: any[]) => any;\n } else if (global.evalWithSourceUrl) {\n // if the runtime doesn't support loading source maps, in dev mode we\n // can pass source url when evaluating the worklet. Now, instead of using\n // the actual file location we use worklet hash, as it the allows us to\n // properly symbolicate traces (see errors.ts for details)\n workletFun = global.evalWithSourceUrl(\n '(' + initData.code + '\\n)',\n `worklet_${workletHash}`\n ) as (...args: any[]) => any;\n } else {\n // in release we use the regular eval to save on JSI calls\n // eslint-disable-next-line no-eval\n workletFun = eval('(' + initData.code + '\\n)') as (\n ...args: any[]\n ) => any;\n }\n workletsCache.set(workletHash, workletFun);\n }\n const functionInstance = workletFun.bind(objectToUnpack);\n objectToUnpack._recur = functionInstance;\n return functionInstance;\n } else if (objectToUnpack.__init) {\n let value = handleCache!.get(objectToUnpack);\n if (value === undefined) {\n value = objectToUnpack.__init();\n handleCache!.set(objectToUnpack, value);\n }\n return value;\n } else if (category === 'RemoteFunction') {\n const fun = () => {\n throw new Error(`Tried to synchronously call a non-worklet function on the UI thread.\n\nPossible solutions are:\n a) If you want to synchronously execute this method, mark it as a worklet\n b) If you want to execute this function on the JS thread, wrap it using \\`runOnJS\\``);\n };\n fun.__remoteFunction = objectToUnpack;\n return fun;\n } else {\n throw new Error('data type not recognized by unpack method');\n }\n}\n\nfunction setupRequestAnimationFrame() {\n 'worklet';\n\n // Jest mocks requestAnimationFrame API and it does not like if that mock gets overridden\n // so we avoid doing requestAnimationFrame batching in Jest environment.\n const nativeRequestAnimationFrame = global.requestAnimationFrame;\n\n let animationFrameCallbacks: Array<(timestamp: number) => void> = [];\n let lastNativeAnimationFrameTimestamp = -1;\n\n global.__flushAnimationFrame = (frameTimestamp: number) => {\n const currentCallbacks = animationFrameCallbacks;\n animationFrameCallbacks = [];\n currentCallbacks.forEach((f) => f(frameTimestamp));\n flushImmediates();\n };\n\n global.requestAnimationFrame = (\n callback: (timestamp: number) => void\n ): number => {\n animationFrameCallbacks.push(callback);\n if (animationFrameCallbacks.length === 1) {\n // We schedule native requestAnimationFrame only when the first callback\n // is added and then use it to execute all the enqueued callbacks. Once\n // the callbacks are run, we clear the array.\n nativeRequestAnimationFrame((timestamp) => {\n if (lastNativeAnimationFrameTimestamp >= timestamp) {\n // Make sure we only execute the callbacks once for a given frame\n return;\n }\n lastNativeAnimationFrameTimestamp = timestamp;\n global.__frameTimestamp = timestamp;\n global.__flushAnimationFrame(timestamp);\n global.__frameTimestamp = undefined;\n });\n }\n // Reanimated currently does not support cancelling calbacks requested with\n // requestAnimationFrame. We return -1 as identifier which isn't in line\n // with the spec but it should give users better clue in case they actually\n // attempt to store the value returned from rAF and use it for cancelling.\n return -1;\n };\n}\n\nexport function initializeUIRuntime() {\n NativeReanimatedModule.installCoreFunctions(callGuardDEV, valueUnpacker);\n\n const IS_JEST = isJest();\n\n if (IS_JEST) {\n // requestAnimationFrame react-native jest's setup is incorrect as it polyfills\n // the method directly using setTimeout, therefore the callback doesn't get the\n // expected timestamp as the only argument: https://github.com/facebook/react-native/blob/main/jest/setup.js#L28\n // We override this setup here to make sure that callbacks get the proper timestamps\n // when executed. For non-jest environments we define requestAnimationFrame in setupRequestAnimationFrame\n // @ts-ignore TypeScript uses Node definition for rAF, setTimeout, etc which returns a Timeout object rather than a number\n global.requestAnimationFrame = (callback: (timestamp: number) => void) => {\n return setTimeout(() => callback(performance.now()), 0);\n };\n }\n\n const capturableConsole = console;\n runOnUIImmediately(() => {\n 'worklet';\n // setup error handler\n global.ErrorUtils = {\n reportFatalError: (error: Error) => {\n runOnJS(reportFatalErrorOnJS)({\n message: error.message,\n stack: error.stack,\n });\n },\n };\n\n // setup console\n // @ts-ignore TypeScript doesn't like that there are missing methods in console object, but we don't provide all the methods for the UI runtime console version\n global.console = {\n debug: runOnJS(capturableConsole.debug),\n log: runOnJS(capturableConsole.log),\n warn: runOnJS(capturableConsole.warn),\n error: runOnJS(capturableConsole.error),\n info: runOnJS(capturableConsole.info),\n };\n\n if (!IS_JEST) {\n setupSetImmediate();\n setupRequestAnimationFrame();\n }\n })();\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;;;AAOA;AACA,SAASA,YAAT,CACEC,EADF,EAGQ;EACN;;EADM,kCADHC,IACG;IADHA,IACG;EAAA;;EAEN,IAAI;IACFD,EAAE,CAAC,GAAGC,IAAJ,CAAF;EACD,CAFD,CAEE,OAAOC,CAAP,EAAU;IACV,IAAIC,MAAM,CAACC,UAAX,EAAuB;MACrBD,MAAM,CAACC,UAAP,CAAkBC,gBAAlB,CAAmCH,CAAnC;IACD,CAFD,MAEO;MACL,MAAMA,CAAN;IACD;EACF;AACF;;AAED,SAASI,aAAT,CAAuBC,cAAvB,EAA4CC,QAA5C,EAAoE;EAClE;;EACA,IAAIC,aAAa,GAAGN,MAAM,CAACO,eAA3B;EACA,IAAIC,WAAW,GAAGR,MAAM,CAACS,aAAzB;;EACA,IAAIH,aAAa,KAAKI,SAAtB,EAAiC;IAC/B;IACAJ,aAAa,GAAGN,MAAM,CAACO,eAAP,GAAyB,IAAII,GAAJ,EAAzC;IACAH,WAAW,GAAGR,M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+21,93 @@ const Extrapolate = {
21
21
  };
22
22
  exports.Extrapolate = Extrapolate;
23
23
 
24
- const interpolateColorsHSV = (value, inputRange, colors) => {
24
+ const interpolateColorsHSV = (value, inputRange, colors, options) => {
25
25
  'worklet';
26
26
 
27
- const h = (0, _interpolation.interpolate)(value, inputRange, colors.h, Extrapolate.CLAMP);
27
+ let h = 0;
28
+ const {
29
+ useCorrectedHSVInterpolation = true
30
+ } = options;
31
+
32
+ if (useCorrectedHSVInterpolation) {
33
+ // if the difference between hues in a range is > 180 deg
34
+ // then move the hue at the right end of the range +/- 360 deg
35
+ // and add the next point in the original place + 0.00001 with original hue
36
+ // to not break the next range
37
+ const correctedInputRange = [inputRange[0]];
38
+ const originalH = colors.h;
39
+ const correctedH = [originalH[0]];
40
+
41
+ for (let i = 1; i < originalH.length; ++i) {
42
+ const d = originalH[i] - originalH[i - 1];
43
+
44
+ if (originalH[i] > originalH[i - 1] && d > 0.5) {
45
+ correctedInputRange.push(inputRange[i]);
46
+ correctedInputRange.push(inputRange[i] + 0.00001);
47
+ correctedH.push(originalH[i] - 1);
48
+ correctedH.push(originalH[i]);
49
+ } else if (originalH[i] < originalH[i - 1] && d < -0.5) {
50
+ correctedInputRange.push(inputRange[i]);
51
+ correctedInputRange.push(inputRange[i] + 0.00001);
52
+ correctedH.push(originalH[i] + 1);
53
+ correctedH.push(originalH[i]);
54
+ } else {
55
+ correctedInputRange.push(inputRange[i]);
56
+ correctedH.push(originalH[i]);
57
+ }
58
+ }
59
+
60
+ h = ((0, _interpolation.interpolate)(value, correctedInputRange, correctedH, Extrapolate.CLAMP) + 1) % 1;
61
+ } else {
62
+ h = (0, _interpolation.interpolate)(value, inputRange, colors.h, Extrapolate.CLAMP);
63
+ }
64
+
28
65
  const s = (0, _interpolation.interpolate)(value, inputRange, colors.s, Extrapolate.CLAMP);
29
66
  const v = (0, _interpolation.interpolate)(value, inputRange, colors.v, Extrapolate.CLAMP);
30
- return (0, _Colors.hsvToColor)(h, s, v);
67
+ const a = (0, _interpolation.interpolate)(value, inputRange, colors.a, Extrapolate.CLAMP);
68
+ return (0, _Colors.hsvToColor)(h, s, v, a);
31
69
  };
32
70
 
33
- const interpolateColorsRGB = (value, inputRange, colors) => {
71
+ const toLinearSpace = (x, gamma) => {
34
72
  'worklet';
35
73
 
36
- const r = (0, _interpolation.interpolate)(value, inputRange, colors.r, Extrapolate.CLAMP);
37
- const g = (0, _interpolation.interpolate)(value, inputRange, colors.g, Extrapolate.CLAMP);
38
- const b = (0, _interpolation.interpolate)(value, inputRange, colors.b, Extrapolate.CLAMP);
74
+ return x.map(v => Math.pow(v / 255, gamma));
75
+ };
76
+
77
+ const toGammaSpace = (x, gamma) => {
78
+ 'worklet';
79
+
80
+ return Math.round(Math.pow(x, 1 / gamma) * 255);
81
+ };
82
+
83
+ const interpolateColorsRGB = (value, inputRange, colors, options) => {
84
+ 'worklet';
85
+
86
+ const {
87
+ gamma = 2.2
88
+ } = options;
89
+ let {
90
+ r: outputR,
91
+ g: outputG,
92
+ b: outputB
93
+ } = colors;
94
+
95
+ if (gamma !== 1) {
96
+ outputR = toLinearSpace(outputR, gamma);
97
+ outputG = toLinearSpace(outputG, gamma);
98
+ outputB = toLinearSpace(outputB, gamma);
99
+ }
100
+
101
+ const r = (0, _interpolation.interpolate)(value, inputRange, outputR, Extrapolate.CLAMP);
102
+ const g = (0, _interpolation.interpolate)(value, inputRange, outputG, Extrapolate.CLAMP);
103
+ const b = (0, _interpolation.interpolate)(value, inputRange, outputB, Extrapolate.CLAMP);
39
104
  const a = (0, _interpolation.interpolate)(value, inputRange, colors.a, Extrapolate.CLAMP);
40
- return (0, _Colors.rgbaColor)(r, g, b, a);
105
+
106
+ if (gamma === 1) {
107
+ return (0, _Colors.rgbaColor)(r, g, b, a);
108
+ }
109
+
110
+ return (0, _Colors.rgbaColor)(toGammaSpace(r, gamma), toGammaSpace(g, gamma), toGammaSpace(b, gamma), a);
41
111
  };
42
112
 
43
113
  const getInterpolateRGB = colors => {
@@ -74,22 +144,26 @@ const getInterpolateHSV = colors => {
74
144
  const h = [];
75
145
  const s = [];
76
146
  const v = [];
147
+ const a = [];
77
148
 
78
149
  for (let i = 0; i < colors.length; ++i) {
79
150
  const color = colors[i];
80
- const processedColor = (0, _Colors.RGBtoHSV)((0, _Colors.processColor)(color));
151
+ const processedColor = (0, _Colors.processColor)(color);
81
152
 
82
- if (processedColor) {
83
- h.push(processedColor.h);
84
- s.push(processedColor.s);
85
- v.push(processedColor.v);
153
+ if (typeof processedColor === 'number') {
154
+ const processedHSVColor = (0, _Colors.RGBtoHSV)((0, _Colors.red)(processedColor), (0, _Colors.green)(processedColor), (0, _Colors.blue)(processedColor));
155
+ h.push(processedHSVColor.h);
156
+ s.push(processedHSVColor.s);
157
+ v.push(processedHSVColor.v);
158
+ a.push((0, _Colors.opacity)(processedColor));
86
159
  }
87
160
  }
88
161
 
89
162
  return {
90
163
  h,
91
164
  s,
92
- v
165
+ v,
166
+ a
93
167
  };
94
168
  };
95
169
 
@@ -97,11 +171,12 @@ const interpolateColor = function (value, inputRange, outputRange) {
97
171
  'worklet';
98
172
 
99
173
  let colorSpace = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'RGB';
174
+ let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
100
175
 
101
176
  if (colorSpace === 'HSV') {
102
- return interpolateColorsHSV(value, inputRange, getInterpolateHSV(outputRange));
177
+ return interpolateColorsHSV(value, inputRange, getInterpolateHSV(outputRange), options);
103
178
  } else if (colorSpace === 'RGB') {
104
- return interpolateColorsRGB(value, inputRange, getInterpolateRGB(outputRange));
179
+ return interpolateColorsRGB(value, inputRange, getInterpolateRGB(outputRange), options);
105
180
  }
106
181
 
107
182
  throw new Error(`Invalid color space provided: ${colorSpace}. Supported values are: ['RGB', 'HSV']`);
@@ -118,11 +193,13 @@ exports.ColorSpace = ColorSpace;
118
193
 
119
194
  function useInterpolateConfig(inputRange, outputRange) {
120
195
  let colorSpace = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ColorSpace.RGB;
196
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
121
197
  return (0, _useSharedValue.useSharedValue)({
122
198
  inputRange,
123
199
  outputRange,
124
200
  colorSpace,
125
- cache: (0, _core.makeMutable)(null)
201
+ cache: (0, _core.makeMutable)(null),
202
+ options
126
203
  });
127
204
  }
128
205
 
@@ -137,14 +214,14 @@ const interpolateSharableColor = (value, interpolateConfig) => {
137
214
  interpolateConfig.value.cache.value = colors;
138
215
  }
139
216
 
140
- return interpolateColorsRGB(value, interpolateConfig.value.inputRange, colors);
217
+ return interpolateColorsRGB(value, interpolateConfig.value.inputRange, colors, interpolateConfig.value.options);
141
218
  } else if (interpolateConfig.value.colorSpace === ColorSpace.HSV) {
142
219
  if (!colors) {
143
220
  colors = getInterpolateHSV(interpolateConfig.value.outputRange);
144
221
  interpolateConfig.value.cache.value = colors;
145
222
  }
146
223
 
147
- return interpolateColorsHSV(value, interpolateConfig.value.inputRange, colors);
224
+ return interpolateColorsHSV(value, interpolateConfig.value.inputRange, colors, interpolateConfig.value.options);
148
225
  }
149
226
 
150
227
  throw new Error(`Invalid color space provided: ${interpolateConfig.value.colorSpace}. Supported values are: ['RGB', 'HSV']`);