React Native Skills 是一套针对 React Native 和 Expo 应用的综合性最佳实践集合,包含覆盖性能、动画、UI 模式以及平台特定优化等多个类别的规则。
用途
在以下场景中可参考这些指南:
- 构建 React Native 或 Expo 应用
- 优化列表与滚动性能
- 使用 Reanimated 实现动画
- 处理图片与媒体
- 配置原生模块或字体
- 组织含原生依赖的 Monorepo 项目
规则类别与优先级
规则按优先级和影响程度分类,并带有前缀标识:
| 优先级 | 类别 | 影响 | 前缀 |
|---|---|---|---|
| 1 | 列表性能 | CRITICAL | list-performance- |
| 2 | 动画 | HIGH | animation- |
| 3 | 导航 | HIGH | navigation- |
| 4 | UI 模式 | HIGH | ui- |
| 5 | 状态管理 | MEDIUM | react-state- |
| 6 | 渲染 | MEDIUM | rendering- |
| 7 | Monorepo | MEDIUM | monorepo- |
| 8 | 配置 | LOW | fonts-, imports- |
主要能力(规则速查)
1. 列表性能(CRITICAL)
- list-performance-virtualize:大型列表使用 FlashList
- 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:为异构列表使用 item types
2. 动画(HIGH)
- animation-gpu-properties:仅对 transform 和 opacity 做动画
- animation-derived-value:使用 useDerivedValue 处理计算型动画
- animation-gesture-detector-press:使用 Gesture.Tap 替代 Pressable
3. 导航(HIGH)
- navigation-native-navigators:优先使用原生 stack 和原生 tabs,而非 JS 导航器
4. UI 模式(HIGH)
- ui-expo-image:所有图片使用 expo-image
- ui-image-gallery:图片灯箱使用 Galeria
- ui-pressable:使用 Pressable 替代 TouchableOpacity
- ui-safe-area-scroll:在 ScrollView 中处理安全区域
- ui-scrollview-content-inset:为头部使用 contentInset
- ui-menus:使用原生上下文菜单
- ui-native-modals:尽可能使用原生模态框
- ui-measure-views:使用 onLayout,而非 measure()
- ui-styling:使用 StyleSheet.create 或 Nativewind
5. 状态管理(MEDIUM)
- react-state-minimize:最小化状态订阅
- react-state-dispatcher:为回调使用 dispatcher 模式
- react-state-fallback:首次渲染时显示 fallback
- react-compiler-destructure-functions:为 React Compiler 解构函数
- react-compiler-reanimated-shared-values:配合编译器处理 shared values
6. 渲染(MEDIUM)
- rendering-text-in-text-component:将文本包裹在 Text 组件中
- rendering-no-falsy-and:避免使用 falsy && 做条件渲染
7. Monorepo(MEDIUM)
- monorepo-native-deps-in-app:将原生依赖保留在应用包中
- monorepo-single-dependency-versions:跨包使用单一版本
8. 配置(LOW)
- fonts-config-plugin:使用 config plugins 配置自定义字体
- imports-design-system-folder:组织设计系统导入
- js-hoist-intl:提升 Intl 对象创建
使用方式
阅读各个规则文件以获取详细说明和代码示例,例如:
- rules/list-performance-virtualize.md
- rules/animation-gpu-properties.md
每个规则文件包含:
- 为什么重要的简要说明
- 带解释的错误代码示例
- 带解释的正确代码示例
- 额外上下文与参考
完整编译文档
如需包含所有规则展开的完整指南,请参阅:AGENTS.md
限制
资料未提供该技能的具体安装命令、收费方式、支持平台或版本要求等信息,暂未提供。