react-native-unistyles 3.0.0-rc.4 → 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 (338) hide show
  1. package/README.md +9 -7
  2. package/Unistyles.podspec +12 -1
  3. package/android/build.gradle +1 -1
  4. package/android/src/main/cxx/NativeUnistylesModule.cpp +5 -8
  5. package/android/src/main/cxx/NativeUnistylesModule.h +4 -4
  6. package/android/src/main/java/com/unistyles/NativePlatform+android.kt +1 -0
  7. package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +21 -9
  8. package/android/src/main/java/com/unistyles/UnistylesModule.kt +8 -7
  9. package/cxx/core/UnistyleWrapper.h +4 -1
  10. package/cxx/core/UnistylesCommitShadowNode.h +0 -21
  11. package/cxx/core/UnistylesRegistry.cpp +52 -49
  12. package/cxx/core/UnistylesRegistry.h +2 -1
  13. package/cxx/core/UnistylesState.cpp +10 -0
  14. package/cxx/core/UnistylesState.h +3 -0
  15. package/cxx/hybridObjects/HybridShadowRegistry.cpp +6 -1
  16. package/cxx/hybridObjects/HybridShadowRegistry.h +6 -0
  17. package/cxx/hybridObjects/HybridStyleSheet.cpp +13 -16
  18. package/cxx/hybridObjects/HybridStyleSheet.h +2 -7
  19. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +17 -2
  20. package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -0
  21. package/cxx/parser/Parser.cpp +175 -110
  22. package/cxx/parser/Parser.h +1 -0
  23. package/cxx/shadowTree/ShadowTreeManager.cpp +36 -33
  24. package/cxx/shadowTree/ShadowTreeManager.h +0 -1
  25. package/get_rn_version.rb +28 -0
  26. package/ios/UnistylesModuleOnLoad.h +1 -5
  27. package/ios/UnistylesModuleOnLoad.mm +10 -13
  28. package/lib/commonjs/components/AdaptiveTheme.js +35 -0
  29. package/lib/commonjs/components/AdaptiveTheme.js.map +1 -0
  30. package/lib/commonjs/components/ApplyScopedTheme.js +19 -0
  31. package/lib/commonjs/components/ApplyScopedTheme.js.map +1 -0
  32. package/lib/commonjs/components/NamedTheme.js +31 -0
  33. package/lib/commonjs/components/NamedTheme.js.map +1 -0
  34. package/lib/commonjs/components/ScopedTheme.js +30 -21
  35. package/lib/commonjs/components/ScopedTheme.js.map +1 -1
  36. package/lib/commonjs/components/native/Image.js +1 -2
  37. package/lib/commonjs/components/native/Image.js.map +1 -1
  38. package/lib/commonjs/components/native/ImageBackground.js +1 -2
  39. package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
  40. package/lib/commonjs/components/native/Pressable.js +1 -2
  41. package/lib/commonjs/components/native/Pressable.js.map +1 -1
  42. package/lib/commonjs/components/native/Pressable.native.js +1 -2
  43. package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
  44. package/lib/commonjs/core/createUnistylesElement.js +5 -5
  45. package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
  46. package/lib/commonjs/core/createUnistylesElement.native.js +18 -31
  47. package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
  48. package/lib/commonjs/core/createUnistylesImageBackground.js +6 -21
  49. package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
  50. package/lib/commonjs/core/getClassname.js +1 -2
  51. package/lib/commonjs/core/getClassname.js.map +1 -1
  52. package/lib/commonjs/core/parseBoxShadow.js +57 -0
  53. package/lib/commonjs/core/parseBoxShadow.js.map +1 -0
  54. package/lib/commonjs/core/useProxifiedUnistyles/listener.js +2 -3
  55. package/lib/commonjs/core/useProxifiedUnistyles/listener.js.map +1 -1
  56. package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js +2 -1
  57. package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js.map +1 -1
  58. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +14 -2
  59. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  60. package/lib/commonjs/core/withUnistyles/withUnistyles.js +10 -5
  61. package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
  62. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +10 -5
  63. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
  64. package/lib/commonjs/index.js +6 -0
  65. package/lib/commonjs/index.js.map +1 -1
  66. package/lib/commonjs/mocks.js +26 -2
  67. package/lib/commonjs/mocks.js.map +1 -1
  68. package/lib/commonjs/reanimated/index.js +7 -0
  69. package/lib/commonjs/reanimated/index.js.map +1 -1
  70. package/lib/commonjs/reanimated/variant/index.js +17 -0
  71. package/lib/commonjs/reanimated/variant/index.js.map +1 -0
  72. package/lib/commonjs/reanimated/variant/types.js +2 -0
  73. package/lib/commonjs/reanimated/variant/types.js.map +1 -0
  74. package/lib/commonjs/reanimated/variant/useAnimatedVariantColor.js +38 -0
  75. package/lib/commonjs/reanimated/variant/useAnimatedVariantColor.js.map +1 -0
  76. package/lib/commonjs/reanimated/variant/useUpdateVariantColor.js +66 -0
  77. package/lib/commonjs/reanimated/variant/useUpdateVariantColor.js.map +1 -0
  78. package/lib/commonjs/reanimated/variant/useUpdateVariantColor.native.js +39 -0
  79. package/lib/commonjs/reanimated/variant/useUpdateVariantColor.native.js.map +1 -0
  80. package/lib/commonjs/server/getServerUnistyles.js +1 -2
  81. package/lib/commonjs/server/getServerUnistyles.js.map +1 -1
  82. package/lib/commonjs/server/hydrateServerUnistyles.js +1 -2
  83. package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -1
  84. package/lib/commonjs/server/resetServerUnistyles.js +1 -2
  85. package/lib/commonjs/server/resetServerUnistyles.js.map +1 -1
  86. package/lib/commonjs/specs/ShadowRegistry/index.js +6 -1
  87. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  88. package/lib/commonjs/specs/StyleSheet/index.js +3 -1
  89. package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
  90. package/lib/commonjs/specs/UnistylesRuntime/index.js +0 -1
  91. package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
  92. package/lib/commonjs/utils.js +0 -3
  93. package/lib/commonjs/utils.js.map +1 -1
  94. package/lib/commonjs/web/convert/object/boxShadow.js.map +1 -1
  95. package/lib/commonjs/web/convert/pseudo.js +13 -3
  96. package/lib/commonjs/web/convert/pseudo.js.map +1 -1
  97. package/lib/commonjs/web/convert/utils.js +1 -0
  98. package/lib/commonjs/web/convert/utils.js.map +1 -1
  99. package/lib/commonjs/web/create.js +2 -3
  100. package/lib/commonjs/web/create.js.map +1 -1
  101. package/lib/commonjs/web/css/core.js +9 -2
  102. package/lib/commonjs/web/css/core.js.map +1 -1
  103. package/lib/commonjs/web/css/state.js +10 -7
  104. package/lib/commonjs/web/css/state.js.map +1 -1
  105. package/lib/commonjs/web/index.js +1 -2
  106. package/lib/commonjs/web/index.js.map +1 -1
  107. package/lib/commonjs/web/listener.js +4 -2
  108. package/lib/commonjs/web/listener.js.map +1 -1
  109. package/lib/commonjs/web/runtime.js +26 -2
  110. package/lib/commonjs/web/runtime.js.map +1 -1
  111. package/lib/commonjs/web/shadowRegistry.js +5 -3
  112. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  113. package/lib/commonjs/web/state.js +1 -10
  114. package/lib/commonjs/web/state.js.map +1 -1
  115. package/lib/commonjs/web/types.js.map +1 -1
  116. package/lib/commonjs/web/utils/createUnistylesRef.js +1 -2
  117. package/lib/commonjs/web/utils/createUnistylesRef.js.map +1 -1
  118. package/lib/commonjs/web/utils/unistyle.js +26 -4
  119. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  120. package/lib/module/components/AdaptiveTheme.js +29 -0
  121. package/lib/module/components/AdaptiveTheme.js.map +1 -0
  122. package/lib/module/components/ApplyScopedTheme.js +14 -0
  123. package/lib/module/components/ApplyScopedTheme.js.map +1 -0
  124. package/lib/module/components/NamedTheme.js +25 -0
  125. package/lib/module/components/NamedTheme.js.map +1 -0
  126. package/lib/module/components/ScopedTheme.js +30 -20
  127. package/lib/module/components/ScopedTheme.js.map +1 -1
  128. package/lib/module/core/createUnistylesElement.js +5 -5
  129. package/lib/module/core/createUnistylesElement.js.map +1 -1
  130. package/lib/module/core/createUnistylesElement.native.js +18 -30
  131. package/lib/module/core/createUnistylesElement.native.js.map +1 -1
  132. package/lib/module/core/createUnistylesImageBackground.js +5 -19
  133. package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
  134. package/lib/module/core/parseBoxShadow.js +52 -0
  135. package/lib/module/core/parseBoxShadow.js.map +1 -0
  136. package/lib/module/core/useProxifiedUnistyles/listener.js +1 -1
  137. package/lib/module/core/useProxifiedUnistyles/listener.js.map +1 -1
  138. package/lib/module/core/useProxifiedUnistyles/listener.native.js +2 -1
  139. package/lib/module/core/useProxifiedUnistyles/listener.native.js.map +1 -1
  140. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +14 -2
  141. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  142. package/lib/module/core/withUnistyles/withUnistyles.js +9 -3
  143. package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
  144. package/lib/module/core/withUnistyles/withUnistyles.native.js +9 -3
  145. package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
  146. package/lib/module/index.js +5 -0
  147. package/lib/module/index.js.map +1 -1
  148. package/lib/module/mocks.js +26 -2
  149. package/lib/module/mocks.js.map +1 -1
  150. package/lib/module/reanimated/index.js +1 -0
  151. package/lib/module/reanimated/index.js.map +1 -1
  152. package/lib/module/reanimated/variant/index.js +4 -0
  153. package/lib/module/reanimated/variant/index.js.map +1 -0
  154. package/lib/module/reanimated/variant/types.js +2 -0
  155. package/lib/module/reanimated/variant/types.js.map +1 -0
  156. package/lib/module/reanimated/variant/useAnimatedVariantColor.js +33 -0
  157. package/lib/module/reanimated/variant/useAnimatedVariantColor.js.map +1 -0
  158. package/lib/module/reanimated/variant/useUpdateVariantColor.js +61 -0
  159. package/lib/module/reanimated/variant/useUpdateVariantColor.js.map +1 -0
  160. package/lib/module/reanimated/variant/useUpdateVariantColor.native.js +34 -0
  161. package/lib/module/reanimated/variant/useUpdateVariantColor.native.js.map +1 -0
  162. package/lib/module/specs/ShadowRegistry/index.js +6 -1
  163. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  164. package/lib/module/specs/StyleSheet/index.js +3 -1
  165. package/lib/module/specs/StyleSheet/index.js.map +1 -1
  166. package/lib/module/specs/UnistylesRuntime/index.js +0 -1
  167. package/lib/module/specs/UnistylesRuntime/index.js.map +1 -1
  168. package/lib/module/utils.js +0 -3
  169. package/lib/module/utils.js.map +1 -1
  170. package/lib/module/web/convert/object/boxShadow.js.map +1 -1
  171. package/lib/module/web/convert/pseudo.js +10 -2
  172. package/lib/module/web/convert/pseudo.js.map +1 -1
  173. package/lib/module/web/convert/utils.js +1 -0
  174. package/lib/module/web/convert/utils.js.map +1 -1
  175. package/lib/module/web/create.js +1 -1
  176. package/lib/module/web/create.js.map +1 -1
  177. package/lib/module/web/css/core.js +9 -2
  178. package/lib/module/web/css/core.js.map +1 -1
  179. package/lib/module/web/css/state.js +10 -7
  180. package/lib/module/web/css/state.js.map +1 -1
  181. package/lib/module/web/listener.js +4 -2
  182. package/lib/module/web/listener.js.map +1 -1
  183. package/lib/module/web/runtime.js +27 -3
  184. package/lib/module/web/runtime.js.map +1 -1
  185. package/lib/module/web/shadowRegistry.js +5 -3
  186. package/lib/module/web/shadowRegistry.js.map +1 -1
  187. package/lib/module/web/state.js +1 -10
  188. package/lib/module/web/state.js.map +1 -1
  189. package/lib/module/web/types.js.map +1 -1
  190. package/lib/module/web/utils/unistyle.js +24 -3
  191. package/lib/module/web/utils/unistyle.js.map +1 -1
  192. package/lib/typescript/plugin/src/consts.d.ts +17 -0
  193. package/lib/typescript/plugin/src/consts.d.ts.map +1 -0
  194. package/lib/typescript/repack-plugin/src/index.d.ts +18 -0
  195. package/lib/typescript/repack-plugin/src/index.d.ts.map +1 -0
  196. package/lib/typescript/repack-plugin/src/loader.d.ts +9 -0
  197. package/lib/typescript/repack-plugin/src/loader.d.ts.map +1 -0
  198. package/lib/typescript/src/components/AdaptiveTheme.d.ts +8 -0
  199. package/lib/typescript/src/components/AdaptiveTheme.d.ts.map +1 -0
  200. package/lib/typescript/src/components/ApplyScopedTheme.d.ts +7 -0
  201. package/lib/typescript/src/components/ApplyScopedTheme.d.ts.map +1 -0
  202. package/lib/typescript/src/components/NamedTheme.d.ts +10 -0
  203. package/lib/typescript/src/components/NamedTheme.d.ts.map +1 -0
  204. package/lib/typescript/src/components/ScopedTheme.d.ts +10 -0
  205. package/lib/typescript/src/components/ScopedTheme.d.ts.map +1 -1
  206. package/lib/typescript/src/components/native/Animated.d.ts.map +1 -1
  207. package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
  208. package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
  209. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
  210. package/lib/typescript/src/core/getClassname.d.ts.map +1 -1
  211. package/lib/typescript/src/core/parseBoxShadow.d.ts +11 -0
  212. package/lib/typescript/src/core/parseBoxShadow.d.ts.map +1 -0
  213. package/lib/typescript/src/core/passForwardRef.d.ts.map +1 -1
  214. package/lib/typescript/src/core/useProxifiedUnistyles/listener.d.ts.map +1 -1
  215. package/lib/typescript/src/core/useProxifiedUnistyles/listener.native.d.ts.map +1 -1
  216. package/lib/typescript/src/core/useProxifiedUnistyles/types.d.ts +1 -1
  217. package/lib/typescript/src/core/useProxifiedUnistyles/types.d.ts.map +1 -1
  218. package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
  219. package/lib/typescript/src/core/warn.d.ts.map +1 -1
  220. package/lib/typescript/src/core/withUnistyles/types.d.ts +3 -1
  221. package/lib/typescript/src/core/withUnistyles/types.d.ts.map +1 -1
  222. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
  223. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
  224. package/lib/typescript/src/hooks/useMedia.d.ts.map +1 -1
  225. package/lib/typescript/src/hooks/useMedia.native.d.ts.map +1 -1
  226. package/lib/typescript/src/index.d.ts.map +1 -1
  227. package/lib/typescript/src/reanimated/index.d.ts +1 -0
  228. package/lib/typescript/src/reanimated/index.d.ts.map +1 -1
  229. package/lib/typescript/src/reanimated/variant/index.d.ts +2 -0
  230. package/lib/typescript/src/reanimated/variant/index.d.ts.map +1 -0
  231. package/lib/typescript/src/reanimated/variant/types.d.ts +10 -0
  232. package/lib/typescript/src/reanimated/variant/types.d.ts.map +1 -0
  233. package/lib/typescript/src/reanimated/variant/useAnimatedVariantColor.d.ts +3 -0
  234. package/lib/typescript/src/reanimated/variant/useAnimatedVariantColor.d.ts.map +1 -0
  235. package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.d.ts +6 -0
  236. package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.d.ts.map +1 -0
  237. package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.native.d.ts +6 -0
  238. package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.native.d.ts.map +1 -0
  239. package/lib/typescript/src/server/getServerUnistyles.d.ts.map +1 -1
  240. package/lib/typescript/src/server/serialize.d.ts.map +1 -1
  241. package/lib/typescript/src/server/useServerUnistyles.d.ts.map +1 -1
  242. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +1 -0
  243. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  244. package/lib/typescript/src/specs/StatusBar/index.d.ts.map +1 -1
  245. package/lib/typescript/src/specs/StyleSheet/index.d.ts +2 -0
  246. package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
  247. package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts +2 -0
  248. package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts.map +1 -1
  249. package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts.map +1 -1
  250. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  251. package/lib/typescript/src/utils.d.ts.map +1 -1
  252. package/lib/typescript/src/web/convert/index.d.ts.map +1 -1
  253. package/lib/typescript/src/web/convert/object/boxShadow.d.ts.map +1 -1
  254. package/lib/typescript/src/web/convert/object/filter.d.ts.map +1 -1
  255. package/lib/typescript/src/web/convert/object/objectStyle.d.ts.map +1 -1
  256. package/lib/typescript/src/web/convert/object/transform.d.ts.map +1 -1
  257. package/lib/typescript/src/web/convert/pseudo.d.ts +6 -3
  258. package/lib/typescript/src/web/convert/pseudo.d.ts.map +1 -1
  259. package/lib/typescript/src/web/convert/shadow/boxShadow.d.ts.map +1 -1
  260. package/lib/typescript/src/web/convert/shadow/getShadowBreakpoints.d.ts.map +1 -1
  261. package/lib/typescript/src/web/convert/shadow/textShadow.d.ts.map +1 -1
  262. package/lib/typescript/src/web/convert/style.d.ts.map +1 -1
  263. package/lib/typescript/src/web/convert/utils.d.ts.map +1 -1
  264. package/lib/typescript/src/web/create.d.ts.map +1 -1
  265. package/lib/typescript/src/web/css/core.d.ts.map +1 -1
  266. package/lib/typescript/src/web/css/state.d.ts +2 -1
  267. package/lib/typescript/src/web/css/state.d.ts.map +1 -1
  268. package/lib/typescript/src/web/css/utils.d.ts.map +1 -1
  269. package/lib/typescript/src/web/listener.d.ts +4 -2
  270. package/lib/typescript/src/web/listener.d.ts.map +1 -1
  271. package/lib/typescript/src/web/registry.d.ts.map +1 -1
  272. package/lib/typescript/src/web/runtime.d.ts +2 -0
  273. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  274. package/lib/typescript/src/web/shadowRegistry.d.ts +2 -0
  275. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  276. package/lib/typescript/src/web/state.d.ts.map +1 -1
  277. package/lib/typescript/src/web/types.d.ts +4 -1
  278. package/lib/typescript/src/web/types.d.ts.map +1 -1
  279. package/lib/typescript/src/web/utils/common.d.ts.map +1 -1
  280. package/lib/typescript/src/web/utils/createUnistylesRef.d.ts.map +1 -1
  281. package/lib/typescript/src/web/utils/unistyle.d.ts +5 -1
  282. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  283. package/lib/typescript/src/web/variants.d.ts.map +1 -1
  284. package/lib/typescript/src/web-only/getWebProps.d.ts.map +1 -1
  285. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +1 -0
  286. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.cpp +2 -0
  287. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +2 -0
  288. package/package.json +33 -23
  289. package/plugin/index.d.ts +6 -5
  290. package/plugin/index.js +11 -6
  291. package/repack-plugin/index.d.ts +19 -0
  292. package/repack-plugin/index.js +149 -0
  293. package/src/components/AdaptiveTheme.tsx +34 -0
  294. package/src/components/ApplyScopedTheme.tsx +17 -0
  295. package/src/components/NamedTheme.tsx +33 -0
  296. package/src/components/ScopedTheme.tsx +51 -24
  297. package/src/core/createUnistylesElement.native.tsx +21 -31
  298. package/src/core/createUnistylesElement.tsx +8 -6
  299. package/src/core/createUnistylesImageBackground.tsx +7 -22
  300. package/src/core/parseBoxShadow.ts +87 -0
  301. package/src/core/useProxifiedUnistyles/listener.native.ts +3 -1
  302. package/src/core/useProxifiedUnistyles/listener.ts +1 -1
  303. package/src/core/useProxifiedUnistyles/types.ts +1 -1
  304. package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +19 -2
  305. package/src/core/withUnistyles/types.ts +1 -1
  306. package/src/core/withUnistyles/withUnistyles.native.tsx +10 -3
  307. package/src/core/withUnistyles/withUnistyles.tsx +11 -8
  308. package/src/index.ts +8 -0
  309. package/src/mocks.ts +28 -2
  310. package/src/reanimated/index.ts +1 -0
  311. package/src/reanimated/variant/index.ts +1 -0
  312. package/src/reanimated/variant/types.ts +14 -0
  313. package/src/reanimated/variant/useAnimatedVariantColor.ts +38 -0
  314. package/src/reanimated/variant/useUpdateVariantColor.native.ts +38 -0
  315. package/src/reanimated/variant/useUpdateVariantColor.ts +81 -0
  316. package/src/specs/ShadowRegistry/index.ts +7 -1
  317. package/src/specs/StyleSheet/index.ts +5 -2
  318. package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.ts +2 -0
  319. package/src/specs/UnistylesRuntime/index.ts +0 -1
  320. package/src/utils.ts +1 -3
  321. package/src/web/convert/object/boxShadow.ts +2 -2
  322. package/src/web/convert/pseudo.ts +23 -52
  323. package/src/web/convert/utils.ts +2 -1
  324. package/src/web/create.ts +1 -1
  325. package/src/web/css/core.ts +12 -2
  326. package/src/web/css/state.ts +10 -8
  327. package/src/web/listener.ts +10 -6
  328. package/src/web/runtime.ts +37 -3
  329. package/src/web/shadowRegistry.ts +5 -3
  330. package/src/web/state.ts +7 -17
  331. package/src/web/types.ts +4 -1
  332. package/src/web/utils/unistyle.ts +34 -4
  333. package/cxx/core/UnistylesCommitHook.cpp +0 -59
  334. package/cxx/core/UnistylesCommitHook.h +0 -27
  335. package/cxx/core/UnistylesMountHook.cpp +0 -26
  336. package/cxx/core/UnistylesMountHook.h +0 -24
  337. package/lib/module/package.json +0 -1
  338. /package/{web-only → web}/package.json +0 -0
