react-native-unistyles 2.8.0-beta.5 → 2.8.0-rc.1
Sign up to get free protection for your applications and to get access to all the features.
- package/android/src/main/cxx/cpp-adapter.cpp +1 -1
- package/android/src/main/cxx/helpers.cpp +61 -0
- package/android/src/main/cxx/helpers.h +5 -0
- package/android/src/main/cxx/platform.cpp +51 -41
- package/android/src/main/cxx/platform.h +7 -4
- package/android/src/main/java/com/unistyles/Models.kt +13 -50
- package/android/src/main/java/com/unistyles/Platform.kt +175 -40
- package/android/src/main/java/com/unistyles/UnistylesModule.kt +17 -93
- package/cxx/UnistylesImpl.cpp +57 -2
- package/cxx/UnistylesModel.cpp +6 -2
- package/cxx/UnistylesModel.h +34 -8
- package/cxx/UnistylesRuntime.h +9 -1
- package/ios/platform/Platform_Shared.h +2 -0
- package/ios/platform/Platform_Shared.mm +84 -1
- package/ios/platform/Platform_iOS.h +2 -0
- package/ios/platform/Platform_iOS.mm +57 -14
- package/lib/commonjs/core/UnistylesModule.js +17 -2
- package/lib/commonjs/core/UnistylesModule.js.map +1 -1
- package/lib/commonjs/core/UnistylesRuntime.js +65 -4
- package/lib/commonjs/core/UnistylesRuntime.js.map +1 -1
- package/lib/commonjs/core/mocks/UnistylesMockedBridge.js +4 -0
- package/lib/commonjs/core/mocks/UnistylesMockedBridge.js.map +1 -1
- package/lib/commonjs/core/mocks/UnistylesMockedRuntime.js +12 -2
- package/lib/commonjs/core/mocks/UnistylesMockedRuntime.js.map +1 -1
- package/lib/commonjs/types/color.js +2 -0
- package/lib/commonjs/types/color.js.map +1 -0
- package/lib/commonjs/types/index.js +11 -0
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/commonjs/useStyles.js +1 -1
- package/lib/commonjs/useStyles.js.map +1 -1
- package/lib/commonjs/utils/index.js +7 -0
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/parseColor.js +30 -0
- package/lib/commonjs/utils/parseColor.js.map +1 -0
- package/lib/module/core/UnistylesModule.js +17 -2
- package/lib/module/core/UnistylesModule.js.map +1 -1
- package/lib/module/core/UnistylesRuntime.js +66 -4
- package/lib/module/core/UnistylesRuntime.js.map +1 -1
- package/lib/module/core/index.js +2 -1
- package/lib/module/core/index.js.map +1 -1
- package/lib/module/core/mocks/UnistylesMockedBridge.js +4 -0
- package/lib/module/core/mocks/UnistylesMockedBridge.js.map +1 -1
- package/lib/module/core/mocks/UnistylesMockedRuntime.js +12 -2
- package/lib/module/core/mocks/UnistylesMockedRuntime.js.map +1 -1
- package/lib/module/types/color.js +2 -0
- package/lib/module/types/color.js.map +1 -0
- package/lib/module/types/index.js +1 -0
- package/lib/module/types/index.js.map +1 -1
- package/lib/module/useStyles.js +1 -1
- package/lib/module/useStyles.js.map +1 -1
- package/lib/module/utils/index.js +1 -0
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/parseColor.js +23 -0
- package/lib/module/utils/parseColor.js.map +1 -0
- package/lib/typescript/src/core/UnistylesModule.d.ts +1 -0
- package/lib/typescript/src/core/UnistylesModule.d.ts.map +1 -1
- package/lib/typescript/src/core/UnistylesRuntime.d.ts +52 -5
- package/lib/typescript/src/core/UnistylesRuntime.d.ts.map +1 -1
- package/lib/typescript/src/core/index.d.ts +3 -1
- package/lib/typescript/src/core/index.d.ts.map +1 -1
- package/lib/typescript/src/core/mocks/UnistylesMockedBridge.d.ts +4 -0
- package/lib/typescript/src/core/mocks/UnistylesMockedBridge.d.ts.map +1 -1
- package/lib/typescript/src/core/mocks/UnistylesMockedRuntime.d.ts +7 -1
- package/lib/typescript/src/core/mocks/UnistylesMockedRuntime.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types/breakpoints.d.ts +2 -2
- package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/types/color.d.ts +4 -0
- package/lib/typescript/src/types/color.d.ts.map +1 -0
- package/lib/typescript/src/types/index.d.ts +1 -0
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts +2 -2
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
- package/lib/typescript/src/types/unistyles.d.ts +8 -2
- package/lib/typescript/src/types/unistyles.d.ts.map +1 -1
- package/lib/typescript/src/utils/index.d.ts +1 -0
- package/lib/typescript/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/parseColor.d.ts +3 -0
- package/lib/typescript/src/utils/parseColor.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/core/UnistylesModule.ts +19 -3
- package/src/core/UnistylesRuntime.ts +67 -5
- package/src/core/index.ts +7 -1
- package/src/core/mocks/UnistylesMockedBridge.ts +4 -0
- package/src/core/mocks/UnistylesMockedRuntime.ts +15 -3
- package/src/index.ts +3 -2
- package/src/types/breakpoints.ts +2 -2
- package/src/types/color.ts +26 -0
- package/src/types/index.ts +1 -0
- package/src/types/stylesheet.ts +2 -2
- package/src/types/unistyles.ts +10 -4
- package/src/useStyles.ts +1 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/parseColor.ts +27 -0
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"stylesheet.d.ts","sourceRoot":"","sources":["../../../../src/types/stylesheet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAA;AAC3E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AACrD,OAAO,KAAK,EAAE,
|
1
|
+
{"version":3,"file":"stylesheet.d.ts","sourceRoot":"","sources":["../../../../src/types/stylesheet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EA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AM,oBAAoB,GAAG,MAAM,CAAA;AAE3E,MAAM,MAAM,eAAe,GAAG;KACzB,QAAQ,IAAI,gBAAgB,CAAC,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG;SAC3D,GAAG,IAAI,yBAAyB,CAAC,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC;KACpE;CACJ,GAAG,QAAQ,GAAG;KACV,QAAQ,IAAI,UAAU,CAAC,CAAC,EAAE,oBAAoB,CAAC,QAAQ,CAAC;CAC5D,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACrB,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,eAAe,CAAC,CAAA;CAC7E,CAAA;AAED,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,oBAAoB,KAAK,UAAU,CAAC,GAAG,UAAU,CAAA"}
|
@@ -14,10 +14,12 @@ export type ScreenDimensions = {
|
|
14
14
|
width: number;
|
15
15
|
};
|
16
16
|
export interface StatusBar extends ScreenDimensions {
|
17
|
-
setColor(color?: string): void;
|
17
|
+
setColor(color?: string, alpha?: number): void;
|
18
|
+
setHidden(hidden: boolean): void;
|
18
19
|
}
|
19
20
|
export interface NavigationBar extends ScreenDimensions {
|
20
|
-
setColor(color?: string): void;
|
21
|
+
setColor(color?: string, alpha?: number): void;
|
22
|
+
setHidden(hidden: boolean): void;
|
21
23
|
}
|
22
24
|
export type UnistylesConfig = {
|
23
25
|
adaptiveThemes?: boolean;
|
@@ -38,6 +40,8 @@ export type UnistylesBridge = {
|
|
38
40
|
insets: ScreenInsets;
|
39
41
|
statusBar: StatusBar;
|
40
42
|
navigationBar: NavigationBar;
|
43
|
+
pixelRatio: number;
|
44
|
+
fontScale: number;
|
41
45
|
themes: Array<keyof UnistylesThemes>;
|
42
46
|
useBreakpoints(breakpoints: UnistylesBreakpoints): void;
|
43
47
|
useTheme(name: keyof UnistylesThemes): void;
|
@@ -45,6 +49,8 @@ export type UnistylesBridge = {
|
|
45
49
|
useAdaptiveThemes(enable: boolean): void;
|
46
50
|
addPlugin(pluginName: string, notify: boolean): void;
|
47
51
|
removePlugin(pluginName: string): void;
|
52
|
+
setRootViewBackgroundColor(color?: string, alpha?: number): void;
|
53
|
+
setImmersiveMode(isEnabled: boolean): void;
|
48
54
|
};
|
49
55
|
export type UnistylesThemeEvent = {
|
50
56
|
type: UnistylesEventType.Theme;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"unistyles.d.ts","sourceRoot":"","sources":["../../../../src/types/unistyles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAA;AACrH,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE/C,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,MAAM,GAAG,aAAa,CAAA;AAE9D,MAAM,MAAM,YAAY,GAAG;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,WAAW,SAAU,SAAQ,gBAAgB;IAC/C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;
|
1
|
+
{"version":3,"file":"unistyles.d.ts","sourceRoot":"","sources":["../../../../src/types/unistyles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB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AE,MAAM,eAAe,CAAA;KACnC,CAAA;CACJ,CAAA;AAED,MAAM,MAAM,0BAA0B,GAAG;IACrC,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC;IAChC,OAAO,EAAE;QACL,MAAM,EAAE,UAAU,CAAC;QACnB,SAAS,EAAE,gBAAgB,CAAC;QAC5B,aAAa,EAAE,gBAAgB,CAAC;QAChC,MAAM,EAAE,YAAY,CAAC;QACrB,UAAU,EAAE,MAAM,oBAAoB,CAAC;QACvC,WAAW,EAAE,OAAO,iBAAiB,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAA;KACxE,CAAA;CACJ,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IAC/B,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAA;CAClC,CAAA;AAED,MAAM,MAAM,6BAA6B,GAAG;IACxC,IAAI,EAAE,kBAAkB,CAAC,eAAe,CAAC;IACzC,OAAO,EAAE;QACL,mBAAmB,EAAE,sBAAsB,GAAG,0BAA0B,CAAA;KAC3E,CAAA;CACJ,CAAA;AAED,MAAM,MAAM,eAAe,GAAG,mBAAmB,GAAG,0BAA0B,GAAG,oBAAoB,GAAG,6BAA6B,CAAA"}
|
@@ -5,4 +5,5 @@ 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';
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAA;AACzB,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,EAAE,4BAA4B,EAAE,yBAAyB,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AACvH,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAA"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAA;AACzB,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,EAAE,4BAA4B,EAAE,yBAAyB,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AACvH,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"parseColor.d.ts","sourceRoot":"","sources":["../../../../src/utils/parseColor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAUrC,eAAO,MAAM,UAAU,WAAY,KAAK,UAAS,MAAM,KAAO,CAAC,MAAM,EAAE,MAAM,CAgB5E,CAAA"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { NativeEventEmitter, NativeModules } from 'react-native'
|
2
2
|
import type { UnistylesThemes, UnistylesBreakpoints } from 'react-native-unistyles'
|
3
|
-
import type { ColorSchemeName, ScreenInsets, StatusBar, NavigationBar } from '../types'
|
3
|
+
import type { ColorSchemeName, ScreenInsets, StatusBar, NavigationBar, Color } from '../types'
|
4
4
|
import { normalizeWebStylesPlugin } from '../plugins'
|
5
5
|
import { isServer } from '../common'
|
6
6
|
|
@@ -28,13 +28,17 @@ export class UnistylesBridgeWeb {
|
|
28
28
|
#statusBar: StatusBar = {
|
29
29
|
height: 0,
|
30
30
|
width: 0,
|
31
|
-
setColor: () => {}
|
31
|
+
setColor: () => {},
|
32
|
+
setHidden: () => {}
|
32
33
|
}
|
33
34
|
#navigationBar: NavigationBar = {
|
34
35
|
height: 0,
|
35
36
|
width: 0,
|
36
|
-
setColor: () => {}
|
37
|
+
setColor: () => {},
|
38
|
+
setHidden: () => {}
|
37
39
|
}
|
40
|
+
#pixelRatio = 1.0
|
41
|
+
#fontScale = 1.0
|
38
42
|
|
39
43
|
constructor() {
|
40
44
|
if (!isServer) {
|
@@ -76,6 +80,10 @@ export class UnistylesBridgeWeb {
|
|
76
80
|
return this.#statusBar
|
77
81
|
case 'navigationBar':
|
78
82
|
return this.#navigationBar
|
83
|
+
case 'pixelRatio':
|
84
|
+
return this.#pixelRatio
|
85
|
+
case 'fontScale':
|
86
|
+
return this.#fontScale
|
79
87
|
case 'useTheme':
|
80
88
|
return (themeName: keyof UnistylesThemes) => this.useTheme(themeName)
|
81
89
|
case 'updateTheme':
|
@@ -88,6 +96,10 @@ export class UnistylesBridgeWeb {
|
|
88
96
|
return (pluginName: string, notify: boolean) => this.addPlugin(pluginName, notify)
|
89
97
|
case 'removePlugin':
|
90
98
|
return (pluginName: string) => this.removePlugin(pluginName)
|
99
|
+
case 'setRootViewBackgroundColor':
|
100
|
+
return (color: Color | string) => this.setRootViewBackgroundColor(color)
|
101
|
+
case 'setImmersiveMode':
|
102
|
+
return () => {}
|
91
103
|
default:
|
92
104
|
return Reflect.get(this, prop)
|
93
105
|
}
|
@@ -228,6 +240,10 @@ export class UnistylesBridgeWeb {
|
|
228
240
|
return 'light'
|
229
241
|
}
|
230
242
|
|
243
|
+
private setRootViewBackgroundColor(color?: Color | string) {
|
244
|
+
document.body.style.backgroundColor = color as string
|
245
|
+
}
|
246
|
+
|
231
247
|
private emitPluginChange() {
|
232
248
|
this.#unistylesEvents.emit('__unistylesOnChange', {
|
233
249
|
type: 'plugin'
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import { ScreenOrientation, UnistylesError } from '../common'
|
2
|
-
import type { UnistylesBridge, UnistylesPlugin } from '../types'
|
2
|
+
import type { Color, UnistylesBridge, UnistylesPlugin } from '../types'
|
3
3
|
import type { UnistylesThemes } from '../global'
|
4
4
|
import type { UnistyleRegistry } from './UnistyleRegistry'
|
5
|
+
import { parseColor } from '../utils'
|
5
6
|
|
6
7
|
/**
|
7
8
|
* Utility to interact with the Unistyles during runtime
|
@@ -9,6 +10,30 @@ import type { UnistyleRegistry } from './UnistyleRegistry'
|
|
9
10
|
export class UnistylesRuntime {
|
10
11
|
constructor(private unistylesBridge: UnistylesBridge, private unistylesRegistry: UnistyleRegistry) {}
|
11
12
|
|
13
|
+
/**
|
14
|
+
* Get the mini runtime injected to creteStyleSheet
|
15
|
+
* @returns - The mini runtime
|
16
|
+
*/
|
17
|
+
public get miniRuntime() {
|
18
|
+
return {
|
19
|
+
contentSizeCategory: this.contentSizeCategory,
|
20
|
+
breakpoint: this.breakpoint,
|
21
|
+
screen: this.screen,
|
22
|
+
insets: this.insets,
|
23
|
+
statusBar: {
|
24
|
+
width: this.statusBar.width,
|
25
|
+
height: this.statusBar.height
|
26
|
+
},
|
27
|
+
navigationBar: {
|
28
|
+
width: this.navigationBar.width,
|
29
|
+
height: this.navigationBar.height
|
30
|
+
},
|
31
|
+
orientation: this.orientation,
|
32
|
+
pixelRatio: this.pixelRatio,
|
33
|
+
fontScale: this.fontScale
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
12
37
|
/**
|
13
38
|
* Get the current color scheme
|
14
39
|
* @returns - The current color scheme
|
@@ -86,25 +111,27 @@ export class UnistylesRuntime {
|
|
86
111
|
|
87
112
|
/**
|
88
113
|
* Get the status bar info
|
89
|
-
* @returns - The status bar api { width, height, setColor }
|
114
|
+
* @returns - The status bar api { width, height, setColor, setHidden }
|
90
115
|
*/
|
91
116
|
public get statusBar() {
|
92
117
|
return {
|
93
118
|
width: this.unistylesBridge.statusBar.width,
|
94
119
|
height: this.unistylesBridge.statusBar.height,
|
95
|
-
setColor: (color?:
|
120
|
+
setColor: (color?: Color, alpha?: number) => this.unistylesBridge.statusBar.setColor(...parseColor(color, alpha)),
|
121
|
+
setHidden: (hidden: boolean) => this.unistylesBridge.statusBar.setHidden(hidden)
|
96
122
|
}
|
97
123
|
}
|
98
124
|
|
99
125
|
/**
|
100
126
|
* Get the navigation bar info (Android)
|
101
|
-
* @returns - The navigation bar api { width, height, setColor }
|
127
|
+
* @returns - The navigation bar api { width, height, setColor, setHidden }
|
102
128
|
*/
|
103
129
|
public get navigationBar() {
|
104
130
|
return {
|
105
131
|
width: this.unistylesBridge.navigationBar.width,
|
106
132
|
height: this.unistylesBridge.navigationBar.height,
|
107
|
-
setColor: (color?:
|
133
|
+
setColor: (color?: Color, alpha?: number) => this.unistylesBridge.navigationBar.setColor(...parseColor(color, alpha)),
|
134
|
+
setHidden: (hidden: boolean) => this.unistylesBridge.navigationBar.setHidden(hidden)
|
108
135
|
}
|
109
136
|
}
|
110
137
|
|
@@ -122,6 +149,41 @@ export class UnistylesRuntime {
|
|
122
149
|
return ScreenOrientation.Portrait
|
123
150
|
}
|
124
151
|
|
152
|
+
/**
|
153
|
+
* Get the pixel ratio
|
154
|
+
* @returns - The pixel ratio
|
155
|
+
*/
|
156
|
+
public get pixelRatio() {
|
157
|
+
return this.unistylesBridge.pixelRatio
|
158
|
+
}
|
159
|
+
|
160
|
+
/**
|
161
|
+
* Get the font scale
|
162
|
+
* @returns - The font scale
|
163
|
+
*/
|
164
|
+
public get fontScale() {
|
165
|
+
const fontScale = this.unistylesBridge.fontScale
|
166
|
+
|
167
|
+
return fontScale === 1.0 ? 1 : fontScale.toFixed(2)
|
168
|
+
}
|
169
|
+
|
170
|
+
/**
|
171
|
+
* Get the immersive mode (both status bar and navigation bar hidden (Android))
|
172
|
+
* @param isEnabled
|
173
|
+
*/
|
174
|
+
public setImmersiveMode(isEnabled: boolean) {
|
175
|
+
return this.unistylesBridge.setImmersiveMode(isEnabled)
|
176
|
+
}
|
177
|
+
|
178
|
+
/**
|
179
|
+
* Set the root view background color
|
180
|
+
* @param color - The color to set
|
181
|
+
* @param alpha - Color alpha - default is 1
|
182
|
+
*/
|
183
|
+
public setRootViewBackgroundColor = (color?: Color, alpha?: number) => {
|
184
|
+
this.unistylesBridge.setRootViewBackgroundColor(...parseColor(color, alpha))
|
185
|
+
}
|
186
|
+
|
125
187
|
/**
|
126
188
|
* Switch to a different theme
|
127
189
|
* @param name - The name of the theme to switch to
|
package/src/core/index.ts
CHANGED
@@ -14,6 +14,8 @@ export class UnistylesMockedBridge {
|
|
14
14
|
public contentSizeCategory() {}
|
15
15
|
public sortedBreakpointPairs() {}
|
16
16
|
public insets() {}
|
17
|
+
public pixelRatio() {}
|
18
|
+
public fontScale() {}
|
17
19
|
public statusBar() {}
|
18
20
|
public navigationBar() {}
|
19
21
|
public themes(themes: Array<keyof UnistylesThemes>) {}
|
@@ -23,4 +25,6 @@ export class UnistylesMockedBridge {
|
|
23
25
|
public useAdaptiveThemes(enable: boolean) {}
|
24
26
|
public addPlugin(pluginName: string, notify: boolean) {}
|
25
27
|
public removePlugin(pluginName: string) {}
|
28
|
+
public setRootViewBackgroundColor(color?: string, alpha?: number) {}
|
29
|
+
public setImmersiveMode(isEnabled: boolean) {}
|
26
30
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// @ts-nocheck
|
2
2
|
import { ScreenOrientation } from '../../common'
|
3
|
-
import type { UnistylesBridge, UnistylesPlugin } from '../../types'
|
3
|
+
import type { Color, UnistylesBridge, UnistylesPlugin } from '../../types'
|
4
4
|
import type { UnistylesThemes } from '../../global'
|
5
5
|
import type { UnistylesMockedRegistry } from './UnistylesMockedRegistry'
|
6
6
|
import type { UnistyleRegistry } from '../UnistyleRegistry'
|
@@ -66,11 +66,20 @@ export class UnistylesMockedRuntime {
|
|
66
66
|
}
|
67
67
|
}
|
68
68
|
|
69
|
+
public get pixelRatio() {
|
70
|
+
return 1.0
|
71
|
+
}
|
72
|
+
|
73
|
+
public get fontScale() {
|
74
|
+
return 1.0
|
75
|
+
}
|
76
|
+
|
69
77
|
public get statusBar() {
|
70
78
|
return {
|
71
79
|
height: 24,
|
72
80
|
width: 800,
|
73
|
-
setColor: () => {}
|
81
|
+
setColor: () => {},
|
82
|
+
setHidden: () => {}
|
74
83
|
}
|
75
84
|
}
|
76
85
|
|
@@ -78,7 +87,8 @@ export class UnistylesMockedRuntime {
|
|
78
87
|
return {
|
79
88
|
height: 0,
|
80
89
|
width: 0,
|
81
|
-
setColor: () => {}
|
90
|
+
setColor: () => {},
|
91
|
+
setHidden: () => {}
|
82
92
|
}
|
83
93
|
}
|
84
94
|
|
@@ -91,4 +101,6 @@ export class UnistylesMockedRuntime {
|
|
91
101
|
public setAdaptiveThemes = (enabled: boolean) => {}
|
92
102
|
public addPlugin = (plugin: UnistylesPlugin) => {}
|
93
103
|
public removePlugin = (plugin: UnistylesPlugin) => {}
|
104
|
+
public setRootViewBackgroundColor = (color?: Color | string) => {}
|
105
|
+
public setImmersiveMode = (isEnabled: boolean) => {}
|
94
106
|
}
|
package/src/index.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
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, ExtractVariantNames } from './types'
|
5
5
|
import type { UnistylesThemes, UnistylesBreakpoints } from './global'
|
6
6
|
import { ScreenOrientation, AndroidContentSizeCategory, IOSContentSizeCategory } from './common'
|
7
7
|
import { useStyles } from './useStyles'
|
@@ -47,5 +47,6 @@ export type {
|
|
47
47
|
UnistylesThemes,
|
48
48
|
UnistylesBreakpoints,
|
49
49
|
UnistylesPlugin,
|
50
|
-
UnistylesValues
|
50
|
+
UnistylesValues,
|
51
|
+
ExtractVariantNames as UnistylesVariants
|
51
52
|
}
|
package/src/types/breakpoints.ts
CHANGED
@@ -2,7 +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 {
|
5
|
+
import type { UnistylesMiniRuntime } from '../core'
|
6
6
|
|
7
7
|
type ExtractTransformArray<T> = T extends object
|
8
8
|
? { [K in keyof T]: ExtractBreakpoints<T[K]> }
|
@@ -57,6 +57,6 @@ type ParseStyleKeys<T> = T extends object
|
|
57
57
|
? { [K in keyof T]: ParseNestedObject<T[K]> }
|
58
58
|
: never
|
59
59
|
|
60
|
-
export type ReactNativeStyleSheet<T> = T extends (theme: UnistylesTheme, runtime:
|
60
|
+
export type ReactNativeStyleSheet<T> = T extends (theme: UnistylesTheme, runtime: UnistylesMiniRuntime) => infer R
|
61
61
|
? ParseStyleKeys<R>
|
62
62
|
: 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/index.ts
CHANGED
package/src/types/stylesheet.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { 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 {
|
4
|
+
import type { UnistylesMiniRuntime } from '../core'
|
5
5
|
|
6
6
|
// these props are treated differently to nest breakpoints and media queries
|
7
7
|
type NestedKeys = 'shadowOffset' | 'transform' | 'textShadowOffset'
|
@@ -47,4 +47,4 @@ export type StyleSheet = {
|
|
47
47
|
[styleName: string]: UnistylesValues | ((...args: any) => UnistylesValues)
|
48
48
|
}
|
49
49
|
|
50
|
-
export type StyleSheetWithSuperPowers = ((theme: UnistylesTheme,
|
50
|
+
export type StyleSheetWithSuperPowers = ((theme: UnistylesTheme, miniRuntime: UnistylesMiniRuntime) => StyleSheet) | StyleSheet
|
package/src/types/unistyles.ts
CHANGED
@@ -18,11 +18,13 @@ export type ScreenDimensions = {
|
|
18
18
|
}
|
19
19
|
|
20
20
|
export interface StatusBar extends ScreenDimensions {
|
21
|
-
setColor(color?: string): void
|
21
|
+
setColor(color?: string, alpha?: number): void,
|
22
|
+
setHidden(hidden: boolean): void
|
22
23
|
}
|
23
24
|
|
24
25
|
export interface NavigationBar extends ScreenDimensions {
|
25
|
-
setColor(color?: string): void
|
26
|
+
setColor(color?: string, alpha?: number): void,
|
27
|
+
setHidden(hidden: boolean): void
|
26
28
|
}
|
27
29
|
|
28
30
|
export type UnistylesConfig = {
|
@@ -45,7 +47,9 @@ export type UnistylesBridge = {
|
|
45
47
|
sortedBreakpointPairs: Array<[keyof UnistylesBreakpoints, UnistylesBreakpoints[keyof UnistylesBreakpoints]]>,
|
46
48
|
insets: ScreenInsets,
|
47
49
|
statusBar: StatusBar,
|
48
|
-
navigationBar: NavigationBar
|
50
|
+
navigationBar: NavigationBar,
|
51
|
+
pixelRatio: number,
|
52
|
+
fontScale: number
|
49
53
|
|
50
54
|
// setters
|
51
55
|
themes: Array<keyof UnistylesThemes>,
|
@@ -54,7 +58,9 @@ export type UnistylesBridge = {
|
|
54
58
|
updateTheme(name: keyof UnistylesThemes): void,
|
55
59
|
useAdaptiveThemes(enable: boolean): void,
|
56
60
|
addPlugin(pluginName: string, notify: boolean): void,
|
57
|
-
removePlugin(pluginName: string): void
|
61
|
+
removePlugin(pluginName: string): void,
|
62
|
+
setRootViewBackgroundColor(color?: string, alpha?: number): void,
|
63
|
+
setImmersiveMode(isEnabled: boolean): void
|
58
64
|
}
|
59
65
|
|
60
66
|
export type UnistylesThemeEvent = {
|
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, unistyles.runtime)
|
29
|
+
? stylesheet(theme, unistyles.runtime.miniRuntime)
|
30
30
|
: stylesheet, [theme, stylesheet, layout])
|
31
31
|
|
32
32
|
const dynamicStyleSheet = useMemo(() => Object
|
package/src/utils/index.ts
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
import type { Color } from '../types'
|
2
|
+
|
3
|
+
const parseAlpha = (alpha: number) => {
|
4
|
+
if (alpha > 1 || alpha < 0) {
|
5
|
+
return 1
|
6
|
+
}
|
7
|
+
|
8
|
+
return alpha
|
9
|
+
}
|
10
|
+
|
11
|
+
export const parseColor = (color?: Color, alpha: number = 1): [string, number] => {
|
12
|
+
if (!color) {
|
13
|
+
return ['', 1]
|
14
|
+
}
|
15
|
+
|
16
|
+
// ignore alpha for 8 digit hex colors
|
17
|
+
if (color.startsWith('#') && color.length === 9) {
|
18
|
+
return [color, 1]
|
19
|
+
}
|
20
|
+
|
21
|
+
if (color.startsWith('#') && color.length === 7) {
|
22
|
+
return [color, parseAlpha(alpha)]
|
23
|
+
}
|
24
|
+
|
25
|
+
// named colors
|
26
|
+
return [color, 1]
|
27
|
+
}
|