目录 / new-rn-component
new-rn-component
创建一个带有 StyleSheet、主题常量和 TypeScript 属性的新 React Native 组件。 ```tsx import React from 'react'; import { View, Text, StyleSheet, ViewStyle, TextStyle } from 'react-native'; // 主题常量 const theme = { colors: { primary: '#007AFF', secondary: '#5856D6', background: '#F2F2F7', surface: '#FFFFFF', text: '#000000', textSecondary: '#8E8E93', border: '#C6C6C8', error: '#FF3B30', success: '#34C759', warning: '#FF9500', }, spacing: { xs: 4, sm: 8, md: 16, lg: 24, xl: 32, }, borderRadius: { sm: 4, md: 8, lg: 12, xl: 16, }, fontSizes: { xs: 12, sm: 14, md: 16, lg: 18, xl: 20, xxl: 24, }, fontWeights: { normal: '400' as const, medium: '500' as const, semibold: '600' as const, bold: '700' as const, }, }; // TypeScript 属性接口 interface CustomComponentProps { title: string; subtitle?: string; variant?: 'primary' | 'secondary' | 'success' | 'warning' | 'error'; size?: 'small' | 'medium' | 'large'; disabled?: boolean; onPress?: () => void; style?: ViewStyle; textStyle?: TextStyle; } // 组件实现 const CustomComponent: React.FC<CustomComponentProps> = ({ title, subtitle, variant = 'primary', size = 'medium', disabled = false, onPress, style, textStyle, }) => { const getVariantColors = () => { switch (variant) { case 'secondary': return { backgroundColor: theme.colors.secondary, textColor: theme.colors.surface, }; case 'success': return { backgroundColor: theme.colors.success, textColor: theme.colors.surface, }; case 'warning': return { backgroundColor: theme.colors.warning, textColor: theme.colors.surface, }; case 'error': return { backgroundColor: theme.colors.error, textColor: theme.colors.surface, }; default: return { backgroundC...
这是模型对公开材料的总结,不是官方声明,请以原链内容为准。
存档时间线
| 版本 | 存档时间 | 内容哈希 | 内容 |
|---|---|---|---|
| v1 | 2026-11-15 15:28 | 01f6a748 | 可取 |
版本索引永久保留;内容副本只保留最新 1 份,更早版本仅留索引与哈希(存档时间线的证据链不会因此断裂)。
提交举报 / 纠错
侵权举报经核验成立后,我们会即时下线该条目并删除已存的内容副本。