@@ -7,14 +7,16 @@ import { createUnistylesRef } from '../web/utils/createUnistylesRef'
7
7
  import { getClassName } from './getClassname'
8
8
  import { maybeWarnAboutMultipleUnistyles } from './warn'
9
9
 
10
- const STYLE_PROPS = ['style', 'contentContainerStyle', 'columnWrapperStyle'] as const
10
+ const STYLE_PROPS = ['contentContainerStyle', 'columnWrapperStyle'] as const
11
+
12
+ type StyleProp = typeof STYLE_PROPS[number] | 'style'
11
13
 
12
14
  type ComponentProps = {
13
- [K in typeof STYLE_PROPS[number]]?: UnistylesValues
15
+ [K in StyleProp]?: UnistylesValues
14
16
  }
15
17
 
16
18
  const buildUnistylesProps = (Component: any, props: ComponentProps, forwardedRef: React.ForwardedRef<unknown>) => {
17
- const componentStyleProps = STYLE_PROPS.filter(styleProp => styleProp in props)
19
+ const componentStyleProps = ['style' as const, ...STYLE_PROPS.filter(styleProp => styleProp in props)]
18
20
  const classNames = Object.fromEntries(componentStyleProps.map(styleProp => [styleProp, getClassName(props[styleProp])]))
19
21
  const refs = componentStyleProps.map(styleProp => {
20
22
  return createUnistylesRef(
@@ -34,14 +36,14 @@ const buildUnistylesProps = (Component: any, props: ComponentProps, forwardedRef
34
36
  }
35
37
 
36
38
  export const createUnistylesElement = (Component: any) => {
37
- const UnistylesComponent = React.forwardRef<unknown, ComponentProps>((props, forwardedRef) => {
39
+ const UnistylesComponent = (props: any) => {
38
40
  return (
39
41
  <Component
40
42
  {...props}
41
- {...buildUnistylesProps(Component, props, forwardedRef)}
43
+ {...buildUnistylesProps(Component, props, props.ref)}
42
44
  />
43
45
  )
44
- })
46
+ }
45
47
 
46
48
  return copyComponentProperties(Component, UnistylesComponent)
47
49
  }
@@ -1,5 +1,5 @@
1
- import React, { useLayoutEffect, useRef } from 'react'
2
- import type { Image, ImageBackground, ImageBackgroundProps } from 'react-native'
1
+ import React from 'react'
2
+ import type { ImageBackground, ImageBackgroundProps } from 'react-native'
3
3
  import { UnistylesShadowRegistry } from '../specs'
4
4
  import { copyComponentProperties } from '../utils'
5
5
  import { passForwardedRef } from './passForwardRef'
@@ -7,17 +7,6 @@ import { maybeWarnAboutMultipleUnistyles } from './warn'
7
7
 
8
8
  export const createUnistylesImageBackground = (Component: typeof ImageBackground) => {
9
9
  const UnistylesImageBackground = React.forwardRef<ImageBackground, ImageBackgroundProps>((props, forwardedRef) => {
10
- const storedImageRef = useRef<Image | null>(null)
11
-
12
- useLayoutEffect(() => {
13
- return () => {
14
- if (storedImageRef.current) {
15
- // @ts-ignore
16
- UnistylesShadowRegistry.remove(storedImageRef.current)
17
- }
18
- }
19
- }, [])
20
-
21
10
  // @ts-expect-error we don't know the type of the component
22
11
  maybeWarnAboutMultipleUnistyles(props.style, 'ImageBackground')
23
12
  // @ts-ignore we don't know the type of the component
@@ -37,21 +26,17 @@ export const createUnistylesImageBackground = (Component: typeof ImageBackground
37
26
  () => {
38
27
  // @ts-expect-error - this is hidden from TS
39
28
  UnistylesShadowRegistry.remove(ref)
40
-
41
- if (storedImageRef.current) {
42
- // @ts-expect-error - this is hidden from TS
43
- UnistylesShadowRegistry.remove(storedImageRef.current)
44
- }
45
29
  }
46
30
  )
47
31
  }}
48
32
  imageRef={ref => {
49
- if (ref) {
50
- storedImageRef.current = ref
51
- }
52
-
53
33
  // @ts-expect-error web types are not compatible with RN styles
54
34
  UnistylesShadowRegistry.add(ref, props.imageStyle)
35
+
36
+ return () => {
37
+ // @ts-ignore this is hidden from TS
38
+ UnistylesShadowRegistry.remove(ref)
39
+ }
55
40
  }}
56
41
  />
57
42
  )
@@ -0,0 +1,87 @@
1
+ import { processColor } from 'react-native'
2
+
3
+ type BoxShadow = {
4
+ inset?: boolean
5
+ offsetX?: number
6
+ offsetY?: number
7
+ blurRadius?: number
8
+ spreadDistance?: number
9
+ color?: string
10
+ }
11
+
12
+ const isValue = (str: string | undefined) => str && (str === '0' || str.endsWith('px'))
13
+
14
+ const parseBoxShadow = (str: string): BoxShadow | undefined => {
15
+ if (str === 'none') {
16
+ return undefined
17
+ }
18
+
19
+ // split by space, but not if it's inside of ()
20
+ const parts = str.split(/\s+(?![^(]*\))/)
21
+ const lastIndex = parts.length - 1
22
+ const insetIndex = parts.findIndex(part => part === 'inset')
23
+
24
+ // inset can only be at the start or end
25
+ if (![-1, 0, lastIndex].includes(insetIndex)) {
26
+ return undefined
27
+ }
28
+
29
+ // if there is no inset, color can only be at the start or end
30
+ const maybeColorsIndexes = insetIndex === -1
31
+ ? [0, lastIndex]
32
+ : insetIndex === lastIndex
33
+ ? [0, lastIndex - 1]
34
+ : [1, lastIndex]
35
+
36
+ const colorIndex = maybeColorsIndexes.find(index => !isValue(parts[index])) ?? -1
37
+ const maybeColor = colorIndex !== -1
38
+ ? parts[colorIndex]
39
+ : undefined
40
+ const color = maybeColor && processColor(maybeColor)
41
+ ? parts[colorIndex]
42
+ : undefined
43
+ const values = parts.filter((_, index) => index !== colorIndex && index !== insetIndex)
44
+
45
+ // at this point there can be only 4 values
46
+ if (values.length > 4) {
47
+ return undefined
48
+ }
49
+
50
+ const [offsetX, offsetY, blurRadius, spreadRadius] = values
51
+
52
+ if (!isValue(offsetX) || !isValue(offsetY)) {
53
+ return undefined
54
+ }
55
+
56
+ const blurRadiusValue = isValue(blurRadius)
57
+ ? Number.parseFloat(blurRadius as string)
58
+ : undefined
59
+
60
+ if (blurRadiusValue !== undefined && blurRadiusValue < 0) {
61
+ return undefined
62
+ }
63
+
64
+ return {
65
+ inset: insetIndex !== -1
66
+ ? true
67
+ : undefined,
68
+ offsetX: Number.parseFloat(offsetX as string),
69
+ offsetY: Number.parseFloat(offsetY as string),
70
+ blurRadius: blurRadiusValue ?? 0,
71
+ spreadDistance: spreadRadius
72
+ ? Number.parseFloat(spreadRadius as string)
73
+ : 0,
74
+ color
75
+ }
76
+ }
77
+
78
+ export const parseBoxShadowString = (str: string): Array<BoxShadow> => {
79
+ const parts = str
80
+ .split(/,(?![^()]*\))/)
81
+ .map(part => part.trim().replace('\n', ''))
82
+ .filter(Boolean)
83
+ .map(parseBoxShadow)
84
+ .filter(Boolean) as Array<BoxShadow>
85
+
86
+ return parts
87
+ }
@@ -10,7 +10,9 @@ export const listener = ({ dependencies, updateTheme, updateRuntime }: ListenerP
10
10
  }
11
11
 
12
12
  if (changedDependencies.some((dependency: UnistyleDependency) => dependencies.includes(dependency))) {
13
- updateRuntime()
13
+ const hasThemeNameChange = changedDependencies.includes(UnistyleDependency.ThemeName)
14
+
15
+ updateRuntime(hasThemeNameChange)
14
16
  }
15
17
  })
16
18
 
@@ -4,7 +4,7 @@ import type { ListenerProps } from './types'
4
4
 
5
5
  export const listener = ({ dependencies, updateTheme, updateRuntime }: ListenerProps) => {
6
6
  const disposeTheme = unistyles.services.listener.addListeners(dependencies.filter(dependency => dependency === UnistyleDependency.Theme), updateTheme)
7
- const disposeRuntime = unistyles.services.listener.addListeners(dependencies.filter(dependency => dependency !== UnistyleDependency.Theme), updateRuntime)
7
+ const disposeRuntime = unistyles.services.listener.addListeners(dependencies.filter(dependency => dependency !== UnistyleDependency.Theme), dependency => updateRuntime(dependency === UnistyleDependency.ThemeName))
8
8
 
9
9
  return () => {
10
10
  disposeTheme()
@@ -2,6 +2,6 @@ import type { UnistyleDependency } from '../../specs'
2
2
 
3
3
  export type ListenerProps = {
4
4
  updateTheme: VoidFunction,
5
- updateRuntime: VoidFunction,
5
+ updateRuntime(themeNameChange: boolean): void,
6
6
  dependencies: Array<UnistyleDependency>
7
7
  }
@@ -28,7 +28,7 @@ const RTDependencyMap = {
28
28
  } satisfies Partial<Record<keyof UnistylesMiniRuntime, UnistyleDependency>>
29
29
 
30
30
  export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
31
- const scopedTheme = forcedTheme ?? UnistylesShadowRegistry.getScopedTheme() as UnistylesTheme
31
+ const [scopedTheme, setScopedTheme] = useState(forcedTheme ?? UnistylesShadowRegistry.getScopedTheme() as UnistylesTheme)
32
32
  const [dependencies] = useState(() => new Set<number>())
33
33
  const [theme, setTheme] = useState(UnistylesRuntime.getTheme(scopedTheme))
34
34
  const [_, runtimeChanged] = useReducer(() => ({}), {})
@@ -45,7 +45,13 @@ export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
45
45
 
46
46
  setTheme(UnistylesRuntime.getTheme(scopedTheme))
47
47
  },
48
- updateRuntime: () => runtimeChanged()
48
+ updateRuntime: (hasThemeNameChange: boolean) => {
49
+ if (hasThemeNameChange && scopedTheme) {
50
+ return
51
+ }
52
+
53
+ runtimeChanged()
54
+ }
49
55
  })
