react-native-unistyles 3.0.0-alpha.24 → 3.0.0-alpha.26

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. package/cxx/common/Helpers.h +10 -0
  2. package/cxx/core/UnistylesRegistry.cpp +10 -10
  3. package/cxx/core/UnistylesState.cpp +17 -1
  4. package/cxx/core/UnistylesState.h +2 -1
  5. package/cxx/hybridObjects/HybridStyleSheet.cpp +49 -10
  6. package/cxx/hybridObjects/HybridStyleSheet.h +8 -0
  7. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +23 -3
  8. package/cxx/hybridObjects/HybridUnistylesRuntime.h +5 -0
  9. package/cxx/parser/Parser.cpp +1 -1
  10. package/ios/Equatable.swift +2 -1
  11. package/ios/NativePlatform+ios.swift +4 -1
  12. package/ios/UnistylesModuleOnLoad.h +10 -1
  13. package/lib/commonjs/core/index.js +20 -0
  14. package/lib/commonjs/core/index.js.map +1 -0
  15. package/lib/commonjs/core/useBreakpoint.js +22 -0
  16. package/lib/commonjs/core/useBreakpoint.js.map +1 -0
  17. package/lib/commonjs/core/useBreakpoint.native.js +24 -0
  18. package/lib/commonjs/core/useBreakpoint.native.js.map +1 -0
  19. package/lib/commonjs/core/useTheme.js +22 -0
  20. package/lib/commonjs/core/useTheme.js.map +1 -0
  21. package/lib/commonjs/core/useTheme.native.js +24 -0
  22. package/lib/commonjs/core/useTheme.native.js.map +1 -0
  23. package/lib/commonjs/index.js +16 -15
  24. package/lib/commonjs/index.js.map +1 -1
  25. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
  26. package/lib/commonjs/specs/NavigtionBar/index.js.map +1 -1
  27. package/lib/commonjs/specs/StatusBar/index.js.map +1 -1
  28. package/lib/commonjs/specs/StyleSheet/index.js +1 -0
  29. package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
  30. package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
  31. package/lib/commonjs/specs/index.js +7 -0
  32. package/lib/commonjs/specs/index.js.map +1 -1
  33. package/lib/commonjs/web/runtime.js +13 -9
  34. package/lib/commonjs/web/runtime.js.map +1 -1
  35. package/lib/module/core/index.js +5 -0
  36. package/lib/module/core/index.js.map +1 -0
  37. package/lib/module/core/useBreakpoint.js +17 -0
  38. package/lib/module/core/useBreakpoint.js.map +1 -0
  39. package/lib/module/core/useBreakpoint.native.js +19 -0
  40. package/lib/module/core/useBreakpoint.native.js.map +1 -0
  41. package/lib/module/core/useTheme.js +17 -0
  42. package/lib/module/core/useTheme.js.map +1 -0
  43. package/lib/module/core/useTheme.native.js +19 -0
  44. package/lib/module/core/useTheme.native.js.map +1 -0
  45. package/lib/module/index.js +1 -13
  46. package/lib/module/index.js.map +1 -1
  47. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
  48. package/lib/module/specs/NavigtionBar/index.js.map +1 -1
  49. package/lib/module/specs/StatusBar/index.js.map +1 -1
  50. package/lib/module/specs/StyleSheet/index.js +1 -0
  51. package/lib/module/specs/StyleSheet/index.js.map +1 -1
  52. package/lib/module/specs/UnistylesRuntime/index.js.map +1 -1
  53. package/lib/module/specs/index.js +2 -1
  54. package/lib/module/specs/index.js.map +1 -1
  55. package/lib/module/web/runtime.js +13 -9
  56. package/lib/module/web/runtime.js.map +1 -1
  57. package/lib/typescript/example/App.d.ts.map +1 -1
  58. package/lib/typescript/example/Typography.d.ts +28 -5
  59. package/lib/typescript/example/Typography.d.ts.map +1 -1
  60. package/lib/typescript/src/core/index.d.ts +3 -0
  61. package/lib/typescript/src/core/index.d.ts.map +1 -0
  62. package/lib/typescript/src/core/useBreakpoint.d.ts +2 -0
  63. package/lib/typescript/src/core/useBreakpoint.d.ts.map +1 -0
  64. package/lib/typescript/src/core/useBreakpoint.native.d.ts +2 -0
  65. package/lib/typescript/src/core/useBreakpoint.native.d.ts.map +1 -0
  66. package/lib/typescript/src/core/useTheme.d.ts +41 -0
  67. package/lib/typescript/src/core/useTheme.d.ts.map +1 -0
  68. package/lib/typescript/src/core/useTheme.native.d.ts +41 -0
  69. package/lib/typescript/src/core/useTheme.native.d.ts.map +1 -0
  70. package/lib/typescript/src/index.d.ts +2 -0
  71. package/lib/typescript/src/index.d.ts.map +1 -1
  72. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts +2 -1
  73. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts.map +1 -1
  74. package/lib/typescript/src/specs/NavigtionBar/index.d.ts +5 -0
  75. package/lib/typescript/src/specs/NavigtionBar/index.d.ts.map +1 -1
  76. package/lib/typescript/src/specs/StatusBar/index.d.ts +5 -0
  77. package/lib/typescript/src/specs/StatusBar/index.d.ts.map +1 -1
  78. package/lib/typescript/src/specs/StyleSheet/UnistylesStyleSheet.nitro.d.ts +2 -0
  79. package/lib/typescript/src/specs/StyleSheet/UnistylesStyleSheet.nitro.d.ts.map +1 -1
  80. package/lib/typescript/src/specs/StyleSheet/index.d.ts +2 -1
  81. package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
  82. package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts +0 -1
  83. package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts.map +1 -1
  84. package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts +3 -1
  85. package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts.map +1 -1
  86. package/lib/typescript/src/specs/index.d.ts +4 -2
  87. package/lib/typescript/src/specs/index.d.ts.map +1 -1
  88. package/lib/typescript/src/types/index.d.ts +1 -1
  89. package/lib/typescript/src/types/index.d.ts.map +1 -1
  90. package/lib/typescript/src/types/variants.d.ts +3 -0
  91. package/lib/typescript/src/types/variants.d.ts.map +1 -1
  92. package/lib/typescript/src/web/runtime.d.ts +1 -0
  93. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  94. package/nitrogen/generated/android/c++/JUnistylesNativeMiniRuntime.hpp +8 -6
  95. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistylesNativeMiniRuntime.kt +2 -1
  96. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.hpp +2 -2
  97. package/nitrogen/generated/ios/swift/UnistylesNativeMiniRuntime.swift +16 -5
  98. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.cpp +1 -0
  99. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.hpp +6 -3
  100. package/nitrogen/generated/shared/c++/UnistylesCxxMiniRuntime.hpp +10 -9
  101. package/nitrogen/generated/shared/c++/UnistylesNativeMiniRuntime.hpp +9 -8
  102. package/package.json +1 -1
  103. package/plugin/common.js +3 -1
  104. package/plugin/stylesheet.js +2 -1
  105. package/src/core/index.ts +2 -0
  106. package/src/core/useBreakpoint.native.ts +21 -0
  107. package/src/core/useBreakpoint.ts +18 -0
  108. package/src/core/useTheme.native.ts +21 -0
  109. package/src/core/useTheme.ts +18 -0
  110. package/src/index.ts +2 -15
  111. package/src/specs/NativePlatform/NativePlatform.nitro.ts +2 -1
  112. package/src/specs/NavigtionBar/index.ts +5 -0
  113. package/src/specs/StatusBar/index.ts +5 -0
  114. package/src/specs/StyleSheet/UnistylesStyleSheet.nitro.ts +3 -0
  115. package/src/specs/StyleSheet/index.ts +4 -1
  116. package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.ts +0 -1
  117. package/src/specs/UnistylesRuntime/index.ts +3 -1
  118. package/src/specs/index.ts +6 -2
  119. package/src/types/index.ts +1 -1
  120. package/src/types/variants.ts +6 -0
  121. package/src/web/runtime.ts +17 -12
