uniwind-best-practices
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUniwind Best Practices
Uniwind 最佳实践
Comprehensive performance optimization and best practices guide for Uniwind - the fastest Tailwind CSS bindings for React Native. Contains 45+ rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
这是针对Uniwind(React Native最快的Tailwind CSS绑定库)的全面性能优化与最佳实践指南。指南包含8个类别下的45+条规则,按影响优先级排序,可指导自动化重构与代码生成。
When to Apply
适用场景
Reference these guidelines when:
- Setting up Uniwind in a new React Native project
- Configuring Metro plugin and CSS entry points
- Building theme systems with CSS variables
- Integrating third-party components with className support
- Creating responsive layouts for mobile and tablet
- Optimizing styling performance
- Migrating from NativeWind to Uniwind
在以下场景中,可参考本指南:
- 在新的React Native项目中配置Uniwind
- 配置Metro插件与CSS入口文件
- 使用CSS变量构建主题系统
- 集成支持className的第三方组件
- 为手机与平板创建响应式布局
- 优化样式性能
- 从NativeWind迁移至Uniwind
Rule Categories by Priority
按优先级划分的规则类别
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Build-Time Configuration | CRITICAL | |
| 2 | Theme Architecture | CRITICAL | |
| 3 | Component Integration | HIGH | |
| 4 | Responsive Design | HIGH | |
| 5 | Performance Optimization | MEDIUM-HIGH | |
| 6 | Platform Patterns | MEDIUM | |
| 7 | State & Interaction | MEDIUM | |
| 8 | Migration & Compatibility | LOW-MEDIUM | |
| 优先级 | 类别 | 影响级别 | 前缀 |
|---|---|---|---|
| 1 | 构建时配置 | 关键 | |
| 2 | 主题架构 | 关键 | |
| 3 | 组件集成 | 高 | |
| 4 | 响应式设计 | 高 | |
| 5 | 性能优化 | 中高 | |
| 6 | 平台适配模式 | 中 | |
| 7 | 状态与交互 | 中 | |
| 8 | 迁移与兼容性 | 中低 | |
Quick Reference
快速参考
1. Build-Time Configuration (CRITICAL)
1. 构建时配置(关键)
- - Configure Metro Plugin with Required Options
build-metro-config - - Place CSS Entry File in App Root Directory
build-css-entry - - Configure TypeScript Definition File Location
build-typescript-types - - Restart Metro After Configuration Changes
build-restart-metro - - Enable Debug Mode During Development
build-debug-mode - - Configure rem Base Value for Design System Consistency
build-rem-polyfill
- - 配置Metro插件的必填选项
build-metro-config - - 将CSS入口文件放置在应用根目录
build-css-entry - - 配置TypeScript定义文件的存放位置
build-typescript-types - - 配置变更后重启Metro服务
build-restart-metro - - 开发阶段启用调试模式
build-debug-mode - - 配置rem基准值以保证设计系统一致性
build-rem-polyfill
2. Theme Architecture (CRITICAL)
2. 主题架构(关键)
- - Define Theme Variables with @theme Directive
theme-css-variables - - Use @variant Blocks for Theme Definitions
theme-variant-blocks - - Define Identical Variables Across All Themes
theme-consistent-variables - - Register Custom Themes in Metro Config
theme-custom-registration - - Use OKLCH Color Space for Perceptual Uniformity
theme-oklch-colors - - Use light-dark() Function for Adaptive Colors
theme-light-dark-function - - Remove ThemeProvider Wrapper from App
theme-no-provider
- - 使用@theme指令定义主题变量
theme-css-variables - - 使用@variant块定义主题
theme-variant-blocks - - 在所有主题中定义一致的变量
theme-consistent-variables - - 在Metro配置中注册自定义主题
theme-custom-registration - - 使用OKLCH色彩空间实现感知一致性
theme-oklch-colors - - 使用light-dark()函数实现自适应色彩
theme-light-dark-function - - 移除应用中的ThemeProvider包装器
theme-no-provider
3. Component Integration (HIGH)
3. 组件集成(高)
- - Use withUniwind for Third-Party Components
comp-with-uniwind - - Define Wrapped Components at Module Level
comp-module-level - - Use Custom Prop Mappings for Non-Style Props
comp-prop-mapping - - Use accent-* Classes for Color Prop Extraction
comp-accent-colors - - Reanimated Components Work Without withUniwind
comp-reanimated - - Use Custom CSS Classes for Complex Reusable Styles
comp-custom-css
- - 为第三方组件使用withUniwind
comp-with-uniwind - - 在模块级别定义包装后的组件
comp-module-level - - 为非样式属性使用自定义属性映射
comp-prop-mapping - - 使用accent-*类提取色彩属性
comp-accent-colors - - Reanimated组件无需withUniwind即可使用
comp-reanimated - - 为复杂可复用样式使用自定义CSS类
comp-custom-css
4. Responsive Design (HIGH)
4. 响应式设计(高)
- - Design Mobile-First with Progressive Enhancement
resp-mobile-first - - Limit Breakpoints to 3-5 for Maintainability
resp-limit-breakpoints - - Use hidden/flex for Responsive Visibility
resp-visibility-toggle - - Define Custom Breakpoints with Semantic Names
resp-custom-breakpoints - - Scale Spacing and Typography Responsively
resp-responsive-spacing
- - 采用移动优先设计,逐步增强功能
resp-mobile-first - - 将断点数量限制在3-5个以提升可维护性
resp-limit-breakpoints - - 使用hidden/flex实现响应式可见性切换
resp-visibility-toggle - - 使用语义化名称定义自定义断点
resp-custom-breakpoints - - 响应式调整间距与排版
resp-responsive-spacing
5. Performance Optimization (MEDIUM-HIGH)
5. 性能优化(中高)
- - Use Complete Static Class Names for Build-Time Resolution
perf-static-classnames - - Use useResolveClassNames Sparingly
perf-use-resolve-sparingly - - Memoize Variant Style Objects
perf-memoize-variants - - Use tailwind-merge for Class Deduplication
perf-tailwind-merge - - Prefer className Over Inline style Prop
perf-avoid-inline-styles - - Combine className and style Prop Correctly
perf-combine-styles
- - 使用完整的静态类名以实现构建时解析
perf-static-classnames - - 谨慎使用useResolveClassNames
perf-use-resolve-sparingly - - 对变体样式对象进行记忆化处理
perf-memoize-variants - - 使用tailwind-merge实现类名去重
perf-tailwind-merge - - 优先使用className而非内联style属性
perf-avoid-inline-styles - - 正确组合className与style属性
perf-combine-styles
6. Platform Patterns (MEDIUM)
6. 平台适配模式(中)
- - Use Platform Selectors for iOS/Android Differences
plat-ios-android-selectors - - Use react-native-safe-area-context for Safe Areas
plat-safe-area-context - - Understand Yoga Layout Engine Differences
plat-yoga-layout - - Use web: Selector for Cross-Platform Apps
plat-web-selector - - Configure Font Families Without Fallbacks
plat-font-families
- - 使用平台选择器适配iOS/Android差异
plat-ios-android-selectors - - 使用react-native-safe-area-context处理安全区域
plat-safe-area-context - - 了解Yoga布局引擎的差异
plat-yoga-layout - - 为跨平台应用使用web:选择器
plat-web-selector - - 配置字体族时不使用回退选项
plat-font-families
7. State & Interaction (MEDIUM)
7. 状态与交互(中)
- - Use Pressable with active:/focus:/disabled: States
state-pressable-states - - Use Data Selectors for Component State Styling
state-data-selectors - - Avoid hover: on Native - Use active: Instead
state-no-hover - - Use Group Variants for Parent-Child Styling (WIP)
state-group-variants - - Use dark: Variant for Dark Mode Styles
state-dark-mode
- - 结合Pressable使用active:/focus:/disabled:状态
state-pressable-states - - 使用数据选择器实现组件状态样式
state-data-selectors - - 原生平台避免使用hover:,改用active:
state-no-hover - - 使用组变体实现父子组件样式(开发中)
state-group-variants - - 使用dark:变体实现暗黑模式样式
state-dark-mode
8. Migration & Compatibility (LOW-MEDIUM)
8. 迁移与兼容性(中低)
- - Follow NativeWind Migration Checklist
compat-nativewind-migration - - Use Tailwind 4 CSS-First Configuration
compat-tailwind-4-syntax - - Account for Different rem Default Values
compat-rem-default - - Replace cssInterop with withUniwind
compat-cssinterop-replacement - - Replace *-safe Classes with Safe Area Context
compat-safe-area-changes
- - 遵循NativeWind迁移检查清单
compat-nativewind-migration - - 使用Tailwind 4的CSS优先配置方式
compat-tailwind-4-syntax - - 注意不同环境下rem默认值的差异
compat-rem-default - - 用withUniwind替代cssInterop
compat-cssinterop-replacement - - 用安全区域上下文替代*-safe类
compat-safe-area-changes
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 |
|---|---|
| AGENTS.md | Complete compiled guide with all rules |
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |
| 文件 | 描述 |
|---|---|
| AGENTS.md | 包含所有规则的完整编译指南 |
| references/_sections.md | 类别定义与排序说明 |
| assets/templates/_template.md | 新规则模板 |
| metadata.json | 版本与参考信息 |