react-native-unistyles 3.0.0-rc.4 → 3.0.0-rc.5

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 (288) hide show
  1. package/README.md +10 -8
  2. package/android/src/main/cxx/NativeUnistylesModule.cpp +3 -7
  3. package/android/src/main/cxx/NativeUnistylesModule.h +0 -4
  4. package/android/src/main/java/com/unistyles/UnistylesModule.kt +1 -7
  5. package/cxx/core/UnistyleWrapper.h +4 -1
  6. package/cxx/core/UnistylesCommitShadowNode.h +0 -21
  7. package/cxx/core/UnistylesRegistry.cpp +45 -49
  8. package/cxx/core/UnistylesState.cpp +10 -0
  9. package/cxx/core/UnistylesState.h +3 -0
  10. package/cxx/hybridObjects/HybridShadowRegistry.cpp +6 -1
  11. package/cxx/hybridObjects/HybridShadowRegistry.h +6 -0
  12. package/cxx/hybridObjects/HybridStyleSheet.cpp +13 -16
  13. package/cxx/hybridObjects/HybridStyleSheet.h +2 -7
  14. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +8 -0
  15. package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -0
  16. package/cxx/parser/Parser.cpp +175 -110
  17. package/cxx/parser/Parser.h +1 -0
  18. package/cxx/shadowTree/ShadowTreeManager.cpp +36 -33
  19. package/cxx/shadowTree/ShadowTreeManager.h +0 -1
  20. package/ios/UnistylesModuleOnLoad.h +1 -5
  21. package/ios/UnistylesModuleOnLoad.mm +5 -13
  22. package/lib/commonjs/components/AdaptiveTheme.js +35 -0
  23. package/lib/commonjs/components/AdaptiveTheme.js.map +1 -0
  24. package/lib/commonjs/components/ApplyScopedTheme.js +19 -0
  25. package/lib/commonjs/components/ApplyScopedTheme.js.map +1 -0
  26. package/lib/commonjs/components/NamedTheme.js +31 -0
  27. package/lib/commonjs/components/NamedTheme.js.map +1 -0
  28. package/lib/commonjs/components/ScopedTheme.js +24 -20
  29. package/lib/commonjs/components/ScopedTheme.js.map +1 -1
  30. package/lib/commonjs/components/native/Image.js +1 -2
  31. package/lib/commonjs/components/native/Image.js.map +1 -1
  32. package/lib/commonjs/components/native/ImageBackground.js +1 -2
  33. package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
  34. package/lib/commonjs/components/native/Pressable.js +1 -2
  35. package/lib/commonjs/components/native/Pressable.js.map +1 -1
  36. package/lib/commonjs/components/native/Pressable.native.js +1 -2
  37. package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
  38. package/lib/commonjs/core/createUnistylesElement.js +3 -3
  39. package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
  40. package/lib/commonjs/core/createUnistylesElement.native.js +18 -31
  41. package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
  42. package/lib/commonjs/core/createUnistylesImageBackground.js +6 -21
  43. package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
  44. package/lib/commonjs/core/getClassname.js +1 -2
  45. package/lib/commonjs/core/getClassname.js.map +1 -1
  46. package/lib/commonjs/core/parseBoxShadow.js +57 -0
  47. package/lib/commonjs/core/parseBoxShadow.js.map +1 -0
  48. package/lib/commonjs/core/useProxifiedUnistyles/listener.js +1 -2
  49. package/lib/commonjs/core/useProxifiedUnistyles/listener.js.map +1 -1
  50. package/lib/commonjs/core/withUnistyles/withUnistyles.js +1 -2
  51. package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
  52. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +1 -2
  53. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
  54. package/lib/commonjs/index.js +6 -0
  55. package/lib/commonjs/index.js.map +1 -1
  56. package/lib/commonjs/mocks.js +5 -2
  57. package/lib/commonjs/mocks.js.map +1 -1
  58. package/lib/commonjs/reanimated/index.js +7 -0
  59. package/lib/commonjs/reanimated/index.js.map +1 -1
  60. package/lib/commonjs/reanimated/variant/index.js +17 -0
  61. package/lib/commonjs/reanimated/variant/index.js.map +1 -0
  62. package/lib/commonjs/reanimated/variant/types.js +2 -0
  63. package/lib/commonjs/reanimated/variant/types.js.map +1 -0
  64. package/lib/commonjs/reanimated/variant/useAnimatedVariantColor.js +38 -0
  65. package/lib/commonjs/reanimated/variant/useAnimatedVariantColor.js.map +1 -0
  66. package/lib/commonjs/reanimated/variant/useUpdateVariantColor.js +66 -0
  67. package/lib/commonjs/reanimated/variant/useUpdateVariantColor.js.map +1 -0
  68. package/lib/commonjs/reanimated/variant/useUpdateVariantColor.native.js +39 -0
  69. package/lib/commonjs/reanimated/variant/useUpdateVariantColor.native.js.map +1 -0
  70. package/lib/commonjs/server/getServerUnistyles.js +1 -2
  71. package/lib/commonjs/server/getServerUnistyles.js.map +1 -1
  72. package/lib/commonjs/server/hydrateServerUnistyles.js +1 -2
  73. package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -1
  74. package/lib/commonjs/server/resetServerUnistyles.js +1 -2
  75. package/lib/commonjs/server/resetServerUnistyles.js.map +1 -1
  76. package/lib/commonjs/specs/ShadowRegistry/index.js +6 -1
  77. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  78. package/lib/commonjs/specs/StyleSheet/index.js +3 -1
  79. package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
  80. package/lib/commonjs/utils.js +0 -3
  81. package/lib/commonjs/utils.js.map +1 -1
  82. package/lib/commonjs/web/create.js +2 -3
  83. package/lib/commonjs/web/create.js.map +1 -1
  84. package/lib/commonjs/web/css/core.js +6 -1
  85. package/lib/commonjs/web/css/core.js.map +1 -1
  86. package/lib/commonjs/web/css/state.js +10 -7
  87. package/lib/commonjs/web/css/state.js.map +1 -1
  88. package/lib/commonjs/web/index.js +1 -2
  89. package/lib/commonjs/web/index.js.map +1 -1
  90. package/lib/commonjs/web/listener.js +2 -0
  91. package/lib/commonjs/web/listener.js.map +1 -1
  92. package/lib/commonjs/web/runtime.js +15 -1
  93. package/lib/commonjs/web/runtime.js.map +1 -1
  94. package/lib/commonjs/web/shadowRegistry.js +5 -3
  95. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  96. package/lib/commonjs/web/state.js +1 -10
  97. package/lib/commonjs/web/state.js.map +1 -1
  98. package/lib/commonjs/web/types.js.map +1 -1
  99. package/lib/commonjs/web/utils/createUnistylesRef.js +1 -2
  100. package/lib/commonjs/web/utils/createUnistylesRef.js.map +1 -1
  101. package/lib/commonjs/web/utils/unistyle.js +26 -4
  102. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  103. package/lib/module/components/AdaptiveTheme.js +29 -0
  104. package/lib/module/components/AdaptiveTheme.js.map +1 -0
  105. package/lib/module/components/ApplyScopedTheme.js +14 -0
  106. package/lib/module/components/ApplyScopedTheme.js.map +1 -0
  107. package/lib/module/components/NamedTheme.js +25 -0
  108. package/lib/module/components/NamedTheme.js.map +1 -0
  109. package/lib/module/components/ScopedTheme.js +24 -19
  110. package/lib/module/components/ScopedTheme.js.map +1 -1
  111. package/lib/module/core/createUnistylesElement.js +3 -3
  112. package/lib/module/core/createUnistylesElement.js.map +1 -1
  113. package/lib/module/core/createUnistylesElement.native.js +18 -30
  114. package/lib/module/core/createUnistylesElement.native.js.map +1 -1
  115. package/lib/module/core/createUnistylesImageBackground.js +5 -19
  116. package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
  117. package/lib/module/core/parseBoxShadow.js +52 -0
  118. package/lib/module/core/parseBoxShadow.js.map +1 -0
  119. package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
  120. package/lib/module/index.js +5 -0
  121. package/lib/module/index.js.map +1 -1
  122. package/lib/module/mocks.js +5 -2
  123. package/lib/module/mocks.js.map +1 -1
  124. package/lib/module/reanimated/index.js +1 -0
  125. package/lib/module/reanimated/index.js.map +1 -1
  126. package/lib/module/reanimated/variant/index.js +4 -0
  127. package/lib/module/reanimated/variant/index.js.map +1 -0
  128. package/lib/module/reanimated/variant/types.js +2 -0
  129. package/lib/module/reanimated/variant/types.js.map +1 -0
  130. package/lib/module/reanimated/variant/useAnimatedVariantColor.js +33 -0
  131. package/lib/module/reanimated/variant/useAnimatedVariantColor.js.map +1 -0
  132. package/lib/module/reanimated/variant/useUpdateVariantColor.js +61 -0
  133. package/lib/module/reanimated/variant/useUpdateVariantColor.js.map +1 -0
  134. package/lib/module/reanimated/variant/useUpdateVariantColor.native.js +34 -0
  135. package/lib/module/reanimated/variant/useUpdateVariantColor.native.js.map +1 -0
  136. package/lib/module/specs/ShadowRegistry/index.js +6 -1
  137. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  138. package/lib/module/specs/StyleSheet/index.js +3 -1
  139. package/lib/module/specs/StyleSheet/index.js.map +1 -1
  140. package/lib/module/utils.js +0 -3
  141. package/lib/module/utils.js.map +1 -1
  142. package/lib/module/web/create.js +1 -1
  143. package/lib/module/web/create.js.map +1 -1
  144. package/lib/module/web/css/core.js +6 -1
  145. package/lib/module/web/css/core.js.map +1 -1
  146. package/lib/module/web/css/state.js +10 -7
  147. package/lib/module/web/css/state.js.map +1 -1
  148. package/lib/module/web/listener.js +2 -0
  149. package/lib/module/web/listener.js.map +1 -1
  150. package/lib/module/web/runtime.js +16 -2
  151. package/lib/module/web/runtime.js.map +1 -1
  152. package/lib/module/web/shadowRegistry.js +5 -3
  153. package/lib/module/web/shadowRegistry.js.map +1 -1
  154. package/lib/module/web/state.js +1 -10
  155. package/lib/module/web/state.js.map +1 -1
  156. package/lib/module/web/types.js.map +1 -1
  157. package/lib/module/web/utils/unistyle.js +24 -3
  158. package/lib/module/web/utils/unistyle.js.map +1 -1
  159. package/lib/typescript/plugin/src/consts.d.ts +17 -0
  160. package/lib/typescript/plugin/src/consts.d.ts.map +1 -0
  161. package/lib/typescript/repack-plugin/src/index.d.ts +18 -0
  162. package/lib/typescript/repack-plugin/src/index.d.ts.map +1 -0
  163. package/lib/typescript/repack-plugin/src/loader.d.ts +9 -0
  164. package/lib/typescript/repack-plugin/src/loader.d.ts.map +1 -0
  165. package/lib/typescript/src/components/AdaptiveTheme.d.ts +8 -0
  166. package/lib/typescript/src/components/AdaptiveTheme.d.ts.map +1 -0
  167. package/lib/typescript/src/components/ApplyScopedTheme.d.ts +7 -0
  168. package/lib/typescript/src/components/ApplyScopedTheme.d.ts.map +1 -0
  169. package/lib/typescript/src/components/NamedTheme.d.ts +10 -0
  170. package/lib/typescript/src/components/NamedTheme.d.ts.map +1 -0
  171. package/lib/typescript/src/components/ScopedTheme.d.ts +4 -0
  172. package/lib/typescript/src/components/ScopedTheme.d.ts.map +1 -1
  173. package/lib/typescript/src/components/native/Animated.d.ts.map +1 -1
  174. package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
  175. package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
  176. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
  177. package/lib/typescript/src/core/getClassname.d.ts.map +1 -1
  178. package/lib/typescript/src/core/parseBoxShadow.d.ts +11 -0
  179. package/lib/typescript/src/core/parseBoxShadow.d.ts.map +1 -0
  180. package/lib/typescript/src/core/passForwardRef.d.ts.map +1 -1
  181. package/lib/typescript/src/core/useProxifiedUnistyles/listener.d.ts.map +1 -1
  182. package/lib/typescript/src/core/useProxifiedUnistyles/listener.native.d.ts.map +1 -1
  183. package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
  184. package/lib/typescript/src/core/warn.d.ts.map +1 -1
  185. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
  186. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
  187. package/lib/typescript/src/hooks/useMedia.d.ts.map +1 -1
  188. package/lib/typescript/src/hooks/useMedia.native.d.ts.map +1 -1
  189. package/lib/typescript/src/index.d.ts.map +1 -1
  190. package/lib/typescript/src/reanimated/index.d.ts +1 -0
  191. package/lib/typescript/src/reanimated/index.d.ts.map +1 -1
  192. package/lib/typescript/src/reanimated/variant/index.d.ts +2 -0
  193. package/lib/typescript/src/reanimated/variant/index.d.ts.map +1 -0
  194. package/lib/typescript/src/reanimated/variant/types.d.ts +10 -0
  195. package/lib/typescript/src/reanimated/variant/types.d.ts.map +1 -0
  196. package/lib/typescript/src/reanimated/variant/useAnimatedVariantColor.d.ts +3 -0
  197. package/lib/typescript/src/reanimated/variant/useAnimatedVariantColor.d.ts.map +1 -0
  198. package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.d.ts +6 -0
  199. package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.d.ts.map +1 -0
  200. package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.native.d.ts +6 -0
  201. package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.native.d.ts.map +1 -0
  202. package/lib/typescript/src/server/getServerUnistyles.d.ts.map +1 -1
  203. package/lib/typescript/src/server/serialize.d.ts.map +1 -1
  204. package/lib/typescript/src/server/useServerUnistyles.d.ts.map +1 -1
  205. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +1 -0
  206. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  207. package/lib/typescript/src/specs/StatusBar/index.d.ts.map +1 -1
  208. package/lib/typescript/src/specs/StyleSheet/index.d.ts +2 -0
  209. package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
  210. package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts +2 -0
  211. package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts.map +1 -1
  212. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  213. package/lib/typescript/src/utils.d.ts.map +1 -1
  214. package/lib/typescript/src/web/convert/index.d.ts.map +1 -1
  215. package/lib/typescript/src/web/convert/object/boxShadow.d.ts.map +1 -1
  216. package/lib/typescript/src/web/convert/object/filter.d.ts.map +1 -1
  217. package/lib/typescript/src/web/convert/object/objectStyle.d.ts.map +1 -1
  218. package/lib/typescript/src/web/convert/object/transform.d.ts.map +1 -1
  219. package/lib/typescript/src/web/convert/pseudo.d.ts.map +1 -1
  220. package/lib/typescript/src/web/convert/shadow/boxShadow.d.ts.map +1 -1
  221. package/lib/typescript/src/web/convert/shadow/getShadowBreakpoints.d.ts.map +1 -1
  222. package/lib/typescript/src/web/convert/shadow/textShadow.d.ts.map +1 -1
  223. package/lib/typescript/src/web/convert/style.d.ts.map +1 -1
  224. package/lib/typescript/src/web/convert/utils.d.ts.map +1 -1
  225. package/lib/typescript/src/web/create.d.ts.map +1 -1
  226. package/lib/typescript/src/web/css/core.d.ts.map +1 -1
  227. package/lib/typescript/src/web/css/state.d.ts +2 -1
  228. package/lib/typescript/src/web/css/state.d.ts.map +1 -1
  229. package/lib/typescript/src/web/css/utils.d.ts.map +1 -1
  230. package/lib/typescript/src/web/listener.d.ts.map +1 -1
  231. package/lib/typescript/src/web/registry.d.ts.map +1 -1
  232. package/lib/typescript/src/web/runtime.d.ts +2 -0
  233. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  234. package/lib/typescript/src/web/shadowRegistry.d.ts +2 -0
  235. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  236. package/lib/typescript/src/web/state.d.ts.map +1 -1
  237. package/lib/typescript/src/web/types.d.ts +4 -1
  238. package/lib/typescript/src/web/types.d.ts.map +1 -1
  239. package/lib/typescript/src/web/utils/common.d.ts.map +1 -1
  240. package/lib/typescript/src/web/utils/createUnistylesRef.d.ts.map +1 -1
  241. package/lib/typescript/src/web/utils/unistyle.d.ts +5 -1
  242. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  243. package/lib/typescript/src/web/variants.d.ts.map +1 -1
  244. package/lib/typescript/src/web-only/getWebProps.d.ts.map +1 -1
  245. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +1 -0
  246. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.cpp +2 -0
  247. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +2 -0
  248. package/package.json +32 -23
  249. package/plugin/index.d.ts +6 -5
  250. package/plugin/index.js +11 -6
  251. package/repack-plugin/index.d.ts +19 -0
  252. package/repack-plugin/index.js +149 -0
  253. package/src/components/AdaptiveTheme.tsx +34 -0
  254. package/src/components/ApplyScopedTheme.tsx +17 -0
  255. package/src/components/NamedTheme.tsx +33 -0
  256. package/src/components/ScopedTheme.tsx +42 -22
  257. package/src/core/createUnistylesElement.native.tsx +21 -31
  258. package/src/core/createUnistylesElement.tsx +3 -3
  259. package/src/core/createUnistylesImageBackground.tsx +7 -22
  260. package/src/core/parseBoxShadow.ts +87 -0
  261. package/src/core/withUnistyles/withUnistyles.native.tsx +1 -0
  262. package/src/index.ts +8 -0
  263. package/src/mocks.ts +5 -2
  264. package/src/reanimated/index.ts +1 -0
  265. package/src/reanimated/variant/index.ts +1 -0
  266. package/src/reanimated/variant/types.ts +14 -0
  267. package/src/reanimated/variant/useAnimatedVariantColor.ts +38 -0
  268. package/src/reanimated/variant/useUpdateVariantColor.native.ts +38 -0
  269. package/src/reanimated/variant/useUpdateVariantColor.ts +81 -0
  270. package/src/specs/ShadowRegistry/index.ts +7 -1
  271. package/src/specs/StyleSheet/index.ts +5 -2
  272. package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.ts +2 -0
  273. package/src/utils.ts +1 -3
  274. package/src/web/create.ts +1 -1
  275. package/src/web/css/core.ts +9 -1
  276. package/src/web/css/state.ts +10 -8
  277. package/src/web/listener.ts +2 -0
  278. package/src/web/runtime.ts +23 -2
  279. package/src/web/shadowRegistry.ts +5 -3
  280. package/src/web/state.ts +7 -17
  281. package/src/web/types.ts +4 -1
  282. package/src/web/utils/unistyle.ts +34 -4
  283. package/cxx/core/UnistylesCommitHook.cpp +0 -59
  284. package/cxx/core/UnistylesCommitHook.h +0 -27
  285. package/cxx/core/UnistylesMountHook.cpp +0 -26
  286. package/cxx/core/UnistylesMountHook.h +0 -24
  287. package/lib/module/package.json +0 -1
  288. /package/{web-only → web}/package.json +0 -0
