xref: /MusicFree/src/components/base/themeText.tsx (revision 1119c2ea435417cd5c53719f91691ff2b1aa8670)
119dc08ecS猫头猫import React from 'react';
24060c00aS猫头猫import {Text, TextProps} from 'react-native';
34060c00aS猫头猫import {
44060c00aS猫头猫    ColorKey,
54060c00aS猫头猫    colorMap,
64060c00aS猫头猫    fontSizeConst,
74060c00aS猫头猫    fontWeightConst,
84060c00aS猫头猫} from '@/constants/uiConst';
9e650bfb3S猫头猫import useColors from '@/hooks/useColors';
1019dc08ecS猫头猫
1119dc08ecS猫头猫type IThemeTextProps = TextProps & {
12e650bfb3S猫头猫    color?: string;
1319dc08ecS猫头猫    fontColor?: ColorKey;
1419dc08ecS猫头猫    fontSize?: keyof typeof fontSizeConst;
1519dc08ecS猫头猫    fontWeight?: keyof typeof fontWeightConst;
16*1119c2eaS猫头猫    opacity?: number;
1719dc08ecS猫头猫};
1819dc08ecS猫头猫
1919dc08ecS猫头猫export default function ThemeText(props: IThemeTextProps) {
20e650bfb3S猫头猫    const colors = useColors();
214060c00aS猫头猫    const {
224060c00aS猫头猫        style,
23e650bfb3S猫头猫        color,
244060c00aS猫头猫        children,
254060c00aS猫头猫        fontSize = 'content',
264060c00aS猫头猫        fontColor = 'normal',
274060c00aS猫头猫        fontWeight = 'regular',
28*1119c2eaS猫头猫        opacity,
294060c00aS猫头猫    } = props;
3019dc08ecS猫头猫
3119dc08ecS猫头猫    const themeStyle = {
32e650bfb3S猫头猫        color: color ?? colors[colorMap[fontColor]],
3319dc08ecS猫头猫        fontSize: fontSizeConst[fontSize],
3419dc08ecS猫头猫        fontWeight: fontWeightConst[fontWeight],
3519dc08ecS猫头猫        includeFontPadding: false,
36*1119c2eaS猫头猫        opacity,
3719dc08ecS猫头猫    };
3819dc08ecS猫头猫
3919dc08ecS猫头猫    const _style = Array.isArray(style)
4019dc08ecS猫头猫        ? [themeStyle, ...style]
4119dc08ecS猫头猫        : [themeStyle, style];
4219dc08ecS猫头猫
4319dc08ecS猫头猫    return (
4415feccc1S猫头猫        <Text {...props} style={_style} allowFontScaling={false}>
4519dc08ecS猫头猫            {children}
4619dc08ecS猫头猫        </Text>
4719dc08ecS猫头猫    );
4819dc08ecS猫头猫}
49