SuperAPI AI 工具集

vercel-react-native-skills

编程与开发

查看项目

更新于 10-15 10:54

技能介绍

React Native Skills 是针对 React Native 和 Expo 应用的综合性最佳实践集合,包含覆盖性能、动画、UI 模式与平台特定优化的多类规则。

适用时机:在构建 React Native 或 Expo 应用、优化列表与滚动性能、使用 Reanimated 实现动画、处理图片与媒体、配置原生模块或字体、以及组织含原生依赖的 Monorepo 项目时,可参考这些指南。

规则按优先级分类

优先级 / 类别 / 影响 / 前缀: 1 / List Performance(列表性能)/ CRITICAL / list-performance- 2 / Animation(动画)/ HIGH / animation- 3 / Navigation(导航)/ HIGH / navigation- 4 / UI Patterns(UI 模式)/ HIGH / ui- 5 / State Management(状态管理)/ MEDIUM / react-state- 6 / Rendering(渲染)/ MEDIUM / rendering- 7 / Monorepo / MEDIUM / monorepo- 8 / Configuration(配置)/ 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 navigator

  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 - 原生依赖保留在 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