3v324v23 commited on
Commit
692fef9
·
1 Parent(s): cba4e90

initial commit

Browse files
Files changed (7) hide show
  1. .dockerignore +9 -0
  2. App.tsx +7 -4
  3. Dockerfile +26 -0
  4. README.md +58 -0
  5. package-lock.json +0 -0
  6. package.json +4 -1
  7. src/components/MainScreen.tsx +224 -0
.dockerignore ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ node_modules
2
+ .expo
3
+ dist
4
+ .git
5
+ .gitignore
6
+ .dockerignore
7
+ npm-debug.log*
8
+ yarn-debug.log*
9
+ yarn-error.log*
App.tsx CHANGED
@@ -1,10 +1,15 @@
1
  import { StatusBar } from 'expo-status-bar';
2
- import { StyleSheet, Text, View } from 'react-native';
 
3
 
 
 
 
4
  export default function App() {
5
  return (
6
  <View style={styles.container}>
7
- <Text>Open up App.tsx to start working on your app!</Text>
 
8
  <StatusBar style="auto" />
9
  </View>
10
  );
@@ -14,7 +19,5 @@ const styles = StyleSheet.create({
14
  container: {
15
  flex: 1,
16
  backgroundColor: '#fff',
17
- alignItems: 'center',
18
- justifyContent: 'center',
19
  },
20
  });
 
1
  import { StatusBar } from 'expo-status-bar';
2
+ import { StyleSheet, View } from 'react-native';
3
+ import { MainScreen } from './src/components/MainScreen';
4
 
5
+ /**
6
+ * 应用根组件 - 引入主屏幕
7
+ */
8
  export default function App() {
9
  return (
10
  <View style={styles.container}>
11
+ {/* 渲染主屏幕 */}
12
+ <MainScreen />
13
  <StatusBar style="auto" />
14
  </View>
15
  );
 
19
  container: {
20
  flex: 1,
21
  backgroundColor: '#fff',
 
 
22
  },
23
  });
Dockerfile ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 使用 Node.js LTS 版本作为基础镜像
2
+ FROM node:20-slim
3
+
4
+ # 设置工作目录
5
+ WORKDIR /app
6
+
7
+ # 安装必要的构建工具和 serve
8
+ RUN npm install -g serve
9
+
10
+ # 复制 package.json 和 package-lock.json
11
+ COPY package*.json ./
12
+
13
+ # 安装项目依赖
14
+ RUN npm install
15
+
16
+ # 复制项目源代码
17
+ COPY . .
18
+
19
+ # 构建 Web 版本
20
+ RUN npx expo export --platform web
21
+
22
+ # 暴露端口 (Hugging Face Spaces 默认使用 7860)
23
+ EXPOSE 7860
24
+
25
+ # 运行服务,将静态资源映射到 7860 端口
26
+ CMD ["serve", "-s", "dist", "-l", "7860"]
README.md ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: 中文 React Native 项目
3
+ emoji: 📱
4
+ colorFrom: blue
5
+ colorTo: indigo
6
+ sdk: docker
7
+ pinned: false
8
+ short_description: "中文 React Native 项目:支持 iOS, Android 和 Web 的全平台适配示例"
9
+ ---
10
+
11
+ # 中文 React Native 项目
12
+
13
+ 这是一个使用 **Expo** 构建的 React Native 示例项目。它被设计为兼顾移动平台(iOS, Android)和主流 Web 平台,并提供全面的中文本地化支持。
14
+
15
+ ## 项目特点
16
+
17
+ - **全平台支持**:使用 React Native Web 实现一套代码,多端运行。
18
+ - **中文汉化**:代码注释、UI 文本均采用中文,方便学习与二次开发。
19
+ - **响应式布局**:针对不同屏幕尺寸进行优化,提供流畅的用户体验。
20
+ - **Hugging Face 适配**:内置 `Dockerfile`,可直接在 Hugging Face Spaces 上作为 Docker 应用运行。
21
+
22
+ ## 本地开发指南
23
+
24
+ ### 前置条件
25
+
26
+ 确保已安装 [Node.js](https://nodejs.org/)。
27
+
28
+ ### 安装依赖
29
+
30
+ ```bash
31
+ npm install
32
+ ```
33
+
34
+ ### 运行项目
35
+
36
+ - **启动 Web 版** (默认浏览器打开):
37
+ ```bash
38
+ npm run web
39
+ ```
40
+
41
+ - **启动 Expo 开发服务器** (支持扫码预览):
42
+ ```bash
43
+ npm start
44
+ ```
45
+
46
+ ## 项目结构
47
+
48
+ - `App.tsx`: 应用程序入口
49
+ - `src/components/MainScreen.tsx`: 核心展示页面 (包含详细中文注释)
50
+ - `Dockerfile`: 用于 Hugging Face 部署的容器化配置
51
+ - `app.json`: Expo 配置文件
52
+
53
+ ## 关于部署
54
+
55
+ 本项目已配置为在 Hugging Face Spaces 上使用 Docker 部署。容器将构建 Web 版本的静态资源,并使用 `serve` 在 `7860` 端口上提供服务。
56
+
57
+ ---
58
+ 由 Trae AI 生成并优化。
package-lock.json ADDED
The diff for this file is too large to render. See raw diff
 
package.json CHANGED
@@ -9,10 +9,13 @@
9
  "web": "expo start --web"
10
  },