50
56
  }
51
57
 
@@ -55,6 +61,13 @@ export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
55
61
  return () => disposeRef.current?.()
56
62
  }, [dependencies.size])
57
63
 
64
+
65
+ const maybeNewScopedTheme = UnistylesShadowRegistry.getScopedTheme() as UnistylesTheme
66
+
67
+ if (scopedTheme && maybeNewScopedTheme && scopedTheme !== maybeNewScopedTheme) {
68
+ setScopedTheme(maybeNewScopedTheme)
69
+ }
70
+
58
71
  const proxifiedTheme = new Proxy(theme, {
59
72
  get: (target, prop) => {
60
73
  dependencies.add(UnistyleDependency.Theme)
@@ -84,6 +97,10 @@ export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
84
97
  dependencies.add(RTDependencyMap[prop as keyof typeof RTDependencyMap])
85
98
  }
86
99
 
100
+ if (prop === 'themeName' && scopedTheme) {
101
+ return scopedTheme
102
+ }
103
+
87
104
  return target[prop as keyof typeof target]
88
105
  }
89
106
  })
@@ -4,4 +4,4 @@ import type { UnistylesTheme } from '../../types';
4
4
  export const SUPPORTED_STYLE_PROPS = ['style', 'contentContainerStyle'] as const
5
5
 
