react-native-elements
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCommunity React Native Elements Best Practices
社区版React Native Elements最佳实践
Comprehensive best practices guide for React Native Elements applications. Contains 45 rules across 8 categories, prioritized by impact to guide component usage, theming, and performance optimization.
这是一份针对React Native Elements应用的综合最佳实践指南,包含8个类别共45条规则,按影响程度排序,指导组件使用、主题定制和性能优化。
When to Apply
适用场景
Reference these guidelines when:
- Setting up React Native Elements in a new project
- Configuring ThemeProvider and createTheme
- Building lists with ListItem components
- Implementing form inputs with Input and SearchBar
- Optimizing FlatList performance with RNE components
- Reviewing code using React Native Elements
在以下场景中可参考本指南:
- 在新项目中搭建React Native Elements环境
- 配置ThemeProvider与createTheme
- 使用ListItem组件构建列表
- 用Input和SearchBar实现表单输入
- 结合RNE组件优化FlatList性能
- 审查使用React Native Elements的代码
Rule Categories by Priority
按优先级划分的规则类别
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Import & Setup | CRITICAL | |
| 2 | Theme Architecture | CRITICAL | |
| 3 | Component Selection | HIGH | |
| 4 | List Performance | HIGH | |
| 5 | Props & Configuration | MEDIUM-HIGH | |
| 6 | Styling Patterns | MEDIUM | |
| 7 | Callbacks & Events | MEDIUM | |
| 8 | Advanced Patterns | LOW | |
| 优先级 | 类别 | 影响程度 | 前缀 |
|---|---|---|---|
| 1 | 导入与搭建 | 关键 | |
| 2 | 主题架构 | 关键 | |
| 3 | 组件选择 | 高 | |
| 4 | 列表性能 | 高 | |
| 5 | 属性与配置 | 中高 | |
| 6 | 样式模式 | 中 | |
| 7 | 回调与事件 | 中 | |
| 8 | 高级模式 | 低 | |
Quick Reference
快速参考
1. Import & Setup (CRITICAL)
1. 导入与搭建(关键)
- - Wrap app with ThemeProvider for consistent theming
setup-themeprovider - - Use @rneui/themed vs @rneui/base correctly
setup-imports - - Type-safe theme configuration with createTheme
setup-createtheme - - Enable proper tree-shaking for bundle size
setup-tree-shaking - - Configure SafeAreaProvider for notched devices
setup-safe-area
- - 用ThemeProvider包裹应用以实现一致的主题效果
setup-themeprovider - - 正确区分使用@rneui/themed与@rneui/base
setup-imports - - 用createTheme实现类型安全的主题配置
setup-createtheme - - 启用正确的Tree Shaking以减小包体积
setup-tree-shaking - - 为带刘海的设备配置SafeAreaProvider
setup-safe-area
2. Theme Architecture (CRITICAL)
2. 主题架构(关键)
- - Access theme reactively with useTheme
theme-usetheme-hook - - Configure light/dark mode with createTheme
theme-dark-mode - - Set component defaults in theme
theme-component-defaults - - Runtime theme updates without remount
theme-updatetheme - - Sync with system color scheme
theme-color-scheme - - Extend theme with custom colors safely
theme-custom-colors
- - 用useTheme钩子响应式访问主题
theme-usetheme-hook - - 用createTheme配置明暗模式
theme-dark-mode - - 在主题中设置组件默认值
theme-component-defaults - - 在运行时更新主题而无需重新挂载组件
theme-updatetheme - - 与系统配色方案同步
theme-color-scheme - - 安全地扩展主题自定义颜色
theme-custom-colors
3. Component Selection (HIGH)
3. 组件选择(高)
- - Use ListItem for list rows
comp-listitem-over-view - - Use Input for form fields
comp-input-over-textinput - - Platform-specific SearchBar variants
comp-searchbar-platform - - Use Button type prop for variants
comp-button-type - - Choose Icon type wisely for bundle size
comp-icon-source - - Use Avatar for profile images
comp-avatar-vs-image
- - 用ListItem实现列表行
comp-listitem-over-view - - 用Input实现表单字段
comp-input-over-textinput - - 适配平台的SearchBar变体
comp-searchbar-platform - - 用Button的type属性选择变体
comp-button-type - - 合理选择Icon类型以减小包体积
comp-icon-source - - 用Avatar实现头像图片
comp-avatar-vs-image
4. List Performance (HIGH)
4. 列表性能(高)
- - Memoize ListItem in FlatList
list-memo-items - - Always provide keyExtractor
list-keyextractor - - Use getItemLayout for fixed heights
list-getitemlayout - - Extract renderItem with useCallback
list-renderitem-callback - - Configure windowSize for memory balance
list-windowsize - - Use FlatList over ScrollView
list-virtualized - - Configure removeClippedSubviews carefully
list-removeClipped
- - 在FlatList中对ListItem进行记忆化处理
list-memo-items - - 始终提供keyExtractor
list-keyextractor - - 对固定高度的列表使用getItemLayout
list-getitemlayout - - 用useCallback提取renderItem
list-renderitem-callback - - 配置windowSize以平衡内存占用
list-windowsize - - 用FlatList替代ScrollView
list-virtualized - - 谨慎配置removeClippedSubviews
list-removeClipped
5. Props & Configuration (MEDIUM-HIGH)
5. 属性与配置(中高)
- - Use loading prop for async operations
props-loading-state - - Configure disabledStyle for feedback
props-disabled-styling - - Use errorMessage for validation
props-input-validation - - Configure Icon props correctly
props-icon-configuration - - Show loading state in SearchBar
props-searchbar-loading - - Use color prop for semantic colors
props-button-color
- - 用loading属性处理异步操作
props-loading-state - - 配置disabledStyle以提供反馈
props-disabled-styling - - 用errorMessage实现验证
props-input-validation - - 正确配置Icon属性
props-icon-configuration - - 在SearchBar中显示加载状态
props-searchbar-loading - - 用color属性设置语义化颜色
props-button-color
6. Styling Patterns (MEDIUM)
6. 样式模式(中)
- - Use StyleSheet.create over inline objects
style-stylesheet - - Use containerStyle for wrappers
style-containerStyle - - Memoize dynamic styles
style-usememo-dynamic - - Use theme colors over hardcoded values
style-theme-colors - - Prefer component-specific style props
style-component-props
- - 用StyleSheet.create替代内联样式对象
style-stylesheet - - 用containerStyle实现容器样式
style-containerStyle - - 对动态样式进行记忆化处理
style-usememo-dynamic - - 使用主题颜色而非硬编码值
style-theme-colors - - 优先使用组件专属的样式属性
style-component-props
7. Callbacks & Events (MEDIUM)
7. 回调与事件(中)
- - Wrap handlers in useCallback
event-usecallback - - Debounce SearchBar onChangeText
event-debounce-search - - Pass item data correctly
event-listitem-onpress - - Avoid anonymous functions in renders
event-avoid-anonymous - - Configure Input handlers efficiently
event-input-handlers
- - 用useCallback包裹事件处理器
event-usecallback - - 对SearchBar的onChangeText进行防抖处理
event-debounce-search - - 正确传递item数据
event-listitem-onpress - - 在渲染中避免使用匿名函数
event-avoid-anonymous - - 高效配置Input事件处理器
event-input-handlers
8. Advanced Patterns (LOW)
8. 高级模式(低)
- - Wrap RNE components correctly
adv-custom-component - - Handle platform-specific props
adv-platform-specific - - Use makeStyles for theme-aware styles
adv-makeStyles - - Choose Overlay vs Modal correctly
adv-overlay-modal - - Configure Avatar ImageComponent for caching
adv-image-component
- - 正确封装RNE组件
adv-custom-component - - 处理平台专属属性
adv-platform-specific - - 用makeStyles实现主题感知的样式
adv-makeStyles - - 正确选择Overlay与Modal
adv-overlay-modal - - 配置Avatar的ImageComponent以实现缓存
adv-image-component
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
阅读单个参考文件以获取详细说明和代码示例:
- 章节定义 - 类别结构与影响等级
- 规则模板 - 添加新规则的模板
Reference Files
参考文件
| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |
| 文件 | 描述 |
|---|---|
| references/_sections.md | 类别定义与排序规则 |
| assets/templates/_template.md | 新规则模板 |
| metadata.json | 版本与参考信息 |