blob: 170a6d65b8a70e6fe0312fe89ac5b8ad2c1e61d5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
import { useColorScheme } from 'react-native';
import { Colors, type ThemeColors } from '../constants/Colors';
/**
* Hook to get the current theme colors
* @returns The colors for the current color scheme
*/
export function useThemeColors(): ThemeColors {
const colorScheme = useColorScheme() ?? 'dark';
return Colors[colorScheme];
}
/**
* Hook to get a specific color from the theme
* @param colorName - The name of the color to retrieve
* @returns The color value for the current theme
*/
export function useThemeColor<K extends keyof ThemeColors>(
colorName: K
): ThemeColors[K] {
const colors = useThemeColors();
return colors[colorName];
}
/**
* Hook to get multiple colors from the theme
* @param colorNames - Array of color names to retrieve
* @returns Object with requested color values
*/
export function useThemeColorSet<K extends keyof ThemeColors>(
colorNames: K[]
): Pick<ThemeColors, K> {
const colors = useThemeColors();
return colorNames.reduce((acc, name) => {
acc[name] = colors[name];
return acc;
}, {} as Pick<ThemeColors, K>);
}
/**
* Hook to check if the current theme is dark
* @returns boolean indicating if dark mode is active
*/
export function useIsDarkMode(): boolean {
const colorScheme = useColorScheme();
return colorScheme === 'dark';
}
|