6
6
  export type SupportedStyleProps = typeof SUPPORTED_STYLE_PROPS[number]
7
- export type Mappings<T = {}> = (theme: UnistylesTheme, rt: UnistylesMiniRuntime) => Omit<Partial<T>, SupportedStyleProps>
7
+ export type Mappings<T = {}> = (theme: UnistylesTheme, rt: UnistylesMiniRuntime) => Omit<Partial<T>, SupportedStyleProps> & { key?: string }
@@ -26,6 +26,7 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
26
26
  type PropsWithUnistyles = Partial<TProps> & {
27
27
  uniProps?: Mappings<TProps>
28
28
  }
29
+
29
30
  const getSecrets = (styleProps: Record<string, any> = {}): MappedSecrets => {
30
31
  const styles = Array.isArray(styleProps)
31
32
  ? styleProps.flat()
@@ -74,8 +75,8 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
74
75
  addDependencies(Array.from(new Set([...styleSecrets.dependencies, ...contentContainerStyleSecrets.dependencies])))
75
76
  }, [narrowedProps.style, narrowedProps.contentContainerStyle])
76
77
 
77
- const mappingsProps = mappings ? mappings(proxifiedTheme, proxifiedRuntime) : {}
78
- const unistyleProps = narrowedProps.uniProps ? narrowedProps.uniProps(proxifiedTheme, proxifiedRuntime) : {}
78
+ const { key: mappingsKey, ...mappingsProps } = mappings ? mappings(proxifiedTheme, proxifiedRuntime) : {}
79
+ const { key: uniPropsKey, ...unistyleProps } = narrowedProps.uniProps ? narrowedProps.uniProps(proxifiedTheme, proxifiedRuntime) : {}
79
80
 
