您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ThemedText.tsx 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { Text, type TextProps, StyleSheet } from 'react-native';
  2. import { useThemeColor } from '@/hooks/useThemeColor';
  3. export type ThemedTextProps = TextProps & {
  4. lightColor?: string;
  5. darkColor?: string;
  6. type?: 'default' | 'title' | 'defaultSemiBold' | 'subtitle' | 'link';
  7. };
  8. export function ThemedText({
  9. style,
  10. lightColor,
  11. darkColor,
  12. type = 'default',
  13. ...rest
  14. }: ThemedTextProps) {
  15. const color = useThemeColor({ light: lightColor, dark: darkColor }, 'text');
  16. return (
  17. <Text
  18. style={[
  19. { color },
  20. type === 'default' ? styles.default : undefined,
  21. type === 'title' ? styles.title : undefined,
  22. type === 'defaultSemiBold' ? styles.defaultSemiBold : undefined,
  23. type === 'subtitle' ? styles.subtitle : undefined,
  24. type === 'link' ? styles.link : undefined,
  25. style,
  26. ]}
  27. {...rest}
  28. />
  29. );
  30. }
  31. const styles = StyleSheet.create({
  32. default: {
  33. fontSize: 16,
  34. lineHeight: 24,
  35. },
  36. defaultSemiBold: {
  37. fontSize: 16,
  38. lineHeight: 24,
  39. fontWeight: '600',
  40. },
  41. title: {
  42. fontSize: 32,
  43. fontWeight: 'bold',
  44. lineHeight: 32,
  45. },
  46. subtitle: {
  47. fontSize: 20,
  48. fontWeight: 'bold',
  49. },
  50. link: {
  51. lineHeight: 30,
  52. fontSize: 16,
  53. color: '#0a7ea4',
  54. },
  55. });