react-native-unistyles 2.4.0 → 2.4.1

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 (266) hide show
  1. package/README.md +72 -26
  2. package/android/CMakeLists.txt +18 -2
  3. package/android/build.gradle +5 -1
  4. package/android/src/main/cxx/cpp-adapter.cpp +16 -80
  5. package/android/src/main/cxx/helpers.cpp +61 -0
  6. package/android/src/main/cxx/helpers.h +7 -0
  7. package/android/src/main/cxx/platform.cpp +170 -0
  8. package/android/src/main/cxx/platform.h +20 -0
  9. package/android/src/main/java/com/unistyles/Models.kt +12 -70
  10. package/android/src/main/java/com/unistyles/Platform.kt +311 -10
  11. package/android/src/main/java/com/unistyles/UnistylesModule.kt +145 -153
  12. package/cxx/Macros.h +11 -0
  13. package/cxx/UnistylesImpl.cpp +310 -0
  14. package/cxx/UnistylesModel.cpp +234 -0
  15. package/cxx/UnistylesModel.h +141 -0
  16. package/cxx/UnistylesRuntime.cpp +17 -356
  17. package/cxx/UnistylesRuntime.h +71 -87
  18. package/ios/UnistylesModule.h +13 -0
  19. package/ios/UnistylesModule.mm +20 -90
  20. package/ios/platform/Platform_Shared.h +8 -0
  21. package/ios/platform/Platform_Shared.mm +160 -0
  22. package/ios/platform/Platform_iOS.h +6 -10
  23. package/ios/platform/Platform_iOS.mm +143 -93
  24. package/ios/platform/Platform_macOS.h +3 -7
  25. package/ios/platform/Platform_macOS.mm +52 -34
  26. package/ios/platform/Platform_tvOS.h +17 -0
  27. package/ios/platform/Platform_tvOS.mm +96 -0
  28. package/ios/platform/Platform_visionOS.h +20 -0
  29. package/ios/platform/Platform_visionOS.mm +120 -0
  30. package/lib/commonjs/UnistylesProvider.js +32 -0
  31. package/lib/commonjs/UnistylesProvider.js.map +1 -0
  32. package/lib/commonjs/common.js +3 -2
  33. package/lib/commonjs/common.js.map +1 -1
  34. package/lib/commonjs/core/UnistyleRegistry.js +14 -4
  35. package/lib/commonjs/core/UnistyleRegistry.js.map +1 -1
  36. package/lib/commonjs/core/Unistyles.js +7 -0
  37. package/lib/commonjs/core/Unistyles.js.map +1 -1
  38. package/lib/commonjs/core/UnistylesModule.js +52 -8
  39. package/lib/commonjs/core/UnistylesModule.js.map +1 -1
  40. package/lib/commonjs/core/UnistylesModule.native.js.map +1 -1
  41. package/lib/commonjs/core/UnistylesModule.windows.js.map +1 -1
  42. package/lib/commonjs/core/UnistylesRuntime.js +114 -4
  43. package/lib/commonjs/core/UnistylesRuntime.js.map +1 -1
  44. package/lib/commonjs/core/index.js.map +1 -1
  45. package/lib/commonjs/core/mocks/UnistylesMockedBridge.js +36 -0
  46. package/lib/commonjs/core/mocks/UnistylesMockedBridge.js.map +1 -0
  47. package/lib/commonjs/core/mocks/UnistylesMockedRegistry.js +46 -0
  48. package/lib/commonjs/core/mocks/UnistylesMockedRegistry.js.map +1 -0
  49. package/lib/commonjs/core/mocks/UnistylesMockedRuntime.js +122 -0
  50. package/lib/commonjs/core/mocks/UnistylesMockedRuntime.js.map +1 -0
  51. package/lib/commonjs/core/mocks/index.js +27 -0
  52. package/lib/commonjs/core/mocks/index.js.map +1 -0
  53. package/lib/commonjs/createStyleSheet.js.map +1 -1
  54. package/lib/commonjs/global.js.map +1 -1
  55. package/lib/commonjs/hooks/index.js.map +1 -1
  56. package/lib/commonjs/hooks/useCSS.js.map +1 -1
  57. package/lib/commonjs/hooks/useCSS.native.js.map +1 -1
  58. package/lib/commonjs/hooks/useInitialTheme.js.map +1 -1
  59. package/lib/commonjs/hooks/useSharedContext.js +77 -0
  60. package/lib/commonjs/hooks/useSharedContext.js.map +1 -0
  61. package/lib/commonjs/hooks/useUnistyles.js +18 -65
  62. package/lib/commonjs/hooks/useUnistyles.js.map +1 -1
  63. package/lib/commonjs/hooks/useVariants.js.map +1 -1
  64. package/lib/commonjs/index.js +7 -0
  65. package/lib/commonjs/index.js.map +1 -1
  66. package/lib/commonjs/normalizer/index.js.map +1 -1
  67. package/lib/commonjs/normalizer/module.d.js.map +1 -1
  68. package/lib/commonjs/normalizer/normalizeStyle.js.map +1 -1
  69. package/lib/commonjs/normalizer/normalizer.js +1 -1
  70. package/lib/commonjs/normalizer/normalizer.js.map +1 -1
  71. package/lib/commonjs/normalizer/normalizer.macos.js.map +1 -1
  72. package/lib/commonjs/plugins/cssMediaQueriesPlugin.js.map +1 -1
  73. package/lib/commonjs/plugins/index.js.map +1 -1
  74. package/lib/commonjs/plugins/normalizeWebStylesPlugin.js.map +1 -1
  75. package/lib/commonjs/types/breakpoints.js.map +1 -1
  76. package/lib/commonjs/types/color.js +2 -0
  77. package/lib/commonjs/types/color.js.map +1 -0
  78. package/lib/commonjs/types/common.js.map +1 -1
  79. package/lib/commonjs/types/core.js.map +1 -1
  80. package/lib/commonjs/types/index.js +11 -0
  81. package/lib/commonjs/types/index.js.map +1 -1
  82. package/lib/commonjs/types/normalizer.js.map +1 -1
  83. package/lib/commonjs/types/plugin.js.map +1 -1
  84. package/lib/commonjs/types/stylesheet.js.map +1 -1
  85. package/lib/commonjs/types/unistyles.js.map +1 -1
  86. package/lib/commonjs/types/variants.js.map +1 -1
  87. package/lib/commonjs/useStyles.js +1 -1
  88. package/lib/commonjs/useStyles.js.map +1 -1
  89. package/lib/commonjs/utils/breakpoints.js.map +1 -1
  90. package/lib/commonjs/utils/cssMediaQuery.js.map +1 -1
  91. package/lib/commonjs/utils/generateId.js.map +1 -1
  92. package/lib/commonjs/utils/hash32.js.map +1 -1
  93. package/lib/commonjs/utils/index.js +7 -0
  94. package/lib/commonjs/utils/index.js.map +1 -1
  95. package/lib/commonjs/utils/mq.js.map +1 -1
  96. package/lib/commonjs/utils/mqParser.js.map +1 -1
  97. package/lib/commonjs/utils/parseColor.js +35 -0
  98. package/lib/commonjs/utils/parseColor.js.map +1 -0
  99. package/lib/commonjs/utils/styles.js +15 -1
  100. package/lib/commonjs/utils/styles.js.map +1 -1
  101. package/lib/commonjs/utils/withPlugins.js.map +1 -1
  102. package/lib/module/UnistylesProvider.js +24 -0
  103. package/lib/module/UnistylesProvider.js.map +1 -0
  104. package/lib/module/common.js +2 -1
  105. package/lib/module/common.js.map +1 -1
  106. package/lib/module/core/UnistyleRegistry.js +15 -5
  107. package/lib/module/core/UnistyleRegistry.js.map +1 -1
  108. package/lib/module/core/Unistyles.js +8 -1
  109. package/lib/module/core/Unistyles.js.map +1 -1
  110. package/lib/module/core/UnistylesModule.js +52 -8
  111. package/lib/module/core/UnistylesModule.js.map +1 -1
  112. package/lib/module/core/UnistylesModule.native.js.map +1 -1
  113. package/lib/module/core/UnistylesModule.windows.js.map +1 -1
  114. package/lib/module/core/UnistylesRuntime.js +115 -4
  115. package/lib/module/core/UnistylesRuntime.js.map +1 -1
  116. package/lib/module/core/index.js +2 -1
  117. package/lib/module/core/index.js.map +1 -1
  118. package/lib/module/core/mocks/UnistylesMockedBridge.js +29 -0
  119. package/lib/module/core/mocks/UnistylesMockedBridge.js.map +1 -0
  120. package/lib/module/core/mocks/UnistylesMockedRegistry.js +39 -0
  121. package/lib/module/core/mocks/UnistylesMockedRegistry.js.map +1 -0
  122. package/lib/module/core/mocks/UnistylesMockedRuntime.js +114 -0
  123. package/lib/module/core/mocks/UnistylesMockedRuntime.js.map +1 -0
  124. package/lib/module/core/mocks/index.js +4 -0
  125. package/lib/module/core/mocks/index.js.map +1 -0
  126. package/lib/module/createStyleSheet.js.map +1 -1
  127. package/lib/module/global.js.map +1 -1
  128. package/lib/module/hooks/index.js.map +1 -1
  129. package/lib/module/hooks/useCSS.js.map +1 -1
  130. package/lib/module/hooks/useCSS.native.js.map +1 -1
  131. package/lib/module/hooks/useInitialTheme.js.map +1 -1
  132. package/lib/module/hooks/useSharedContext.js +70 -0
  133. package/lib/module/hooks/useSharedContext.js.map +1 -0
  134. package/lib/module/hooks/useUnistyles.js +19 -66
  135. package/lib/module/hooks/useUnistyles.js.map +1 -1
  136. package/lib/module/hooks/useVariants.js.map +1 -1
  137. package/lib/module/index.js +2 -2
  138. package/lib/module/index.js.map +1 -1
  139. package/lib/module/normalizer/index.js.map +1 -1
  140. package/lib/module/normalizer/module.d.js.map +1 -1
  141. package/lib/module/normalizer/normalizeStyle.js.map +1 -1
  142. package/lib/module/normalizer/normalizer.js.map +1 -1
  143. package/lib/module/normalizer/normalizer.macos.js.map +1 -1
  144. package/lib/module/plugins/cssMediaQueriesPlugin.js.map +1 -1
  145. package/lib/module/plugins/index.js.map +1 -1
  146. package/lib/module/plugins/normalizeWebStylesPlugin.js.map +1 -1
  147. package/lib/module/types/breakpoints.js.map +1 -1
  148. package/lib/module/types/color.js +2 -0
  149. package/lib/module/types/color.js.map +1 -0
  150. package/lib/module/types/common.js.map +1 -1
  151. package/lib/module/types/core.js.map +1 -1
  152. package/lib/module/types/index.js +1 -0
  153. package/lib/module/types/index.js.map +1 -1
  154. package/lib/module/types/normalizer.js.map +1 -1
  155. package/lib/module/types/plugin.js.map +1 -1
  156. package/lib/module/types/stylesheet.js.map +1 -1
  157. package/lib/module/types/unistyles.js.map +1 -1
  158. package/lib/module/types/variants.js.map +1 -1
  159. package/lib/module/useStyles.js +1 -1
  160. package/lib/module/useStyles.js.map +1 -1
  161. package/lib/module/utils/breakpoints.js.map +1 -1
  162. package/lib/module/utils/cssMediaQuery.js.map +1 -1
  163. package/lib/module/utils/generateId.js.map +1 -1
  164. package/lib/module/utils/hash32.js.map +1 -1
  165. package/lib/module/utils/index.js +1 -0
  166. package/lib/module/utils/index.js.map +1 -1
  167. package/lib/module/utils/mq.js.map +1 -1
  168. package/lib/module/utils/mqParser.js.map +1 -1
  169. package/lib/module/utils/parseColor.js +28 -0
  170. package/lib/module/utils/parseColor.js.map +1 -0
  171. package/lib/module/utils/styles.js +15 -1
  172. package/lib/module/utils/styles.js.map +1 -1
  173. package/lib/module/utils/withPlugins.js.map +1 -1
  174. package/lib/typescript/src/UnistylesProvider.d.ts +20 -0
  175. package/lib/typescript/src/UnistylesProvider.d.ts.map +1 -0
  176. package/lib/typescript/src/common.d.ts +3 -2
  177. package/lib/typescript/src/common.d.ts.map +1 -1
  178. package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +1 -1
  179. package/lib/typescript/src/core/Unistyles.d.ts.map +1 -1
  180. package/lib/typescript/src/core/UnistylesModule.d.ts +1 -0
  181. package/lib/typescript/src/core/UnistylesModule.d.ts.map +1 -1
  182. package/lib/typescript/src/core/UnistylesModule.native.d.ts.map +1 -1
  183. package/lib/typescript/src/core/UnistylesModule.windows.d.ts.map +1 -1
  184. package/lib/typescript/src/core/UnistylesRuntime.d.ts +84 -8
  185. package/lib/typescript/src/core/UnistylesRuntime.d.ts.map +1 -1
  186. package/lib/typescript/src/core/index.d.ts +3 -1
  187. package/lib/typescript/src/core/index.d.ts.map +1 -1
  188. package/lib/typescript/src/core/mocks/UnistylesMockedBridge.d.ts +28 -0
  189. package/lib/typescript/src/core/mocks/UnistylesMockedBridge.d.ts.map +1 -0
  190. package/lib/typescript/src/core/mocks/UnistylesMockedRegistry.d.ts +21 -0
  191. package/lib/typescript/src/core/mocks/UnistylesMockedRegistry.d.ts.map +1 -0
  192. package/lib/typescript/src/core/mocks/UnistylesMockedRuntime.d.ts +79 -0
  193. package/lib/typescript/src/core/mocks/UnistylesMockedRuntime.d.ts.map +1 -0
  194. package/lib/typescript/src/core/mocks/index.d.ts +4 -0
  195. package/lib/typescript/src/core/mocks/index.d.ts.map +1 -0
  196. package/lib/typescript/src/createStyleSheet.d.ts.map +1 -1
  197. package/lib/typescript/src/hooks/useCSS.d.ts.map +1 -1
  198. package/lib/typescript/src/hooks/useCSS.native.d.ts.map +1 -1
  199. package/lib/typescript/src/hooks/useSharedContext.d.ts +33 -0
  200. package/lib/typescript/src/hooks/useSharedContext.d.ts.map +1 -0
  201. package/lib/typescript/src/hooks/useUnistyles.d.ts +4 -19
  202. package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -1
  203. package/lib/typescript/src/hooks/useVariants.d.ts.map +1 -1
  204. package/lib/typescript/src/index.d.ts +7 -15
  205. package/lib/typescript/src/index.d.ts.map +1 -1
  206. package/lib/typescript/src/normalizer/normalizeStyle.d.ts.map +1 -1
  207. package/lib/typescript/src/types/breakpoints.d.ts +9 -8
  208. package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
  209. package/lib/typescript/src/types/color.d.ts +4 -0
  210. package/lib/typescript/src/types/color.d.ts.map +1 -0
  211. package/lib/typescript/src/types/core.d.ts +2 -2
  212. package/lib/typescript/src/types/core.d.ts.map +1 -1
  213. package/lib/typescript/src/types/index.d.ts +2 -1
  214. package/lib/typescript/src/types/index.d.ts.map +1 -1
  215. package/lib/typescript/src/types/normalizer.d.ts +1 -1
  216. package/lib/typescript/src/types/normalizer.d.ts.map +1 -1
  217. package/lib/typescript/src/types/stylesheet.d.ts +9 -6
  218. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  219. package/lib/typescript/src/types/unistyles.d.ts +20 -9
  220. package/lib/typescript/src/types/unistyles.d.ts.map +1 -1
  221. package/lib/typescript/src/useStyles.d.ts +1 -1
  222. package/lib/typescript/src/useStyles.d.ts.map +1 -1
  223. package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
  224. package/lib/typescript/src/utils/index.d.ts +1 -0
  225. package/lib/typescript/src/utils/index.d.ts.map +1 -1
  226. package/lib/typescript/src/utils/mqParser.d.ts.map +1 -1
  227. package/lib/typescript/src/utils/parseColor.d.ts +3 -0
  228. package/lib/typescript/src/utils/parseColor.d.ts.map +1 -0
  229. package/lib/typescript/src/utils/styles.d.ts.map +1 -1
  230. package/package.json +38 -25
  231. package/react-native-unistyles.podspec +4 -1
  232. package/src/UnistylesProvider.tsx +33 -0
  233. package/src/common.ts +3 -2
  234. package/src/core/UnistyleRegistry.ts +19 -5
  235. package/src/core/Unistyles.ts +10 -1
  236. package/src/core/UnistylesModule.ts +61 -14
  237. package/src/core/UnistylesRuntime.ts +120 -5
  238. package/src/core/index.ts +7 -1
  239. package/src/core/mocks/UnistylesMockedBridge.ts +30 -0
  240. package/src/core/mocks/UnistylesMockedRegistry.ts +47 -0
  241. package/src/core/mocks/UnistylesMockedRuntime.ts +144 -0
  242. package/src/core/mocks/index.ts +3 -0
  243. package/src/hooks/useSharedContext.ts +83 -0
  244. package/src/hooks/useUnistyles.ts +15 -71
  245. package/src/index.ts +10 -4
  246. package/src/types/breakpoints.ts +19 -9
  247. package/src/types/color.ts +26 -0
  248. package/src/types/core.ts +2 -2
  249. package/src/types/index.ts +5 -1
  250. package/src/types/normalizer.ts +1 -1
  251. package/src/types/stylesheet.ts +10 -7
  252. package/src/types/unistyles.ts +28 -12
  253. package/src/useStyles.ts +1 -1
  254. package/src/utils/index.ts +1 -0
  255. package/src/utils/parseColor.ts +33 -0
  256. package/src/utils/styles.ts +24 -1
  257. package/windows/ExperimentalFeatures.props +4 -4
  258. package/windows/NuGet.Config +0 -1
  259. package/windows/ReactNativeUnistyles/ReactNativeUnistyles.h +42 -118
  260. package/windows/ReactNativeUnistyles/ReactNativeUnistyles.vcxproj +7 -2
  261. package/windows/ReactNativeUnistyles/ReactNativeUnistyles.vcxproj.filters +6 -1
  262. package/windows/ReactNativeUnistyles/packages.lock.json +31 -31
  263. package/android/src/main/java/com/unistyles/Config.kt +0 -116
  264. package/android/src/main/java/com/unistyles/Insets.kt +0 -138
  265. package/ios/UnistylesHelpers.h +0 -3
  266. package/ios/UnistylesHelpers.mm +0 -5
