Skip to content

参考

基于 callstackincubator/agent-skills 官方 skills 的 README 与各 skills/*/SKILL.mdreferences/ 编写。

速查

  • 仓库callstackincubator/agent-skills(MIT,Callstack 官方)
  • /plugin marketplace add callstackincubator/agent-skills/plugin install react-native-best-practices@callstack-agent-skills
  • 核心技能 react-native-best-practicesjs-*(9)+ native-*(10)+ bundle-*(9)= 29 篇优化指南,标 Impact
  • 每技能结构SKILL.md(必)+ 可选 references/ + 可选 agents/openai.yaml(Codex UI)
  • 工作流:Measure → Optimize → Re-measure → Validate
  • 格式:遵 agentskills.io;源自《The Ultimate Guide to React Native Optimization》

技能清单

技能触发/何时用覆盖
react-native-best-practices卡顿/掉帧/启动慢/内存/包体JS/Native/Bundling 三大类 29 篇,按 Impact 分级
assess-react-native-migration原生 App 要不要迁 RN只读决策:brownfield/greenfield/checkpoint + ROI,一次一问
create-react-native-library建库/本地原生模块create-react-native-library(Builder Bob),Turbo Module/Fabric
github-actionsCI 云构建移动产物iOS 模拟器 .app.tar.gz / Android 模拟器 .apkgh/REST 下载
upgrading-react-native升 RN 版本升级工作流:模板、依赖、常见坑
react-native-brownfield-migration原生 App 里嵌 RN@callstack/react-native-brownfield 分阶段集成
githubPR/评审/分支GitHub 工作流模式

react-native-best-practices:优先级分级

优先级类别Impact前缀
1FPS 与重渲染CRITICALjs-*
2Bundle 体积CRITICALbundle-*
3TTI 优化HIGHnative-* bundle-*
4原生性能HIGHnative-*
5内存管理MEDIUM-HIGHjs-* native-*
6动画MEDIUMjs-*

JavaScript / React(js-*,9 篇)

文件Impact要点
js-lists-flatlist-flashlistCRITICALScrollView → FlatList/FlashList/Legend List;FlashList v2 弃用 estimatedItemSizegetItemType 按类型回收
js-measure-fpsHIGHFPS 监测与测量
js-atomic-stateHIGHJotai/Zustand 细粒度订阅,selector 减重渲染
js-concurrent-reactHIGHuseDeferredValueuseTransition
js-react-compilerHIGH自动 memo;react-compiler-healthcheck"use no memo" 退出
js-bottomsheetHIGHBottom sheet 重渲染优化
js-uncontrolled-componentsHIGH非受控 TextInput 减重渲染
js-profile-reactMEDIUMagent-device react-devtools profiling
js-memory-leaksMEDIUMDevTools Memory 抓 JS 泄漏(useEffect cleanup)

Native iOS/Android(native-*,10 篇)

文件Impact要点
native-android-16kb-alignmentCRITICALAndroid 15+ 上架必须;第三方 .so zipalign -c -P 16
native-turbo-modulesHIGH后台线程(DispatchQueue/Coroutines),异步优于同步,C++ 走 JSI
native-sdks-over-polyfillsHIGH原生 crypto/导航替 JS polyfill;Intl 按 Hermes 支持精简
native-measure-ttiHIGHreact-native-performance marker,只测冷启动
native-threading-modelHIGHTurbo Module 线程模型
native-profilingMEDIUMXcode Instruments / Android Studio Profiler
native-platform-setupMEDIUMiOS/Android 工具链
native-view-flatteningMEDIUM视图层级扁平化
native-memory-patternsMEDIUMC++/Swift/Kotlin 内存
native-memory-leaksMEDIUM原生侧内存泄漏

Bundling(bundle-*,9 篇)

文件Impact要点
bundle-barrel-exportsCRITICAL避免 barrel 导入,直接路径导入;eslint-plugin-no-barrel-files
bundle-analyze-jsCRITICALsource-map-explorer 可视化 JS 包
bundle-tree-shakingHIGHExpo SDK 52+ 实验性摇树(ESM/生产);Platform 摇树
bundle-analyze-appHIGHEmerge Tools / Ruler 拆解 App 体积
bundle-r8-androidHIGHminifyEnabled true 减 20~33% 包体
bundle-hermes-mmapHIGHRN ≤0.78 关 bundle 压缩启用 Hermes mmap(TTI -16%)
bundle-native-assetsHIGHAsset catalog 配置
bundle-library-sizeMEDIUM评估依赖体积
bundle-code-splittingMEDIUM远程 chunk 加载安全护栏(可信 HTTPS、绑发布)

问题 → 起手技能

问题从这里开始
App 卡/掉帧js-measure-fpsjs-profile-react
重渲染太多js-profile-reactjs-react-compiler
启动慢(TTI)native-measure-ttibundle-analyze-js
App 体积大bundle-analyze-appbundle-r8-android
内存增长js-memory-leaksnative-memory-leaks
动画掉帧js-animations-reanimated
列表滚动卡js-lists-flatlist-flashlist
TextInput 卡js-uncontrolled-components
原生模块慢native-turbo-modulesnative-threading-model
原生库对齐问题native-android-16kb-alignment

关键版本护栏

事项护栏
FlashListv1 用 estimatedItemSizev2 弃用(新架构,自动测算),别报缺失
React CompilerRN 0.76+ / Expo SDK 52+;先跑 react-compiler-healthcheck
Hermes bundle 压缩RN ≤0.78 手动关;RN 0.79+ 默认非压缩
Android 16KB 对齐RN 0.79+ 官方二进制已对齐,第三方 .so 仍要查
tree shaking仅生产构建、须 ESM、库声明 sideEffects
Platform 摇树必须直接 import { Platform } from 'react-native'

安装命令

bash
# Claude Code
/plugin marketplace add callstackincubator/agent-skills
/plugin install react-native-best-practices@callstack-agent-skills

# Codex
$skill-installer install react-native-best-practices from callstackincubator/agent-skills

# Gemini CLI
gemini skills install https://github.com/callstackincubator/agent-skills.git

# 手动克隆(任意 agent 裸读 skills/)
git clone https://github.com/callstackincubator/agent-skills.git

目录结构

agent-skills/
├── .claude-plugin/marketplace.json   # Claude Code 插件定义
├── .agents/plugins/marketplace.json  # Codex 插件定义
├── plugins/                          # 可装 Codex 插件包
└── skills/
    ├── react-native-best-practices/
    │   ├── SKILL.md                  # 主文件 + 速查
    │   └── references/               # js-* / native-* / bundle-* + images/
    ├── assess-react-native-migration/
    ├── create-react-native-library/
    ├── github-actions/
    ├── upgrading-react-native/
    ├── react-native-brownfield-migration/
    └── github/

许可与出处

  • 许可:MIT
  • 出品Callstack(React / React Native 专家团队)
  • 来源:《The Ultimate Guide to React Native Optimization》电子书
  • 代码示例仓callstack/optimization-best-practices(React Compiler、原生 SDK vs Web polyfill、R8 示例)

资源链接