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
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useRef","initialUpdaterRun","makeMutable","startMapper","stopMapper","useDerivedValue","processor","dependencies","initRef","inputs","Object","values","_closure","undefined","__workletHash","push","current","sharedValue","fun","value","mapperId"],"sources":["useDerivedValue.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { initialUpdaterRun } from '../animation';\nimport { BasicWorkletFunction, SharedValue } from '../commonTypes';\nimport { makeMutable, startMapper, stopMapper } from '../core';\nimport { DependencyList } from './commonTypes';\n\nexport type DerivedValue<T> = Readonly<SharedValue<T>>;\n\nexport function useDerivedValue<T>(\n processor: BasicWorkletFunction<T>,\n dependencies: DependencyList\n): DerivedValue<T> {\n const initRef = useRef<SharedValue<T> | null>(null);\n const inputs = Object.values(processor._closure ?? {});\n\n // build dependencies\n if (dependencies === undefined) {\n dependencies = [...inputs, processor.__workletHash];\n } else {\n dependencies.push(processor.__workletHash);\n }\n\n if (initRef.current === null) {\n initRef.current = makeMutable(initialUpdaterRun(processor));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const sharedValue: SharedValue<T> = initRef.current!;\n\n useEffect(() => {\n const fun = () => {\n 'worklet';\n sharedValue.value = processor();\n };\n const mapperId = startMapper(fun, inputs, [sharedValue]);\n return () => {\n stopMapper(mapperId);\n };\n }, dependencies);\n\n useEffect(() => {\n return () => {\n initRef.current = null;\n };\n }, []);\n\n return sharedValue;\n}\n"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,MAApB,QAAkC,OAAlC;AACA,SAASC,iBAAT,QAAkC,cAAlC;AAEA,SAASC,WAAT,EAAsBC,WAAtB,EAAmCC,UAAnC,QAAqD,SAArD;AAKA,OAAO,SAASC,eAAT,CACLC,SADK,EAELC,YAFK,EAGY;EACjB,MAAMC,OAAO,GAAGR,MAAM,CAAwB,IAAxB,CAAtB;EACA,MAAMS,MAAM,GAAGC,MAAM,CAACC,MAAP,CAAcL,SAAS,CAACM,QAAV,IAAsB,EAApC,CAAf,CAFiB,CAIjB;;EACA,IAAIL,YAAY,KAAKM,SAArB,EAAgC;IAC9BN,YAAY,GAAG,CAAC,GAAGE,MAAJ,EAAYH,SAAS,CAACQ,aAAtB,CAAf;EACD,CAFD,MAEO;IACLP,YAAY,CAACQ,IAAb,CAAkBT,SAAS,CAACQ,aAA5B;EACD;;EAED,IAAIN,OAAO,CAACQ,OAAR,KAAoB,IAAxB,EAA8B;IAC5BR,OAAO,CAACQ,OAAR,GAAkBd,WAAW,CAACD,iBAAiB,CAACK,SAAD,CAAlB,CAA7B;EACD,CAbgB,CAejB;;;EACA,MAAMW,WAA2B,GAAGT,OAAO,CAACQ,OAA5C;EAEAjB,SAAS,CAAC,MAAM;IACd,MAAMmB,GAAG,GAAG,MAAM;MAChB;;MACAD,WAAW,CAACE,KAAZ,GAAoBb,SAAS,EAA7B;IACD,CAHD;;IAIA,MAAMc,QAAQ,GAAGjB,WAAW,CAACe,GAAD,EAAMT,MAAN,EAAc,CAACQ,WAAD,CAAd,CAA5B;IACA,OAAO,MAAM;MACXb,UAAU,CAACgB,QAAD,CAAV;IACD,CAFD;EAGD,CATQ,EASNb,YATM,CAAT;EAWAR,SAAS,CAAC,MAAM;IACd,OAAO,MAAM;MACXS,OAAO,CAACQ,OAAR,GAAkB,IAAlB;IACD,CAFD;EAGD,CAJQ,EAIN,EAJM,CAAT;EAMA,OAAOC,WAAP;AACD"}
1
+ {"version":3,"names":["useEffect","useRef","initialUpdaterRun","makeMutable","startMapper","stopMapper","shouldBeUseWeb","useDerivedValue","processor","dependencies","initRef","inputs","Object","values","_closure","length","undefined","__workletHash","push","current","sharedValue","fun","value","mapperId"],"sources":["useDerivedValue.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { initialUpdaterRun } from '../animation';\nimport { BasicWorkletFunction, SharedValue } from '../commonTypes';\nimport { makeMutable, startMapper, stopMapper } from '../core';\nimport { DependencyList } from './commonTypes';\nimport { shouldBeUseWeb } from '../PlatformChecker';\n\nexport type DerivedValue<T> = Readonly<SharedValue<T>>;\n\nexport function useDerivedValue<T>(\n processor: BasicWorkletFunction<T>,\n dependencies: DependencyList\n): DerivedValue<T> {\n const initRef = useRef<SharedValue<T> | null>(null);\n let inputs = Object.values(processor._closure ?? {});\n if (shouldBeUseWeb()) {\n if (!inputs.length && dependencies?.length) {\n // let web work without a Babel/SWC plugin\n inputs = dependencies;\n }\n }\n\n // build dependencies\n if (dependencies === undefined) {\n dependencies = [...inputs, processor.__workletHash];\n } else {\n dependencies.push(processor.__workletHash);\n }\n\n if (initRef.current === null) {\n initRef.current = makeMutable(initialUpdaterRun(processor));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const sharedValue: SharedValue<T> = initRef.current!;\n\n useEffect(() => {\n const fun = () => {\n 'worklet';\n sharedValue.value = processor();\n };\n const mapperId = startMapper(fun, inputs, [sharedValue]);\n return () => {\n stopMapper(mapperId);\n };\n }, dependencies);\n\n useEffect(() => {\n return () => {\n initRef.current = null;\n };\n }, []);\n\n return sharedValue;\n}\n"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,MAApB,QAAkC,OAAlC;AACA,SAASC,iBAAT,QAAkC,cAAlC;AAEA,SAASC,WAAT,EAAsBC,WAAtB,EAAmCC,UAAnC,QAAqD,SAArD;AAEA,SAASC,cAAT,QAA+B,oBAA/B;AAIA,OAAO,SAASC,eAAT,CACLC,SADK,EAELC,YAFK,EAGY;EACjB,MAAMC,OAAO,GAAGT,MAAM,CAAwB,IAAxB,CAAtB;EACA,IAAIU,MAAM,GAAGC,MAAM,CAACC,MAAP,CAAcL,SAAS,CAACM,QAAV,IAAsB,EAApC,CAAb;;EACA,IAAIR,cAAc,EAAlB,EAAsB;IAAA;;IACpB,IAAI,CAACK,MAAM,CAACI,MAAR,qBAAkBN,YAAlB,0CAAkB,cAAcM,MAApC,EAA4C;MAC1C;MACAJ,MAAM,GAAGF,YAAT;IACD;EACF,CARgB,CAUjB;;;EACA,IAAIA,YAAY,KAAKO,SAArB,EAAgC;IAC9BP,YAAY,GAAG,CAAC,GAAGE,MAAJ,EAAYH,SAAS,CAACS,aAAtB,CAAf;EACD,CAFD,MAEO;IACLR,YAAY,CAACS,IAAb,CAAkBV,SAAS,CAACS,aAA5B;EACD;;EAED,IAAIP,OAAO,CAACS,OAAR,KAAoB,IAAxB,EAA8B;IAC5BT,OAAO,CAACS,OAAR,GAAkBhB,WAAW,CAACD,iBAAiB,CAACM,SAAD,CAAlB,CAA7B;EACD,CAnBgB,CAqBjB;;;EACA,MAAMY,WAA2B,GAAGV,OAAO,CAACS,OAA5C;EAEAnB,SAAS,CAAC,MAAM;IACd,MAAMqB,GAAG,GAAG,MAAM;MAChB;;MACAD,WAAW,CAACE,KAAZ,GAAoBd,SAAS,EAA7B;IACD,CAHD;;IAIA,MAAMe,QAAQ,GAAGnB,WAAW,CAACiB,GAAD,EAAMV,MAAN,EAAc,CAACS,WAAD,CAAd,CAA5B;IACA,OAAO,MAAM;MACXf,UAAU,CAACkB,QAAD,CAAV;IACD,CAFD;EAGD,CATQ,EASNd,YATM,CAAT;EAWAT,SAAS,CAAC,MAAM;IACd,OAAO,MAAM;MACXU,OAAO,CAACS,OAAR,GAAkB,IAAlB;IACD,CAFD;EAGD,CAJQ,EAIN,EAJM,CAAT;EAMA,OAAOC,WAAP;AACD"}
@@ -2,14 +2,14 @@ import { useEffect, useRef } from 'react';
2
2
  import { findNodeHandle } from 'react-native';
3
3
  import { useEvent } from './utils';
4
4
  import { useSharedValue } from './useSharedValue';
5
- const subscribeForEvents = ['onScroll', 'onScrollBeginDrag', 'onScrollEndDrag', 'onMomentumScrollBegin', 'onMomentumScrollEnd'];
5
+ const scrollEventNames = ['onScroll', 'onScrollBeginDrag', 'onScrollEndDrag', 'onMomentumScrollBegin', 'onMomentumScrollEnd'];
6
6
  export function useScrollViewOffset(aref) {
7
7
  const offsetRef = useRef(useSharedValue(0));
8
8
  const event = useEvent(event => {
9
9
  'worklet';
10
10
 
11
11
  offsetRef.current.value = event.contentOffset.x === 0 ? event.contentOffset.y : event.contentOffset.x;
12
- }, subscribeForEvents);
12
+ }, scrollEventNames);
13
13
  useEffect(() => {
14
14
  var _event$current;
15
15
 
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useRef","findNodeHandle","useEvent","useSharedValue","subscribeForEvents","useScrollViewOffset","aref","offsetRef","event","current","value","contentOffset","x","y","viewTag","registerForEvents"],"sources":["useScrollViewOffset.ts"],"sourcesContent":["import { RefObject, useEffect, useRef } from 'react';\n\nimport type Animated from 'react-native-reanimated';\nimport { ScrollEvent } from './useAnimatedScrollHandler';\nimport { SharedValue } from '../commonTypes';\nimport { findNodeHandle } from 'react-native';\nimport { useEvent } from './utils';\nimport { useSharedValue } from './useSharedValue';\n\nconst subscribeForEvents = [\n 'onScroll',\n 'onScrollBeginDrag',\n 'onScrollEndDrag',\n 'onMomentumScrollBegin',\n 'onMomentumScrollEnd',\n];\n\nexport function useScrollViewOffset(\n aref: RefObject<Animated.ScrollView>\n): SharedValue<number> {\n const offsetRef = useRef(useSharedValue(0));\n\n const event = useEvent<ScrollEvent>((event: ScrollEvent) => {\n 'worklet';\n offsetRef.current.value =\n event.contentOffset.x === 0\n ? event.contentOffset.y\n : event.contentOffset.x;\n }, subscribeForEvents);\n\n useEffect(() => {\n const viewTag = findNodeHandle(aref.current);\n event.current?.registerForEvents(viewTag as number);\n }, [aref.current]);\n\n return offsetRef.current;\n}\n"],"mappings":"AAAA,SAAoBA,SAApB,EAA+BC,MAA/B,QAA6C,OAA7C;AAKA,SAASC,cAAT,QAA+B,cAA/B;AACA,SAASC,QAAT,QAAyB,SAAzB;AACA,SAASC,cAAT,QAA+B,kBAA/B;AAEA,MAAMC,kBAAkB,GAAG,CACzB,UADyB,EAEzB,mBAFyB,EAGzB,iBAHyB,EAIzB,uBAJyB,EAKzB,qBALyB,CAA3B;AAQA,OAAO,SAASC,mBAAT,CACLC,IADK,EAEgB;EACrB,MAAMC,SAAS,GAAGP,MAAM,CAACG,cAAc,CAAC,CAAD,CAAf,CAAxB;EAEA,MAAMK,KAAK,GAAGN,QAAQ,CAAeM,KAAD,IAAwB;IAC1D;;IACAD,SAAS,CAACE,OAAV,CAAkBC,KAAlB,GACEF,KAAK,CAACG,aAAN,CAAoBC,CAApB,KAA0B,CAA1B,GACIJ,KAAK,CAACG,aAAN,CAAoBE,CADxB,GAEIL,KAAK,CAACG,aAAN,CAAoBC,CAH1B;EAID,CANqB,EAMnBR,kBANmB,CAAtB;EAQAL,SAAS,CAAC,MAAM;IAAA;;IACd,MAAMe,OAAO,GAAGb,cAAc,CAACK,IAAI,CAACG,OAAN,CAA9B;IACA,kBAAAD,KAAK,CAACC,OAAN,kEAAeM,iBAAf,CAAiCD,OAAjC;EACD,CAHQ,EAGN,CAACR,IAAI,CAACG,OAAN,CAHM,CAAT;EAKA,OAAOF,SAAS,CAACE,OAAjB;AACD"}
1
+ {"version":3,"names":["useEffect","useRef","findNodeHandle","useEvent","useSharedValue","scrollEventNames","useScrollViewOffset","aref","offsetRef","event","current","value","contentOffset","x","y","viewTag","registerForEvents"],"sources":["useScrollViewOffset.ts"],"sourcesContent":["import { RefObject, useEffect, useRef } from 'react';\n\nimport type Animated from 'react-native-reanimated';\nimport { ScrollEvent } from './useAnimatedScrollHandler';\nimport { SharedValue } from '../commonTypes';\nimport { findNodeHandle } from 'react-native';\nimport { useEvent } from './utils';\nimport { useSharedValue } from './useSharedValue';\n\nconst scrollEventNames = [\n 'onScroll',\n 'onScrollBeginDrag',\n 'onScrollEndDrag',\n 'onMomentumScrollBegin',\n 'onMomentumScrollEnd',\n];\n\nexport function useScrollViewOffset(\n aref: RefObject<Animated.ScrollView>\n): SharedValue<number> {\n const offsetRef = useRef(useSharedValue(0));\n\n const event = useEvent<ScrollEvent>((event: ScrollEvent) => {\n 'worklet';\n offsetRef.current.value =\n event.contentOffset.x === 0\n ? event.contentOffset.y\n : event.contentOffset.x;\n }, scrollEventNames);\n\n useEffect(() => {\n const viewTag = findNodeHandle(aref.current);\n event.current?.registerForEvents(viewTag as number);\n }, [aref.current]);\n\n return offsetRef.current;\n}\n"],"mappings":"AAAA,SAAoBA,SAApB,EAA+BC,MAA/B,QAA6C,OAA7C;AAKA,SAASC,cAAT,QAA+B,cAA/B;AACA,SAASC,QAAT,QAAyB,SAAzB;AACA,SAASC,cAAT,QAA+B,kBAA/B;AAEA,MAAMC,gBAAgB,GAAG,CACvB,UADuB,EAEvB,mBAFuB,EAGvB,iBAHuB,EAIvB,uBAJuB,EAKvB,qBALuB,CAAzB;AAQA,OAAO,SAASC,mBAAT,CACLC,IADK,EAEgB;EACrB,MAAMC,SAAS,GAAGP,MAAM,CAACG,cAAc,CAAC,CAAD,CAAf,CAAxB;EAEA,MAAMK,KAAK,GAAGN,QAAQ,CAAeM,KAAD,IAAwB;IAC1D;;IACAD,SAAS,CAACE,OAAV,CAAkBC,KAAlB,GACEF,KAAK,CAACG,aAAN,CAAoBC,CAApB,KAA0B,CAA1B,GACIJ,KAAK,CAACG,aAAN,CAAoBE,CADxB,GAEIL,KAAK,CAACG,aAAN,CAAoBC,CAH1B;EAID,CANqB,EAMnBR,gBANmB,CAAtB;EAQAL,SAAS,CAAC,MAAM;IAAA;;IACd,MAAMe,OAAO,GAAGb,cAAc,CAACK,IAAI,CAACG,OAAN,CAA9B;IACA,kBAAAD,KAAK,CAACC,OAAN,kEAAeM,iBAAf,CAAiCD,OAAjC;EACD,CAHQ,EAGN,CAACR,IAAI,CAACG,OAAN,CAHM,CAAT;EAKA,OAAOF,SAAS,CAACE,OAAjB;AACD"}
@@ -120,81 +120,38 @@ export function parseColors(updates) {
120
120
  }
121
121
  }
122
122
  }
123
- export function canApplyOptimalisation(upadterFn) {
124
- const FUNCTIONLESS_FLAG = 0b00000001;
125
- const STATEMENTLESS_FLAG = 0b00000010; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
126
-
127
- const optimalization = upadterFn.__optimalization;
128
- return optimalization & FUNCTIONLESS_FLAG && optimalization & STATEMENTLESS_FLAG;
129
- }
130
123
  export function isAnimated(prop) {
131
124
  'worklet';
132
125
 
133
- const propsToCheck = [prop];
134
-
135
- while (propsToCheck.length > 0) {
136
- const currentProp = propsToCheck.pop();
137
-
138
- if (Array.isArray(currentProp)) {
139
- for (const item of currentProp) {
140
- propsToCheck.push(item);
141
- }
142
- } else if ((currentProp === null || currentProp === void 0 ? void 0 : currentProp.onFrame) !== undefined) {
126
+ if (Array.isArray(prop)) {
127
+ return prop.some(isAnimated);
128
+ } else if (typeof prop === 'object') {
129
+ if (prop.onFrame !== undefined) {
143
130
  return true;
144
- } else if (typeof currentProp === 'object') {
145
- for (const item of Object.values(currentProp)) {
146
- propsToCheck.push(item);
147
- }
148
- } // if none of the above, it's not the animated prop, check next one
149
-
150
- } // when none of the props were animated return false
151
-
152
-
153
- return false;
154
- }
155
- export function styleDiff(oldStyle, newStyle) {
156
- 'worklet';
157
-
158
- const diff = {};
159
-
160
- for (const key in oldStyle) {
161
- if (newStyle[key] === undefined) {
162
- diff[key] = null;
163
- }
164
- }
165
-
166
- for (const key in newStyle) {
167
- const value = newStyle[key];
168
- const oldValue = oldStyle[key];
169
-
170
- if (isAnimated(value)) {
171
- // do nothing
172
- continue;
173
- }
174
-
175
- if (oldValue !== value) {
176
- diff[key] = value;
131
+ } else {
132
+ return Object.values(prop).some(isAnimated);
177
133
  }
178
134
  }
179
135
 
180
- return diff;
136
+ return false;
181
137
  }
182
- export function getStyleWithoutAnimations(newStyle) {
138
+ export function shallowEqual(a, b) {
183
139
  'worklet';
184
140
 
185
- const diff = {};
141
+ const aKeys = Object.keys(a);
142
+ const bKeys = Object.keys(b);
186
143
 
187
- for (const key in newStyle) {
188
- const value = newStyle[key];
144
+ if (aKeys.length !== bKeys.length) {
145
+ return false;
146
+ }
189
147
 
190
- if (isAnimated(value)) {
191
- continue;
148
+ for (let i = 0; i < aKeys.length; i++) {
149
+ if (a[aKeys[i]] !== b[aKeys[i]]) {
150
+ return false;
192
151
  }
193
-
194
- diff[key] = value;
195
152
  }
196
153
 
197
- return diff;
154
+ return true;
198
155
  }
199
156
  export const validateAnimatedStyles = styles => {
200
157
  'worklet';
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useRef","processColor","makeRemote","isWeb","isJest","colorProps","WorkletEventHandler","useEvent","handler","eventNames","rebuild","initRef","current","updateWorklet","useHandler","handlers","dependencies","context","savedDependencies","buildDependencies","doDependenciesDiffer","areDependenciesEqual","useWeb","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","key","has","parseColors","indexOf","processedColor","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,SAA2BA,SAA3B,EAAsCC,MAAtC,QAAoD,OAApD;AACA,SAASC,YAAT,QAA6B,WAA7B;AAUA,SAASC,UAAT,QAA2B,SAA3B;AACA,SAASC,KAAT,EAAgBC,MAAhB,QAA8B,oBAA9B;AACA,SAASC,UAAT,QAA2B,gBAA3B;AACA,OAAOC,mBAAP,MAAgC,wBAAhC;AAiBA,OAAO,SAASC,QAAT,CACLC,OADK,EAI4C;EAAA,IAFjDC,UAEiD,uEAF1B,EAE0B;EAAA,IADjDC,OACiD,uEADvC,KACuC;EACjD,MAAMC,OAAO,GAAGX,MAAM,CAAgC,IAAhC,CAAtB;;EACA,IAAIW,OAAO,CAACC,OAAR,KAAoB,IAAxB,EAA8B;IAC5BD,OAAO,CAACC,OAAR,GAAkB,IAAIN,mBAAJ,CAAwBE,OAAxB,EAAiCC,UAAjC,CAAlB;EACD,CAFD,MAEO,IAAIC,OAAJ,EAAa;IAClBC,OAAO,CAACC,OAAR,CAAgBC,aAAhB,CAA8BL,OAA9B;EACD;;EAED,OAAOG,OAAP;AACD;AAED,OAAO,SAASG,UAAT,CACLC,QADK,EAELC,YAFK,EAGwB;EAC7B,MAAML,OAAO,GAAGX,MAAM,CAA2C,IAA3C,CAAtB;;EACA,IAAIW,OAAO,CAACC,OAAR,KAAoB,IAAxB,EAA8B;IAC5BD,OAAO,CAACC,OAAR,GAAkB;MAChBK,OAAO,EAAEf,UAAU,CAAW,EAAX,CADH;MAEhBgB,iBAAiB,EAAE;IAFH,CAAlB;EAID;;EAEDnB,SAAS,CAAC,MAAM;IACd,OAAO,MAAM;MACXY,OAAO,CAACC,OAA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0JADI,CAAN;EAGD;AACF,CAXM"}
1
+ {"version":3,"names":["useEffect","useRef","processColor","makeRemote","isWeb","isJest","colorProps","WorkletEventHandler","useEvent","handler","eventNames","rebuild","initRef","current","updateWorklet","useHandler","handlers","dependencies","context","savedDependencies","buildDependencies","doDependenciesDiffer","areDependenciesEqual","useWeb","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","key","has","parseColors","indexOf","processedColor","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,SAA2BA,SAA3B,EAAsCC,MAAtC,QAAoD,OAApD;AACA,SAASC,YAAT,QAA6B,WAA7B;AASA,SAASC,UAAT,QAA2B,SAA3B;AACA,SAASC,KAAT,EAAgBC,MAAhB,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imation';
11
11
  export * from './utils';
12
12
  export * from './commonTypes';
13
+ export * from './pluginUtils';
13
14
  //# 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,cAAc,QAAd;AACA,cAAc,QAAd;AACA,cAAc,aAAd;AACA,cAAc,iBAAd;AACA,cAAc,oBAAd;AACA,cAAc,UAAd;AACA,cAAc,iBAAd;AACA,cAAc,UAAd;AACA,cAAc,gBAAd;AACA,cAAc,qBAAd;AACA,cAAc,SAAd;AACA,cAAc,eAAd"}
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,cAAc,QAAd;AACA,cAAc,QAAd;AACA,cAAc,aAAd;AACA,cAAc,iBAAd;AACA,cAAc,oBAAd;AACA,cAAc,UAAd;AACA,cAAc,iBAAd;AACA,cAAc,UAAd;AACA,cAAc,gBAAd;AACA,cAAc,qBAAd;AACA,cAAc,SAAd;AACA,cAAc,eAAd;AACA,cAAc,eAAd"}
@@ -1,7 +1,7 @@
1
1
  import { reportFatalErrorOnJS } from './errors';
2
2
  import NativeReanimatedModule from './NativeReanimated';
3
3
  import { isJest } from './PlatformChecker';
4
- import { runOnUI, runOnJS } from './threads'; // callGuard is only used with debug builds
4
+ import { runOnJS, setupSetImmediate, flushImmediates, runOnUIImmediately } from './threads'; // callGuard is only used with debug builds
5
5
 
6
6
  function callGuardDEV(fn) {
7
7
  'worklet';
@@ -33,29 +33,33 @@ function valueUnpacker(objectToUnpack, category) {
33
33
  handleCache = global.__handleCache = new WeakMap();
34
34
  }
35
35
 
36
- if (objectToUnpack.__workletHash) {
37
- let workletFun = workletsCache.get(objectToUnpack.__workletHash);
36
+ const workletHash = objectToUnpack.__workletHash;
37
+
38
+ if (workletHash !== undefined) {
39
+ let workletFun = workletsCache.get(workletHash);
38
40
 
39
41
  if (workletFun === undefined) {
42
+ const initData = objectToUnpack.__initData;
43
+
40
44
  if (global.evalWithSourceMap) {
41
45
  // if the runtime (hermes only for now) supports loading source maps
42
46
  // we want to use the proper filename for the location as it guarantees
43
47
  // that debugger understands and loads the source code of the file where
44
48
  // the worklet is defined.
45
- workletFun = global.evalWithSourceMap('(' + objectToUnpack.asString + '\n)', objectToUnpack.__location, objectToUnpack.__sourceMap);
49
+ workletFun = global.evalWithSourceMap('(' + initData.code + '\n)', initData.location, initData.sourceMap);
46
50
  } else if (global.evalWithSourceUrl) {
47
51
  // if the runtime doesn't support loading source maps, in dev mode we
48
52
  // can pass source url when evaluating the worklet. Now, instead of using
49
53
  // the actual file location we use worklet hash, as it the allows us to
50
54
  // properly symbolicate traces (see errors.ts for details)
51
- workletFun = global.evalWithSourceUrl('(' + objectToUnpack.asString + '\n)', `worklet_${objectToUnpack.__workletHash}`);
55
+ workletFun = global.evalWithSourceUrl('(' + initData.code + '\n)', `worklet_${workletHash}`);
52
56
  } else {
53
57
  // in release we use the regular eval to save on JSI calls
54
58
  // eslint-disable-next-line no-eval
55
- workletFun = eval('(' + objectToUnpack.asString + '\n)');
59
+ workletFun = eval('(' + initData.code + '\n)');
56
60
  }
57
61
 
58
- workletsCache.set(objectToUnpack.__workletHash, workletFun);
62
+ workletsCache.set(workletHash, workletFun);
59
63
  }
60
64
 
61
65
  const functionInstance = workletFun.bind(objectToUnpack);
@@ -86,11 +90,69 @@ Possible solutions are:
86
90
  }
87
91
  }
88
92
 
93
+ function setupRequestAnimationFrame() {
94
+ 'worklet'; // Jest mocks requestAnimationFrame API and it does not like if that mock gets overridden
95
+ // so we avoid doing requestAnimationFrame batching in Jest environment.
96
+
97
+ const nativeRequestAnimationFrame = global.requestAnimationFrame;
98
+ let animationFrameCallbacks = [];
99
+ let lastNativeAnimationFrameTimestamp = -1;
100
+
101
+ global.__flushAnimationFrame = frameTimestamp => {
102
+ const currentCallbacks = animationFrameCallbacks;
103
+ animationFrameCallbacks = [];
104
+ currentCallbacks.forEach(f => f(frameTimestamp));
105
+ flushImmediates();
106
+ };
107
+
108
+ global.requestAnimationFrame = callback => {
109
+ animationFrameCallbacks.push(callback);
110
+
111
+ if (animationFrameCallbacks.length === 1) {
112
+ // We schedule native requestAnimationFrame only when the first callback
113
+ // is added and then use it to execute all the enqueued callbacks. Once
114
+ // the callbacks are run, we clear the array.
115
+ nativeRequestAnimationFrame(timestamp => {
116
+ if (lastNativeAnimationFrameTimestamp >= timestamp) {
117
+ // Make sure we only execute the callbacks once for a given frame
118
+ return;
119
+ }
120
+
121
+ lastNativeAnimationFrameTimestamp = timestamp;
122
+ global.__frameTimestamp = timestamp;
123
+
124
+ global.__flushAnimationFrame(timestamp);
125
+
126
+ global.__frameTimestamp = undefined;
127
+ });
128
+ } // Reanimated currently does not support cancelling calbacks requested with
129
+ // requestAnimationFrame. We return -1 as identifier which isn't in line
130
+ // with the spec but it should give users better clue in case they actually
131
+ // attempt to store the value returned from rAF and use it for cancelling.
132
+
133
+
134
+ return -1;
135
+ };
136
+ }
137
+
89
138
  export function initializeUIRuntime() {
90
139
  NativeReanimatedModule.installCoreFunctions(callGuardDEV, valueUnpacker);
91
140
  const IS_JEST = isJest();
141
+
142
+ if (IS_JEST) {
143
+ // requestAnimationFrame react-native jest's setup is incorrect as it polyfills
144
+ // the method directly using setTimeout, therefore the callback doesn't get the
145
+ // expected timestamp as the only argument: https://github.com/facebook/react-native/blob/main/jest/setup.js#L28
146
+ // We override this setup here to make sure that callbacks get the proper timestamps
147
+ // when executed. For non-jest environments we define requestAnimationFrame in setupRequestAnimationFrame
148
+ // @ts-ignore TypeScript uses Node definition for rAF, setTimeout, etc which returns a Timeout object rather than a number
149
+ global.requestAnimationFrame = callback => {
150
+ return setTimeout(() => callback(performance.now()), 0);
151
+ };
152
+ }
153
+
92
154
  const capturableConsole = console;
93
- runOnUI(() => {
155
+ runOnUIImmediately(() => {
94
156
  'worklet'; // setup error handler
95
157
 
96
158
  global.ErrorUtils = {
@@ -112,31 +174,8 @@ export function initializeUIRuntime() {
112
174
  };
113
175
 
114
176
  if (!IS_JEST) {
115
- // Jest mocks requestAnimationFrame API and it does not like if that mock gets overridden
116
- // so we avoid doing requestAnimationFrame batching in Jest environment.
117
- const nativeRequestAnimationFrame = global.requestAnimationFrame;
118
- let callbacks = [];
119
-
120
- global.requestAnimationFrame = callback => {
121
- callbacks.push(callback);
122
-
123
- if (callbacks.length === 1) {
124
- // We schedule native requestAnimationFrame only when the first callback
125
- // is added and then use it to execute all the enqueued callbacks. Once
126
- // the callbacks are run, we clear the array.
127
- nativeRequestAnimationFrame(timestamp => {
128
- const currentCallbacks = callbacks;
129
- callbacks = [];
130
- currentCallbacks.forEach(f => f(timestamp));
131
- });
132
- } // Reanimated currently does not support cancelling calbacks requested with
133
- // requestAnimationFrame. We return -1 as identifier which isn't in line
134
- // with the spec but it should give users better clue in case they actually
135
- // attempt to store the value returned from rAF and use it for cancelling.
136
-
137
-
138
- return -1;
139
- };
177
+ setupSetImmediate();
178
+ setupRequestAnimationFrame();
140
179
  }
141
180
  })();
142
181
  }
@@ -1 +1 @@
1
- {"version":3,"names":["reportFatalErrorOnJS","NativeReanimatedModule","isJest","runOnUI","runOnJS","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","installCoreFunctions","IS_JEST","capturableConsole","console","error","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,SAASA,oBAAT,QAAqC,UAArC;AACA,OAAOC,sBAAP,MAAmC,oBAAnC;AACA,SAASC,MAAT,QAAuB,mBAAvB;AACA,SAASC,OAAT,EAAkBC,OAAlB,QAAiC,WAAjC,C,CAEA;;AACA,SAASC,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,aAAP,GAAuB,IAAIG,OAAJ,EAArC;EACD;;EACD,IAAIR,cAAc,CAACS,aAAnB,EAAkC;IAChC,IAAIC,UAAU,GAAGR,aAAa,CAACS,GAAd,CAAkBX,cAAc,CAACS,aAAjC,CAAjB;;IACA,IAAIC,UAAU,KAAKJ,SAAnB,EAA8B;MAC5B,IAAIV,MAAM,CAACgB,iB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AG,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,CAhDM,CAAP;AAiDD"}
1
+ {"version":3,"names":["reportFatalErrorOnJS","NativeReanimatedModule","isJest","runOnJS","setupSetImmediate","flushImmediates","runOnUIImmediately","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","callback","push","length","timestamp","__frameTimestamp","initializeUIRuntime","installCoreFunctions","IS_JEST","setTimeout","performance","now","capturableConsole","console","error","message","stack","debug","log","warn","info"],"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,SAASA,oBAAT,QAAqC,UAArC;AACA,OAAOC,sBAAP,MAAmC,oBAAnC;AACA,SAASC,MAAT,QAAuB,mBAAvB;AACA,SACEC,OADF,EAEEC,iBAFF,EAGEC,eAHF,EAIEC,kBAJF,QAKO,WALP,C,CAOA;;AACA,SAASC,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,aAAP,GAAuB,IAAIG,OAAJ,EAArC;EACD;;EACD,MAAMC,WAAW,GAAGT,cAAc,CAACU,aAAnC;;EACA,IAAID,WAAW,KAAKH,SAApB,EAA+B;I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O,aAA1D;EAEA,MAAMgD,OAAO,GAAG5D,MAAM,EAAtB;;EAEA,IAAI4D,OAAJ,EAAa;IACX;IACA;IACA;IACA;IACA;IACA;IACAnD,MAAM,CAACoC,qBAAP,GAAgCQ,QAAD,IAA2C;MACxE,OAAOQ,UAAU,CAAC,MAAMR,QAAQ,CAACS,WAAW,CAACC,GAAZ,EAAD,CAAf,EAAoC,CAApC,CAAjB;IACD,CAFD;EAGD;;EAED,MAAMC,iBAAiB,GAAGC,OAA1B;EACA7D,kBAAkB,CAAC,MAAM;IACvB,UADuB,CAEvB;;IACAK,MAAM,CAACC,UAAP,GAAoB;MAClBC,gBAAgB,EAAGuD,KAAD,IAAkB;QAClCjE,OAAO,CAACH,oBAAD,CAAP,CAA8B;UAC5BqE,OAAO,EAAED,KAAK,CAACC,OADa;UAE5BC,KAAK,EAAEF,KAAK,CAACE;QAFe,CAA9B;MAID;IANiB,CAApB,CAHuB,CAYvB;IACA;;IACA3D,MAAM,CAACwD,OAAP,GAAiB;MACfI,KAAK,EAAEpE,OAAO,CAAC+D,iBAAiB,CAACK,KAAnB,CADC;MAEfC,GAAG,EAAErE,OAAO,CAAC+D,iBAAiB,CAACM,GAAnB,CAFG;MAGfC,IAAI,EAAEtE,OAAO,CAAC+D,iBAAiB,CAACO,IAAnB,CAHE;MAIfL,KAAK,EAAEjE,OAAO,CAAC+D,iBAAiB,CAACE,KAAnB,CAJC;MAKfM,IAAI,EAAEvE,OAAO,CAAC+D,iBAAiB,CAACQ,IAAnB;IALE,CAAjB;;IAQA,IAAI,CAACZ,OAAL,EAAc;MACZ1D,iBAAiB;MACjByC,0BAA0B;IAC3B;EACF,CA1BiB,CAAlB;AA2BD"}
@@ -8,23 +8,93 @@ export const Extrapolate = {
8
8
  IDENTITY: 'identity'
9
9
  };
10
10
 
11
- const interpolateColorsHSV = (value, inputRange, colors) => {
11
+ const interpolateColorsHSV = (value, inputRange, colors, options) => {
12
12
  'worklet';
13
13
 
14
- const h = interpolate(value, inputRange, colors.h, Extrapolate.CLAMP);
14
+ let h = 0;
15
+ const {
16
+ useCorrectedHSVInterpolation = true
17
+ } = options;
18
+
19
+ if (useCorrectedHSVInterpolation) {
20
+ // if the difference between hues in a range is > 180 deg
21
+ // then move the hue at the right end of the range +/- 360 deg
22
+ // and add the next point in the original place + 0.00001 with original hue
23
+ // to not break the next range
24
+ const correctedInputRange = [inputRange[0]];
25
+ const originalH = colors.h;
26
+ const correctedH = [originalH[0]];
27
+
28
+ for (let i = 1; i < originalH.length; ++i) {
29
+ const d = originalH[i] - originalH[i - 1];
30
+
31
+ if (originalH[i] > originalH[i - 1] && d > 0.5) {
32
+ correctedInputRange.push(inputRange[i]);
33
+ correctedInputRange.push(inputRange[i] + 0.00001);
34
+ correctedH.push(originalH[i] - 1);
35
+ correctedH.push(originalH[i]);
36
+ } else if (originalH[i] < originalH[i - 1] && d < -0.5) {
37
+ correctedInputRange.push(inputRange[i]);
38
+ correctedInputRange.push(inputRange[i] + 0.00001);
39
+ correctedH.push(originalH[i] + 1);
40
+ correctedH.push(originalH[i]);
41
+ } else {
42
+ correctedInputRange.push(inputRange[i]);
43
+ correctedH.push(originalH[i]);
44
+ }
45
+ }
46
+
47
+ h = (interpolate(value, correctedInputRange, correctedH, Extrapolate.CLAMP) + 1) % 1;
48
+ } else {
49
+ h = interpolate(value, inputRange, colors.h, Extrapolate.CLAMP);
50
+ }
51
+
15
52
  const s = interpolate(value, inputRange, colors.s, Extrapolate.CLAMP);
16
53
  const v = interpolate(value, inputRange, colors.v, Extrapolate.CLAMP);
17
- return hsvToColor(h, s, v);
54
+ const a = interpolate(value, inputRange, colors.a, Extrapolate.CLAMP);
55
+ return hsvToColor(h, s, v, a);
18
56
  };
19
57
 
20
- const interpolateColorsRGB = (value, inputRange, colors) => {
58
+ const toLinearSpace = (x, gamma) => {
21
59
  'worklet';
22
60
 
23
- const r = interpolate(value, inputRange, colors.r, Extrapolate.CLAMP);
24
- const g = interpolate(value, inputRange, colors.g, Extrapolate.CLAMP);
25
- const b = interpolate(value, inputRange, colors.b, Extrapolate.CLAMP);
61
+ return x.map(v => Math.pow(v / 255, gamma));
62
+ };
63
+
64
+ const toGammaSpace = (x, gamma) => {
65
+ 'worklet';
66
+
67
+ return Math.round(Math.pow(x, 1 / gamma) * 255);
68
+ };
69
+
70
+ const interpolateColorsRGB = (value, inputRange, colors, options) => {
71
+ 'worklet';
72
+
73
+ const {
74
+ gamma = 2.2
75
+ } = options;
76
+ let {
77
+ r: outputR,
78
+ g: outputG,
79
+ b: outputB
80
+ } = colors;
81
+
82
+ if (gamma !== 1) {
83
+ outputR = toLinearSpace(outputR, gamma);
84
+ outputG = toLinearSpace(outputG, gamma);
85
+ outputB = toLinearSpace(outputB, gamma);
86
+ }
87
+
88
+ const r = interpolate(value, inputRange, outputR, Extrapolate.CLAMP);
89
+ const g = interpolate(value, inputRange, outputG, Extrapolate.CLAMP);
90
+ const b = interpolate(value, inputRange, outputB, Extrapolate.CLAMP);
26
91
  const a = interpolate(value, inputRange, colors.a, Extrapolate.CLAMP);
27
- return rgbaColor(r, g, b, a);
92
+
93
+ if (gamma === 1) {
94
+ return rgbaColor(r, g, b, a);
95
+ }
96
+
97
+ return rgbaColor(toGammaSpace(r, gamma), toGammaSpace(g, gamma), toGammaSpace(b, gamma), a);
28
98
  };
29
99
 
30
100
  const getInterpolateRGB = colors => {
@@ -61,22 +131,26 @@ const getInterpolateHSV = colors => {
61
131
  const h = [];
62
132
  const s = [];
63
133
  const v = [];
134
+ const a = [];
64
135
 
65
136
  for (let i = 0; i < colors.length; ++i) {
66
137
  const color = colors[i];
67
- const processedColor = RGBtoHSV(processColor(color));
138
+ const processedColor = processColor(color);
68
139
 
69
- if (processedColor) {
70
- h.push(processedColor.h);
71
- s.push(processedColor.s);
72
- v.push(processedColor.v);
140
+ if (typeof processedColor === 'number') {
141
+ const processedHSVColor = RGBtoHSV(red(processedColor), green(processedColor), blue(processedColor));
142
+ h.push(processedHSVColor.h);
143
+ s.push(processedHSVColor.s);
144
+ v.push(processedHSVColor.v);
145
+ a.push(opacity(processedColor));
73
146
  }
74
147
  }
75
148
 
76
149
  return {
77
150
  h,
78
151
  s,
79
- v
152
+ v,
153
+ a
80
154
  };
81
155
  };
82
156
 
@@ -84,11 +158,12 @@ export const interpolateColor = function (value, inputRange, outputRange) {
84
158
  'worklet';
85
159
 
86
160
  let colorSpace = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'RGB';
161
+ let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
87
162
 
88
163
  if (colorSpace === 'HSV') {
89
- return interpolateColorsHSV(value, inputRange, getInterpolateHSV(outputRange));
164
+ return interpolateColorsHSV(value, inputRange, getInterpolateHSV(outputRange), options);
90
165
  } else if (colorSpace === 'RGB') {
91
- return interpolateColorsRGB(value, inputRange, getInterpolateRGB(outputRange));
166
+ return interpolateColorsRGB(value, inputRange, getInterpolateRGB(outputRange), options);
92
167
  }
93
168
 
94
169
  throw new Error(`Invalid color space provided: ${colorSpace}. Supported values are: ['RGB', 'HSV']`);
@@ -102,11 +177,13 @@ export let ColorSpace;
102
177
 
103
178
  export function useInterpolateConfig(inputRange, outputRange) {
104
179
  let colorSpace = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ColorSpace.RGB;
180
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
105
181
  return useSharedValue({
106
182
  inputRange,
107
183
  outputRange,
108
184
  colorSpace,
109
- cache: makeMutable(null)
185
+ cache: makeMutable(null),
186
+ options
110
187
  });
111
188
  }
112
189
  export const interpolateSharableColor = (value, interpolateConfig) => {
@@ -120,14 +197,14 @@ export const interpolateSharableColor = (value, interpolateConfig) => {
120
197
  interpolateConfig.value.cache.value = colors;
121
198
  }
122
199
 
123
- return interpolateColorsRGB(value, interpolateConfig.value.inputRange, colors);
200
+ return interpolateColorsRGB(value, interpolateConfig.value.inputRange, colors, interpolateConfig.value.options);
124
201
  } else if (interpolateConfig.value.colorSpace === ColorSpace.HSV) {
125
202
  if (!colors) {
126
203
  colors = getInterpolateHSV(interpolateConfig.value.outputRange);
127
204
  interpolateConfig.value.cache.value = colors;
128
205
  }
129
206
 
130
- return interpolateColorsHSV(value, interpolateConfig.value.inputRange, colors);
207
+ return interpolateColorsHSV(value, interpolateConfig.value.inputRange, colors, interpolateConfig.value.options);
131
208
  }
132
209
 
133
210
  throw new Error(`Invalid color space provided: ${interpolateConfig.value.colorSpace}. Supported values are: ['RGB', 'HSV']`);