react-native-unistyles 3.0.0-nightly-20250607 → 3.0.0-nightly-20250613

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 (136) hide show
  1. package/README.md +4 -6
  2. package/android/src/main/cxx/NativeUnistylesModule.cpp +2 -1
  3. package/android/src/main/cxx/NativeUnistylesModule.h +4 -0
  4. package/android/src/main/java/com/unistyles/UnistylesModule.kt +7 -0
  5. package/cxx/core/UnistyleWrapper.h +4 -1
  6. package/cxx/core/UnistylesRegistry.cpp +7 -6
  7. package/cxx/core/UnistylesRegistry.h +2 -1
  8. package/ios/UnistylesModuleOnLoad.mm +5 -0
  9. package/lib/commonjs/components/AdaptiveTheme.js +35 -0
  10. package/lib/commonjs/components/AdaptiveTheme.js.map +1 -0
  11. package/lib/commonjs/components/ApplyScopedTheme.js +19 -0
  12. package/lib/commonjs/components/ApplyScopedTheme.js.map +1 -0
  13. package/lib/commonjs/components/NamedTheme.js +31 -0
  14. package/lib/commonjs/components/NamedTheme.js.map +1 -0
  15. package/lib/commonjs/components/ScopedTheme.js +24 -23
  16. package/lib/commonjs/components/ScopedTheme.js.map +1 -1
  17. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
  18. package/lib/commonjs/reanimated/index.js +7 -0
  19. package/lib/commonjs/reanimated/index.js.map +1 -1
  20. package/lib/commonjs/reanimated/variant/index.js +17 -0
  21. package/lib/commonjs/reanimated/variant/index.js.map +1 -0
  22. package/lib/commonjs/reanimated/variant/types.js +2 -0
  23. package/lib/commonjs/reanimated/variant/types.js.map +1 -0
  24. package/lib/commonjs/reanimated/variant/useAnimatedVariantColor.js +38 -0
  25. package/lib/commonjs/reanimated/variant/useAnimatedVariantColor.js.map +1 -0
  26. package/lib/commonjs/reanimated/variant/useUpdateVariantColor.js +66 -0
  27. package/lib/commonjs/reanimated/variant/useUpdateVariantColor.js.map +1 -0
  28. package/lib/commonjs/reanimated/variant/useUpdateVariantColor.native.js +39 -0
  29. package/lib/commonjs/reanimated/variant/useUpdateVariantColor.native.js.map +1 -0
  30. package/lib/commonjs/specs/ShadowRegistry/index.js +6 -1
  31. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  32. package/lib/commonjs/web/convert/pseudo.js +13 -3
  33. package/lib/commonjs/web/convert/pseudo.js.map +1 -1
  34. package/lib/commonjs/web/create.js +1 -1
  35. package/lib/commonjs/web/create.js.map +1 -1
  36. package/lib/commonjs/web/css/core.js +3 -1
  37. package/lib/commonjs/web/css/core.js.map +1 -1
  38. package/lib/commonjs/web/listener.js +2 -0
  39. package/lib/commonjs/web/listener.js.map +1 -1
  40. package/lib/commonjs/web/shadowRegistry.js +3 -2
  41. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  42. package/lib/commonjs/web/types.js.map +1 -1
  43. package/lib/commonjs/web/utils/unistyle.js +13 -1
  44. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  45. package/lib/module/components/AdaptiveTheme.js +29 -0
  46. package/lib/module/components/AdaptiveTheme.js.map +1 -0
  47. package/lib/module/components/ApplyScopedTheme.js +14 -0
  48. package/lib/module/components/ApplyScopedTheme.js.map +1 -0
  49. package/lib/module/components/NamedTheme.js +25 -0
  50. package/lib/module/components/NamedTheme.js.map +1 -0
  51. package/lib/module/components/ScopedTheme.js +24 -23
  52. package/lib/module/components/ScopedTheme.js.map +1 -1
  53. package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
  54. package/lib/module/reanimated/index.js +1 -0
  55. package/lib/module/reanimated/index.js.map +1 -1
  56. package/lib/module/reanimated/variant/index.js +4 -0
  57. package/lib/module/reanimated/variant/index.js.map +1 -0
  58. package/lib/module/reanimated/variant/types.js +2 -0
  59. package/lib/module/reanimated/variant/types.js.map +1 -0
  60. package/lib/module/reanimated/variant/useAnimatedVariantColor.js +33 -0
  61. package/lib/module/reanimated/variant/useAnimatedVariantColor.js.map +1 -0
  62. package/lib/module/reanimated/variant/useUpdateVariantColor.js +61 -0
  63. package/lib/module/reanimated/variant/useUpdateVariantColor.js.map +1 -0
  64. package/lib/module/reanimated/variant/useUpdateVariantColor.native.js +34 -0
  65. package/lib/module/reanimated/variant/useUpdateVariantColor.native.js.map +1 -0
  66. package/lib/module/specs/ShadowRegistry/index.js +6 -1
  67. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  68. package/lib/module/web/convert/pseudo.js +10 -2
  69. package/lib/module/web/convert/pseudo.js.map +1 -1
  70. package/lib/module/web/create.js +1 -1
  71. package/lib/module/web/create.js.map +1 -1
  72. package/lib/module/web/css/core.js +3 -1
  73. package/lib/module/web/css/core.js.map +1 -1
  74. package/lib/module/web/listener.js +2 -0
  75. package/lib/module/web/listener.js.map +1 -1
  76. package/lib/module/web/shadowRegistry.js +3 -2
  77. package/lib/module/web/shadowRegistry.js.map +1 -1
  78. package/lib/module/web/types.js.map +1 -1
  79. package/lib/module/web/utils/unistyle.js +12 -1
  80. package/lib/module/web/utils/unistyle.js.map +1 -1
  81. package/lib/typescript/plugin/src/consts.d.ts.map +1 -1
  82. package/lib/typescript/src/components/AdaptiveTheme.d.ts +8 -0
  83. package/lib/typescript/src/components/AdaptiveTheme.d.ts.map +1 -0
  84. package/lib/typescript/src/components/ApplyScopedTheme.d.ts +7 -0
  85. package/lib/typescript/src/components/ApplyScopedTheme.d.ts.map +1 -0
  86. package/lib/typescript/src/components/NamedTheme.d.ts +10 -0
  87. package/lib/typescript/src/components/NamedTheme.d.ts.map +1 -0
  88. package/lib/typescript/src/components/ScopedTheme.d.ts +4 -0
  89. package/lib/typescript/src/components/ScopedTheme.d.ts.map +1 -1
  90. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
  91. package/lib/typescript/src/reanimated/index.d.ts +1 -0
  92. package/lib/typescript/src/reanimated/index.d.ts.map +1 -1
  93. package/lib/typescript/src/reanimated/variant/index.d.ts +2 -0
  94. package/lib/typescript/src/reanimated/variant/index.d.ts.map +1 -0
  95. package/lib/typescript/src/reanimated/variant/types.d.ts +10 -0
  96. package/lib/typescript/src/reanimated/variant/types.d.ts.map +1 -0
  97. package/lib/typescript/src/reanimated/variant/useAnimatedVariantColor.d.ts +3 -0
  98. package/lib/typescript/src/reanimated/variant/useAnimatedVariantColor.d.ts.map +1 -0
  99. package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.d.ts +6 -0
  100. package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.d.ts.map +1 -0
  101. package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.native.d.ts +6 -0
  102. package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.native.d.ts.map +1 -0
  103. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  104. package/lib/typescript/src/web/convert/pseudo.d.ts +6 -3
  105. package/lib/typescript/src/web/convert/pseudo.d.ts.map +1 -1
  106. package/lib/typescript/src/web/css/core.d.ts.map +1 -1
  107. package/lib/typescript/src/web/listener.d.ts.map +1 -1
  108. package/lib/typescript/src/web/shadowRegistry.d.ts +1 -0
  109. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  110. package/lib/typescript/src/web/types.d.ts +4 -1
  111. package/lib/typescript/src/web/types.d.ts.map +1 -1
  112. package/lib/typescript/src/web/utils/unistyle.d.ts +4 -1
  113. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  114. package/package.json +3 -3
  115. package/plugin/index.d.ts +1 -1
  116. package/plugin/index.js +1 -4
  117. package/repack-plugin/index.js +1 -4
  118. package/src/components/AdaptiveTheme.tsx +34 -0
  119. package/src/components/ApplyScopedTheme.tsx +17 -0
  120. package/src/components/NamedTheme.tsx +33 -0
  121. package/src/components/ScopedTheme.tsx +42 -27
  122. package/src/core/withUnistyles/withUnistyles.native.tsx +1 -0
  123. package/src/reanimated/index.ts +1 -0
  124. package/src/reanimated/variant/index.ts +1 -0
  125. package/src/reanimated/variant/types.ts +14 -0
  126. package/src/reanimated/variant/useAnimatedVariantColor.ts +38 -0
  127. package/src/reanimated/variant/useUpdateVariantColor.native.ts +38 -0
  128. package/src/reanimated/variant/useUpdateVariantColor.ts +81 -0
  129. package/src/specs/ShadowRegistry/index.ts +6 -1
  130. package/src/web/convert/pseudo.ts +23 -52
  131. package/src/web/create.ts +1 -1
  132. package/src/web/css/core.ts +3 -1
  133. package/src/web/listener.ts +2 -0
  134. package/src/web/shadowRegistry.ts +2 -2
  135. package/src/web/types.ts +4 -1
  136. package/src/web/utils/unistyle.ts +18 -2
