expo
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCommunity Expo React Native Best Practices
社区版 Expo React Native 最佳实践
Comprehensive performance optimization guide for Expo React Native applications. Contains 54 rules across 9 categories, prioritized by impact to guide automated refactoring and code generation.
Expo React Native 应用的全面性能优化指南。包含9个类别共54条规则,按影响程度优先级排序,可指导自动化重构与代码生成。
When to Apply
适用场景
Reference these guidelines when:
- Writing new Expo React Native components
- Optimizing app startup and Time to Interactive
- Implementing lists, images, or animations
- Reducing bundle size and memory usage
- Reviewing code for mobile performance issues
在以下场景中参考本指南:
- 编写新的 Expo React Native 组件
- 优化应用启动速度与交互就绪时间
- 实现列表、图片或动画功能
- 减小包体积与内存占用
- 评审代码以排查移动端性能问题
Rule Categories by Priority
按优先级划分的规则类别
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Launch Time Optimization | CRITICAL | |
| 2 | Bundle Size Optimization | CRITICAL | |
| 3 | List Virtualization | HIGH | |
| 4 | Image Optimization | HIGH | |
| 5 | Data Fetching Patterns | HIGH | |
| 6 | Navigation Performance | MEDIUM-HIGH | |
| 7 | Re-render Prevention | MEDIUM | |
| 8 | Animation Performance | MEDIUM | |
| 9 | Memory Management | LOW-MEDIUM | |
| 优先级 | 类别 | 影响程度 | 前缀 |
|---|---|---|---|
| 1 | 启动时间优化 | 关键 | |
| 2 | 包体积优化 | 关键 | |
| 3 | 列表虚拟化 | 高 | |
| 4 | 图片优化 | 高 | |
| 5 | 数据获取模式 | 高 | |
| 6 | 导航性能 | 中高 | |
| 7 | 重渲染预防 | 中 | |
| 8 | 动画性能 | 中 | |
| 9 | 内存管理 | 中低 | |
Quick Reference
快速参考
1. Launch Time Optimization (CRITICAL)
1. 启动时间优化(关键)
- - Control splash screen visibility during asset loading
launch-splash-screen-control - - Preload fonts and images during splash
launch-preload-critical-assets - - Use Hermes engine for faster startup
launch-hermes-engine - - Defer non-critical initialization
launch-defer-non-critical - - Enable New Architecture for synchronous native communication
launch-new-architecture - - Minimize imports in root App component
launch-minimize-root-imports
- - 在资源加载期间控制启动屏的可见性
launch-splash-screen-control - - 在启动屏显示阶段预加载字体与图片
launch-preload-critical-assets - - 使用 Hermes 引擎加快启动速度
launch-hermes-engine - - 延迟非关键代码的初始化
launch-defer-non-critical - - 启用新架构以实现同步原生通信
launch-new-architecture - - 减少根 App 组件中的导入项
launch-minimize-root-imports
2. Bundle Size Optimization (CRITICAL)
2. 包体积优化(关键)
- - Avoid barrel file imports
bundle-avoid-barrel-files - - Analyze bundle size before release
bundle-analyze-size - - Remove unused dependencies
bundle-remove-unused-dependencies - - Generate architecture-specific APKs
bundle-split-by-architecture - - Enable ProGuard for Android release builds
bundle-enable-proguard - - Subset custom fonts to used characters
bundle-optimize-fonts - - Use lightweight library alternatives
bundle-use-lightweight-alternatives
- - 避免使用桶文件导入
bundle-avoid-barrel-files - - 发布前分析包体积
bundle-analyze-size - - 移除未使用的依赖
bundle-remove-unused-dependencies - - 生成针对特定架构的 APK
bundle-split-by-architecture - - 为 Android 发布版本启用 ProGuard
bundle-enable-proguard - - 对自定义字体进行子集化,仅保留使用到的字符
bundle-optimize-fonts - - 使用轻量级的替代库
bundle-use-lightweight-alternatives
3. List Virtualization (HIGH)
3. 列表虚拟化(高)
- - Use FlashList instead of FlatList
list-use-flashlist - - Provide accurate estimatedItemSize
list-provide-estimated-size - - Avoid inline functions in renderItem
list-avoid-inline-functions - - Provide getItemLayout for fixed-height items
list-provide-getitemlayout - - Avoid key prop inside FlashList items
list-avoid-key-prop - - Configure list batch rendering
list-batch-rendering - - Memoize list item components
list-memoize-item-components
- - 使用 FlashList 替代 FlatList
list-use-flashlist - - 提供准确的 estimatedItemSize
list-provide-estimated-size - - 避免在 renderItem 中使用内联函数
list-avoid-inline-functions - - 为固定高度的列表项提供 getItemLayout
list-provide-getitemlayout - - 避免在 FlashList 列表项内部使用 key 属性
list-avoid-key-prop - - 配置列表的批量渲染
list-batch-rendering - - 对列表项组件进行 memo 缓存
list-memoize-item-components
4. Image Optimization (HIGH)
4. 图片优化(高)
- - Use expo-image instead of React Native Image
image-use-expo-image - - Resize images to display size
image-resize-to-display-size - - Use WebP format for smaller file sizes
image-use-webp-format - - Use BlurHash or ThumbHash placeholders
image-use-placeholders - - Preload critical above-the-fold images
image-preload-critical - - Lazy load off-screen images
image-lazy-load-offscreen
- - 使用 expo-image 替代 React Native Image
image-use-expo-image - - 将图片调整为显示尺寸
image-resize-to-display-size - - 使用 WebP 格式以减小文件大小
image-use-webp-format - - 使用 BlurHash 或 ThumbHash 作为占位图
image-use-placeholders - - 预加载首屏关键图片
image-preload-critical - - 懒加载屏幕外的图片
image-lazy-load-offscreen
5. Data Fetching Patterns (HIGH)
5. 数据获取模式(高)
- - Fetch independent data in parallel
data-parallel-fetching - - Deduplicate concurrent requests
data-request-deduplication - - Abort requests on component unmount
data-abort-requests - - Implement efficient pagination strategies
data-pagination - - Use appropriate caching strategies
data-cache-strategies - - Apply optimistic updates for responsiveness
data-optimistic-updates
- - 并行获取独立数据
data-parallel-fetching - - 去重并发请求
data-request-deduplication - - 在组件卸载时终止请求
data-abort-requests - - 实现高效的分页策略
data-pagination - - 使用合适的缓存策略
data-cache-strategies - - 应用乐观更新以提升响应速度
data-optimistic-updates
6. Navigation Performance (MEDIUM-HIGH)
6. 导航性能(中高)
- - Use native stack navigator
nav-use-native-stack - - Unmount inactive tab screens
nav-unmount-inactive-screens - - Prefetch data before navigation
nav-prefetch-screen-data - - Optimize screen options
nav-optimize-screen-options - - Avoid deeply nested navigators
nav-avoid-deep-nesting
- - 使用原生栈导航器
nav-use-native-stack - - 卸载非活跃的标签页屏幕
nav-unmount-inactive-screens - - 在导航前预加载屏幕数据
nav-prefetch-screen-data - - 优化屏幕配置选项
nav-optimize-screen-options - - 避免深度嵌套的导航器
nav-avoid-deep-nesting
7. Re-render Prevention (MEDIUM)
7. 重渲染预防(中)
- - Memoize expensive components with React.memo
rerender-use-memo-components - - Stabilize callbacks with useCallback
rerender-use-callback - - Memoize expensive computations with useMemo
rerender-use-memo-values - - Avoid overusing Context for frequent updates
rerender-avoid-context-overuse - - Split components to isolate updating state
rerender-split-component-state - - Enable React Compiler for automatic memoization
rerender-use-react-compiler - - Avoid anonymous components in JSX
rerender-avoid-anonymous-components
- - 使用 React.memo 缓存性能开销大的组件
rerender-use-memo-components - - 使用 useCallback 稳定回调函数
rerender-use-callback - - 使用 useMemo 缓存开销大的计算结果
rerender-use-memo-values - - 避免过度使用 Context 处理频繁更新
rerender-avoid-context-overuse - - 拆分组件以隔离更新状态
rerender-split-component-state - - 启用 React Compiler 实现自动缓存
rerender-use-react-compiler - - 避免在 JSX 中使用匿名组件
rerender-avoid-anonymous-components
8. Animation Performance (MEDIUM)
8. 动画性能(中)
- - Use Reanimated for UI thread animations
anim-use-reanimated - - Enable useNativeDriver for Animated API
anim-use-native-driver - - Prefer transform over layout animations
anim-avoid-layout-animation - - Use Gesture Handler with Reanimated
anim-gesture-handler-integration - - Defer heavy work during animations
anim-interaction-manager
- - 使用 Reanimated 实现 UI 线程动画
anim-use-reanimated - - 为 Animated API 启用 useNativeDriver
anim-use-native-driver - - 优先使用 transform 而非布局动画
anim-avoid-layout-animation - - 将 Gesture Handler 与 Reanimated 集成
anim-gesture-handler-integration - - 在动画执行期间延迟繁重任务
anim-interaction-manager
9. Memory Management (LOW-MEDIUM)
9. 内存管理(中低)
- - Clean up subscriptions and timers
mem-cleanup-useeffect - - Abort fetch requests on unmount
mem-abort-fetch-requests - - Avoid closure-based memory leaks
mem-avoid-closure-leaks - - Release heavy resources when not needed
mem-release-heavy-resources - - Profile memory usage with development tools
mem-profile-with-tools
- - 清理订阅与定时器
mem-cleanup-useeffect - - 在组件卸载时终止请求
mem-abort-fetch-requests - - 避免闭包导致的内存泄漏
mem-avoid-closure-leaks - - 在不需要时释放重型资源
mem-release-heavy-resources - - 使用开发工具分析内存占用
mem-profile-with-tools
How to Use
使用方法
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
- Example rules: launch-splash-screen-control, list-use-flashlist
阅读单个参考文件以获取详细说明与代码示例:
- 章节定义 - 类别结构与影响程度说明
- 规则模板 - 添加新规则的模板
- 示例规则:launch-splash-screen-control, list-use-flashlist
Full Compiled Document
完整编译文档
For the complete guide with all rules expanded:
AGENTS.md包含所有规则详细内容的完整指南:
AGENTS.md