React Native 技能集 是做什麼的?
React Native 和 Expo 應用程式的全面最佳實踐。包含跨多個類別的規則,涵蓋效能、動畫、UI 模式以及平台特定的優化。
何時套用
請在以下情況參考這些指南:
- 建構 React Native 或 Expo 應用程式
- 優化列表和滾動效能
- 使用 Reanimated 實作動畫
- 處理圖片和多媒體
- 設定原生模組或字型
- 使用原生依賴項結構化單體倉庫專案
依優先級分類的規則類別
| 優先級 | 類別 | 影響力 | 前綴 |
|---|---|---|---|
| 1 | 列表效能 | 關鍵 | list-performance- |
| 2 | 動畫 | 高 | animation- |
| 3 | 導航 | 高 | navigation- |
| 4 | UI 模式 | 高 | ui- |
| 5 | 狀態管理 | 中 | react-state- |
| 6 | 渲染 | 中 | rendering- |
| 7 | 單體倉庫 | 中 | monorepo- |
| 8 | 設定 | 低 | fonts-, imports- |
快速參考
1. 列表效能(關鍵)
list-performance-virtualize- 對大型列表使用 FlashListlist-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. 動畫(高)
animation-gpu-properties- 僅對 transform 和 opacity 屬性進行動畫animation-derived-value- 對計算後的動畫使用 useDerivedValueanimation-gesture-detector-press- 使用 Gesture.Tap 代替 Pressable
3. 導航(高)
navigation-native-navigators- 使用原生堆疊和原生標籤頁導航器,而非 JS 導航器
4. UI 模式(高)
ui-expo-image- 所有圖片使用 expo-imageui-image-gallery- 圖片燈箱使用 Galeriaui-pressable- 使用 Pressable 代替 TouchableOpacityui-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. 狀態管理(中)
react-state-minimize- 最小化狀態訂閱react-state-dispatcher- 對回呼使用分發器模式react-state-fallback- 首次渲染時顯示備用內容react-compiler-destructure-functions- 為 React Compiler 解構函式react-compiler-reanimated-shared-values- 使用編譯器處理共享值
6. 渲染(中)
rendering-text-in-text-component- 將文字包裹在 Text 元件中rendering-no-falsy-and- 避免使用 falsy && 進行條件渲染
7. 單體倉庫(中)
monorepo-native-deps-in-app- 將原生依賴項保留在應用程式套件中monorepo-single-dependency-versions- 跨套件使用單一版本
8. 設定(低)
fonts-config-plugin- 使用設定外掛處理自訂字型imports-design-system-folder- 組織設計系統匯入js-hoist-intl- 提升 Intl 物件的建立
如何使用
閱讀個別規則檔案以取得詳細說明和程式碼範例:
rules/list-performance-virtualize.md
rules/animation-gpu-properties.md
每個規則檔案包含:
- 簡要說明為何重要
- 錯誤的程式碼範例與說明
- 正確的程式碼範例與說明
- 額外的上下文和參考資料
完整彙編文件
如需所有規則展開的完整指南:AGENTS.md