package/src/index.ts CHANGED
@@ -1,18 +1,5 @@
1
- import React from 'react'
2
-
3
1
  export * from './specs'
4
2
  export { mq } from './mq'
5
3
  export type { UnistylesThemes, UnistylesBreakpoints } from './global'
6
- // TODO: export Native createUnistylesComponent
7
- // can't import it this way, it will break native build
8
- // export { createUnistylesComponent } from './web/createUnistylesComponent'
9
-
10
- // todo verify true min version
11
- const minReactVersionRequiredByUnistyles = '18.3.1'
12
-
13
- if (React.version < minReactVersionRequiredByUnistyles) {
14
- throw new Error(`
15
- You are using an outdated version of React (${React.version}).
16
- Unistyles requires at least React ${minReactVersionRequiredByUnistyles}.
17
- `)
18
- }
4
+ export { useTheme, useBreakpoint } from './core'
5
+ export type { UnistylesVariants } from './types'
@@ -31,7 +31,8 @@ export interface UnistylesNativeMiniRuntime {
31
31
  readonly rtl: boolean
32
32
  readonly statusBar: Dimensions,
33
33
  readonly navigationBar: Dimensions
34
- readonly orientation: Orientation
34
+ readonly isPortrait: boolean,
35
+ readonly isLandscape: boolean
35
36
  }