@@ -0,0 +1,17 @@
1
+ import { useLayoutEffect } from 'react'
2
+ import type { UnistylesThemes } from '../global'
3
+ import { UnistylesShadowRegistry } from '../specs'
4
+
5
+ type ApplyScopedThemeProps = {
6
+ name?: keyof UnistylesThemes
7
+ }
8
+
9
+ export const ApplyScopedTheme: React.FunctionComponent<ApplyScopedThemeProps> = ({ name }) => {
10
+ UnistylesShadowRegistry.setScopedTheme(name)
11
+
12
+ useLayoutEffect(() => {
13
+ UnistylesShadowRegistry.setScopedTheme(name)
14
+ })
15
+
16
+ return null
17
+ }
@@ -0,0 +1,33 @@
1
+ import React, { useLayoutEffect } from 'react'
2
+ import type { PropsWithChildren } from 'react'
3
+ import type { UnistylesThemes } from '../global'
4
+ import { UnistylesShadowRegistry } from '../specs'
5
+ import { ApplyScopedTheme } from './ApplyScopedTheme'
6
+
7
+ interface NamedThemeProps extends PropsWithChildren {
8
+ name: keyof UnistylesThemes,
9
+ previousScopedTheme?: string
10
+ }
11
+
12
+ export const NamedTheme: React.FunctionComponent<NamedThemeProps> = ({
13
+ name,
14
+ children,
15
+ previousScopedTheme
16
+ }) => {
17
+ const mappedChildren = [
18
+ <ApplyScopedTheme key={name} name={name} />,
19
+ children,
20
+ <ApplyScopedTheme key='dispose' name={previousScopedTheme as keyof UnistylesThemes | undefined} />
21
+ ]
22
+
23
+ useLayoutEffect(() => {
24
+ // this will affect only scoped styles as other styles are not yet mounted
25
+ UnistylesShadowRegistry.flush()
26
+ })
27
+
28
+ return (
29
+ <React.Fragment>
30
+ {mappedChildren}
31
+ </React.Fragment>
32
+ )
33
+ }
@@ -1,32 +1,52 @@
1
- import React, { useLayoutEffect } from 'react'
1
+ import React from 'react'
2
2
  import type { UnistylesThemes } from '../global'