80
81
  const styleSecrets = getSecrets(narrowedProps.style)
81
82
  const contentContainerStyleSecrets = getSecrets(narrowedProps.contentContainerStyle)
@@ -90,6 +91,12 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
90
91
  } : {},
91
92
  } as any
92
93
 
93
- return <NativeComponent {...finalProps as TProps} ref={ref} />
94
+ return (
95
+ <NativeComponent
96
+ key={uniPropsKey || mappingsKey}
97
+ {...finalProps as TProps}
98
+ ref={ref}
99
+ />
100
+ )
94
101
  })
95
102
  }
@@ -27,16 +27,15 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
27
27
  const contentContainerStyleClassNames = getClassName(narrowedProps.contentContainerStyle)
28
28
  const { proxifiedRuntime, proxifiedTheme } = useProxifiedUnistyles()
29
29
 
30
- const mappingsProps = mappings ? mappings(proxifiedTheme, proxifiedRuntime) : {}
31
- const unistyleProps = narrowedProps.uniProps ? narrowedProps.uniProps(proxifiedTheme, proxifiedRuntime) : {}
32
-
30
+ const { key: mappingsKey, ...mappingsProps } = mappings ? mappings(proxifiedTheme, proxifiedRuntime) : {}
31
+ const { key: uniPropsKey, ...unistyleProps } = narrowedProps.uniProps ? narrowedProps.uniProps(proxifiedTheme, proxifiedRuntime) : {}
33
32
 
