返回全部 Skills

react-native-dev

开发工具 官方认证

React Native 和 Expo 开发指南,涵盖组件、样式、动画、导航、 状态管理、表单、网络、性能优化、测试、原生能力、 以及工程化(项目结构、部署、SDK 升级、CI/CD)。 使用场景:构建 React Native 或 Expo 应用、实现动画或原生 UI、管理 状态、获取数据、编写测试、优化性能、部署到 App Store/Play Store、 设置 CI/CD、升级 Expo SDK,或配置 Tailwind/NativeWind。

43

下载量

AI SkillHub 能力展示图

安装方式

命令行安装

在项目根目录执行以下命令,完成 Skill 安装。

npx bzskills add MiniMax-AI/skills --skill react-native-dev

skill.md

name: react-native-dev
description: |-
    React Native 和 Expo 开发指南,涵盖组件、样式、动画、导航、
    状态管理、表单、网络、性能优化、测试、原生能力、
    以及工程化(项目结构、部署、SDK 升级、CI/CD)。
    使用场景:构建 React Native 或 Expo 应用、实现动画或原生 UI、管理
    状态、获取数据、编写测试、优化性能、部署到 App Store/Play Store、
    设置 CI/CD、升级 Expo SDK,或配置 Tailwind/NativeWind。
license: MIT
metadata:
    version: "1.0.0"
    category: mobile
    sources:
        - expo/skills by Expo (https://github.com/expo/skills) — Native UI, navigation, and animation patterns
        - Expo documentation (docs.expo.dev)
        - React Native documentation (reactnative.dev)
        - EAS (Expo Application Services) documentation

React Native & Expo 开发指南

构建可用于生产环境的 React Native 和 Expo 应用实用指南。涵盖 UI、动画、状态管理、测试、性能优化和部署上线。

参考资料

根据需要查阅以下资源:

  • [references/navigation.md](references/navigation.md) — Expo Router:Stack、Tabs、NativeTabs(headerLargeTitleheaderBackButtonDisplayMode)、链接、模态、sheet、上下文菜单
  • [references/components.md](references/components.md) — FlashList 模式、expo-image、安全区域(contentInsetAdjustmentBehavior)、原生控件、毛玻璃效果、存储
  • [references/styling.md](references/styling.md) — StyleSheet、NativeWind/Tailwind、平台样式、主题、深色模式
  • [references/animations.md](references/animations.md) — Reanimated 3:进入/退出动画、共享值、手势、滚动驱动
  • [references/state-management.md](references/state-management.md) — Zustand(选择器、持久化)、Jotai(原子、派生)、React Query、Context
  • [references/forms.md](references/forms.md) — React Hook Form + Zod:表单验证、多步骤、动态数组
  • [references/networking.md](references/networking.md) — fetch 封装、React Query(乐观更新)、认证令牌、离线支持、API 路由、webhook
  • [references/performance.md](references/performance.md) — 性能分析工作流、FlashList + memo、包体积分析、TTI、内存泄漏、动画性能
  • [references/testing.md](references/testing.md) — Jest、React Native Testing Library、使用 Maestro 进行端到端测试
  • [references/native-capabilities.md](references/native-capabilities.md) — 相机、定位、权限(use*Permissions hooks)、触感反馈、通知、生物识别
  • [references/engineering.md](references/engineering.md) — 项目结构(components/ui/stores/services/)、路径别名、SDK 升级、EAS 构建/提交、CI/CD、DOM 组件

快速参考

组件推荐对照表

用途推荐使用替代(不推荐)
列表FlashList@shopify/flash-list)+ memoFlatList(无视图复用)
图片expo-imageRN <Image>(无缓存、不支持 WebP)
点击PressableTouchableOpacity(旧版)
音频expo-audioexpo-av(已弃用)
视频expo-videoexpo-av(已弃用)
动画Reanimated 3RN Animated API(功能有限)
手势Gesture HandlerPanResponder(旧版)
平台判断process.env.EXPO_OSPlatform.OS
ContextReact.use()React.useContext()(React 18)
安全区域滚动contentInsetAdjustmentBehavior="automatic"<SafeAreaView>
SF Symbolsexpo-image 搭配 source="sf:name"expo-symbols

