返回顶部
r

react-native-devReact原生开发

|

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
187
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

react-native-dev

React Native & Expo 开发指南

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

参考文档

根据需要查阅以下资源:

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

快速参考

组件选择偏好

用途推荐使用替代方案
列表FlashList(@shopify/flash-list)+ memo 项FlatList(无视图回收)
图片
expo-image | RN (无缓存、不支持 WebP) | | 点击 | Pressable | TouchableOpacity(已过时) | | 音频 | expo-audio | expo-av(已弃用) | | 视频 | expo-video | expo-av(已弃用) | | 动画 | Reanimated 3 | RN Animated API(功能有限) | | 手势 | Gesture Handler | PanResponder(已过时) | | 平台检测 | process.env.EXPO_OS | Platform.OS | | 上下文 | React.use() | React.useContext()(React 18) | | 安全区域滚动 | contentInsetAdjustmentBehavior=automatic | | | SF Symbols | 使用 source=sf:name 的 expo-image | expo-symbols |

扩展方案

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

状态管理

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

性能优化优先级

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

新项目初始化

bash

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. 1. 在 package.json 中设置入口点:main: expo-router/entry
  2. 在 app.json 中添加 scheme:scheme: my-app
  3. 删除 App.tsx 和 index.ts
  4. 创建 app/layout.tsx 作为根堆栈布局
  5. 创建 app/(tabs)/layout.tsx 用于标签导航
  6. 在 app/(tabs)/ 中创建路由文件(参见 navigation.md

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

核心原则

实现前查阅参考文档:在实现导航、列表、网络请求或项目设置时,先阅读上述对应的参考文件,了解模式和注意事项。

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

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

动画规则:仅动画化 transform 和 opacity — GPU 合成,不会引起布局抖动。

导入规则:始终从源文件直接导入,而非桶文件 — 避免包体积膨胀。

列表和图片:在使用 FlatList 或 RN Image 之前,先查看上方的组件选择偏好表 — FlashList 和 expo-image 几乎总是正确的选择。

路由文件:始终使用短横线命名法(kebab-case),切勿在 app/ 中放置组件/类型/工具函数。

检查清单

新项目设置

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

发布前检查

  • - [ ] 在 --profile 模式下进行性能分析,修复超过 16ms 的帧
  • [ ] 进行打包分析(source-map-explorer),无桶导入
  • [ ] 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. 的商标。所有其他产品名称均为其各自所有者的商标。

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 minimax-react-native-dev-1775904788 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 minimax-react-native-dev-1775904788 技能

通过命令行安装

skillhub install minimax-react-native-dev-1775904788

下载

⬇ 下载 react-native-dev v1.0.0(免费)

文件大小: 3.78 KB | 发布时间: 2026-4-12 10:36

v1.0.0 最新 2026-4-12 10:36
Initial release: Practical React Native & Expo development guide

- Covers components, styling, animations, navigation, state management, forms, networking, performance, testing, deployment, and CI/CD.
- Includes quick-reference tables for tool and library choices.
- Provides checklists for new project setup and pre-shipping tasks.
- Links to topical reference files for in-depth patterns and best practices.
- Offers recommendations and practical rules for production-grade React Native and Expo apps.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部