vercel-react-native-skills
原文:🇺🇸 英文
已翻译
构建高性能移动应用的React Native和Expo最佳实践。适用于构建React Native组件、优化列表性能、实现动画或使用原生模块的场景。当涉及React Native、Expo、移动性能或原生平台API的任务时触发。
13.3k次下载
查看 GitHub 仓库添加于
SKILL.md 内容
查看翻译对照 →React Native 实践技巧
为React Native和Expo应用提供的全面最佳实践。涵盖性能、动画、UI模式和平台特定优化等多个类别的规则。
适用场景
在以下场景中参考这些指南:
- 构建React Native或Expo应用
- 优化列表和滚动性能
- 使用Reanimated实现动画
- 处理图片和媒体资源
- 配置原生模块或字体
- 构建包含原生依赖的单仓库(Monorepo)项目
按优先级划分的规则类别
| 优先级 | 类别 | 影响程度 | 前缀 |
|---|---|---|---|
| 1 | 列表性能 | 关键 | |
| 2 | 动画 | 高 | |
| 3 | 导航 | 高 | |
| 4 | UI模式 | 高 | |
| 5 | 状态管理 | 中 | |
| 6 | 渲染 | 中 | |
| 7 | 单仓库(Monorepo) | 中 | |
| 8 | 配置 | 低 | |
快速参考
1. 列表性能(关键)
- - 对大型列表使用FlashList
list-performance-virtualize - - 对列表项组件进行Memo化处理
list-performance-item-memo - - 稳定回调引用
list-performance-callbacks - - 避免内联样式对象
list-performance-inline-objects - - 在渲染外部提取函数
list-performance-function-references - - 优化列表中的图片
list-performance-images - - 将耗时操作移出列表项
list-performance-item-expensive - - 对异构列表使用项类型
list-performance-item-types
2. 动画(高)
- - 仅对transform和opacity属性执行动画
animation-gpu-properties - - 使用useDerivedValue实现计算式动画
animation-derived-value - - 使用Gesture.Tap替代Pressable
animation-gesture-detector-press
3. 导航(高)
- - 使用原生栈和原生标签导航器替代JS导航器
navigation-native-navigators
4. UI模式(高)
- - 对所有图片使用expo-image
ui-expo-image - - 使用Galeria实现图片灯箱
ui-image-gallery - - 使用Pressable替代TouchableOpacity
ui-pressable - - 在ScrollViews中处理安全区域
ui-safe-area-scroll - - 对头部使用contentInset
ui-scrollview-content-inset - - 使用原生上下文菜单
ui-menus - - 尽可能使用原生模态框
ui-native-modals - - 使用onLayout而非measure()
ui-measure-views - - 使用StyleSheet.create或Nativewind
ui-styling
5. 状态管理(中)
- - 减少状态订阅
react-state-minimize - - 对回调使用调度器模式
react-state-dispatcher - - 在首次渲染时显示回退内容
react-state-fallback - - 为React Compiler进行解构
react-compiler-destructure-functions - - 配合编译器处理共享值
react-compiler-reanimated-shared-values
6. 渲染(中)
- - 将文本包裹在Text组件中
rendering-text-in-text-component - - 避免使用falsy &&进行条件渲染
rendering-no-falsy-and
7. 单仓库(Monorepo)(中)
- - 将原生依赖保留在应用包中
monorepo-native-deps-in-app - - 在所有包中使用统一的依赖版本
monorepo-single-dependency-versions
8. 配置(低)
- - 使用配置插件处理自定义字体
fonts-config-plugin - - 组织设计系统的导入
imports-design-system-folder - - 提升Intl对象创建
js-hoist-intl
使用方法
阅读单个规则文件获取详细说明和代码示例:
rules/list-performance-virtualize.md
rules/animation-gpu-properties.md每个规则文件包含:
- 规则重要性的简要说明
- 错误代码示例及解释
- 正确代码示例及解释
- 额外背景信息和参考资料
完整编译文档
如需查看包含所有扩展规则的完整指南:
AGENTS.md