扩展与升级

场景考虑方案
长列表滚动卡顿虚拟化列表库(例如 FlashList)
想要 Tailwind 类名NativeWind v4
高频存储读取基于同步的存储(例如 MMKV)
使用 Expo 的新项目Expo Router 而非裸 React Navigation

状态管理

状态类型解决方案
本地 UI 状态useState / useReducer
共享应用状态Zustand 或 Jotai
服务端/异步数据React Query
表单状态React Hook Form + Zod

性能优先级

优先级问题修复方案
严重长列表卡顿FlashList + 记忆化项
严重包体积过大避免 barrel 导入,启用 R8
过多重渲染Zustand 选择器、React Compiler
启动慢禁用包体积压缩、原生导航
动画掉帧仅动画化 transform / opacity

新项目初始化

# 1. 创建项目
npx create-expo-app@latest my-app --template blank-typescript
cd my-app

# 2. 安装 Expo Router + 核心依赖
npx expo install expo-router react-native-safe-area-context react-native-screens

# 3. (可选)常用额外依赖
npx expo install expo-image react-native-reanimated react-native-gesture-handler

随后配置:

  1. package.json 中设置入口点:"main": "expo-router/entry"
  2. app.json 中添加 scheme:"scheme": "my-app"
  3. 删除 App.tsxindex.ts
  4. 创建 app/_layout.tsx 作为根 Stack 布局
  5. 创建 app/(tabs)/_layout.tsx 用于标签导航
  6. app/(tabs)/ 下创建路由文件(参见 [navigation.md](references/navigation.md))

如需支持 Web,还需安装:npx expo install react-native-web react-dom @expo/metro-runtime

核心原则

在编写代码前先查阅参考资料:当实现导航、列表、网络请求或项目配置时,请先阅读对应的参考文件,了解模式与陷阱。

优先尝试 Expo Gonpx expo start)。仅在需要使用本地 Expo 模块、Apple 目标或 Expo Go 中不包含的第三方原生模块时,才使用自定义构建(eas build)。

条件渲染:使用 {count > 0 && <Text />} 而非 {count && <Text />}(后者会渲染 "0")。

动画规则:仅对 transformopacity 做动画——这些由 GPU 合成,不会触发布局抖动。

导入方式:始终从源文件直接导入,避免使用 barrel 文件——否则会导致包体积膨胀。

列表与图片:在使用 FlatList 或 RN Image 之前,先查看上方的组件推荐对照表——FlashListexpo-image 几乎总是更好的选择。

路由文件:始终使用 kebab-case 命名,不要在 app/ 中混入组件、类型或工具函数。

检查清单

新项目配置

  • [ ] tsconfig.json 路径别名已配置
  • [ ] 每个环境已设置 EXPO_PUBLIC_API_URL 环境变量
  • [ ] 根布局包含 GestureHandlerRootView(如果使用手势)
  • [ ] 所有滚动视图已设置 contentInsetAdjustmentBehavior="automatic"
  • [ ] 列表长度超过 20 项时使用 FlashList 而非 FlatList

上线前检查

  • [ ] 在 --profile 模式下分析,修复超过 16ms 的帧
  • [ ] 包体积已分析(source-map-explorer),无 barrel 导入
  • [ ] Android 已启用 R8
  • [ ] 关键路径有单元测试和组件测试
  • [ ] 登录、核心功能、结账流程的端到端测试通过

---

Flutter 开发 → 参见 flutter-dev 技能。

iOS 原生(UIKit/SwiftUI) → 参见 ios-application-dev 技能。

Android 原生(Kotlin/Compose) → 参见 android-native-dev 技能。

*React Native 是 Meta Platforms, Inc. 的商标。Expo 是 650 Industries, Inc. 的商标。所有其他产品名称均为其各自所有者的商标。*