Text 컴포넌트 래핑으로
최소 폰트 사이즈를 16, 기본 color 를 black 으로 하는 예제
import React from 'react';
import {Text as RNText, TextProps as RNTextProps} from 'react-native';
interface TextProps extends RNTextProps {
children?: React.ReactNode;
}
const Text: React.FC<TextProps> = ({style, children, ...props}) => {
const defaultStyle = {
color: '#000',
};
// 배열 대응을 위해 flat
const flatStyle = Array.isArray(style) ? Object.assign({}, ...style) : style;
const userFontSize = flatStyle?.fontSize;
const finalFontSize = userFontSize && userFontSize > 16 ? userFontSize : 16;
return (
<RNText style={[defaultStyle, style, {fontSize: finalFontSize}]} {...props}>
{children}
</RNText>
);
};
export default Text;
import Text from './Text';
export const Custom = {
Text,
};
export {default as Text} from './Text';
import {Custom} from '@/components/common'
<Custom.Text>hi<Custom.Text>
cd [프로젝트 path] &&
sed -i '' 's/<Text/<Custom.Text/g; s/<\/Text>/<\/Custom.Text>/g' src/screen/[수정할 컴포넌트 path]