模板说明
该模板提供 React Native 移动应用的完整起点,覆盖导航、类型、主题和发布配置。
包含内容
包含应用配置、导航栈与文件路由、TypeScript 严格配置、基础组件、网络层和测试入口。
使用建议
导航与页面职责分离,跨页面状态放入合适的 store 或查询缓存。网络层统一处理认证、超时和错误。OTA 更新需保持原生与 JS 兼容,并在发布前灰度。
验证方式
在 iOS 和 Android 真机测试导航、离线、权限与更新;运行类型检查和测试。发布前确认签名、隐私声明、包体积和回滚路径。
交付检查
使用该模板初始化项目后,先运行安装、类型检查、测试与生产构建;再按模板说明逐项核对环境变量、权限边界、错误处理和关闭流程。把实际命令输出保留为交付证据,不要只依据 README 声明。
代码示例
package.json
app.json
app/_layout.tsx
app/index.tsx
app/details.tsx
{
"name": "react-native-mobile-app",
"version": "1.0.0",
"main": "expo-router/entry",
"scripts": {
"start": "expo start",
"ios": "expo run:ios",
"android": "expo run:android"
},
"dependencies": {
"expo": "~52.0.0",
"expo-router": "~4.0.0",
"react": "18.3.1",
"react-native": "0.76.0",
"@react-navigation/native": "^7.0.0",
"@react-navigation/stack": "^7.0.0"
},
"devDependencies": {
"typescript": "^5.6.0"
}
}
{
"expo": {
"name": "React Native App",
"slug": "react-native-mobile-app",
"version": "1.0.0",
"scheme": "myapp",
"platforms": ["ios", "android"],
"ios": { "supportsTablet": true },
"android": { "package": "com.example.myapp" },
"plugins": ["expo-router"]
}
}
import { Stack } from 'expo-router';
export default function RootLayout() {
return (
<Stack>
<Stack.Screen name="index" options={{ title: 'Home' }} />
<Stack.Screen name="details" options={{ title: 'Details' }} />
</Stack>
);
}
import { View, Text, Pressable, StyleSheet } from 'react-native';
import { router } from 'expo-router';
export default function HomeScreen() {
return (
<View style={styles.container}>
<Text style={styles.title}>React Native App</Text>
<Pressable style={styles.button} onPress={() => router.push('/details')}>
<Text style={styles.buttonText}>Go to Details</Text>
</Pressable>
</View>
);
}
const styles = StyleSheet.create({
container: { flex: 1, justifyContent: 'center', alignItems: 'center' },
title: { fontSize: 24, fontWeight: 'bold', marginBottom: 20 },
button: { backgroundColor: '#007AFF', paddingHorizontal: 20, paddingVertical: 10, borderRadius: 8 },
buttonText: { color: 'white', fontSize: 16 },
});
import { View, Text, StyleSheet } from 'react-native';
export default function DetailsScreen() {
return (
<View style={styles.container}>
<Text style={styles.title}>Details Page</Text>
<Text>This is the details screen.</Text>
</View>
);
}
const styles = StyleSheet.create({
container: { flex: 1, justifyContent: 'center', alignItems: 'center' },
title: { fontSize: 24, fontWeight: 'bold', marginBottom: 20 },
});