xref: /MusicFree/src/components/base/themeText.tsx (revision e650bfb34226e2a09d15cbf7832c4805a87cd60e)
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';
9*e650bfb3S猫头猫import useColors from '@/hooks/useColors';
1019dc08ecS猫头猫
1119dc08ecS猫头猫type IThemeTextProps = TextProps & {
12*e650bfb3S猫头猫    color?: string;
1319dc08ecS猫头猫    fontColor?: ColorKey;
1419dc08ecS猫头猫    fontSize?: keyof typeof fontSizeConst;
1519dc08ecS猫头猫    fontWeight?: keyof typeof fontWeightConst;
1619dc08ecS猫头猫};
1719dc08ecS猫头猫
1819dc08ecS猫头猫export default function ThemeText(props: IThemeTextProps) {
19*e650bfb3S猫头猫    const colors = useColors();
204060c00aS猫头猫    const {
214060c00aS猫头猫        style,
22*e650bfb3S猫头猫        color,
234060c00aS猫头猫        children,
244060c00aS猫头猫        fontSize = 'content',
254060c00aS猫头猫        fontColor = 'normal',
264060c00aS猫头猫        fontWeight = 'regular',
274060c00aS猫头猫    } = props;
2819dc08ecS猫头猫
2919dc08ecS猫头猫    const themeStyle = {
30*e650bfb3S猫头猫        color: color ?? colors[colorMap[fontColor]],
3119dc08ecS猫头猫        fontSize: fontSizeConst[fontSize],
3219dc08ecS猫头猫        fontWeight: fontWeightConst[fontWeight],
3319dc08ecS猫头猫        includeFontPadding: false,
3419dc08ecS猫头猫    };
3519dc08ecS猫头猫
3619dc08ecS猫头猫    const _style = Array.isArray(style)
3719dc08ecS猫头猫        ? [themeStyle, ...style]
3819dc08ecS猫头猫        : [themeStyle, style];
3919dc08ecS猫头猫
4019dc08ecS猫头猫    return (
4115feccc1S猫头猫        <Text {...props} style={_style} allowFontScaling={false}>
4219dc08ecS猫头猫            {children}
4319dc08ecS猫头猫        </Text>
4419dc08ecS猫头猫    );
4519dc08ecS猫头猫}
46