react-native
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseReact Native with Expo
基于Expo的React Native
Overview
概述
Expo is an open-source framework for building universal native apps with React Native from a single TypeScript codebase. It provides file-based routing (Expo Router), cloud build services (EAS Build/Submit/Update), and a rich set of native modules for device APIs.
When to use: Mobile apps targeting iOS and Android, universal apps with web support, projects needing OTA updates, apps requiring native device APIs (camera, notifications, haptics), teams preferring managed infrastructure over bare React Native.
When NOT to use: Apps requiring heavy custom native code incompatible with Expo Modules API, brownfield integration into existing native apps, apps with native-only CI/CD requirements.
Expo是一个开源框架,可通过单一TypeScript代码库,基于React Native构建跨平台原生应用。它提供了基于文件的路由(Expo Router)、云构建服务(EAS Build/Submit/Update),以及一套丰富的原生模块用于设备API调用。
适用场景: 面向iOS和Android的移动应用、支持Web端的跨平台应用、需要OTA更新的项目、需要调用相机、通知、触觉反馈等原生设备API的应用、偏好托管式基础设施而非裸React Native的团队。
不适用场景: 需要大量与Expo Modules API不兼容的自定义原生代码的应用、需集成到现有原生应用的棕场项目、有原生专属CI/CD需求的应用。
Quick Reference
快速参考
| Pattern | API | Key Points |
|---|---|---|
| Stack navigation | | File-based, |
| Tab navigation | | |
| Drawer navigation | | Requires |
| Typed routes | | Enable |
| Dev build | | Custom native code + dev tools |
| EAS Build | | Cloud builds for app stores |
| EAS Submit | | Automated store submission |
| OTA Update | | JS-only updates, no rebuild needed |
| Native module | Expo Modules API | Swift/Kotlin with |
| Platform code | | Per-platform logic or entire files |
| Styled lists | | Virtualized, |
| Camera | | Permissions via |
| Notifications | | Push tokens via |
| Haptics | | |
| Tailwind (RN) | NativeWind v4 | |
| 模式 | API | 关键点 |
|---|---|---|
| 栈导航 | | 基于文件路由, |
| 标签栏导航 | | 包含 |
| 抽屉导航 | | 需要 |
| 类型化路由 | | 在 |
| 开发构建 | | 自定义原生代码 + 开发工具 |
| EAS构建 | | 用于应用商店的云构建 |
| EAS提交 | | 自动化应用商店提交 |
| OTA更新 | | 仅JS代码更新,无需重新构建 |
| 原生模块 | Expo Modules API | 搭配 |
| 平台特定代码 | | 平台专属逻辑或独立文件 |
| 样式化列表 | | 虚拟化渲染,需 |
| 相机 | | 通过 |
| 通知 | | 通过 |
| 触觉反馈 | | |
| RN版Tailwind | NativeWind v4 | 支持 |
Common Mistakes
常见错误
| Mistake | Correct Pattern |
|---|---|
Using | Expo Router wraps React Navigation with file-based routing |
Forgetting | Every directory with routes needs a layout file |
Using | Use |
Running | Native changes require |
Hardcoding platform checks with | Use |
| Not requesting permissions before accessing device APIs | Always check/request permissions before camera, notifications |
Using | Use |
| Inline styles in render functions | Define styles with |
Missing | Always provide |
Importing from | Prefer |
| 错误做法 | 正确实践 |
|---|---|
直接使用 | Expo Router基于React Navigation封装,提供基于文件的路由 |
路由目录中遗漏 | 所有包含路由的目录都需要布局文件 |
使用 | 搭配 |
原生依赖变更后执行 | 原生变更需要执行 |
使用 | 使用 |
| 访问设备API前未请求权限 | 在调用相机、通知等API前,务必检查/请求权限 |
长列表使用 | 使用 |
| 在渲染函数中内联样式 | 在组件外部使用 |
| 务必提供 |
从 | 优先使用 |
Delegation
任务分工
- Pattern discovery: Use agent
Explore - Build/deployment review: Use agent
Task - Code review: Delegate to agent
code-reviewer
If theskill is available, delegate React component patterns and hooks to it. If thereact-patternsskill is available, delegate data fetching and caching to it. If thetanstack-queryskill is available, delegate client-side state management to it. If thezustandskill is available, delegate unit and component testing patterns to it. If thevitest-testingskill is available, delegate Tailwind CSS utility patterns to it (NativeWind uses Tailwind CSS syntax). If thetailwindskill is available, delegate mobile accessibility patterns to it.accessibility
- 模式探索:使用agent
Explore - 构建/部署评审:使用agent
Task - 代码评审:委托给agent
code-reviewer
若技能可用,将React组件模式和钩子相关任务委托给它。 若react-patterns技能可用,将数据获取和缓存相关任务委托给它。 若tanstack-query技能可用,将客户端状态管理相关任务委托给它。 若zustand技能可用,将单元和组件测试模式相关任务委托给它。 若vitest-testing技能可用,将Tailwind CSS工具类模式相关任务委托给它(NativeWind使用Tailwind CSS语法)。 若tailwind技能可用,将移动应用无障碍模式相关任务委托给它。accessibility
References
参考资料
- Core patterns: StyleSheet, FlatList, Platform-specific code
- Expo Router navigation: stack, tabs, drawer, typed routes
- EAS Build, Submit, and Update workflows
- Dev client and native modules with Expo Modules API
- Device APIs: camera, notifications, haptics
- NativeWind Tailwind CSS integration
- App configuration and environment setup
- Performance optimization patterns
- 核心模式:StyleSheet、FlatList、平台特定代码
- Expo Router导航:栈、标签栏、抽屉、类型化路由
- EAS Build、Submit和Update工作流
- 开发客户端与基于Expo Modules API的原生模块
- 设备API:相机、通知、触觉反馈
- NativeWind Tailwind CSS集成
- 应用配置与环境搭建
- 性能优化模式