34
33
  const emptyStyles = narrowedProps.style
35
34
  ? Object.fromEntries(
36
- Object.entries(Object.getOwnPropertyDescriptors(narrowedProps.style))
37
- .filter(([key]) => !key.startsWith("unistyles") && !key.startsWith("_"))
38
- .map(([key]) => [key, undefined])
39
- )
35
+ Object.entries(Object.getOwnPropertyDescriptors(narrowedProps.style))
36
+ .filter(([key]) => !key.startsWith("unistyles") && !key.startsWith("_"))
37
+ .map(([key]) => [key, undefined])
38
+ )
40
39
  : undefined
41
40
 
42
41
  const combinedProps = {
@@ -63,7 +62,11 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
63
62
  className={classNames?.hash}
64
63
  style={{ display: 'contents' }}
65
64
  >
66
- <NativeComponent {...combinedProps} ref={ref} />
65
+ <NativeComponent
66
+ key={uniPropsKey || mappingsKey}
67
+ {...combinedProps}
68
+ ref={ref}
69
+ />
67
70
  </div>
68
71
  )
69
72
  })
package/src/index.ts CHANGED
@@ -1,3 +1,11 @@
1
+ import React from 'react'
2
+
3
+ const [majorReactVersions] = React.version.split('.').map(Number.parseInt)
4
+
5
+ if (majorReactVersions === undefined || majorReactVersions < 19) {
6
+ throw new Error('Unistyles 🦄: To enable full Fabric power you need to use React 19.0.0 or higher')
7
+ }
8
+
1
9
  export { StyleSheet, UnistylesRuntime, StatusBar, NavigationBar } from './specs'
2
10
  export { mq } from './mq'
3
11
  export type { UnistylesThemes, UnistylesBreakpoints } from './global'
