xref: /MusicFree/src/hooks/useColors.ts (revision 5589cdf32b2bb0f641e5ac7bf1f6152cd6b9b70e)
1*5589cdf3S猫头猫import {Theme, useTheme} from '@react-navigation/native';
26cfecf1cS猫头猫import Color from 'color';
36cfecf1cS猫头猫import {useMemo} from 'react';
4fe32deaaS猫头猫
5fe32deaaS猫头猫type IColors = Theme['colors'];
6fe32deaaS猫头猫
76cfecf1cS猫头猫export interface CustomizedColors extends IColors {
8fe32deaaS猫头猫    /** 普通文字 */
9fe32deaaS猫头猫    text: string;
10fe32deaaS猫头猫    /** 副标题文字颜色 */
11fe32deaaS猫头猫    textSecondary?: string;
12277c5280S猫头猫    /** 高亮文本颜色,也就是主色调 */
13fe32deaaS猫头猫    textHighlight?: string;
14fe32deaaS猫头猫    /** 页面背景 */
15fe32deaaS猫头猫    pageBackground?: string;
16fe32deaaS猫头猫    /** 阴影 */
17fe32deaaS猫头猫    shadow?: string;
186cfecf1cS猫头猫    /** 标题栏颜色 */
196cfecf1cS猫头猫    appBar?: string;
20277c5280S猫头猫    /** 标题栏字体颜色 */
21277c5280S猫头猫    appBarText?: string;
22fe32deaaS猫头猫    /** 音乐栏颜色 */
23fe32deaaS猫头猫    musicBar?: string;
24277c5280S猫头猫    /** 音乐栏字体颜色 */
25277c5280S猫头猫    musicBarText?: string;
26fe32deaaS猫头猫    /** 分割线 */
27fe32deaaS猫头猫    divider?: string;
28fe32deaaS猫头猫    /** 高亮颜色 */
29fe32deaaS猫头猫    listActive?: string;
30fe32deaaS猫头猫    /** 输入框背景色 */
31fe32deaaS猫头猫    placeholder?: string;
32277c5280S猫头猫    /** 弹窗、浮层、菜单背景色 */
336cfecf1cS猫头猫    backdrop?: string;
34277c5280S猫头猫    /** 卡片背景色 */
35277c5280S猫头猫    card: string;
36277c5280S猫头猫    /** paneltabbar 背景色 */
37277c5280S猫头猫    tabBar?: string;
38fe32deaaS猫头猫}
39ec26b768S猫头猫
40ec26b768S猫头猫export default function useColors() {
41ec26b768S猫头猫    const {colors} = useTheme();
42fe32deaaS猫头猫
436cfecf1cS猫头猫    const cColors: CustomizedColors = useMemo(() => {
446cfecf1cS猫头猫        return {
456cfecf1cS猫头猫            ...colors,
462210bf0bS猫头猫            textSecondary: Color(colors.text).alpha(0.7).toString(),
476cfecf1cS猫头猫            // @ts-ignore
48277c5280S猫头猫            background: colors.pageBackground ?? colors.background,
496cfecf1cS猫头猫        };
506cfecf1cS猫头猫    }, [colors]);
516cfecf1cS猫头猫
526cfecf1cS猫头猫    return cColors;
53ec26b768S猫头猫}
54