@idealyst/theme 1.2.74 → 1.2.76
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.
- package/package.json +1 -1
- package/src/colorScheme.ts +53 -0
- package/src/index.ts +3 -0
package/package.json
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { UnistylesRuntime } from 'react-native-unistyles';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Color scheme preference type.
|
|
5
|
+
*/
|
|
6
|
+
export type ColorScheme = 'light' | 'dark';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Get the current system/device color scheme preference.
|
|
10
|
+
*
|
|
11
|
+
* @returns 'light', 'dark', or null if not available
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const scheme = getColorScheme();
|
|
16
|
+
* if (scheme) {
|
|
17
|
+
* console.log(scheme); // 'dark'
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function getColorScheme(): ColorScheme | null {
|
|
22
|
+
const scheme = UnistylesRuntime.colorScheme;
|
|
23
|
+
if (scheme === 'light' || scheme === 'dark') {
|
|
24
|
+
return scheme;
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Theme settings controller - wraps Unistyles runtime for theme management.
|
|
31
|
+
*/
|
|
32
|
+
export const ThemeSettings = {
|
|
33
|
+
/**
|
|
34
|
+
* Set the active theme by name with content color scheme.
|
|
35
|
+
*
|
|
36
|
+
* @param themeName - The theme name to activate
|
|
37
|
+
* @param contentColor - The content color scheme ('light' or 'dark')
|
|
38
|
+
* @param animated - Whether to animate the status bar transition (default: false)
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* ThemeSettings.setTheme('darkBlue', 'dark');
|
|
43
|
+
* ThemeSettings.setTheme('light', 'light', true); // animated
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
setTheme(themeName: string, contentColor: ColorScheme, animated: boolean = false): void {
|
|
47
|
+
UnistylesRuntime.setTheme(themeName as any);
|
|
48
|
+
UnistylesRuntime.setRootViewBackgroundColor(
|
|
49
|
+
contentColor === 'dark' ? '#000000' : '#ffffff'
|
|
50
|
+
);
|
|
51
|
+
UnistylesRuntime.statusBar.setStyle(contentColor === 'dark' ? 'light' : 'dark', animated);
|
|
52
|
+
},
|
|
53
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -25,6 +25,9 @@ export * from './responsive';
|
|
|
25
25
|
export * from './breakpoints';
|
|
26
26
|
export * from './useResponsiveStyle';
|
|
27
27
|
|
|
28
|
+
// Color scheme utilities
|
|
29
|
+
export * from './colorScheme';
|
|
30
|
+
|
|
28
31
|
// Style props hook (platform-specific via .native.ts)
|
|
29
32
|
export { useStyleProps, type StyleProps } from './useStyleProps';
|
|
30
33
|
|