@@ -1 +1 @@
1
- {"version":3,"file":"unistyle.d.ts","sourceRoot":"","sources":["../../../../../src/web/utils/unistyle.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iDAAiD,CAAA;AACzF,OAAO,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAA;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAGpG,OAAO,EAA4C,KAAK,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAG3F,eAAO,MAAM,aAAa,GAAI,QAAQ,WAAW,qBAQhD,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC1B,iBAAiB,EAAE,yBAAyB,CAAC,UAAU,CAAC,CAAC;IACzD,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAA;CAC/D,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,CAAC,EAAE,QAAQ,CAAC,EAAE,SAAS,eAAe,MAanE,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,QAAQ,GAAG;;aAYzC,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,QAAQ,eAAe,OAUzD,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,EAAE,gBAAgB,KAAK,CAAC,MAAM,CAAC,WA6BzE,CAAA;AAED,eAAO,MAAM,2BAA2B,GAAI,OAAO,GAAG,yBAQrD,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,OAAO,GAAG,EAAE,MAAM,MAAM,KAAG,OAcvD,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,OAAO,GAAG,KAAG,OAgB7C,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAI,OAAO,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAG,KAAK,IAAI,iBAIzE,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,EAAE,OAAO,GAAG,EAAE,aAAU,KAAG,CAAC,MAAM,EAAE,GAAG,CAU9E,CAAA"}
1
+ {"version":3,"file":"unistyle.d.ts","sourceRoot":"","sources":["../../../../../src/web/utils/unistyle.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iDAAiD,CAAA;AACzF,OAAO,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAA;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAEpG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD,OAAO,EAA4C,KAAK,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAG3F,eAAO,MAAM,aAAa,GAAI,QAAQ,WAAW,qBAQhD,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC1B,iBAAiB,EAAE,yBAAyB,CAAC,UAAU,CAAC,CAAC;IACzD,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IACzB,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAA;CACrE,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,CAAC,EAAE,QAAQ,CAAC,EAAE,SAAS,eAAe,MAanE,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,QAAQ,GAAG;;aAYzC,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,QAAQ,eAAe,OAUzD,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,EAAE,gBAAgB,KAAK,CAAC,MAAM,CAAC,WA6BzE,CAAA;AAED,eAAO,MAAM,2BAA2B,GAAI,OAAO,GAAG,yBAQrD,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,OAAO,GAAG,EAAE,MAAM,MAAM,KAAG,OAcvD,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,OAAO,GAAG,KAAG,OAgB7C,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAI,OAAO,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAG,KAAK,IAAI,iBAIzE,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,EAAE,OAAO,GAAG,EAAE,aAAU,KAAG,CAAC,MAAM,EAAE,GAAG,CAU9E,CAAA;AAED,eAAO,MAAM,yBAAyB,GAAI,CAAC,EAAE,SAAS,gBAAgB,EAAE,QAAQ,OAAO,CAAC,MAAM,CAAC,MAAM,oBAAoB,EAAE,CAAC,CAAC,CAAC,kBAa7H,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "3.0.0-nightly-20250607",
3
+ "version": "3.0.0-nightly-20250613",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "NODE_ENV=babel-test jest ./plugin",
@@ -147,11 +147,11 @@
147
147
  "husky": "9.1.7",
148
148
  "jest": "29.7.0",
149
149
  "metro-react-native-babel-preset": "0.77.0",
150
- "nitro-codegen": "0.26.0",
150
+ "nitro-codegen": "0.26.2",
151
151
  "react": "19.1.0",
152
152
  "react-native": "0.79.2",
153
153
  "react-native-builder-bob": "0.40.10",
154
- "react-native-nitro-modules": "0.26.0",
154
+ "react-native-nitro-modules": "0.26.2",
155
155
  "react-native-reanimated": "3.17.5",
156
156
  "react-native-web": "0.20.0",
157
157
  "react-test-renderer": "19.1.0",
package/plugin/index.d.ts CHANGED
@@ -104,7 +104,7 @@ export interface UnistylesPluginOptions {
104
104
  * Defaults to:
105
105
  *
106
106
  * ```ts
107
- * ['react-native-reanimated/src/component', 'react-native-gesture-handler/src/components']
107
+ * ['react-native-reanimated/src/component']
108
108
  * ```
109
109
  */
110
110
  autoProcessPaths?: Array<string>,
package/plugin/index.js CHANGED
@@ -60,10 +60,7 @@ var REACT_NATIVE_COMPONENT_NAMES = [
60
60
  ];
61
61
  var REPLACE_WITH_UNISTYLES_PATHS = [
62
62
  "react-native-reanimated/src/component",
63
- "react-native-reanimated/lib/module/component",
64
- "react-native-gesture-handler/lib/module/components",
65
- "react-native-gesture-handler/lib/commonjs/components",
66
- "react-native-gesture-handler/src/components"
63
+ "react-native-reanimated/lib/module/component"
67
64
  ];
68
65
  var REPLACE_WITH_UNISTYLES_EXOTIC_PATHS = [];
69
66
  var NATIVE_COMPONENTS_PATHS = {
@@ -54,10 +54,7 @@ var REACT_NATIVE_COMPONENT_NAMES = [
54
54
  ];
55
55
  var REPLACE_WITH_UNISTYLES_PATHS = [
56
56
  "react-native-reanimated/src/component",
57
- "react-native-reanimated/lib/module/component",
58
- "react-native-gesture-handler/lib/module/components",
59
- "react-native-gesture-handler/lib/commonjs/components",
60
- "react-native-gesture-handler/src/components"
57
+ "react-native-reanimated/lib/module/component"
61
58
  ];
62
59
 
63
60
  // repack-plugin/src/loader.ts
@@ -0,0 +1,34 @@
1
+ import React, { useLayoutEffect } from 'react'
2
+ import type { PropsWithChildren } from 'react'
3
+ import { useUnistyles } from '../core'
4
+ import type { UnistylesThemes } from '../global'
5
+ import { UnistylesShadowRegistry } from '../specs'
6
+ import { ApplyScopedTheme } from './ApplyScopedTheme'
7
+
8
+ interface AdaptiveThemeProps extends PropsWithChildren {
9
+ previousScopedTheme?: string
10
+ }
11
+
12
+ export const AdaptiveTheme: React.FunctionComponent<AdaptiveThemeProps> = ({
13
+ children,
14
+ previousScopedTheme
15
+ }) => {
16
+ const { rt } = useUnistyles()
17
+ const name = (rt.themeName === 'dark' ? 'light' : 'dark') as keyof UnistylesThemes
18
+ const mappedChildren = [
19
+ <ApplyScopedTheme key={name} name={name} />,
20
+ children,
21
+ <ApplyScopedTheme key='dispose' name={previousScopedTheme as keyof UnistylesThemes | undefined} />
22
+ ]
23
+
24
+ useLayoutEffect(() => {
25
+ // this will affect only scoped styles as other styles are not yet mounted
26
+ UnistylesShadowRegistry.flush()
27
+ })
28
+
29
+ return (
30
+ <React.Fragment key={name}>
31
+ {mappedChildren}
32
+ </React.Fragment>
33
+ )
34
+ }
@@ -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,37 +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
- useLayoutEffect(() => {
28
- // this will affect only scoped styles as other styles are not yet mounted
29
- UnistylesShadowRegistry.flush()
30
- })
31
-
32
- return (
33
- <React.Fragment>
34
- {mappedChildren}
35
- </React.Fragment>
36
- )
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
+
37
52
  }
@@ -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()
@@ -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
+ }
@@ -24,8 +24,13 @@ const findShadowNodeForHandle = (handle: ViewHandle) => {
24
24
  ?? handle?.viewRef?.current?.__internalInstanceHandle?.stateNode?.node
25
25
  ?? handle?._nativeRef?.__internalInstanceHandle?.stateNode?.node
26
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
+
27
32
  if (!node) {
28
- 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'}`)
29
34
  }
30
35
 
31
36
  return node
@@ -1,26 +1,12 @@
1
- export const pseudos = [
2
- '_-moz-broken',
3
- '_-moz-drag-over',
4
- '_-moz-first-node',
5
- '_-moz-handler-blocked',
6
- '_-moz-handler-crashed',
7
- '_-moz-handler-disabled',
8
- '_-moz-last-node',
9
- '_-moz-loading',
10
- '_-moz-locale-dir(ltr)',
11
- '_-moz-locale-dir(rtl)',
12
- '_-moz-only-whitespace',
13
- '_-moz-submit-invalid',
14
- '_-moz-suppressed',
15
- '_-moz-user-disabled',
16
- '_-moz-window-inactive',
1
+ // All non experimental pseudo clasess and elements
2
+
3
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes
4
+ const pseudoClasses = [
17
5
  '_active',
18
6
  '_any-link',
19
7
  '_autofill',
20
- '_blank',
21
8
  '_buffering',
22
9
  '_checked',
23
- '_current',
24
10
  '_default',
25
11
  '_defined',
26
12
  '_dir(',
@@ -33,8 +19,8 @@ export const pseudos = [
33
19
  '_focus',
34
20
  '_focus-visible',
35
21
  '_focus-within',
36
- '_fullscreen',
37
22
  '_future',
23
+ '_has-slotted',
38
24
  '_has(',
39
25
  '_host',
40
26
  '_host-context(',
@@ -49,7 +35,6 @@ export const pseudos = [
49
35
  '_last-of-type',
50
36
  '_left',
51
37
  '_link',
52
- '_local-link',
53
38
  '_modal',
54
39
  '_muted',
55
40
  '_not(',
@@ -59,6 +44,7 @@ export const pseudos = [
59
44
  '_nth-of-type(',
60
45
  '_only-child',
61
46
  '_only-of-type',
47
+ '_open',
62
48
  '_optional',
63
49
  '_out-of-range',
64
50
  '_past',
@@ -71,45 +57,27 @@ export const pseudos = [
71
57
  '_read-write',
72
58
  '_required',
73
59
  '_right',
60
+ '_root',
74
61
  '_scope',
75
62
  '_seeking',
76
63
  '_stalled',
77
64
  '_state(',
78
65
  '_target',
79
- '_target-within',
80
66
  '_user-invalid',
81
67
  '_user-valid',
82
68
  '_valid',
83
69
  '_visited',
84
70
  '_volume-locked',
85
- '_where(',
86
- '_-moz-color-swatch',
87
- '_-moz-focus-inner',
88
- '_-moz-list-bullet',
89
- '_-moz-list-number',
90
- '_-moz-meter-bar',
91
- '_-moz-progress-bar',
92
- '_-moz-range-progress',
93
- '_-moz-range-thumb',
94
- '_-moz-range-track',
95
- '_-webkit-inner-spin-button',
96
- '_-webkit-meter-barDeprecated',
97
- '_-webkit-meter-even-less-good-value',
98
- '_-webkit-meter-inner-element',
99
- '_-webkit-meter-optimum-value',
100
- '_-webkit-meter-suboptimum-value',
101
- '_-webkit-progress-bar',
102
- '_-webkit-progress-inner-element',
103
- '_-webkit-progress-value',
104
- '_-webkit-scrollbar',
105
- '_-webkit-search-cancel-button',
106
- '_-webkit-search-results-button',
107
- '_-webkit-slider-runnable-track',
108
- '_-webkit-slider-thumb',
71
+ '_where',
72
+ ] as const
73
+
74
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements
75
+ const pseudoElements = [
109
76
  '_after',
110
77
  '_backdrop',
111
78
  '_before',
112
79
  '_cue',
80
+ '_details-content',
113
81
  '_file-selector-button',
114
82
  '_first-letter',
115
83
  '_first-line',
@@ -123,15 +91,18 @@ export const pseudos = [
123
91
  '_spelling-error',
124
92
  '_target-text',
125
93
  '_view-transition',
126
- '_view-transition-group',
127
- '_view-transition-image-pair',
128
- '_view-transition-new',
129
- '_view-transition-old',
94
+ '_view-transition-group(',
95
+ '_view-transition-image-pair(',
96
+ '_view-transition-new(',
97
+ '_view-transition-old(',
130
98
  ] as const
131
99
 
132
- export const isPseudo = (selector: string) => pseudos.some(pseudo => selector.startsWith(pseudo))
133
-
134
100
  type AddDynamicSelector<T extends string> = T extends `${infer U}(` ? `${U}(${string})` : T
135
101
 
136
- export type Pseudo = AddDynamicSelector<typeof pseudos[number]>
102
+ export type Pseudo = AddDynamicSelector<(typeof pseudoClasses)[number] | (typeof pseudoElements)[number]>
103
+
104
+ export const isPseudoClass = (selector: string) => pseudoClasses.some(pseudo => selector.startsWith(pseudo))
105
+
106
+ export const isPseudoElement = (selector: string) => pseudoElements.some(pseudo => selector.startsWith(pseudo))
137
107
 
108
+ export const isPseudo = (selector: string) => isPseudoClass(selector) || isPseudoElement(selector)
package/src/web/create.ts CHANGED
@@ -21,7 +21,7 @@ export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>, id?: s
21
21
  __uni__key: key,
22
22
  __uni__stylesheet: stylesheet,
23
23
  __uni__args: args,
24
- __uni_variants: variants
24
+ __stylesheetVariants: variants
25
25
  })
26
26
 
27
27
  const createStyleSheetStyles = (variants?: Variants) => {
@@ -1,10 +1,12 @@
1
+ import { isPseudoClass } from '../convert/pseudo'
1
2
  import { getMediaQuery } from '../utils'
2
3
  import type { CSSState } from './state'
3
4
 
4
5
  export const convertToCSS = (hash: string, value: Record<string, any>, state: CSSState) => {
5
6
  Object.entries(value).forEach(([styleKey, styleValue]) => {
6
7
  if (styleKey[0] === '_') {
7
- const pseudoClassName = styleKey.replace('_', `${hash}:`)
8
+ const isStylePseudoClass = isPseudoClass(styleKey)
9
+ const pseudoClassName = `${hash}${isStylePseudoClass ? ':' : '::'}${styleKey.slice(1)}`
8
10
 
9
11
  Object.entries(styleValue).forEach(([pseudoStyleKey, pseudoStyleValue]) => {
10
12
  if (typeof pseudoStyleValue === 'object' && pseudoStyleValue !== null) {
@@ -29,6 +29,7 @@ export class UnistylesListener {
29
29
 
30
30
  if (this.services.runtime.hasAdaptiveThemes) {
31
31
  this.emitChange(UnistyleDependency.Theme)
32
+ this.emitChange(UnistyleDependency.ThemeName)
32
33
  }
33
34
  })
34
35
  this.services.runtime.lightMedia?.addEventListener('change', event => {
@@ -40,6 +41,7 @@ export class UnistylesListener {
40
41
 
41
42
  if (this.services.runtime.hasAdaptiveThemes) {
42
43
  this.emitChange(UnistyleDependency.Theme)
44
+ this.emitChange(UnistyleDependency.ThemeName)
43
45
  }
44
46
  })
45
47
 
@@ -49,7 +49,7 @@ export class UnistylesShadowRegistry {
49
49
  return {}
50
50
  }
51
51
 
52
- const { __uni__key, __uni__stylesheet, __uni__args = [], __uni_variants: variants } = secrets
52
+ const { __uni__key, __uni__stylesheet, __uni__args = [], __stylesheetVariants: variants } = secrets
53
53
  const newComputedStylesheet = this.services.registry.getComputedStylesheet(__uni__stylesheet, scopedTheme)
54
54
  const style = newComputedStylesheet[__uni__key] as (UnistylesValues | ((...args: any) => UnistylesValues))
55
55
  const result = typeof style === 'function'
@@ -94,7 +94,7 @@ export class UnistylesShadowRegistry {
94
94
  ? hash.replace(' > *', '')
95
95
  : hash
96
96
 
97
- return { injectedClassName, hash: hashClassname }
97
+ return { injectedClassName, hash: hashClassname, parsedStyles }
98
98
  }
99
99
 
100
100
  setScopedTheme = (theme?: UnistylesTheme) => {
package/src/web/types.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { UnistylesValues } from '../types'
1
2
  import type { UnistylesListener } from './listener'
2
3
  import type { UnistylesRegistry } from './registry'
3
4
  import type { UnistylesRuntime } from './runtime'
@@ -15,4 +16,6 @@ export type UnistylesServices = {
15
16
  export const UNI_GENERATED_KEYS = ['$$css', 'hash', 'injectedClassName'] as const
16
17
  export type UniGeneratedKey = typeof UNI_GENERATED_KEYS[number]
17
18
 
18
- export type UniGeneratedStyle = Record<UniGeneratedKey, string>
19
+ export type UniGeneratedStyle = Record<UniGeneratedKey, string> & {
20
+ parsedStyles?: UnistylesValues
21
+ }