@@ -0,0 +1,47 @@
1
+ // @ts-nocheck
2
+ import type { UnistylesBreakpoints, UnistylesThemes } from '../../global'
3
+ import type { UnistylesPlugin, UnistylesConfig, UnistylesBridge } from '../../types'
4
+
5
+ export class UnistylesMockedRegistry {
6
+ public config: UnistylesConfig = {}
7
+ public breakpoints: UnistylesBreakpoints = {} as UnistylesBreakpoints
8
+ public sortedBreakpointPairs: Array<[keyof UnistylesBreakpoints, UnistylesBreakpoints[keyof UnistylesBreakpoints]]> = []
9
+ public plugins: Array<UnistylesPlugin> = []
10
+ public themes: UnistylesThemes = {} as UnistylesThemes
11
+ public themeNames: Array<keyof UnistylesThemes> = []
12
+
13
+ constructor(private unistylesBridge: UnistylesBridge) {}
14
+
15
+ public addThemes = (themes: UnistylesThemes) => {
16
+ this.themes = themes
17
+ this.themeNames = Object.keys(themes) as Array<keyof UnistylesThemes>
18
+
19
+ return this
20
+ }
21
+ public addBreakpoints = (breakpoints: UnistylesBreakpoints) => {
22
+ this.breakpoints = breakpoints
23
+ this.sortedBreakpointPairs = Object
24
+ .entries(breakpoints)
25
+ .sort((breakpoint1, breakpoint2) => {
26
+ const [, value1] = breakpoint1
27
+ const [, value2] = breakpoint2
28
+
29
+ return value1 - value2
30
+ }) as Array<[keyof UnistylesBreakpoints, UnistylesBreakpoints[keyof UnistylesBreakpoints]]>
31
+
32
+ return this
33
+ }
34
+ public addConfig = (config: UnistylesConfig) => {}
35
+ public getTheme = (forName: keyof UnistylesThemes) => {
36
+ if (this.themeNames.length === 0) {
37
+ return {} as UnistylesThemes[keyof UnistylesThemes]
38
+ }
39
+
40
+ return this.themes[forName]
41
+ }
42
+
43
+ public addPlugin = (plugin: UnistylesPlugin, notify: boolean = true) => {}
44
+ public removePlugin = (plugin: UnistylesPlugin) => {}
45
+ public updateTheme = (name: keyof UnistylesThemes, theme: UnistylesThemes[keyof UnistylesThemes]) => {}
46
+ public hasTheme = (name: keyof UnistylesThemes) => true
47
+ }
@@ -0,0 +1,144 @@
1
+ // @ts-nocheck
2
+ import { ScreenOrientation } from '../../common'
3
+ import type { Color, UnistylesBridge, UnistylesPlugin } from '../../types'
4
+ import type { UnistylesThemes } from '../../global'
5
+ import type { UnistylesMockedRegistry } from './UnistylesMockedRegistry'
6
+ import type { UnistyleRegistry } from '../UnistyleRegistry'
7
+
8
+ export class UnistylesMockedRuntime {
9
+ private unistylesRegistry: UnistylesMockedRegistry
10
+
11
+ constructor(private unistylesBridge: UnistylesBridge, private unistylesRegistry: UnistyleRegistry) {
12
+ this.unistylesRegistry = unistylesRegistry as unknown as UnistylesMockedRegistry
13
+ }
14
+
15
+ public get miniRuntime() {
16
+ return {
17
+ contentSizeCategory: this.contentSizeCategory,
18
+ breakpoint: this.breakpoint,
19
+ screen: this.screen,
20
+ insets: this.insets,
21
+ statusBar: {
22
+ width: this.statusBar.width,
23
+ height: this.statusBar.height
24
+ },
25
+ navigationBar: {
26
+ width: this.navigationBar.width,
27
+ height: this.navigationBar.height
28
+ },
29
+ orientation: this.orientation,
30
+ pixelRatio: this.pixelRatio,
31
+ fontScale: this.fontScale,
32
+ hairlineWidth: this.hairlineWidth,
33
+ rtl: this.rtl
34
+ }
35
+ }
36
+
37
+ public get colorScheme() {
38
+ return 'dark'
39
+ }
40
+
41
+ public get hasAdaptiveThemes() {
42
+ return true
43
+ }
44
+
45
+ public get themeName() {
46
+ return this.unistylesRegistry.themeNames.length > 0
47
+ ? this.unistylesRegistry.themeNames.at(0)
48
+ : undefined
49
+ }
50
+
51
+ public get contentSizeCategory() {
52
+ return 'unspecified'
53
+ }
54
+
55
+ public get breakpoint() {
56
+ if (this.unistylesRegistry.sortedBreakpointPairs.length === 0) {
57
+ return undefined
58
+ }
59
+
60
+ const firstBreakpoint = this.unistylesRegistry.sortedBreakpointPairs.at(0)
61
+
62
+ return firstBreakpoint
63
+ ? firstBreakpoint.at(0)
64
+ : undefined
65
+ }
66
+
67
+ public get rtl() {
68
+ return false
69
+ }
70
+
71
+ public get breakpoints() {
72
+ return this.unistylesRegistry.breakpoints
73
+ }
74
+
75
+ public get enabledPlugins() {
76
+ return this.unistylesRegistry.plugins
77
+ }
78
+
79
+ public get screen() {
80
+ return {
81
+ width: 360,
82
+ height: 800
83
+ }
84
+ }
85
+
86
+ public get insets() {
87
+ return {
88
+ top: 0,
89
+ right: 0,
90
+ bottom: 0,
91
+ left: 0
92
+ }
93
+ }
94
+
95
+ public get pixelRatio() {
96
+ return 1.0
97
+ }
98
+
99
+ public get hairlineWidth() {
100
+ return 0.333333
101
+ }
102
+
103
+ public get fontScale() {
104
+ return 1.0
105
+ }
106
+
107
+ public get statusBar() {
108
+ return {
109
+ height: 24,
110
+ width: 800,
111
+ setColor: () => {},
112
+ setHidden: () => {}
113
+ }
114
+ }
115
+
116
+ public get navigationBar() {
117
+ return {
118
+ height: 0,
119
+ width: 0,
120
+ setColor: () => {},
121
+ setHidden: () => {}
122
+ }
123
+ }
124
+
125
+ public get orientation() {
126
+ return ScreenOrientation.Portrait
127
+ }
128
+
129
+ public getTheme = (themeName?: keyof UnistylesThemes) => {
130
+ if (!themeName) {
131
+ return this.unistylesRegistry.getTheme(this.themeName)
132
+ }
133
+
134
+ return this.unistylesRegistry.getTheme(themeName)
135
+ }
136
+
137
+ public setTheme = (name: keyof UnistylesThemes) => true
138
+ public updateTheme = (name: keyof UnistylesThemes, theme: UnistylesThemes[keyof UnistylesThemes]) => {}
139
+ public setAdaptiveThemes = (enabled: boolean) => {}
140
+ public addPlugin = (plugin: UnistylesPlugin) => {}
141
+ public removePlugin = (plugin: UnistylesPlugin) => {}
142
+ public setRootViewBackgroundColor = (color?: Color | string) => {}
143
+ public setImmersiveMode = (isEnabled: boolean) => {}
144
+ }
@@ -0,0 +1,3 @@
1
+ export { UnistylesMockedBridge } from './UnistylesMockedBridge'
2
+ export { UnistylesMockedRegistry } from './UnistylesMockedRegistry'
3
+ export { UnistylesMockedRuntime } from './UnistylesMockedRuntime'
@@ -0,0 +1,83 @@
1
+ import { type DependencyList, useEffect, useState } from 'react'
2
+ import { NativeEventEmitter, NativeModules } from 'react-native'
3
+ import { unistyles } from '../core'
4
+ import type { UnistylesEvents, UnistylesMobileLayoutEvent, UnistylesThemeEvent } from '../types'
5
+ import { UnistylesEventType } from '../common'
6
+
7
+ type SharedContextConfig = {
8
+ useContext: boolean,
9
+ deps: DependencyList
10
+ }
11
+
12
+ const unistylesEvents = new NativeEventEmitter(NativeModules.Unistyles)
13
+
14
+ export const useSharedContext = (config: SharedContextConfig) => {
15
+ const [plugins, setPlugins] = useState(unistyles.runtime.enabledPlugins)
16
+ const [theme, setTheme] = useState(unistyles.registry.getTheme(unistyles.runtime.themeName))
17
+ const [layout, setLayout] = useState({
18
+ breakpoint: unistyles.runtime.breakpoint,
19
+ orientation: unistyles.runtime.orientation,
20
+ screen: {
21
+ width: unistyles.runtime.screen.width,
22
+ height: unistyles.runtime.screen.height
23
+ },
24
+ statusBar: {
25
+ width: unistyles.runtime.statusBar.width,
26
+ height: unistyles.runtime.statusBar.height
27
+ },
28
+ navigationBar: {
29
+ width: unistyles.runtime.navigationBar.width,
30
+ height: unistyles.runtime.navigationBar.height
31
+ },
32
+ insets: {
33
+ top: unistyles.runtime.insets.top,
34
+ bottom: unistyles.runtime.insets.bottom,
35
+ left: unistyles.runtime.insets.left,
36
+ right: unistyles.runtime.insets.right
37
+ }
38
+ })
39
+
40
+ useEffect(() => {
41
+ if (config.useContext) {
42
+ return
43
+ }
44
+
45
+ const subscription = unistylesEvents.addListener(
46
+ '__unistylesOnChange',
47
+ (event: UnistylesEvents) => {
48
+ switch (event.type) {
49
+ case UnistylesEventType.Theme: {
50
+ const themeEvent = event as UnistylesThemeEvent
51
+
52
+ return setTheme(unistyles.registry.getTheme(themeEvent.payload.themeName))
53
+ }
54
+ case UnistylesEventType.Layout: {
55
+ const layoutEvent = event as UnistylesMobileLayoutEvent
56
+
57
+ return setLayout({
58
+ breakpoint: layoutEvent.payload.breakpoint,
59
+ orientation: layoutEvent.payload.orientation,
60
+ screen: layoutEvent.payload.screen,
61
+ statusBar: layoutEvent.payload.statusBar,
62
+ insets: layoutEvent.payload.insets,
63
+ navigationBar: layoutEvent.payload.navigationBar
64
+ })
65
+ }
66
+ case UnistylesEventType.Plugin: {
67
+ return setPlugins(unistyles.runtime.enabledPlugins)
68
+ }
69
+ default:
70
+ return
71
+ }
72
+ }
73
+ )
74
+
75
+ return subscription.remove
76
+ }, config.deps)
77
+
78
+ return {
79
+ plugins,
80
+ theme,
81
+ layout
82
+ }
83
+ }
@@ -1,81 +1,25 @@
1
- import { NativeEventEmitter, NativeModules } from 'react-native'
2
- import { useEffect, useState } from 'react'
3
- import { unistyles } from '../core'
4
- import { UnistylesEventType } from '../common'
5
- import type { UnistylesDynamicTypeSizeEvent, UnistylesEvents, UnistylesMobileLayoutEvent, UnistylesThemeEvent } from '../types'
6
-
7
- const unistylesEvents = new NativeEventEmitter(NativeModules.Unistyles)
1
+ import { useContext } from 'react'
2
+ import { UnistylesContext } from '../UnistylesProvider'
3
+ import { useSharedContext } from './useSharedContext'
8
4
 
