xref: /MusicFree/src/components/base/themeText.tsx (revision 277c528005b29b919b3eda695ee03717976a5a83)
119dc08ecS猫头猫import React from 'react';
24060c00aS猫头猫import {Text, TextProps} from 'react-native';
3*277c5280S猫头猫import {fontSizeConst, fontWeightConst} from '@/constants/uiConst';
4*277c5280S猫头猫import useColors, {CustomizedColors} from '@/hooks/useColors';
519dc08ecS猫头猫
619dc08ecS猫头猫type IThemeTextProps = TextProps & {
7e650bfb3S猫头猫    color?: string;
8*277c5280S猫头猫    fontColor?: keyof CustomizedColors;
919dc08ecS猫头猫    fontSize?: keyof typeof fontSizeConst;
1019dc08ecS猫头猫    fontWeight?: keyof typeof fontWeightConst;
111119c2eaS猫头猫    opacity?: number;
1219dc08ecS猫头猫};
1319dc08ecS猫头猫
1419dc08ecS猫头猫export default function ThemeText(props: IThemeTextProps) {
15e650bfb3S猫头猫    const colors = useColors();
164060c00aS猫头猫    const {
174060c00aS猫头猫        style,
18e650bfb3S猫头猫        color,
194060c00aS猫头猫        children,
204060c00aS猫头猫        fontSize = 'content',
21*277c5280S猫头猫        fontColor = 'text',
224060c00aS猫头猫        fontWeight = 'regular',
231119c2eaS猫头猫        opacity,
244060c00aS猫头猫    } = props;
2519dc08ecS猫头猫
2619dc08ecS猫头猫    const themeStyle = {
27*277c5280S猫头猫        color: color ?? colors[fontColor],
2819dc08ecS猫头猫        fontSize: fontSizeConst[fontSize],
2919dc08ecS猫头猫        fontWeight: fontWeightConst[fontWeight],
3019dc08ecS猫头猫        includeFontPadding: false,
311119c2eaS猫头猫        opacity,
3219dc08ecS猫头猫    };
3319dc08ecS猫头猫
3419dc08ecS猫头猫    const _style = Array.isArray(style)
3519dc08ecS猫头猫        ? [themeStyle, ...style]
3619dc08ecS猫头猫        : [themeStyle, style];
3719dc08ecS猫头猫
3819dc08ecS猫头猫    return (
3915feccc1S猫头猫        <Text {...props} style={_style} allowFontScaling={false}>
4019dc08ecS猫头猫            {children}
4119dc08ecS猫头猫        </Text>
4219dc08ecS猫头猫    );
4319dc08ecS猫头猫}
44