Spaces:
Sleeping
Sleeping
File size: 6,859 Bytes
692fef9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | import React, { useState } from 'react';
import { StyleSheet, Text, View, ScrollView, SafeAreaView, TouchableOpacity, Image, Switch } from 'react-native';
import { StatusBar } from 'expo-status-bar';
/**
* 主屏幕组件 - 采用中文显示与注释
* 包含计数器和主题切换功能
*/
export const MainScreen = () => {
const [count, setCount] = useState(0);
const [isDarkMode, setIsDarkMode] = useState(false);
// 主题样式定义
const theme = {
background: isDarkMode ? '#1C1C1E' : '#F5F7FA',
card: isDarkMode ? '#2C2C2E' : '#FFFFFF',
text: isDarkMode ? '#FFFFFF' : '#1C1C1E',
secondaryText: isDarkMode ? '#AEAEB2' : '#3A3A3C',
accent: '#007AFF',
border: isDarkMode ? '#3A3A3C' : '#E5E5EA',
};
return (
<SafeAreaView style={[styles.safeArea, { backgroundColor: theme.background }]}>
<StatusBar style={isDarkMode ? 'light' : 'dark'} />
<ScrollView contentContainerStyle={styles.scrollContainer}>
{/* 顶部标题栏 */}
<View style={[styles.header, { backgroundColor: theme.accent }]}>
<Text style={styles.headerTitle}>React Native 中文项目</Text>
<Text style={styles.headerSubtitle}>跨平台移动端 & Web 应用</Text>
</View>
{/* 核心功能展示区 */}
<View style={styles.content}>
{/* 主题切换卡片 */}
<View style={[styles.card, { backgroundColor: theme.card }]}>
<View style={styles.switchRow}>
<Text style={[styles.cardTitle, { color: theme.text, marginBottom: 0 }]}>
{isDarkMode ? '深色模式' : '浅色模式'}
</Text>
<Switch
value={isDarkMode}
onValueChange={setIsDarkMode}
trackColor={{ false: '#767577', true: '#34C759' }}
thumbColor={isDarkMode ? '#FFFFFF' : '#f4f3f4'}
/>
</View>
</View>
{/* 交互计数器卡片 */}
<View style={[styles.card, { backgroundColor: theme.card }]}>
<Text style={[styles.cardTitle, { color: theme.text }]}>交互计数器</Text>
<View style={styles.counterContainer}>
<Text style={[styles.counterText, { color: theme.text }]}>{count}</Text>
<View style={styles.buttonRow}>
<TouchableOpacity
style={[styles.smallButton, { backgroundColor: theme.accent }]}
onPress={() => setCount(count + 1)}
>
<Text style={styles.smallButtonText}>增加</Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.smallButton, { backgroundColor: '#FF3B30' }]}
onPress={() => setCount(0)}
>
<Text style={styles.smallButtonText}>重置</Text>
</TouchableOpacity>
</View>
</View>
</View>
<View style={[styles.card, { backgroundColor: theme.card }]}>
<Text style={[styles.cardTitle, { color: theme.text }]}>项目特点</Text>
<View style={styles.featureItem}>
<Text style={[styles.featureDot, { color: theme.accent }]}>•</Text>
<Text style={[styles.featureText, { color: theme.secondaryText }]}>全面支持 iOS, Android 和 Web</Text>
</View>
<View style={styles.featureItem}>
<Text style={[styles.featureDot, { color: theme.accent }]}>•</Text>
<Text style={[styles.featureText, { color: theme.secondaryText }]}>中文界面与详细的代码注释</Text>
</View>
<View style={styles.featureItem}>
<Text style={[styles.featureDot, { color: theme.accent }]}>•</Text>
<Text style={[styles.featureText, { color: theme.secondaryText }]}>响应式布局,适配多种屏幕尺寸</Text>
</View>
</View>
{/* 交互示例 */}
<TouchableOpacity
style={[styles.button, { backgroundColor: theme.accent }]}
onPress={() => alert('欢迎使用 React Native!')}
>
<Text style={styles.buttonText}>点击交互示例</Text>
</TouchableOpacity>
{/* 底部信息 */}
<View style={styles.footer}>
<Text style={[styles.footerText, { color: isDarkMode ? '#636366' : '#8E8E93' }]}>
© 2024 中文 React Native 项目
</Text>
<Text style={[styles.footerText, { color: isDarkMode ? '#636366' : '#8E8E93' }]}>
由 Trae AI 强力驱动
</Text>
</View>
</View>
</ScrollView>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
safeArea: {
flex: 1,
},
scrollContainer: {
flexGrow: 1,
},
header: {
padding: 30,
alignItems: 'center',
justifyContent: 'center',
borderBottomLeftRadius: 24,
borderBottomRightRadius: 24,
shadowColor: '#000',
shadowOffset: { width: 0, height: 4 },
shadowOpacity: 0.1,
shadowRadius: 10,
elevation: 5,
},
headerTitle: {
fontSize: 28,
fontWeight: 'bold',
color: '#FFFFFF',
marginBottom: 8,
},
headerSubtitle: {
fontSize: 16,
color: 'rgba(255, 255, 255, 0.8)',
},
content: {
padding: 20,
gap: 15,
},
card: {
borderRadius: 16,
padding: 20,
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.05,
shadowRadius: 8,
elevation: 2,
},
switchRow: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
},
cardTitle: {
fontSize: 20,
fontWeight: '600',
marginBottom: 15,
borderLeftWidth: 4,
borderLeftColor: '#007AFF',
paddingLeft: 10,
},
counterContainer: {
alignItems: 'center',
paddingVertical: 10,
},
counterText: {
fontSize: 48,
fontWeight: 'bold',
marginBottom: 15,
},
buttonRow: {
flexDirection: 'row',
gap: 15,
},
smallButton: {
paddingHorizontal: 20,
paddingVertical: 10,
borderRadius: 8,
minWidth: 80,
alignItems: 'center',
},
smallButtonText: {
color: '#FFFFFF',
fontWeight: '600',
},
featureItem: {
flexDirection: 'row',
alignItems: 'center',
marginBottom: 10,
},
featureDot: {
fontSize: 18,
marginRight: 10,
},
featureText: {
fontSize: 16,
lineHeight: 24,
},
button: {
borderRadius: 12,
paddingVertical: 15,
alignItems: 'center',
justifyContent: 'center',
marginTop: 10,
},
buttonText: {
color: '#FFFFFF',
fontSize: 18,
fontWeight: '600',
},
footer: {
marginTop: 30,
marginBottom: 20,
alignItems: 'center',
},
footerText: {
fontSize: 14,
lineHeight: 20,
},
});
|