36
37
 
37
38
  // represents any native API that can communicate with Unistyles
@@ -3,6 +3,11 @@ import type { UnistylesNavigationBar as UnistylesNavigationBarSpec } from './Uni
3
3
  import type { Color } from '../types'
4
4
 
5
5
  interface PrivateUnistylesNavigationBar extends Omit<UnistylesNavigationBarSpec, 'setBackgroundColor'> {
6
+ /**
7
+ * Apps targeting Android SDK 35
8
+ * This API is deprecated but continues to affect 3-button navigation
9
+ * @deprecated
10
+ */
6
11
  setBackgroundColor(color?: string): void,
7
12
  _setBackgroundColor(color?: Color): void
8
13
  }
@@ -8,6 +8,11 @@ interface PrivateUnistylesStatusBar extends Omit<UnistylesStatusBarSpec, 'setBac
8
8
  setStyle(style: StatusBarStyle, animated?: boolean): void,
9
9
  setHidden(isHidden: boolean, animation?: StatusBarHiddenAnimation): void,
10
10
  _setHidden(isHidden: boolean, animation?: StatusBarHiddenAnimation): void,
11
+ /**
12
+ * Apps targeting Android SDK 35
13
+ * This API is deprecated as status bar background color is always transparent
14
+ * @deprecated
15
+ */
11
16
  setBackgroundColor(color?: string): void,
12
17
  _setBackgroundColor(color?: Color): void
13
18
  }
@@ -1,6 +1,9 @@
1
1
  import type { HybridObject } from 'react-native-nitro-modules'
2
+ import { UnistyleDependency } from '../NativePlatform'
2
3
 
3
4
  export interface UnistylesStyleSheet extends HybridObject<{ ios: 'c++', android: 'c++' }> {
4
5
  readonly hairlineWidth: number
5
6
  readonly unid: number
7
+
8
+ addChangeListener(onChanged: (dependencies: Array<UnistyleDependency>) => void): () => void
6
9
  }