3
- import { UnistylesShadowRegistry } from '../specs'
3
+ import { UnistylesRuntime, UnistylesShadowRegistry } from '../specs'
4
+ import { AdaptiveTheme } from './AdaptiveTheme'
5
+ import { NamedTheme } from './NamedTheme'
4
6
 
5
7
  type ThemeProps = {
6
- name: keyof UnistylesThemes
8
+ name: keyof UnistylesThemes,
9
+ invertedAdaptive?: boolean
10
+ } | {
11
+ name?: undefined,
12
+ invertedAdaptive: true
7
13
  }
8
14
 
9
- const Apply = ({ name }: { name?: keyof UnistylesThemes }) => {
10
- UnistylesShadowRegistry.setScopedTheme(name)
15
+ export const ScopedTheme: React.FunctionComponent<React.PropsWithChildren<ThemeProps>> = ({
16
+ name,
17
+ children,
18
+ invertedAdaptive
19
+ }) => {
20
+ const hasAdaptiveThemes = UnistylesRuntime.hasAdaptiveThemes
21
+ const isAdaptiveTheme = invertedAdaptive && hasAdaptiveThemes
11
22
 
12
- useLayoutEffect(() => {
13
- UnistylesShadowRegistry.setScopedTheme(name)
14
- })
23
+ if (invertedAdaptive && !hasAdaptiveThemes) {
24
+ return children
25
+ }
15
26
 
16
- return null
17
- }
27
+ if (!invertedAdaptive && !name) {
28
+ if (__DEV__) {
29
+ console.error('ScopedTheme: name or invertedAdaptive must be provided')
30
+ }
31
+
32
+ return null
33
+ }
18
34
 
19
- export const ScopedTheme: React.FunctionComponent<React.PropsWithChildren<ThemeProps>> = ({ name, children }) => {
20
35
  const previousScopedTheme = UnistylesShadowRegistry.getScopedTheme()
21
- const mappedChildren = [
22
- <Apply key={name} name={name} />,
23
- children,
24
- <Apply key='dispose' name={previousScopedTheme as keyof UnistylesThemes | undefined} />
25
- ]
26
-
27
- return (
28
- <React.Fragment>
29
- {mappedChildren}
30
- </React.Fragment>
31
- )
36
+
37
+ return isAdaptiveTheme
38
+ ? (
39
+ <AdaptiveTheme previousScopedTheme={previousScopedTheme}>
40
+ {children}
41
+ </AdaptiveTheme>
42
+ )
43
+ : (
44
+ <NamedTheme
45
+ name={name as keyof UnistylesThemes}
46
+ previousScopedTheme={previousScopedTheme}
47
+ >
48
+ {children}
49
+ </NamedTheme>
50
+ )
51
+
32
52
  }
@@ -1,49 +1,39 @@
1
- import React, { useLayoutEffect, useRef } from 'react'
1
+ import React, { useRef } from 'react'
2
+ import type { ScrollView } from 'react-native'
2
3
  import { UnistylesShadowRegistry } from '../specs'
3
4
  import { copyComponentProperties } from '../utils'
4
5
  import { passForwardedRef } from './passForwardRef'
5
6
  import { maybeWarnAboutMultipleUnistyles } from './warn'
6
7
 
7
- const getNativeRef = (Component: any, ref: any) => {
8
- switch (Component.name) {
9
- case 'KeyboardAvoidingView':
10
- return ref.viewRef?.current
11
- case 'FlatList':
12
- return ref.getNativeScrollRef?.()
13
- case 'VirtualizedList':
14
- return ref.getScrollRef?.()
15
- default:
16
- return ref
17
- }
18
- }
19
-
20
8
  export const createUnistylesElement = (Component: any) => {
21
- const UnistylesComponent = React.forwardRef((props, forwardedRef) => {
22
- const storedRef = useRef<unknown>(null)
23
-
24
- useLayoutEffect(() => {
25
- return () => {
26
- if (storedRef.current) {
27
- // @ts-ignore
28
- UnistylesShadowRegistry.remove(storedRef.current)
29
- }
30
- }
31
- }, [])
9
+ const UnistylesComponent = (props: any) => {
10
+ const scrollViewRef = useRef<ScrollView>(null)
32
11
 
33
12
  return (
34
13
  <Component
35
14
  {...props}
36
15
  ref={(ref: unknown) => {
37
- if (ref) {
38
- storedRef.current = getNativeRef(Component, ref)
16
+ maybeWarnAboutMultipleUnistyles(props.style, Component.displayName)
17
+
18
+ // https://github.com/facebook/react-native/issues/51878
19
+ // tested with ScrollView, REA ScrolLView and Animated ScrollView
20
+ const isScrollView = Component.displayName === 'ScrollView'
21
+
22
+ if (isScrollView && ref) {
23
+ scrollViewRef.current = ref as ScrollView
39
24
  }
40
25
 
41
- // @ts-ignore we don't know the type of the component
42
- maybeWarnAboutMultipleUnistyles(props.style, Component.displayName)
26
+ if (isScrollView && !ref) {
27
+ // @ts-ignore this is hidden from TS
28
+ UnistylesShadowRegistry.remove(scrollViewRef.current)
29
+ scrollViewRef.current = null
30
+
31
+ return
32
+ }
43
33
 
44
34
  return passForwardedRef(
45
35
  ref,
46
- forwardedRef,
36
+ props.ref,
47
37
  () => {
48
38
  // @ts-ignore this is hidden from TS
49
39
  UnistylesShadowRegistry.add(ref, props.style)
@@ -56,7 +46,7 @@ export const createUnistylesElement = (Component: any) => {
56
46
  }}
57
47
  />
58
48
  )
59
- })
49
+ }
60
50
 
61
51
  return copyComponentProperties(Component, UnistylesComponent)
62
52
  }
@@ -34,14 +34,14 @@ const buildUnistylesProps = (Component: any, props: ComponentProps, forwardedRef
34
34
  }
35
35
 
36
36
  export const createUnistylesElement = (Component: any) => {
37
- const UnistylesComponent = React.forwardRef<unknown, ComponentProps>((props, forwardedRef) => {
37
+ const UnistylesComponent = (props: any) => {
38
38
  return (
39
39
  <Component
40
40
  {...props}
41
- {...buildUnistylesProps(Component, props, forwardedRef)}
41
+ {...buildUnistylesProps(Component, props, props.ref)}
42
42
  />
43
43
  )
44
- })
44
+ }
45
45
 
46
46
  return copyComponentProperties(Component, UnistylesComponent)
47
47
  }
@@ -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
+ }
@@ -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()
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,
@@ -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,
package/src/utils.ts CHANGED
@@ -35,10 +35,8 @@ export const copyComponentProperties = (Component: any, UnistylesComponent: any)
35
35
  UnistylesComponent[key] = value
36
36
  })
37
37
 
38
- // Those are not enumerable, so we need to copy them manually
39
38
  UnistylesComponent.displayName = Component.displayName
40
- UnistylesComponent.name = Component.name
41
-
39
+
42
40
  return UnistylesComponent
43
41
  }
44
42