9
5
  export const useUnistyles = () => {
10
- const [plugins, setPlugins] = useState(unistyles.runtime.enabledPlugins)
11
- const [theme, setTheme] = useState(unistyles.registry.getTheme(unistyles.runtime.themeName))
12
- const [contentSizeCategory, setContentSizeCategory] = useState(unistyles.runtime.contentSizeCategory)
13
- const [layout, setLayout] = useState({
14
- breakpoint: unistyles.runtime.breakpoint,
15
- orientation: unistyles.runtime.orientation,
16
- screenSize: {
17
- width: unistyles.runtime.screen.width,
18
- height: unistyles.runtime.screen.height
19
- },
20
- statusBar: {
21
- width: unistyles.runtime.statusBar.width,
22
- height: unistyles.runtime.statusBar.height
23
- },
24
- navigationBar: {
25
- width: unistyles.runtime.navigationBar.width,
26
- height: unistyles.runtime.navigationBar.height
27
- },
28
- insets: {
29
- top: unistyles.runtime.insets.top,
30
- bottom: unistyles.runtime.insets.bottom,
31
- left: unistyles.runtime.insets.left,
32
- right: unistyles.runtime.insets.right
33
- }
6
+ const unistylesContext = useContext(UnistylesContext)
7
+ const { theme, layout, plugins } = useSharedContext({
8
+ useContext: unistylesContext !== undefined,
9
+ deps: unistylesContext ? [unistylesContext] : []
34
10
  })
35
11
 
36
- useEffect(() => {
37
- const subscription = unistylesEvents.addListener(
38
- '__unistylesOnChange',
39
- (event: UnistylesEvents) => {
40
- switch (event.type) {
41
- case UnistylesEventType.Theme: {
42
- const themeEvent = event as UnistylesThemeEvent
43
-
44
- return setTheme(unistyles.registry.getTheme(themeEvent.payload.themeName))
45
- }
46
- case UnistylesEventType.Layout: {
47
- const layoutEvent = event as UnistylesMobileLayoutEvent
48
-
49
- return setLayout({
50
- breakpoint: layoutEvent.payload.breakpoint,
51
- orientation: layoutEvent.payload.orientation,
52
- screenSize: layoutEvent.payload.screen,
53
- statusBar: layoutEvent.payload.statusBar,
54
- insets: layoutEvent.payload.insets,
55
- navigationBar: layoutEvent.payload.navigationBar
56
- })
57
- }
58
- case UnistylesEventType.Plugin: {
59
- return setPlugins(unistyles.runtime.enabledPlugins)
60
- }
61
- case UnistylesEventType.DynamicTypeSize: {
62
- const dynamicTypeSizeEvent = event as UnistylesDynamicTypeSizeEvent
63
-
64
- return setContentSizeCategory(dynamicTypeSizeEvent.payload.contentSizeCategory)
65
- }
66
- default:
67
- return
68
- }
69
- }
70
- )
71
-
72
- return subscription.remove
73
- }, [])
12
+ if (unistylesContext !== undefined) {
13
+ return {
14
+ plugins: unistylesContext.plugins,
15
+ theme: unistylesContext.theme,
16
+ layout: unistylesContext.layout
17
+ }
18
+ }
74
19
 
75
20
  return {
76
21
  plugins,
77
22
  theme,
78
- layout,
79
- contentSizeCategory
23
+ layout
80
24
  }
81
25
  }
package/src/index.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { unistyles } from './core'
2
2
  import { mq } from './utils'
3
3
  import { useInitialTheme } from './hooks'
4
- import type { UnistylesPlugin, UnistylesValues } from './types'
4
+ import type { UnistylesPlugin, UnistylesValues, UnistyleText, UnistyleView, UnistyleImage, ExtractVariantNames, UnistylesTheme } from './types'
5
5
  import type { UnistylesThemes, UnistylesBreakpoints } from './global'
6
6
  import { ScreenOrientation, AndroidContentSizeCategory, IOSContentSizeCategory } from './common'
7
7
  import { useStyles } from './useStyles'
8
8
  import { createStyleSheet } from './createStyleSheet'
9
-
9
+ import { UnistylesProvider } from './UnistylesProvider'
10
10
  /**
11
11
  * Utility to interact with the Unistyles
12
12
  * (should be called only once)
@@ -40,12 +40,18 @@ export {
40
40
  AndroidContentSizeCategory,
41
41
  IOSContentSizeCategory,
42
42
  UnistylesRegistry,
43
- UnistylesRuntime
43
+ UnistylesRuntime,
44
+ UnistylesProvider
44
45
  }
45
46
 
46
47
  export type {
48
+ UnistylesTheme,
47
49
  UnistylesThemes,
48
50
  UnistylesBreakpoints,
49
51
  UnistylesPlugin,
50
- UnistylesValues
52
+ UnistylesValues,
53
+ UnistyleText,
54
+ UnistyleView,
55
+ UnistyleImage,
56
+ ExtractVariantNames as UnistylesVariants
51
57
  }
@@ -2,6 +2,7 @@ import type { ColorValue, OpaqueColorValue } from 'react-native'
2
2
  import type { UnistylesTheme } from '../types'
3
3
  import type { BreakpointsOrMediaQueries, ToDeepUnistyles } from './stylesheet'
4
4
  import type { TransformStyles } from './core'
5
+ import type { UnistylesMiniRuntime } from '../core'
5
6
 
6
7
  type ExtractTransformArray<T> = T extends object
7
8
  ? { [K in keyof T]: ExtractBreakpoints<T[K]> }
@@ -17,26 +18,33 @@ type ExtractBreakpoints<T> = T extends object
17
18
  }
18
19
  : T
19
20
 
20
- type ParseNestedObject<T> = T extends (...args: infer A) => infer R
21
- ? (...args: A) => ParseNestedObject<R>
21
+ type ParseNestedObject<T, ShouldFlatten> = T extends (...args: infer A) => infer R
22
+ ? (...args: A) => ParseNestedObject<R, false>
22
23
  : T extends object
23
24
  ? T extends { variants: infer R }
24
- ? ParseVariants<FlattenVariants<R>> & ParseNestedObject<Omit<T, 'variants'>>
25
+ // if intersection of Base and Variants is never, then flatten variants to generic "string"
26
+ ? (ParseVariants<FlattenVariants<R, false>> & ParseNestedObject<Omit<T, 'variants'>, false>) extends never
27
+ ? ParseVariants<FlattenVariants<R, true>> & ParseNestedObject<Omit<T, 'variants'>, false>
28
+ : ParseVariants<FlattenVariants<R, false>> & ParseNestedObject<Omit<T, 'variants'>, false>
25
29
  : {
26
30
  [K in keyof T]: T[K] extends object
27
31
  ? T[K] extends OpaqueColorValue
28
32
  ? ColorValue
29
33
  : ExtractBreakpoints<T[K]>
30
- : T[K]
34
+ : T[K] extends string
35
+ ? ShouldFlatten extends true
36
+ ? string
37
+ : T[K]
38
+ : T[K]
31
39
  }
32
40
  : T
33
41
 
34
- type FlattenVariants<T> = T extends object
42
+ type FlattenVariants<T, ShouldFlatten> = T extends object
35
43
  ? {
36
44
  [K in keyof T]: T[K] extends object
37
45
  ? {
38
46
  [key in keyof T[K]]: T[K][key] extends object
39
- ? ParseNestedObject<T[K][key]>
47
+ ? ParseNestedObject<T[K][key], ShouldFlatten>
40
48
  : never
41
49
  }
42
50
  : never
@@ -45,7 +53,9 @@ type FlattenVariants<T> = T extends object
45
53
 
46
54
  type ParseVariants<T> = T extends object
47
55
  ? T[keyof T] extends object
48
- ? UnionToIntersection<ParseVariants<T[keyof T]>>
56
+ ? UnionToIntersection<ParseVariants<T[keyof T]>> extends never
57
+ ? ParseVariants<T[keyof T]>
58
+ : UnionToIntersection<ParseVariants<T[keyof T]>>
49
59
  : T
50
60
  : T
51
61
 
@@ -53,9 +63,9 @@ type UnionToIntersection<U> =
53
63
  (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never
54
64
 
55
65
  type ParseStyleKeys<T> = T extends object
56
- ? { [K in keyof T]: ParseNestedObject<T[K]> }
66
+ ? { [K in keyof T]: ParseNestedObject<T[K], false> }
57
67
  : never
58
68
 
59
- export type ReactNativeStyleSheet<T> = T extends (theme: UnistylesTheme) => infer R
69
+ export type ReactNativeStyleSheet<T> = T extends (theme: UnistylesTheme, runtime: UnistylesMiniRuntime) => infer R
60
70
  ? ParseStyleKeys<R>
61
71
  : ParseStyleKeys<T>
@@ -0,0 +1,26 @@
1
+ type AndroidColor = 'red'
2
+ | 'blue'
3
+ | 'green'
4
+ | 'black'
5
+ | 'white'
6
+ | 'gray'
7
+ | 'cyan'
8
+ | 'magenta'
9
+ | 'yellow'
10
+ | 'light gray'
11
+ | 'dark gray'
12
+ | 'grey'
13
+ | 'light grey'
14
+ | 'dark grey'
15
+ | 'aqua'
16
+ | 'fuchsia'
17
+ | 'lime'
18
+ | 'maroon'
19
+ | 'navy'
20
+ | 'olive'
21
+ | 'purple'
22
+ | 'silver'
23
+ | 'teal'
24
+ | 'transparent'
25
+
26
+ export type Color = AndroidColor | string | undefined
package/src/types/core.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type {
2
2
  MatrixTransform,
3
- PerpectiveTransform,
3
+ PerspectiveTransform,
4
4
  RotateTransform,
5
5
  RotateXTransform,
6
6
  RotateYTransform,
@@ -22,7 +22,7 @@ export type ShadowOffset = {
22
22
  }
23
23
 
24
24
  export type TransformStyles =
25
- & PerpectiveTransform
25
+ & PerspectiveTransform
26
26
  & RotateTransform
27
27
  & RotateXTransform
28
28
  & RotateYTransform
@@ -1,5 +1,6 @@
1
1
  export * from './normalizer'
2
2
  export * from './unistyles'
3
+ export * from './color'
3
4
  export type { Optional, Nullable } from './common'
4
5
  export type {
5
6
  NestedStylePairs,
@@ -13,7 +14,10 @@ export type {
13
14
  StyleSheetWithSuperPowers,
14
15
  StyleSheet,
15
16
  AllAvailableKeys,
16
- UnistylesValues
17
+ UnistylesValues,
18
+ UnistyleText,
19
+ UnistyleView,
20
+ UnistyleImage
17
21
  } from './stylesheet'
18
22
  export type { ReactNativeStyleSheet } from './breakpoints'
19
23
  export type { ExtractVariantNames } from './variants'
@@ -1,6 +1,6 @@
1
1
  import type { ShadowStyleIOS, TextStyle, TransformsStyle } from 'react-native'
2
2
 
3
- type TransformArrayElement<T> = T extends Array<infer U> ? U : never
3
+ type TransformArrayElement<T> = T extends ReadonlyArray<infer U> ? U : never
4
4
  type BoxShadow = Required<ShadowStyleIOS>
5
5
  type TextShadow = Required<Pick<TextStyle, 'textShadowColor' | 'textShadowOffset' | 'textShadowRadius'>>
6
6
  type Transforms = Array<TransformArrayElement<TransformsStyle['transform']>>
@@ -1,18 +1,21 @@
1
- import type { ImageStyle, TextStyle, ViewStyle } from 'react-native'
1
+ import type { BoxShadowValue, FilterFunction, ImageStyle, TextStyle, ViewStyle } from 'react-native'
2
2
  import type { ShadowOffset, TransformStyles, UnistylesTheme } from './core'
3
3
  import type { UnistylesBreakpoints } from '../global'
4
+ import type { UnistylesMiniRuntime } from '../core'
4
5
 
5
6
  // these props are treated differently to nest breakpoints and media queries
6
- type NestedKeys = 'shadowOffset' | 'transform' | 'textShadowOffset'
7
+ type NestedKeys = 'shadowOffset' | 'transform' | 'textShadowOffset' | 'boxShadow' | 'filter'
7
8
 
8
- type UnistyleView = Omit<ViewStyle, NestedKeys>
9
- type UnistyleText = Omit<TextStyle, NestedKeys>
10
- type UnistyleImage = Omit<ImageStyle, NestedKeys>
9
+ export type UnistyleView = Omit<ViewStyle, NestedKeys>
10
+ export type UnistyleText = Omit<TextStyle, NestedKeys>
11
+ export type UnistyleImage = Omit<ImageStyle, NestedKeys>
11
12
 
12
13
  type UnistyleNestedStyles = {
13
14
  shadowOffset?: ToDeepUnistyles<ShadowOffset>,
14
15
  textShadowOffset?: ToDeepUnistyles<ShadowOffset>,
15
- transform?: Array<ToDeepUnistyles<TransformStyles>>
16
+ transform?: Array<ToDeepUnistyles<TransformStyles>>,
17
+ boxShadow?: Array<ToDeepUnistyles<BoxShadowValue>> | string,
18
+ filter?: Array<ToDeepUnistyles<FilterFunction>> | string
16
19
  }
17
20
 
18
21
  type Variants = {
@@ -46,4 +49,4 @@ export type StyleSheet = {
46
49
  [styleName: string]: UnistylesValues | ((...args: any) => UnistylesValues)
47
50
  }
48
51
 
49
- export type StyleSheetWithSuperPowers = ((theme: UnistylesTheme) => StyleSheet) | StyleSheet
52
+ export type StyleSheetWithSuperPowers = ((theme: UnistylesTheme, miniRuntime: UnistylesMiniRuntime) => StyleSheet) | StyleSheet
@@ -17,11 +17,23 @@ export type ScreenDimensions = {
17
17
  width: number
18
18
  }
19
19
 
20
+ export interface StatusBar extends ScreenDimensions {
21
+ setColor(color?: string, alpha?: number): void,
22
+ setHidden(hidden: boolean): void
23
+ }
24
+
25
+ export interface NavigationBar extends ScreenDimensions {
26
+ setColor(color?: string, alpha?: number): void,
27
+ setHidden(hidden: boolean): void
28
+ }
29
+
20
30
  export type UnistylesConfig = {
21
31
  adaptiveThemes?: boolean,
22
32
  initialTheme?: keyof UnistylesThemes,
23
33
  plugins?: Array<UnistylesPlugin>,
24
- experimentalCSSMediaQueries?: boolean
34
+ experimentalCSSMediaQueries?: boolean,
35
+ windowResizeDebounceTimeMs?: number,
36
+ disableAnimatedInsets?: boolean
25
37
  }
26
38
 
27
39
  export type UnistylesBridge = {
@@ -36,8 +48,11 @@ export type UnistylesBridge = {
36
48
  contentSizeCategory: IOSContentSizeCategory | AndroidContentSizeCategory,
37
49
  sortedBreakpointPairs: Array<[keyof UnistylesBreakpoints, UnistylesBreakpoints[keyof UnistylesBreakpoints]]>,
38
50
  insets: ScreenInsets,
39
- statusBar: ScreenDimensions,
40
- navigationBar: ScreenDimensions
51
+ statusBar: StatusBar,
52
+ navigationBar: NavigationBar,
53
+ pixelRatio: number,
54
+ fontScale: number,
55
+ rtl: boolean
41
56
 
42
57
  // setters
43
58
  themes: Array<keyof UnistylesThemes>,
@@ -46,7 +61,15 @@ export type UnistylesBridge = {
46
61
  updateTheme(name: keyof UnistylesThemes): void,
47
62
  useAdaptiveThemes(enable: boolean): void,
48
63
  addPlugin(pluginName: string, notify: boolean): void,
49
- removePlugin(pluginName: string): void
64
+ removePlugin(pluginName: string): void,
65
+ setRootViewBackgroundColor(color?: string, alpha?: number): void,
66
+ setImmersiveMode(isEnabled: boolean): void
67
+
68
+ // web only
69
+ setWindowResizeDebounceTimeMs(timeMs: number): void
70
+
71
+ // android only
72
+ disableAnimatedInsets(): void
50
73
  }
51
74
 
52
75
  export type UnistylesThemeEvent = {
@@ -72,11 +95,4 @@ export type UnistylesPluginEvent = {
72
95
  type: UnistylesEventType.Plugin
73
96
  }
74
97
 
75
- export type UnistylesDynamicTypeSizeEvent = {
76
- type: UnistylesEventType.DynamicTypeSize,
77
- payload: {
78
- contentSizeCategory: IOSContentSizeCategory | AndroidContentSizeCategory
79
- }
80
- }
81
-
82
- export type UnistylesEvents = UnistylesThemeEvent | UnistylesMobileLayoutEvent | UnistylesPluginEvent | UnistylesDynamicTypeSizeEvent
98
+ export type UnistylesEvents = UnistylesThemeEvent | UnistylesMobileLayoutEvent | UnistylesPluginEvent
package/src/useStyles.ts CHANGED
@@ -26,7 +26,7 @@ export const useStyles = <ST extends StyleSheetWithSuperPowers>(
26
26
  const { theme, layout, plugins } = useUnistyles()
27
27
  const variants = useVariants(variantsMap)
28
28
  const parsedStyles = useMemo(() => typeof stylesheet === 'function'
29
- ? stylesheet(theme)
29
+ ? stylesheet(theme, unistyles.runtime.miniRuntime)
30
30
  : stylesheet, [theme, stylesheet, layout])
31
31
 
32
32
  const dynamicStyleSheet = useMemo(() => Object
@@ -5,3 +5,4 @@ export { getValueForBreakpoint } from './breakpoints'
5
5
  export { proxifyFunction, parseStyle, isPlatformColor } from './styles'
6
6
  export { withPlugins } from './withPlugins'
7
7
  export { generateReactNativeWebId } from './generateId'
8
+ export { parseColor } from './parseColor'