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.
- package/cxx/common/Helpers.h +10 -0
- package/cxx/core/UnistylesRegistry.cpp +10 -10
- package/cxx/core/UnistylesState.cpp +17 -1
- package/cxx/core/UnistylesState.h +2 -1
- package/cxx/hybridObjects/HybridStyleSheet.cpp +49 -10
- package/cxx/hybridObjects/HybridStyleSheet.h +8 -0
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +23 -3
- package/cxx/hybridObjects/HybridUnistylesRuntime.h +5 -0
- package/cxx/parser/Parser.cpp +1 -1
- package/ios/Equatable.swift +2 -1
- package/ios/NativePlatform+ios.swift +4 -1
- package/ios/UnistylesModuleOnLoad.h +10 -1
- package/lib/commonjs/core/index.js +20 -0
- package/lib/commonjs/core/index.js.map +1 -0
- package/lib/commonjs/core/useBreakpoint.js +22 -0
- package/lib/commonjs/core/useBreakpoint.js.map +1 -0
- package/lib/commonjs/core/useBreakpoint.native.js +24 -0
- package/lib/commonjs/core/useBreakpoint.native.js.map +1 -0
- package/lib/commonjs/core/useTheme.js +22 -0
- package/lib/commonjs/core/useTheme.js.map +1 -0
- package/lib/commonjs/core/useTheme.native.js +24 -0
- package/lib/commonjs/core/useTheme.native.js.map +1 -0
- package/lib/commonjs/index.js +16 -15
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
- package/lib/commonjs/specs/NavigtionBar/index.js.map +1 -1
- package/lib/commonjs/specs/StatusBar/index.js.map +1 -1
- package/lib/commonjs/specs/StyleSheet/index.js +1 -0
- package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
- package/lib/commonjs/specs/index.js +7 -0
- package/lib/commonjs/specs/index.js.map +1 -1
- package/lib/commonjs/web/runtime.js +13 -9
- package/lib/commonjs/web/runtime.js.map +1 -1
- package/lib/module/core/index.js +5 -0
- package/lib/module/core/index.js.map +1 -0
- package/lib/module/core/useBreakpoint.js +17 -0
- package/lib/module/core/useBreakpoint.js.map +1 -0
- package/lib/module/core/useBreakpoint.native.js +19 -0
- package/lib/module/core/useBreakpoint.native.js.map +1 -0
- package/lib/module/core/useTheme.js +17 -0
- package/lib/module/core/useTheme.js.map +1 -0
- package/lib/module/core/useTheme.native.js +19 -0
- package/lib/module/core/useTheme.native.js.map +1 -0
- package/lib/module/index.js +1 -13
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
- package/lib/module/specs/NavigtionBar/index.js.map +1 -1
- package/lib/module/specs/StatusBar/index.js.map +1 -1
- package/lib/module/specs/StyleSheet/index.js +1 -0
- package/lib/module/specs/StyleSheet/index.js.map +1 -1
- package/lib/module/specs/UnistylesRuntime/index.js.map +1 -1
- package/lib/module/specs/index.js +2 -1
- package/lib/module/specs/index.js.map +1 -1
- package/lib/module/web/runtime.js +13 -9
- package/lib/module/web/runtime.js.map +1 -1
- package/lib/typescript/example/App.d.ts.map +1 -1
- package/lib/typescript/example/Typography.d.ts +28 -5
- package/lib/typescript/example/Typography.d.ts.map +1 -1
- package/lib/typescript/src/core/index.d.ts +3 -0
- package/lib/typescript/src/core/index.d.ts.map +1 -0
- package/lib/typescript/src/core/useBreakpoint.d.ts +2 -0
- package/lib/typescript/src/core/useBreakpoint.d.ts.map +1 -0
- package/lib/typescript/src/core/useBreakpoint.native.d.ts +2 -0
- package/lib/typescript/src/core/useBreakpoint.native.d.ts.map +1 -0
- package/lib/typescript/src/core/useTheme.d.ts +41 -0
- package/lib/typescript/src/core/useTheme.d.ts.map +1 -0
- package/lib/typescript/src/core/useTheme.native.d.ts +41 -0
- package/lib/typescript/src/core/useTheme.native.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +2 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts +2 -1
- package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/NavigtionBar/index.d.ts +5 -0
- package/lib/typescript/src/specs/NavigtionBar/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/StatusBar/index.d.ts +5 -0
- package/lib/typescript/src/specs/StatusBar/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/StyleSheet/UnistylesStyleSheet.nitro.d.ts +2 -0
- package/lib/typescript/src/specs/StyleSheet/UnistylesStyleSheet.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts +2 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts +0 -1
- package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts +3 -1
- package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/index.d.ts +4 -2
- package/lib/typescript/src/specs/index.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +1 -1
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/types/variants.d.ts +3 -0
- package/lib/typescript/src/types/variants.d.ts.map +1 -1
- package/lib/typescript/src/web/runtime.d.ts +1 -0
- package/lib/typescript/src/web/runtime.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JUnistylesNativeMiniRuntime.hpp +8 -6
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistylesNativeMiniRuntime.kt +2 -1
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.hpp +2 -2
- package/nitrogen/generated/ios/swift/UnistylesNativeMiniRuntime.swift +16 -5
- package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.hpp +6 -3
- package/nitrogen/generated/shared/c++/UnistylesCxxMiniRuntime.hpp +10 -9
- package/nitrogen/generated/shared/c++/UnistylesNativeMiniRuntime.hpp +9 -8
- package/package.json +1 -1
- package/plugin/common.js +3 -1
- package/plugin/stylesheet.js +2 -1
- package/src/core/index.ts +2 -0
- package/src/core/useBreakpoint.native.ts +21 -0
- package/src/core/useBreakpoint.ts +18 -0
- package/src/core/useTheme.native.ts +21 -0
- package/src/core/useTheme.ts +18 -0
- package/src/index.ts +2 -15
- package/src/specs/NativePlatform/NativePlatform.nitro.ts +2 -1
- package/src/specs/NavigtionBar/index.ts +5 -0
- package/src/specs/StatusBar/index.ts +5 -0
- package/src/specs/StyleSheet/UnistylesStyleSheet.nitro.ts +3 -0
- package/src/specs/StyleSheet/index.ts +4 -1
- package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.ts +0 -1
- package/src/specs/UnistylesRuntime/index.ts +3 -1
- package/src/specs/index.ts +6 -2
- package/src/types/index.ts +1 -1
- package/src/types/variants.ts +6 -0
- 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
|
-
|
7
|
-
|
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
|
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
|
-
|
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,
|
package/src/specs/index.ts
CHANGED
@@ -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
|
}
|
package/src/types/index.ts
CHANGED
@@ -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'
|
package/src/types/variants.ts
CHANGED
@@ -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
|
package/src/web/runtime.ts
CHANGED
@@ -67,17 +67,7 @@ class UnistylesRuntimeBuilder {
|
|
67
67
|
}
|
68
68
|
|
69
69
|
get theme() {
|
70
|
-
|
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
|
-
|
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()
|