Files
physical-expo/README.md
2026-01-12 14:18:22 +08:00

143 lines
3.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## 项目简介
本项目为 Expo/React Native 应用,支持 EAS 构建。
### 常用命令
```bash
eas build --platform android --profile development
```
---
## 项目文件结构
```
├── app/ # 页面与路由
├── assets/ # 静态资源(图片、字体等)
├── components/ # 复用组件
├── constants/ # 常量(如颜色)
├── hooks/ # 自定义 hooks
├── scripts/ # 脚本工具
├── app.json # Expo 配置
├── package.json # 项目依赖
├── tsconfig.json # TypeScript 配置
```
### 目录说明及功能
- **app/**
- 存放应用的页面Screen和路由配置。
- 每个文件/文件夹通常对应一个页面或导航结构。
- 例如主界面、Tab 导航、404 页面等。
- **assets/**
- 存放项目用到的静态资源,如图片、字体等。
- 例如logo、icon、启动图、字体文件等。
- **components/**
- 存放可复用的 UI 组件。
- 例如按钮、卡片、列表项、主题文本、Tab 栏等。
- 便于在不同页面间复用,提高开发效率。
- **constants/**
- 存放全局常量配置。
- 例如:`Colors.ts` 统一管理全局颜色值,方便主题切换和维护。
- **hooks/**
- 存放自定义 React Hooks。
- React Hooks 是 React 16.8 及以上版本引入的函数,允许在函数组件中使用 state、生命周期等特性。
- 例如:主题切换、颜色方案、系统偏好、数据获取等逻辑的复用。
- **scripts/**
- 存放自动化脚本或开发辅助工具。
- 例如:重置项目、批量处理文件等脚本。
- **app.json**
- Expo 项目的全局配置文件。
- 包含应用名称、图标、启动页、平台相关设置等。
- **package.json**
- Node.js 项目的依赖、脚本、元数据配置文件。
- 管理依赖包、项目脚本、版本等。
- **tsconfig.json**
- TypeScript 的编译配置文件。
- 配置编译选项、包含/排除的文件等。
---
如需构建 Android APK 包,可根据不同环境选择以下命令:
#### 开发版构建development profile
```bash
eas build --profile development --platform android
```
#### 预览版构建preview profile
```bash
eas build --profile preview --platform android
```
#### 发布版构建production profile
```bash
eas build --profile production --platform android
```
eas build:dev --platform android
# IOS
```bash
eas build --platform ios --profile production
```
```bash
eas submit --platform ios
```
# expo-updates
推送到预览版
eas update --branch preview
推送到生产版
eas update --branch production
# 渠道判断
获取当前的发布渠道
const channel = Updates.channel || "development";
if (channel === "production") {
ToastAndroid.show("欢迎使用生产版本", ToastAndroid.SHORT);
} else if (channel === "preview") {
ToastAndroid.show("欢迎使用预览版本", ToastAndroid.SHORT);
} else {
ToastAndroid.show("欢迎使用开发版本", ToastAndroid.SHORT);
}
Expo Router 的常用方法有:
router.push(path)
跳转到新页面,保留历史,可返回。
router.replace(path)
替换当前页面,不保留历史,常用于登录/登出。
router.back()
返回上一页,类似浏览器的后退。
router.prefetch(path)
预加载某个页面,提高跳转速度。
router.canGoBack()
判断是否可以返回上一页,返回布尔值。