package/src/mocks.ts CHANGED
@@ -65,6 +65,8 @@ jest.mock('react-native-unistyles', () => {
65
65
  colorScheme: 'unspecified' as ColorScheme,
66
66
  contentSizeCategory: 'Medium' as IOSContentSizeCategory,
67
67
  orientation: 'portrait' as Orientation,
68
+ isPortrait: true,
69
+ isLandscape: false,
68
70
  breakpoints: {},
69
71
  dispose: () => { },
70
72
  equals: () => false,
@@ -91,7 +93,7 @@ jest.mock('react-native-unistyles', () => {
91
93
  pixelRatio: 0,
92
94
  rtl: false,
93
95
  getTheme: () => {
94
- return {} as UnistylesTheme
96
+ return (Object.values(_REGISTRY.themes).at(0) ?? {}) as UnistylesTheme
95
97
  },
96
98
  setTheme: () => {},
97
99
  updateTheme: () => {},
@@ -200,7 +202,8 @@ jest.mock('react-native-unistyles', () => {
200
202
  }
201
203
  },
202
204
  jsMethods: {
203
- processColor: () => null
205
+ processColor: () => null,
206
+ parseBoxShadowString: () => []
204
207
  },
205
208
  hairlineWidth: 1,
206
209
  unid: -1,
@@ -214,4 +217,27 @@ jest.mock('react-native-unistyles', () => {
214
217
  }
215
218
  })
216
219
 
220
+ jest.mock('react-native-unistyles/reanimated', () => {
221
+ const unistyles = require('react-native-unistyles')
222
+ const mockedSharedValue = (value: any) => ({
223
+ value
224
+ })
217
225
 
226
+ return {
227
+ useAnimatedTheme: () => {
228
+ const theme = unistyles.useUnistyles().theme
229
+ const sharedTheme = mockedSharedValue(theme)
230
+
231
+ return sharedTheme
232
+ },
233
+ useAnimatedVariantColor: () => {
234
+ const fromValue = mockedSharedValue('#000000')
235
+ const toValue = mockedSharedValue('#FFFFFF')
236
+
237
+ return {
238
+ fromValue,
239
+ toValue
240
+ }
241
+ },
242
+ }
243
+ })
@@ -1 +1,2 @@
1
1
  export { useAnimatedTheme } from './useAnimatedTheme'
2
+ export { useAnimatedVariantColor } from './variant'
@@ -0,0 +1 @@
1
+ export * from './useAnimatedVariantColor'
@@ -0,0 +1,14 @@
1
+ export type ColorKeys<T> = {
2
+ [K in keyof T]: K extends string
3
+ ? K extends `${string}color${string}` | `${string}Color${string}`
4
+ ? K
5
+ : never
6
+ : never
7
+ }[keyof T]
8
+
9
+ export type UseUpdateVariantColorConfig<T extends Record<string, any>> = {
10
+ animateCallback?: (from: string, to: string) => void,
11
+ colorKey: ColorKeys<T>,
12
+ style: T,
13
+ secretKey: string | undefined
14
+ }
@@ -0,0 +1,38 @@
1
+ import { interpolateColor, useDerivedValue, useSharedValue } from 'react-native-reanimated'
2
+ import type { ColorKeys } from './types'
3
+ import { useUpdateVariantColor } from './useUpdateVariantColor'
4
+
5
+ export const useAnimatedVariantColor = <T extends Record<string, any>>(style: T, colorKey: ColorKeys<T>) => {
6
+ const secretKey = Object.keys(style).find(key => key.startsWith('unistyles_'))
7
+ // @ts-ignore this is hidden from TS
8
+ const hasVariants = style[secretKey]?.__stylesheetVariants
9
+
10
+ if (!hasVariants || !colorKey.toLowerCase().includes('color')) {
11
+ throw new Error('useAnimatedVariantColor: Style was not created by Unistyles, does not have variants or has no color property')
12
+ }
13
+
14
+ const { fromValue, toValue } = useUpdateVariantColor({
15
+ animateCallback: (from, to) => animate(from, to),
16
+ colorKey,
17
+ secretKey,
18
+ style,
19
+ })
20
+
21
+ const progress = useSharedValue(1)
22
+ const animate = (from: string, to: string) => {
23
+ 'worklet'
24
+
25
+ fromValue.set(from)
26
+ toValue.set(to)
27
+ }
28
+
29
+ const derivedColor = useDerivedValue(() => {
30
+ return interpolateColor(
31
+ progress.value,
32
+ [0, 1],
33
+ [fromValue.get(), toValue.get()]
34
+ )
35
+ })
36
+
37
+ return derivedColor
38
+ }
@@ -0,0 +1,38 @@
1
+ import { useEffect, useLayoutEffect } from 'react'
2
+ import { useSharedValue } from 'react-native-reanimated'
3
+ import { StyleSheet, UnistyleDependency } from '../../specs'
4
+ import type { UseUpdateVariantColorConfig } from './types'
5
+
6
+ export const useUpdateVariantColor = <T extends Record<string, any>>({
7
+ colorKey,
8
+ style,
9
+ secretKey
10
+ }: UseUpdateVariantColorConfig<T>) => {
11
+ const fromValue = useSharedValue<string>(style[colorKey])
12
+ const toValue = useSharedValue<string>(style[colorKey])
13
+
14
+ useEffect(() => {
15
+ // @ts-ignore this is hidden from TS
16
+ const dispose = StyleSheet.addChangeListener(changedDependencies => {
17
+ if (changedDependencies.includes(UnistyleDependency.Theme) || changedDependencies.includes(UnistyleDependency.Breakpoints)) {
18
+ // @ts-ignore
19
+ const newStyles = style[secretKey]?.uni__getStyles()
20
+
21
+ fromValue.set(toValue.value)
22
+ toValue.set(newStyles[colorKey])
23
+ }
24
+ })
25
+
26
+ return () => dispose()
27
+ }, [style, colorKey])
28
+
29
+ useLayoutEffect(() => {
30
+ fromValue.set(toValue.value)
31
+ toValue.set(style[colorKey])
32
+ }, [style, colorKey])
33
+
34
+ return {
35
+ fromValue,
36
+ toValue
37
+ }
38
+ }
@@ -0,0 +1,81 @@
1
+ import { useCallback, useEffect, useLayoutEffect, useMemo, useState } from 'react'
2
+ import { runOnUI, useSharedValue } from 'react-native-reanimated'
3
+ import { UnistyleDependency } from '../../specs'
4
+ import type { UnistylesValues } from '../../types'
5
+ import { services } from '../../web/services'
6
+ import { getClosestBreakpointValue } from '../../web/utils'
7
+ import type { UseUpdateVariantColorConfig } from './types'
8
+
9
+ export const useUpdateVariantColor = <T extends Record<string, any>>({
10
+ animateCallback,
11
+ colorKey,
12
+ style
13
+ }: UseUpdateVariantColorConfig<T>) => {
14
+ const [dummyDiv] = useState(() => {
15
+ const div = document.createElement('div')
16
+
17
+ div.style.display = 'none'
18
+ document.body.appendChild(div)
19
+
20
+ return div
21
+ })
22
+ const parsedStyles = useMemo(() => {
23
+ return services.shadowRegistry.addStyles([style]).parsedStyles
24
+ }, [style])
25
+ const getCurrentColor = useCallback(
26
+ () => {
27
+ if (!parsedStyles) {
28
+ return 'rgb(0, 0, 0)'
29
+ }
30
+
31
+ const currentColor = parsedStyles[colorKey as keyof UnistylesValues] as string | Record<string, string>
32
+ const currentColorVar = typeof currentColor === 'string'
33
+ ? currentColor
34
+ : getClosestBreakpointValue<string>(services.runtime, currentColor) ?? 'rgb(0, 0, 0)'
35
+
36
+ if (currentColorVar.startsWith('var(--')) {
37
+ dummyDiv.style.color = currentColorVar
38
+
39
+ return getComputedStyle(dummyDiv).color
40
+ }
41
+
42
+ return currentColorVar
43
+ },
44
+ [style, colorKey]
45
+ )
46
+ const fromValue = useSharedValue<string>(getCurrentColor())
47
+ const toValue = useSharedValue<string>(getCurrentColor())
48
+
49
+ useEffect(() => {
50
+ const dispose = services.listener.addListeners([UnistyleDependency.Theme], () => {
51
+ runOnUI(() => {
52
+ animateCallback?.(toValue.get(), getCurrentColor())
53
+ })()
54
+ })
55
+
56
+ return () => dispose()
57
+ }, [style, colorKey])
58
+
59
+ useLayoutEffect(() => {
60
+ animateCallback?.(toValue.get(), getCurrentColor())
61
+
62
+ const colorStyle = parsedStyles?.[colorKey as keyof UnistylesValues]
63
+
64
+ if (typeof colorStyle !== 'object' || colorStyle === null) {
65
+ return
66
+ }
67
+
68
+ const dispose = services.listener.addListeners([UnistyleDependency.Breakpoints], () => {
69
+ animateCallback?.(toValue.get(), getCurrentColor())
70
+ })
71
+
72
+ return () => dispose()
73
+ }, [style, colorKey])
74
+
75
+ useEffect(() => () => dummyDiv.remove(), [])
76
+
77
+ return {
78
+ fromValue,
79
+ toValue
80
+ }
81
+ }
@@ -9,6 +9,7 @@ interface ShadowRegistry extends UnistylesShadowRegistrySpec {
9
9
  // JSI
10
10
  link(node: ShadowNode, styles?: Array<Unistyle>): void,
11
11
  unlink(node: ShadowNode): void,
12
+ flush(): void,
12
13
  setScopedTheme(themeName?: string): void,
13
14
  getScopedTheme(): string | undefined
14
15
  }
@@ -23,8 +24,13 @@ const findShadowNodeForHandle = (handle: ViewHandle) => {
23
24
  ?? handle?.viewRef?.current?.__internalInstanceHandle?.stateNode?.node
24
25
  ?? handle?._nativeRef?.__internalInstanceHandle?.stateNode?.node
25
26
 
27
+ // @ts-ignore we don't know the type of handle
28
+ if (!node && handle?.props?.horizontal && handle?.constructor?.name === 'FlatList') {
29
+ throw new Error('Unistyles: detected an unsupported FlatList with the horizontal prop. This will cause crashes on Android due to a bug in React Native core. Read more: https://github.com/facebook/react-native/issues/51601')
30
+ }
31
+
26
32
  if (!node) {
27
- throw new Error(`Unistyles: Could not find shadow node for one of your components of type ${handle?.__internalInstanceHandle?.elementType ?? 'unknown'}`)
33
+ throw new Error(`Unistyles: Could not find shadow node for one of your components of type ${handle?.constructor?.name ?? 'unknown'}`)
28
34
  }
29
35
 
30
36
  return node
@@ -1,6 +1,7 @@
1
1
  import { StyleSheet as NativeStyleSheet, processColor } from 'react-native'
2
2
  import type { StyleSheet as NativeStyleSheetType } from 'react-native'
3
3
  import { NitroModules } from 'react-native-nitro-modules'
4
+ import { parseBoxShadowString } from '../../core/parseBoxShadow'
4
5
  import type { UnistylesBreakpoints, UnistylesThemes } from '../../global'
5
6
  import type { CreateUnistylesStyleSheet } from '../../types'
6
7
  import type { UnistylesStyleSheet as UnistylesStyleSheetSpec } from './UnistylesStyleSheet.nitro'
@@ -33,7 +34,8 @@ export interface UnistylesStyleSheet extends UnistylesStyleSheetSpec {
33
34
  create: CreateUnistylesStyleSheet,
34
35
  configure(config: UnistylesConfig): void,
35
36
  jsMethods: {
36
- processColor: typeof processColor
37
+ processColor: typeof processColor,
38
+ parseBoxShadowString: typeof parseBoxShadowString
37
39
  }
38
40
  }
39
41
 
@@ -45,7 +47,8 @@ HybridUnistylesStyleSheet.absoluteFill = NativeStyleSheet.absoluteFill
45
47
  HybridUnistylesStyleSheet.flatten = NativeStyleSheet.flatten
46
48
  HybridUnistylesStyleSheet.compose = NativeStyleSheet.compose
47
49
  HybridUnistylesStyleSheet.jsMethods = {
48
- processColor
50
+ processColor,
51
+ parseBoxShadowString
49
52
  }
50
53
 
51
54
  HybridUnistylesStyleSheet.init()
@@ -36,6 +36,8 @@ export interface UnistylesRuntime extends HybridObject<{ ios: 'c++', android: 'c
36
36
  readonly pixelRatio: number,
37
37
  readonly fontScale: number,
38
38
  readonly rtl: boolean,
39
+ readonly isLandscape: boolean,
40
+ readonly isPortrait: boolean,
39
41
 
40
42
  setTheme(themeName: string): void,
41
43
  setAdaptiveThemes(isEnabled: boolean): void,
@@ -44,7 +44,6 @@ const HybridUnistylesRuntime = NitroModules
44
44
 
45
45
  HybridUnistylesRuntime.statusBar = HybridUnistylesRuntime.createHybridStatusBar()
46
46
  HybridUnistylesRuntime.navigationBar = HybridUnistylesRuntime.createHybridNavigationBar()
47
- HybridUnistylesRuntime._setRootViewBackgroundColor = HybridUnistylesRuntime.setRootViewBackgroundColor
48
47
 
49
48
  HybridUnistylesRuntime.setRootViewBackgroundColor = (color?: string) => {
50
49
  const parsedColor = processColor(color) ?? 0