11
  "dependencies": {
 
12
  "expo": "~55.0.5",
13
  "expo-status-bar": "~55.0.4",
14
  "react": "19.2.0",
15
- "react-native": "0.83.2"
 
 
16
  },
17
  "devDependencies": {
18
  "@types/react": "~19.2.2",
 
9
  "web": "expo start --web"
10
  },
11
  "dependencies": {
12
+ "@expo/metro-runtime": "~55.0.6",
13
  "expo": "~55.0.5",
14
  "expo-status-bar": "~55.0.4",
15
  "react": "19.2.0",
16
+ "react-dom": "19.2.0",
17
+ "react-native": "0.83.2",
18
+ "react-native-web": "^0.21.0"
19
  },
20
  "devDependencies": {
21
  "@types/react": "~19.2.2",
src/components/MainScreen.tsx ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React, { useState } from 'react';
2
+ import { StyleSheet, Text, View, ScrollView, SafeAreaView, TouchableOpacity, Image, Switch } from 'react-native';
3
+ import { StatusBar } from 'expo-status-bar';
4
+
5
+ /**
6
+ * 主屏幕组件 - 采用中文显示与注释
7
+ * 包含计数器和主题切换功能
8
+ */
9
+ export const MainScreen = () => {
10
+ const [count, setCount] = useState(0);
11
+ const [isDarkMode, setIsDarkMode] = useState(false);
12
+
13
+ // 主题样式定义
14
+ const theme = {
15
+ background: isDarkMode ? '#1C1C1E' : '#F5F7FA',
16
+ card: isDarkMode ? '#2C2C2E' : '#FFFFFF',
17
+ text: isDarkMode ? '#FFFFFF' : '#1C1C1E',
18
+ secondaryText: isDarkMode ? '#AEAEB2' : '#3A3A3C',
19
+ accent: '#007AFF',
20
+ border: isDarkMode ? '#3A3A3C' : '#E5E5EA',
21
+ };
22
+
23
+ return (
24
+ <SafeAreaView style={[styles.safeArea, { backgroundColor: theme.background }]}>
25
+ <StatusBar style={isDarkMode ? 'light' : 'dark'} />
26
+ <ScrollView contentContainerStyle={styles.scrollContainer}>
27
+ {/* 顶部标题栏 */}
28
+ <View style={[styles.header, { backgroundColor: theme.accent }]}>
29
+ <Text style={styles.headerTitle}>React Native 中文项目</Text>
30
+ <Text style={styles.headerSubtitle}>跨平台移动端 & Web 应用</Text>
31
+ </View>
32
+
33
+ {/* 核心功能展示区 */}
34
+ <View style={styles.content}>
35
+ {/* 主题切换卡片 */}
36
+ <View style={[styles.card, { backgroundColor: theme.card }]}>
37
+ <View style={styles.switchRow}>
38
+ <Text style={[styles.cardTitle, { color: theme.text, marginBottom: 0 }]}>
39
+ {isDarkMode ? '深色模式' : '浅色模式'}
40
+ </Text>
41
+ <Switch
42
+ value={isDarkMode}
43
+ onValueChange={setIsDarkMode}
44
+ trackColor={{ false: '#767577', true: '#34C759' }}
45
+ thumbColor={isDarkMode ? '#FFFFFF' : '#f4f3f4'}
46
+ />
47
+ </View>
48
+ </View>
49
+
50
+ {/* 交互计数器卡片 */}
51
+ <View style={[styles.card, { backgroundColor: theme.card }]}>
52
+ <Text style={[styles.cardTitle, { color: theme.text }]}>交互计数器</Text>
53
+ <View style={styles.counterContainer}>
54
+ <Text style={[styles.counterText, { color: theme.text }]}>{count}</Text>
55
+ <View style={styles.buttonRow}>
56
+ <TouchableOpacity
57
+ style={[styles.smallButton, { backgroundColor: theme.accent }]}
58
+ onPress={() => setCount(count + 1)}
59
+ >
60
+ <Text style={styles.smallButtonText}>增加</Text>
61
+ </TouchableOpacity>
62
+ <TouchableOpacity
63
+ style={[styles.smallButton, { backgroundColor: '#FF3B30' }]}
64
+ onPress={() => setCount(0)}
65
+ >
66
+ <Text style={styles.smallButtonText}>重置</Text>
67
+ </TouchableOpacity>
68
+ </View>
69
+ </View>
70
+ </View>
71
+
72
+ <View style={[styles.card, { backgroundColor: theme.card }]}>
73
+ <Text style={[styles.cardTitle, { color: theme.text }]}>项目特点</Text>
74
+ <View style={styles.featureItem}>
75
+ <Text style={[styles.featureDot, { color: theme.accent }]}>•</Text>
76
+ <Text style={[styles.featureText, { color: theme.secondaryText }]}>全面支持 iOS, Android 和 Web</Text>
77
+ </View>
78
+ <View style={styles.featureItem}>
79
+ <Text style={[styles.featureDot, { color: theme.accent }]}>•</Text>
80
+ <Text style={[styles.featureText, { color: theme.secondaryText }]}>中文界面与详细的代码注释</Text>
81
+ </View>
82
+ <View style={styles.featureItem}>
83
+ <Text style={[styles.featureDot, { color: theme.accent }]}>•</Text>
84
+ <Text style={[styles.featureText, { color: theme.secondaryText }]}>响应式布局,适配多种屏幕尺寸</Text>
85
+ </View>
86
+ </View>
87
+
88
+ {/* 交互示例 */}
89
+ <TouchableOpacity
90
+ style={[styles.button, { backgroundColor: theme.accent }]}
91
+ onPress={() => alert('欢迎使用 React Native!')}
92
+ >
93
+ <Text style={styles.buttonText}>点击交互示例</Text>
94
+ </TouchableOpacity>
95
+
96
+ {/* 底部信息 */}
97
+ <View style={styles.footer}>
98
+ <Text style={[styles.footerText, { color: isDarkMode ? '#636366' : '#8E8E93' }]}>
99
+ © 2024 中文 React Native 项目
100
+ </Text>
101
+ <Text style={[styles.footerText, { color: isDarkMode ? '#636366' : '#8E8E93' }]}>
102
+ 由 Trae AI 强力驱动
103
+ </Text>
104
+ </View>
105
+ </View>
106
+ </ScrollView>
107
+ </SafeAreaView>
108
+ );
109
+ };
110
+
111
+ const styles = StyleSheet.create({
112
+ safeArea: {
113
+ flex: 1,
114
+ },
115
+ scrollContainer: {
116
+ flexGrow: 1,
117
+ },
118
+ header: {
119
+ padding: 30,
120
+ alignItems: 'center',
121
+ justifyContent: 'center',
122
+ borderBottomLeftRadius: 24,
123
+ borderBottomRightRadius: 24,
124
+ shadowColor: '#000',
125
+ shadowOffset: { width: 0, height: 4 },
126
+ shadowOpacity: 0.1,
127
+ shadowRadius: 10,
128
+ elevation: 5,
129
+ },
130
+ headerTitle: {
131
+ fontSize: 28,
132
+ fontWeight: 'bold',
133
+ color: '#FFFFFF',
134
+ marginBottom: 8,
135
+ },
136
+ headerSubtitle: {
137
+ fontSize: 16,
138
+ color: 'rgba(255, 255, 255, 0.8)',
139
+ },
140
+ content: {
141
+ padding: 20,
142
+ gap: 15,
143
+ },
144
+ card: {
145
+ borderRadius: 16,
146
+ padding: 20,
147
+ shadowColor: '#000',
148
+ shadowOffset: { width: 0, height: 2 },
149
+ shadowOpacity: 0.05,
150
+ shadowRadius: 8,
151
+ elevation: 2,
152
+ },
153
+ switchRow: {
154
+ flexDirection: 'row',
155
+ justifyContent: 'space-between',
156
+ alignItems: 'center',
157
+ },
158
+ cardTitle: {
159
+ fontSize: 20,
160
+ fontWeight: '600',
161
+ marginBottom: 15,
162
+ borderLeftWidth: 4,
163
+ borderLeftColor: '#007AFF',
164
+ paddingLeft: 10,
165
+ },
166
+ counterContainer: {
167
+ alignItems: 'center',
168
+ paddingVertical: 10,
169
+ },
170
+ counterText: {
171
+ fontSize: 48,
172
+ fontWeight: 'bold',
173
+ marginBottom: 15,
174
+ },
175
+ buttonRow: {
176
+ flexDirection: 'row',
177
+ gap: 15,
178
+ },
179
+ smallButton: {
180
+ paddingHorizontal: 20,
181
+ paddingVertical: 10,
182
+ borderRadius: 8,
183
+ minWidth: 80,
184
+ alignItems: 'center',
185
+ },
186
+ smallButtonText: {
187
+ color: '#FFFFFF',
188
+ fontWeight: '600',
189
+ },
190
+ featureItem: {
191
+ flexDirection: 'row',
192
+ alignItems: 'center',
193
+ marginBottom: 10,
194
+ },
195
+ featureDot: {
196
+ fontSize: 18,
197
+ marginRight: 10,
198
+ },
199
+ featureText: {
200
+ fontSize: 16,
201
+ lineHeight: 24,
202
+ },
203
+ button: {
204
+ borderRadius: 12,
205
+ paddingVertical: 15,
206
+ alignItems: 'center',
207
+ justifyContent: 'center',
208
+ marginTop: 10,
209
+ },
210
+ buttonText: {
211
+ color: '#FFFFFF',
212
+ fontSize: 18,
213
+ fontWeight: '600',
214
+ },
215
+ footer: {
216
+ marginTop: 30,
217
+ marginBottom: 20,
218
+ alignItems: 'center',
219
+ },
220
+ footerText: {
221
+ fontSize: 14,
222
+ lineHeight: 20,
223
+ },
224
+ });