@@ -23,6 +23,7 @@ export interface UnistylesStyleSheet extends UnistylesStyleSheetSpec {
23
23
  flatten: typeof NativeStyleSheetType.flatten,
24
24
 
25
25
  // overridden methods
26
+ init(): void,
26
27
  create: CreateUnistylesStyleSheet,
27
28
  configure(config: UnistylesConfig): void,
28
29
  jsMethods: {
@@ -41,6 +42,8 @@ HybridUnistylesStyleSheet.jsMethods = {
41
42
  processColor
42
43
  }
43
44
 
44
- type PrivateMethods = 'jsMethods'
45
+ HybridUnistylesStyleSheet.init()
46
+
47
+ type PrivateMethods = 'jsMethods' | 'addChangeListener' | 'init'
45
48
 
46
49
  export const StyleSheet = HybridUnistylesStyleSheet as Omit<UnistylesStyleSheet, PrivateMethods>
@@ -10,7 +10,6 @@ type Orientation = 'portrait' | 'landscape'
10
10
  export interface UnistylesCxxMiniRuntime extends UnistylesNativeMiniRuntime {
11
11
  readonly themeName?: string,
12
12
  readonly breakpoint?: string,
13
- readonly orientation: Orientation,
14
13
  readonly hasAdaptiveThemes: boolean,
15
14
  }
16
15
 
@@ -4,8 +4,9 @@ import type { UnistylesRuntime as UnistylesRuntimeSpec, UnistylesMiniRuntime } f
4
4
  import type { AppBreakpoint, AppTheme, AppThemeName, Color, ColorScheme, Orientation } from '../types'
5
5
  import { attachStatusBarJSMethods, type UnistylesStatusBar } from '../StatusBar'
6
6
  import { attachNavigationBarJSMethods, type UnistylesNavigationBar } from '../NavigtionBar'
7
- import type { AndroidContentSizeCategory, IOSContentSizeCategory } from '../../types'
7
+ import type { AndroidContentSizeCategory, IOSContentSizeCategory, UnistylesTheme } from '../../types'
8
8
  import { isIOS } from '../../common'
9
+ import type { UnistylesThemes } from '../../global'
9
10
 
10
11
  export interface UnistylesRuntimePrivate extends Omit<UnistylesRuntimeSpec, 'setRootViewBackgroundColor'> {
11
12
  readonly colorScheme: ColorScheme,
@@ -18,6 +19,7 @@ export interface UnistylesRuntimePrivate extends Omit<UnistylesRuntimeSpec, 'set
18
19
  statusBar: UnistylesStatusBar,
19
20
  navigationBar: UnistylesNavigationBar,
20
21
 
22
+ getTheme(themeName?: keyof UnistylesThemes): UnistylesTheme,
21
23
  setTheme(themeName: AppThemeName): void
22
24
  updateTheme(themeName: AppThemeName, updater: (currentTheme: AppTheme) => AppTheme): void,
23
25
  setRootViewBackgroundColor(color?: string): void,
@@ -2,14 +2,17 @@ import './TurboUnistyles'
2
2
 
3
3
  import { Runtime } from './UnistylesRuntime'
4
4
  import { StyleSheet } from './StyleSheet'
5
+ import type { UnistylesStyleSheet } from './StyleSheet'
5
6
  import { UnistylesShadowRegistry } from './ShadowRegistry'
6
7
  import type { UnistylesMiniRuntime } from './UnistylesRuntime'
7
8
  import { StatusBarStyle, ColorScheme, Orientation } from './types'
9
+ import { UnistyleDependency } from './NativePlatform'
8
10
 
9
11
  export {
10
12
  StatusBarStyle,
11
13
  ColorScheme,
12
- Orientation
14
+ Orientation,
15
+ UnistyleDependency
13
16
  }
14
17
 
15
18
  export {
@@ -19,5 +22,6 @@ export {
19
22
  }
20
23
 
21
24
  export type {
22
- UnistylesMiniRuntime
25
+ UnistylesMiniRuntime,
26
+ UnistylesStyleSheet
23
27
  }
@@ -17,5 +17,5 @@ export type {
17
17
  UnistyleImage
18
18
  } from './stylesheet'
19
19
  export type { ReactNativeStyleSheet } from './breakpoints'
20
- export type { ExtractVariantNames } from './variants'
20
+ export type { ExtractVariantNames, UnistylesVariants } from './variants'
21
21
  export { AndroidContentSizeCategory, IOSContentSizeCategory, WebContentSizeCategory } from './accessibility'
@@ -21,3 +21,9 @@ type ExtractSubVariantKeys<T> = T extends object
21
21
  type ExtractVariant<T> = T extends { variants: infer V }
22
22
  ? { [key in keyof V]?: ExtractSubVariantKeys<V[key]> }
23
23
  : T
24
+
25
+ export type UnistylesVariants<ST> = ST extends { useVariants: infer V }
26
+ ? V extends (variants: infer T) => void
27
+ ? T
28
+ : never
29
+ : never
@@ -67,17 +67,7 @@ class UnistylesRuntimeBuilder {
67
67
  }
68
68
 
69
69
  get theme() {
70
- if (!this.themeName) {
71
- throw new Error('🦄 No theme selected!')
72
- }
73
-
74
- const theme = UnistylesState.themes.get(this.themeName)
75
-
76
- if (!theme) {
77
- throw new Error(`🦄 Theme "${this.themeName}" is not registered!`)
78
- }
79
-
80
- return theme
70
+ return this.getTheme(this.themeName)
81
71
  }
82
72
 
83
73
  get pixelRatio() {
@@ -134,7 +124,8 @@ class UnistylesRuntimeBuilder {
134
124
  themeName: this.themeName,
135
125
  contentSizeCategory: this.contentSizeCategory,
136
126
  breakpoint: this.breakpoint,
137
- orientation: this.orientation,
127
+ isLandscape: this.orientation === Orientation.Landscape,
128
+ isPortrait: this.orientation === Orientation.Portrait,
138
129
  pixelRatio: this.pixelRatio,
139
130
  screen: this.screen,
140
131
  fontScale: this.fontScale,
@@ -191,6 +182,20 @@ class UnistylesRuntimeBuilder {
191
182
 
192
183
  UnistylesState.themes.set(themeName, updater(oldTheme))
193
184
  }
185
+
186
+ getTheme = (themeName = this.themeName) => {
187
+ if (!themeName) {
188
+ throw new Error('🦄 No theme selected!')
189
+ }
190
+
191
+ const theme = UnistylesState.themes.get(themeName)
192
+
193
+ if (!theme) {
194
+ throw new Error(`🦄 Theme "${this.themeName}" is not registered!`)
195
+ }
196
+
197
+ return theme
198
+ }
194
199
  }
195
200
 
196
201
  export const UnistylesRuntime = new UnistylesRuntimeBuilder()