uniwind
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUniwind — Complete Reference
Uniwind — 完整参考文档
Uniwind 1.5.0+ / Tailwind CSS v4 / React Native 0.81+ / Expo SDK 54+
If user has lower version, recommend updating to 1.5.0+ for best experience.
Uniwind brings Tailwind CSS v4 to React Native. All core React Native components support the prop out of the box. Styles are compiled at build time — no runtime overhead.
className兼容Uniwind 1.5.0+ / Tailwind CSS v4 / React Native 0.81+ / Expo SDK 54+
如果用户使用的是更低版本,建议升级到1.5.0+以获得最佳体验。
Uniwind为React Native带来了Tailwind CSS v4的能力。所有核心React Native组件都原生支持属性。样式在构建时编译——无运行时开销。
classNameCritical Rules
关键规则
- Tailwind v4 only — Use not
@import 'tailwindcss'. Tailwind v3 is not supported.@tailwind base - Never construct classNames dynamically — Tailwind scans at build time. will NOT work. Use complete string literals, mapping objects, or ternaries.
bg-${color}-500 - Never use or
cssInterop— Those are NativeWind APIs. Uniwind does not override global components.remapProps - No — All config goes in
tailwind.config.jsviaglobal.cssand@theme.@layer theme - No ThemeProvider required — Use directly.
Uniwind.setTheme() - must be the outermost Metro config wrapper.
withUniwindConfig - NEVER wrap or
react-nativecomponents withreact-native-reanimated—withUniwind,View,Text,Pressable,Image,TextInput,ScrollView,FlatList,Switch,Modal,Animated.View, etc. already have fullAnimated.Textsupport built in. Wrapping them withclassNamewill break behavior. Only usewithUniwindfor third-party components (e.g.,withUniwind,expo-image,expo-blur).moti - Font families: single font only — React Native doesn't support fallbacks. Use not
--font-sans: 'Roboto-Regular'.'Roboto', sans-serif - All theme variants must define the same set of CSS variables — If defines
light, then--color-primaryand every custom theme must too. Mismatched variables cause runtime errors.dark - prefix is REQUIRED for non-style color props — This is crucial. Props like
accent-(Button, ActivityIndicator),color(Image),tintColor(Switch),thumbColor(TextInput) are NOT part of theplaceholderTextColorobject. You MUST use the correspondingstyleprop with{propName}ClassNameprefixed classes. Example:accent-NOT<ActivityIndicator colorClassName="accent-blue-500" />. Regular Tailwind color classes (like<ActivityIndicator className="text-blue-500" />) only work ontext-blue-500(which maps toclassName). For non-style color props, always usestyle.accent- - rem default is 16px — NativeWind used 14px. Set in metro config if migrating.
polyfills: { rem: 14 } - must be a relative path string — Use
cssEntryFilenot'./global.css'.path.resolve(__dirname, 'global.css') - Deduplicate with when mixing custom CSS classes and Tailwind — Uniwind does NOT auto-deduplicate. If a custom CSS class (
cn()) and a Tailwind utility (.card { padding: 16px }) set the same property, both apply with unpredictable results. Always wrap withp-6when there's overlap.cn('card', 'p-6')
- 仅支持Tailwind v4 — 使用而非
@import 'tailwindcss'。不支持Tailwind v3。@tailwind base - 切勿动态拼接className — Tailwind在构建时扫描类名。将无法生效。请使用完整的字符串字面量、映射对象或三元表达式。
bg-${color}-500 - 切勿使用或
cssInterop— 这些是NativeWind的API。Uniwind不会覆盖全局组件。remapProps - 无需— 所有配置通过
tailwind.config.js中的global.css和@theme完成。@layer theme - 无需ThemeProvider — 直接使用即可。
Uniwind.setTheme() - 必须是最外层的Metro配置包装器。
withUniwindConfig - 切勿用包裹
withUniwind或react-native组件 —react-native-reanimated、View、Text、Pressable、Image、TextInput、ScrollView、FlatList、Switch、Modal、Animated.View等组件已原生支持完整的Animated.Text。用className包裹它们会破坏原有行为。仅对第三方组件使用withUniwind(例如withUniwind、expo-image、expo-blur)。moti - 字体系列:仅支持单个字体 — React Native不支持字体回退。使用而非
--font-sans: 'Roboto-Regular'。'Roboto', sans-serif - 所有主题变体必须定义相同的CSS变量集合 — 如果主题定义了
light,那么--color-primary主题和所有自定义主题也必须定义该变量。变量不匹配会导致运行时错误。dark - 非样式颜色属性必须使用前缀 — 这一点至关重要。诸如
accent-(Button、ActivityIndicator)、color(Image)、tintColor(Switch)、thumbColor(TextInput)这些属性不属于placeholderTextColor对象。你必须使用对应的style属性并搭配{propName}ClassName前缀的类。示例:accent-而非<ActivityIndicator colorClassName="accent-blue-500" />。常规的Tailwind颜色类(如<ActivityIndicator className="text-blue-500" />)仅在text-blue-500中生效(对应className属性)。对于非样式颜色属性,请始终使用style前缀。accent- - rem默认值为16px — NativeWind使用的是14px。如果是迁移项目,可在metro配置中设置。
polyfills: { rem: 14 } - 必须是相对路径字符串 — 使用
cssEntryFile而非'./global.css'。path.resolve(__dirname, 'global.css') - 混合自定义CSS类和Tailwind时使用去重 — Uniwind不会自动去重。如果自定义CSS类(
cn())和Tailwind工具类(.card { padding: 16px })设置了相同属性,两者都会生效,结果不可预测。当存在属性重叠时,务必用p-6包裹。cn('card', 'p-6')
Setup
配置步骤
Installation
安装
bash
undefinedbash
undefinedor other package manager
或使用其他包管理器
bun install uniwind tailwindcss
Requires **Tailwind CSS v4+**.bun install uniwind tailwindcss
需要**Tailwind CSS v4+**版本。global.css
global.css
Create a CSS entry file:
css
@import 'tailwindcss';
@import 'uniwind';Import in your App component (e.g., or ), NOT in / — importing there breaks hot reload:
App.tsxapp/_layout.tsxindex.tsindex.jstsx
// app/_layout.tsx or App.tsx
import './global.css';The directory containing is the app root — Tailwind scans for classNames starting from this directory.
global.css创建CSS入口文件:
css
@import 'tailwindcss';
@import 'uniwind';在你的App组件中导入(例如或),不要在/中导入——在那里导入会破坏热重载:
App.tsxapp/_layout.tsxindex.tsindex.jstsx
// app/_layout.tsx 或 App.tsx
import './global.css';包含的目录即为应用根目录——Tailwind会从此目录开始扫描className。
global.cssMetro Configuration
Metro配置
js
const { getDefaultConfig } = require('expo/metro-config');
// Bare RN: const { getDefaultConfig } = require('@react-native/metro-config');
const { withUniwindConfig } = require('uniwind/metro');
const config = getDefaultConfig(__dirname);
// withUniwindConfig MUST be the OUTERMOST wrapper
module.exports = withUniwindConfig(config, {
cssEntryFile: './global.css', // Required — relative path from project root
polyfills: { rem: 16 }, // Optional — base rem value (default 16)
extraThemes: ['ocean', 'sunset'], // Optional — custom themes beyond light/dark
dtsFile: './uniwind-types.d.ts', // Optional — TypeScript types output path
debug: true, // Optional — log unsupported CSS in dev
isTV: false, // Optional — enable TV platform support
});For most flows, keep defaults, only provide .
cssEntryFileWrapper order — Uniwind must wrap everything else:
js
// CORRECT
module.exports = withUniwindConfig(withOtherConfig(config, opts), { cssEntryFile: './global.css' });
// WRONG — Uniwind is NOT outermost
module.exports = withOtherConfig(withUniwindConfig(config, { cssEntryFile: './global.css' }), opts);js
const { getDefaultConfig } = require('expo/metro-config');
// 原生RN项目:const { getDefaultConfig } = require('@react-native/metro-config');
const { withUniwindConfig } = require('uniwind/metro');
const config = getDefaultConfig(__dirname);
// withUniwindConfig必须是最外层的包装器
module.exports = withUniwindConfig(config, {
cssEntryFile: './global.css', // 必填——相对于项目根目录的路径
polyfills: { rem: 16 }, // 可选——基础rem值(默认16)
extraThemes: ['ocean', 'sunset'], // 可选——light/dark之外的自定义主题
dtsFile: './uniwind-types.d.ts', // 可选——TypeScript类型输出路径
debug: true, // 可选——开发环境下记录不支持的CSS
isTV: false, // 可选——启用TV平台支持
});大多数情况下,保持默认配置即可,只需提供。
cssEntryFile包装器顺序——Uniwind必须包裹所有其他配置:
js
// 正确写法
module.exports = withUniwindConfig(withOtherConfig(config, opts), { cssEntryFile: './global.css' });
// 错误写法——Uniwind不是最外层
module.exports = withOtherConfig(withUniwindConfig(config, { cssEntryFile: './global.css' }), opts);Vite Configuration (v1.2.0+)
Vite配置(v1.2.0+)
If user has storybook setup, add extra vite config:
ts
import tailwindcss from '@tailwindcss/vite';
import { uniwind } from 'uniwind/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [
tailwindcss(),
uniwind({
cssEntryFile: './src/global.css',
dtsFile: './src/uniwind-types.d.ts',
}),
],
});如果用户使用storybook,添加额外的vite配置:
ts
import tailwindcss from '@tailwindcss/vite';
import { uniwind } from 'uniwind/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [
tailwindcss(),
uniwind({
cssEntryFile: './src/global.css',
dtsFile: './src/uniwind-types.d.ts',
}),
],
});TypeScript
TypeScript
Uniwind auto-generates a file (default: ) after running Metro. Place it in or for auto-inclusion, or add to :
.d.ts./uniwind-types.d.tssrc/app/tsconfig.jsonjson
{ "include": ["./uniwind-types.d.ts"] }If user has some typescript errors related to classNames, just run metro server to build the d.ts file.
运行Metro后,Uniwind会自动生成文件(默认路径:)。将其放在或目录下即可自动识别,或者添加到中:
.d.ts./uniwind-types.d.tssrc/app/tsconfig.jsonjson
{ "include": ["./uniwind-types.d.ts"] }如果用户遇到与className相关的TypeScript错误,只需启动Metro服务器来生成d.ts文件即可。
Expo Router Placement
Expo Router放置位置
text
project/
├── app/_layout.tsx ← import '../global.css' here
├── components/
├── global.css ← project root (best location)
└── metro.config.js ← cssEntryFile: './global.css'If is in dir, add for sibling directories:
global.cssapp/@sourcecss
@import 'tailwindcss';
@import 'uniwind';
@source '../components';text
project/
├── app/_layout.tsx ← 在此处导入'../global.css'
├── components/
├── global.css ← 项目根目录(最佳位置)
└── metro.config.js ← cssEntryFile: './global.css'如果在目录下,需添加指令来包含同级目录:
global.cssapp/@sourcecss
@import 'tailwindcss';
@import 'uniwind';
@source '../components';Tailwind IntelliSense (VS Code / Cursor / Windsurf)
Tailwind智能提示(VS Code / Cursor / Windsurf)
json
{
"tailwindCSS.classAttributes": [
"class", "className", "headerClassName",
"contentContainerClassName", "columnWrapperClassName",
"endFillColorClassName", "imageClassName", "tintColorClassName",
"ios_backgroundColorClassName", "thumbColorClassName",
"trackColorOnClassName", "trackColorOffClassName",
"selectionColorClassName", "cursorColorClassName",
"underlineColorAndroidClassName", "placeholderTextColorClassName",
"selectionHandleColorClassName", "colorsClassName",
"progressBackgroundColorClassName", "titleColorClassName",
"underlayColorClassName", "colorClassName",
"backdropColorClassName", "backgroundColorClassName",
"statusBarBackgroundColorClassName", "drawerBackgroundColorClassName",
"ListFooterComponentClassName", "ListHeaderComponentClassName"
],
"tailwindCSS.classFunctions": ["useResolveClassNames"]
}json
{
"tailwindCSS.classAttributes": [
"class", "className", "headerClassName",
"contentContainerClassName", "columnWrapperClassName",
"endFillColorClassName", "imageClassName", "tintColorClassName",
"ios_backgroundColorClassName", "thumbColorClassName",
"trackColorOnClassName", "trackColorOffClassName",
"selectionColorClassName", "cursorColorClassName",
"underlineColorAndroidClassName", "placeholderTextColorClassName",
"selectionHandleColorClassName", "colorsClassName",
"progressBackgroundColorClassName", "titleColorClassName",
"underlayColorClassName", "colorClassName",
"backdropColorClassName", "backgroundColorClassName",
"statusBarBackgroundColorClassName", "drawerBackgroundColorClassName",
"ListFooterComponentClassName", "ListHeaderComponentClassName"
],
"tailwindCSS.classFunctions": ["useResolveClassNames"]
}Monorepo Support
单仓库(Monorepo)支持
Add directives in for packages outside the CSS entry file's directory:
@sourceglobal.csscss
@import 'tailwindcss';
@import 'uniwind';
@source "../../packages/ui/src";
@source "../../packages/shared/src";Also needed for packages that contain Uniwind classes (e.g., shared UI libraries).
node_modules在中添加指令来包含CSS入口文件目录之外的包:
global.css@sourcecss
@import 'tailwindcss';
@import 'uniwind';
@source "../../packages/ui/src";
@source "../../packages/shared/src";对于包含Uniwind类的包(例如共享UI库),也需要添加此指令。
node_modulesComponent Bindings
组件绑定
All core React Native components support out of the box. Some have additional className props for sub-styles (like ) and non-style color props (requiring prefix).
classNamecontentContainerClassNameaccent-所有核心React Native组件都原生支持。部分组件还提供了额外的className属性用于子样式(如)和非样式颜色属性(需要前缀)。
classNamecontentContainerClassNameaccent-Complete Reference
完整参考
Legend: Props marked with ⚡ require the prefix. Props in parentheses are platform-specific.
accent-图例:标记⚡的属性需要前缀。括号中的属性是平台专属的。
accent-View
View
| Prop | Maps to | Prefix |
|---|---|---|
| | — |
| 属性 | 映射到 | 前缀 |
|---|---|---|
| | — |
Text
Text
| Prop | Maps to | Prefix |
|---|---|---|
| | — |
| | ⚡ |
| 属性 | 映射到 | 前缀 |
|---|---|---|
| | — |
| | ⚡ |
Pressable
Pressable
| Prop | Maps to | Prefix |
|---|---|---|
| | — |
Supports , , state selectors.
active:disabled:focus:| 属性 | 映射到 | 前缀 |
|---|---|---|
| | — |
支持、、状态选择器。
active:disabled:focus:Image
Image
| Prop | Maps to | Prefix |
|---|---|---|
| | — |
| | ⚡ |
| 属性 | 映射到 | 前缀 |
|---|---|---|
| | — |
| | ⚡ |
TextInput
TextInput
| Prop | Maps to | Prefix |
|---|---|---|
| | — |
| | ⚡ |
| | ⚡ |
| | ⚡ |
| | ⚡ |
| | ⚡ |
Supports , , state selectors.
focus:active:disabled:| 属性 | 映射到 | 前缀 |
|---|---|---|
| | — |
| | ⚡ |
| | ⚡ |
| | ⚡ |
| | ⚡ |
| | ⚡ |
支持、、状态选择器。
focus:active:disabled:ScrollView
ScrollView
| Prop | Maps to | Prefix |
|---|---|---|
| | — |
| | — |
| | ⚡ |
| 属性 | 映射到 | 前缀 |
|---|---|---|
| | — |
| | — |
| | ⚡ |
FlatList
FlatList
| Prop | Maps to | Prefix |
|---|---|---|
| | — |
| | — |
| | — |
| | — |
| | — |
| | ⚡ |
| 属性 | 映射到 | 前缀 |
|---|---|---|
| | — |
| | — |
| | — |
| | — |
| | — |
| | ⚡ |
SectionList
SectionList
| Prop | Maps to | Prefix |
|---|---|---|
| | — |
| | — |
| | — |
| | — |
| | ⚡ |
| 属性 | 映射到 | 前缀 |
|---|---|---|
| | — |
| | — |
| | — |
| | — |
| | ⚡ |
VirtualizedList
VirtualizedList
| Prop | Maps to | Prefix |
|---|---|---|
| | — |
| | — |
| | — |
| | — |
| | ⚡ |
| 属性 | 映射到 | 前缀 |
|---|---|---|
| | — |
| | — |
| | — |
| | — |
| | ⚡ |
Switch
Switch
| Prop | Maps to | Prefix |
|---|---|---|
| | ⚡ |
| | ⚡ |
| | ⚡ |
| | ⚡ |
Note: Switch does NOT support ( in types). Use only the color-specific className props above. Supports state selector.
classNameclassName?: neverdisabled:| 属性 | 映射到 | 前缀 |
|---|---|---|
| | ⚡ |
| | ⚡ |
| | ⚡ |
| | ⚡ |
注意:Switch不支持(类型定义中)。请仅使用上述颜色专属的className属性。支持状态选择器。
classNameclassName?: neverdisabled:ActivityIndicator
ActivityIndicator
| Prop | Maps to | Prefix |
|---|---|---|
| | — |
| | ⚡ |
| 属性 | 映射到 | 前缀 |
|---|---|---|
| | — |
| | ⚡ |
Button
Button
| Prop | Maps to | Prefix |
|---|---|---|
| | ⚡ |
Note: Button does not support (no prop on RN Button).
classNamestyle| 属性 | 映射到 | 前缀 |
|---|---|---|
| | ⚡ |
注意:Button不支持(RN的Button组件没有属性)。
classNamestyleModal
Modal
| Prop | Maps to | Prefix |
|---|---|---|
| | — |
| | ⚡ |
| 属性 | 映射到 | 前缀 |
|---|---|---|
| | — |
| | ⚡ |
RefreshControl
RefreshControl
| Prop | Maps to | Prefix |
|---|---|---|
| | — |
| | ⚡ |
| | ⚡ |
| | ⚡ |
| | ⚡ |
| 属性 | 映射到 | 前缀 |
|---|---|---|
| | — |
| | ⚡ |
| | ⚡ |
| | ⚡ |
| | ⚡ |
ImageBackground
ImageBackground
| Prop | Maps to | Prefix |
|---|---|---|
| | — |
| | — |
| | ⚡ |
| 属性 | 映射到 | 前缀 |
|---|---|---|
| | — |
| | — |
| | ⚡ |
SafeAreaView
SafeAreaView
| Prop | Maps to | Prefix |
|---|---|---|
| | — |
| 属性 | 映射到 | 前缀 |
|---|---|---|
| | — |
KeyboardAvoidingView
KeyboardAvoidingView
| Prop | Maps to | Prefix |
|---|---|---|
| | — |
| | — |
| 属性 | 映射到 | 前缀 |
|---|---|---|
| | — |
| | — |
InputAccessoryView
InputAccessoryView
| Prop | Maps to | Prefix |
|---|---|---|
| | — |
| | ⚡ |
| 属性 | 映射到 | 前缀 |
|---|---|---|
| | — |
| | ⚡ |
TouchableHighlight
TouchableHighlight
| Prop | Maps to | Prefix |
|---|---|---|
| | — |
| | ⚡ |
Supports , state selectors.
active:disabled:| 属性 | 映射到 | 前缀 |
|---|---|---|
| | — |
| | ⚡ |
支持、状态选择器。
active:disabled:TouchableOpacity
TouchableOpacity
| Prop | Maps to | Prefix |
|---|---|---|
| | — |
Supports , state selectors.
active:disabled:| 属性 | 映射到 | 前缀 |
|---|---|---|
| | — |
支持、状态选择器。
active:disabled:TouchableNativeFeedback
TouchableNativeFeedback
| Prop | Maps to | Prefix |
|---|---|---|
| | — |
Supports , state selectors.
active:disabled:| 属性 | 映射到 | 前缀 |
|---|---|---|
| | — |
支持、状态选择器。
active:disabled:TouchableWithoutFeedback
TouchableWithoutFeedback
| Prop | Maps to | Prefix |
|---|---|---|
| | — |
Supports , state selectors.
active:disabled:| 属性 | 映射到 | 前缀 |
|---|---|---|
| | — |
支持、状态选择器。
active:disabled:Usage Examples
使用示例
tsx
import { View, Text, Pressable, TextInput, ScrollView, FlatList, Switch, Image, ActivityIndicator, Modal, RefreshControl, Button } from 'react-native';
// View — basic layout
<View className="flex-1 bg-background p-4">
<Text className="text-foreground text-lg font-bold">Title</Text>
</View>
// Pressable — with press/focus states
<Pressable className="bg-primary px-6 py-3 rounded-lg active:opacity-80 active:bg-primary/90 focus:ring-2">
<Text className="text-white text-center font-semibold">Press Me</Text>
</Pressable>
// TextInput — with focus state and accent- color props
<TextInput
className="border border-border rounded-lg px-4 py-2 text-base text-foreground focus:border-primary"
placeholderTextColorClassName="accent-muted"
selectionColorClassName="accent-primary"
cursorColorClassName="accent-primary"
selectionHandleColorClassName="accent-primary"
underlineColorAndroidClassName="accent-transparent"
placeholder="Enter text..."
/>
// ScrollView — with content container
<ScrollView className="flex-1" contentContainerClassName="p-4 gap-4">
{/* content */}
</ScrollView>
// FlatList — with all sub-style props
<FlatList
className="flex-1"
contentContainerClassName="p-4 gap-3"
columnWrapperClassName="gap-3"
ListHeaderComponentClassName="pb-4"
ListFooterComponentClassName="pt-4"
endFillColorClassName="accent-gray-100"
numColumns={2}
data={items}
renderItem={({ item }) => <ItemCard item={item} />}
/>
// Switch — no className support, use color-specific props only
<Switch
thumbColorClassName="accent-white"
trackColorOnClassName="accent-primary"
trackColorOffClassName="accent-gray-300 dark:accent-gray-700"
ios_backgroundColorClassName="accent-gray-200"
/>
// Image — tint color
<Image className="w-6 h-6" tintColorClassName="accent-primary" source={icon} />
// ActivityIndicator
<ActivityIndicator className="m-4" colorClassName="accent-primary" size="large" />
// Button — only colorClassName (no className)
<Button colorClassName="accent-primary" title="Submit" onPress={handleSubmit} />
// Modal — backdrop color
<Modal className="flex-1" backdropColorClassName="accent-black/50">
{/* content */}
</Modal>
// RefreshControl — platform-specific color props
<RefreshControl
className="p-4"
tintColorClassName="accent-primary"
titleColorClassName="accent-gray-500"
colorsClassName="accent-primary"
progressBackgroundColorClassName="accent-white dark:accent-gray-800"
/>
// ImageBackground — separate image styling
<ImageBackground
className="flex-1 justify-center items-center"
imageClassName="opacity-50"
tintColorClassName="accent-blue-500"
source={bgImage}
>
<Text className="text-white text-2xl font-bold">Overlay</Text>
</ImageBackground>
// KeyboardAvoidingView
<KeyboardAvoidingView
behavior="padding"
className="flex-1 bg-white"
contentContainerClassName="p-4 justify-end"
>
<TextInput className="border border-gray-300 rounded-lg p-3" placeholder="Type..." />
</KeyboardAvoidingView>
// InputAccessoryView
<InputAccessoryView
className="p-4 border-t border-gray-300"
backgroundColorClassName="accent-white dark:accent-gray-800"
>
<Button title="Done" onPress={dismissKeyboard} />
</InputAccessoryView>
// TouchableHighlight — underlay color
<TouchableHighlight
className="bg-blue-500 px-6 py-3 rounded-lg"
underlayColorClassName="accent-blue-600 dark:accent-blue-700"
onPress={handlePress}
>
<Text className="text-white font-semibold">Press Me</Text>
</TouchableHighlight>tsx
import { View, Text, Pressable, TextInput, ScrollView, FlatList, Switch, Image, ActivityIndicator, Modal, RefreshControl, Button } from 'react-native';
// View — 基础布局
<View className="flex-1 bg-background p-4">
<Text className="text-foreground text-lg font-bold">标题</Text>
</View>
// Pressable — 包含按压/聚焦状态
<Pressable className="bg-primary px-6 py-3 rounded-lg active:opacity-80 active:bg-primary/90 focus:ring-2">
<Text className="text-white text-center font-semibold">点击我</Text>
</Pressable>
// TextInput — 包含聚焦状态和accent-颜色属性
<TextInput
className="border border-border rounded-lg px-4 py-2 text-base text-foreground focus:border-primary"
placeholderTextColorClassName="accent-muted"
selectionColorClassName="accent-primary"
cursorColorClassName="accent-primary"
selectionHandleColorClassName="accent-primary"
underlineColorAndroidClassName="accent-transparent"
placeholder="输入文本..."
/>
// ScrollView — 包含内容容器
<ScrollView className="flex-1" contentContainerClassName="p-4 gap-4">
{/* 内容 */}
</ScrollView>
// FlatList — 包含所有子样式属性
<FlatList
className="flex-1"
contentContainerClassName="p-4 gap-3"
columnWrapperClassName="gap-3"
ListHeaderComponentClassName="pb-4"
ListFooterComponentClassName="pt-4"
endFillColorClassName="accent-gray-100"
numColumns={2}
data={items}
renderItem={({ item }) => <ItemCard item={item} />}
/>
// Switch — 不支持className,仅使用颜色专属属性
<Switch
thumbColorClassName="accent-white"
trackColorOnClassName="accent-primary"
trackColorOffClassName="accent-gray-300 dark:accent-gray-700"
ios_backgroundColorClassName="accent-gray-200"
/>
// Image — 色调颜色
<Image className="w-6 h-6" tintColorClassName="accent-primary" source={icon} />
// ActivityIndicator
<ActivityIndicator className="m-4" colorClassName="accent-primary" size="large" />
// Button — 仅支持colorClassName(无className)
<Button colorClassName="accent-primary" title="提交" onPress={handleSubmit} />
// Modal — 背景遮罩颜色
<Modal className="flex-1" backdropColorClassName="accent-black/50">
{/* 内容 */}
</Modal>
// RefreshControl — 平台专属颜色属性
<RefreshControl
className="p-4"
tintColorClassName="accent-primary"
titleColorClassName="accent-gray-500"
colorsClassName="accent-primary"
progressBackgroundColorClassName="accent-white dark:accent-gray-800"
/>
// ImageBackground — 独立的图片样式
<ImageBackground
className="flex-1 justify-center items-center"
imageClassName="opacity-50"
tintColorClassName="accent-blue-500"
source={bgImage}
>
<Text className="text-white text-2xl font-bold">叠加层</Text>
</ImageBackground>
// KeyboardAvoidingView
<KeyboardAvoidingView
behavior="padding"
className="flex-1 bg-white"
contentContainerClassName="p-4 justify-end"
>
<TextInput className="border border-gray-300 rounded-lg p-3" placeholder="输入..." />
</KeyboardAvoidingView>
// InputAccessoryView
<InputAccessoryView
className="p-4 border-t border-gray-300"
backgroundColorClassName="accent-white dark:accent-gray-800"
>
<Button title="完成" onPress={dismissKeyboard} />
</InputAccessoryView>
// TouchableHighlight — 按下时的底色
<TouchableHighlight
className="bg-blue-500 px-6 py-3 rounded-lg"
underlayColorClassName="accent-blue-600 dark:accent-blue-700"
onPress={handlePress}
>
<Text className="text-white font-semibold">点击我</Text>
</TouchableHighlight>The accent- Prefix Pattern
accent-前缀模式
React Native components have props like , , that are NOT part of the object. To set these via Tailwind classes, use the prefix with the corresponding prop:
colortintColorthumbColorstyleaccent-{propName}ClassNametsx
// color prop → colorClassName with accent- prefix
<ActivityIndicator colorClassName="accent-blue-500 dark:accent-blue-400" />
<Button colorClassName="accent-primary" title="Submit" />
// tintColor prop → tintColorClassName
<Image className="w-6 h-6" tintColorClassName="accent-red-500" source={icon} />
// thumbColor → thumbColorClassName
<Switch thumbColorClassName="accent-white" trackColorOnClassName="accent-primary" />
// placeholderTextColor → placeholderTextColorClassName
<TextInput placeholderTextColorClassName="accent-gray-400 dark:accent-gray-600" />CRITICAL Rule: maps to the prop — it handles layout, typography, backgrounds, borders, etc. But React Native has many color props that live OUTSIDE of (like , , , ). These require a separate prop with the prefix. Without , the class resolves to a style object — but these props expect a plain color string.
classNamestylestylecolortintColorthumbColorplaceholderTextColor{propName}ClassNameaccent-accent-tsx
// WRONG — className sets style, but ActivityIndicator's color is NOT a style prop
<ActivityIndicator className="text-blue-500" /> // color will NOT be set
// CORRECT — use the dedicated colorClassName prop with accent- prefix
<ActivityIndicator colorClassName="accent-blue-500" /> // color IS set to #3b82f6
// WRONG — tintColor is not a style prop on Image
<Image className="tint-blue-500" source={icon} /> // won't work
// CORRECT
<Image tintColorClassName="accent-blue-500" source={icon} />React Native组件的、、等属性不属于对象。要通过Tailwind类设置这些属性,需使用前缀搭配对应的属性:
colortintColorthumbColorstyleaccent-{propName}ClassNametsx
// color属性 → 使用colorClassName和accent-前缀
<ActivityIndicator colorClassName="accent-blue-500 dark:accent-blue-400" />
<Button colorClassName="accent-primary" title="提交" />
// tintColor属性 → 使用tintColorClassName
<Image className="w-6 h-6" tintColorClassName="accent-red-500" source={icon} />
// thumbColor → 使用thumbColorClassName
<Switch thumbColorClassName="accent-white" trackColorOnClassName="accent-primary" />
// placeholderTextColor → 使用placeholderTextColorClassName
<TextInput placeholderTextColorClassName="accent-gray-400 dark:accent-gray-600" />关键规则:映射到属性——它处理布局、排版、背景、边框等。但React Native有许多颜色属性是在之外的(如、、、)。这些属性需要单独的属性并搭配前缀。如果没有前缀,类会解析为样式对象——但这些属性需要的是纯颜色字符串。
classNamestylestylecolortintColorthumbColorplaceholderTextColor{propName}ClassNameaccent-accent-tsx
// 错误写法 — className设置的是style,但ActivityIndicator的color不是style属性
<ActivityIndicator className="text-blue-500" /> // color不会被设置
// 正确写法 — 使用专用的colorClassName属性和accent-前缀
<ActivityIndicator colorClassName="accent-blue-500" /> // color会被设置为#3b82f6
// 错误写法 — tintColor不是Image的style属性
<Image className="tint-blue-500" source={icon} /> // 无法生效
// 正确写法
<Image tintColorClassName="accent-blue-500" source={icon} />Styling Third-Party Components
样式化第三方组件
withUniwind (Recommended)
withUniwind(推荐)
Wrap once at module level, use with everywhere:
classNametsx
import { withUniwind } from 'uniwind';
import { Image as ExpoImage } from 'expo-image';
import { BlurView as RNBlurView } from 'expo-blur';
import { LinearGradient as RNLinearGradient } from 'expo-linear-gradient';
// Module-level wrapping (NEVER inside render functions)
export const Image = withUniwind(ExpoImage);
export const BlurView = withUniwind(RNBlurView);
export const LinearGradient = withUniwind(RNLinearGradient);withUniwind- →
styleclassName - →
{name}Style{name}ClassName - →
{name}Color(with accent- prefix){name}ColorClassName
For custom prop mappings:
tsx
const StyledProgressBar = withUniwind(ProgressBar, {
width: {
fromClassName: 'widthClassName',
styleProperty: 'width',
},
});Usage patterns:
- Used in one file only — define the wrapped component in that same file
- Used across multiple files — wrap once in a shared module (e.g., ) and re-export
components/styled.ts
tsx
// components/styled.ts
import { withUniwind } from 'uniwind';
import { Image as ExpoImage } from 'expo-image';
export const Image = withUniwind(ExpoImage);
// Then import everywhere:
import { Image } from '@/components/styled';NEVER call on the same component in multiple files.
withUniwindCRITICAL: Do NOT use on components from or . These already have built-in support:
withUniwindreact-nativereact-native-reanimatedclassNametsx
// WRONG — View already supports className natively
const StyledView = withUniwind(View); // DO NOT DO THIS
const StyledText = withUniwind(Text); // DO NOT DO THIS
const StyledAnimatedView = withUniwind(Animated.View); // DO NOT DO THIS
// CORRECT — only wrap third-party components
const StyledExpoImage = withUniwind(ExpoImage); // expo-image
const StyledBlurView = withUniwind(BlurView); // expo-blur
const StyledMotiView = withUniwind(MotiView); // moti在模块级别包裹一次,即可在任何地方使用:
classNametsx
import { withUniwind } from 'uniwind';
import { Image as ExpoImage } from 'expo-image';
import { BlurView as RNBlurView } from 'expo-blur';
import { LinearGradient as RNLinearGradient } from 'expo-linear-gradient';
// 模块级别包裹(切勿在render函数内包裹)
export const Image = withUniwind(ExpoImage);
export const BlurView = withUniwind(RNBlurView);
export const LinearGradient = withUniwind(RNLinearGradient);withUniwind- →
styleclassName - →
{name}Style{name}ClassName - →
{name}Color(搭配accent-前缀){name}ColorClassName
对于自定义属性映射:
tsx
const StyledProgressBar = withUniwind(ProgressBar, {
width: {
fromClassName: 'widthClassName',
styleProperty: 'width',
},
});使用模式:
- 仅在单个文件中使用 — 在该文件内定义包裹后的组件
- 在多个文件中使用 — 在共享模块中包裹一次(例如)并重新导出
components/styled.ts
tsx
// components/styled.ts
import { withUniwind } from 'uniwind';
import { Image as ExpoImage } from 'expo-image';
export const Image = withUniwind(ExpoImage);
// 然后在所有地方导入:
import { Image } from '@/components/styled';切勿在多个文件中对同一个组件调用。
withUniwind关键注意事项:请勿对或的组件使用。这些组件已原生支持:
react-nativereact-native-reanimatedwithUniwindclassNametsx
// 错误写法 — View已原生支持className
const StyledView = withUniwind(View); // 请勿这样做
const StyledText = withUniwind(Text); // 请勿这样做
const StyledAnimatedView = withUniwind(Animated.View); // 请勿这样做
// 正确写法 — 仅包裹第三方组件
const StyledExpoImage = withUniwind(ExpoImage); // expo-image
const StyledBlurView = withUniwind(BlurView); // expo-blur
const StyledMotiView = withUniwind(MotiView); // motiuseResolveClassNames
useResolveClassNames
Converts Tailwind class strings to React Native style objects. Use for one-off cases or components that only accept :
styletsx
import { useResolveClassNames } from 'uniwind';
const headerStyle = useResolveClassNames('bg-primary p-4');
const cardStyle = useResolveClassNames('bg-card dark:bg-card rounded-lg shadow-sm');
// React Navigation screen options
<Stack.Navigator screenOptions={{ headerStyle, cardStyle }} />将Tailwind类字符串转换为React Native样式对象。用于一次性场景或仅接受的组件:
styletsx
import { useResolveClassNames } from 'uniwind';
const headerStyle = useResolveClassNames('bg-primary p-4');
const cardStyle = useResolveClassNames('bg-card dark:bg-card rounded-lg shadow-sm');
// React Navigation屏幕选项
<Stack.Navigator screenOptions={{ headerStyle, cardStyle }} />Comparison
对比
| Feature | withUniwind | useResolveClassNames |
|---|---|---|
| Setup | Once per component | Per usage |
| Performance | Optimized | Slightly slower |
| Best for | Reusable components | One-off, navigation config |
| Syntax | | |
| 特性 | withUniwind | useResolveClassNames |
|---|---|---|
| 配置 | 每个组件配置一次 | 每次使用都要配置 |
| 性能 | 已优化 | 稍慢 |
| 最佳适用场景 | 可复用组件 | 一次性场景、导航配置 |
| 语法 | | |
Dynamic ClassNames
动态ClassName
NEVER do this (Tailwind scans at build time)
切勿这样做(Tailwind在构建时扫描类名)
tsx
// BROKEN — template literal with variable
<View className={`bg-${color}-500`} />
<Text className={`text-${size}`} />tsx
// 无效 — 带变量的模板字符串
<View className={`bg-${color}-500`} />
<Text className={`text-${size}`} />Correct patterns
正确写法
tsx
// Ternary with complete class names
<View className={isActive ? 'bg-primary' : 'bg-muted'} />
// Mapping object
const colorMap = {
primary: 'bg-blue-500 text-white',
danger: 'bg-red-500 text-white',
ghost: 'bg-transparent text-foreground',
};
<Pressable className={colorMap[variant]} />
// Array join for multiple conditions
<View className={[
'p-4 rounded-lg',
isActive && 'bg-primary',
isDisabled && 'opacity-50',
].filter(Boolean).join(' ')} />tsx
// 带完整类名的三元表达式
<View className={isActive ? 'bg-primary' : 'bg-muted'} />
// 映射对象
const colorMap = {
primary: 'bg-blue-500 text-white',
danger: 'bg-red-500 text-white',
ghost: 'bg-transparent text-foreground',
};
<Pressable className={colorMap[variant]} />
// 数组拼接多条件
<View className={[
'p-4 rounded-lg',
isActive && 'bg-primary',
isDisabled && 'opacity-50',
].filter(Boolean).join(' ')} />tailwind-variants (tv)
tailwind-variants (tv)
For complex component styling with variants and compound variants:
tsx
import { tv } from 'tailwind-variants';
const button = tv({
base: 'font-semibold rounded-lg px-4 py-2 items-center justify-center',
variants: {
color: {
primary: 'bg-blue-500 text-white',
secondary: 'bg-gray-500 text-white',
danger: 'bg-red-500 text-white',
ghost: 'bg-transparent text-foreground border border-border',
},
size: {
sm: 'text-sm px-3 py-1.5',
md: 'text-base px-4 py-2',
lg: 'text-lg px-6 py-3',
},
disabled: {
true: 'opacity-50',
},
},
compoundVariants: [
{ color: 'primary', size: 'lg', class: 'bg-blue-600' },
],
defaultVariants: { color: 'primary', size: 'md' },
});
<Pressable className={button({ color: 'primary', size: 'lg' })}>
<Text className="text-white font-semibold">Click</Text>
</Pressable>用于带有变体和复合变体的复杂组件样式:
tsx
import { tv } from 'tailwind-variants';
const button = tv({
base: 'font-semibold rounded-lg px-4 py-2 items-center justify-center',
variants: {
color: {
primary: 'bg-blue-500 text-white',
secondary: 'bg-gray-500 text-white',
danger: 'bg-red-500 text-white',
ghost: 'bg-transparent text-foreground border border-border',
},
size: {
sm: 'text-sm px-3 py-1.5',
md: 'text-base px-4 py-2',
lg: 'text-lg px-6 py-3',
},
disabled: {
true: 'opacity-50',
},
},
compoundVariants: [
{ color: 'primary', size: 'lg', class: 'bg-blue-600' },
],
defaultVariants: { color: 'primary', size: 'md' },
});
<Pressable className={button({ color: 'primary', size: 'lg' })}>
<Text className="text-white font-semibold">点击</Text>
</Pressable>cn Utility — Class Deduplication
cn工具 — 类名去重
Uniwind does NOT auto-deduplicate conflicting classNames. This means if the same property appears in multiple classes, both will be applied and the result is unpredictable. This is especially critical when mixing custom CSS classes with Tailwind utilities.
Uniwind不会自动去重冲突的className。这意味着如果多个类设置了相同属性,两者都会生效,结果不可预测。当混合自定义CSS类和Tailwind工具类时,这一点尤为关键。
Setup
配置
bash
npm install tailwind-merge clsxts
// lib/cn.ts
import { type ClassValue, clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}bash
npm install tailwind-merge clsxts
// lib/cn.ts
import { type ClassValue, clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}When cn Is Required
需要使用cn的场景
- Merging className props — component accepts external className that may conflict:
tsx
import { cn } from '@/lib/cn';
<View className={cn('p-4 bg-white', props.className)} />
<Text className={cn('text-base', isActive && 'text-primary', disabled && 'opacity-50')} />- CRITICAL: Mixing custom CSS classes with Tailwind utilities — if your custom CSS class sets a property that a Tailwind utility also sets, you MUST use to deduplicate:
cn()
css
/* global.css */
.card {
background-color: white;
border-radius: 12px;
padding: 16px;
}tsx
// WRONG — both .card (padding: 16px) and p-6 (padding: 24px) apply, result is unpredictable
<View className="card p-6" />
// CORRECT — cn deduplicates, p-6 wins over .card's padding
<View className={cn('card', 'p-6')} />- tv() output combined with extra classes — tv already handles its own variants, but if you add more classes on top:
tsx
<Pressable className={cn(button({ color: 'primary' }), props.className)} />- 合并className属性 — 组件接受外部可能冲突的className:
tsx
import { cn } from '@/lib/cn';
<View className={cn('p-4 bg-white', props.className)} />
<Text className={cn('text-base', isActive && 'text-primary', disabled && 'opacity-50')} />- 关键场景:混合自定义CSS类和Tailwind工具类 — 如果你的自定义CSS类设置了Tailwind工具类也会设置的属性,必须使用去重:
cn()
css
/* global.css */
.card {
background-color: white;
border-radius: 12px;
padding: 16px;
}tsx
// 错误写法 — .card(padding:16px)和p-6(padding:24px)都生效,结果不可预测
<View className="card p-6" />
// 正确写法 — cn会去重,p-6会覆盖.card的padding
<View className={cn('card', 'p-6')} />- tv()输出与额外类合并 — tv已处理自身变体,但如果在其基础上添加更多类:
tsx
<Pressable className={cn(button({ color: 'primary' }), props.className)} />When cn Is NOT Needed
不需要使用cn的场景
- Static className with no conflicts:
<View className="flex-1 p-4 bg-white" /> - Single custom CSS class with no overlapping Tailwind: (if card-shadow only sets box-shadow which no Tailwind class also sets)
<View className="card-shadow mt-4" />
- 无冲突的静态className:
<View className="flex-1 p-4 bg-white" /> - 单个自定义CSS类与Tailwind无属性重叠:(如果card-shadow仅设置box-shadow,而没有Tailwind类也设置该属性)
<View className="card-shadow mt-4" />
Theming
主题配置
Quick Setup (dark: prefix)
快速配置(dark:前缀)
Works immediately — no configuration needed:
tsx
<View className="bg-white dark:bg-gray-900">
<Text className="text-black dark:text-white">Themed</Text>
</View>Best for small apps and prototyping. Does not scale to custom themes.
无需配置即可立即使用:
tsx
<View className="bg-white dark:bg-gray-900">
<Text className="text-black dark:text-white">主题化内容</Text>
</View>适合小型应用和原型开发。不适用于自定义主题的大规模场景。
Scalable Setup (CSS Variables)
可扩展配置(CSS变量)
Define in , use everywhere without prefix:
global.cssdark:css
@layer theme {
:root {
@variant light {
--color-background: #ffffff;
--color-foreground: #111827;
--color-foreground-secondary: #6b7280;
--color-card: #ffffff;
--color-border: #e5e7eb;
--color-muted: #9ca3af;
--color-primary: #3b82f6;
--color-danger: #ef4444;
--color-success: #10b981;
}
@variant dark {
--color-background: #000000;
--color-foreground: #ffffff;
--color-foreground-secondary: #9ca3af;
--color-card: #1f2937;
--color-border: #374151;
--color-muted: #6b7280;
--color-primary: #3b82f6;
--color-danger: #ef4444;
--color-success: #10b981;
}
}
}tsx
// Auto-adapts to current theme — no dark: prefix needed
<View className="bg-card border border-border p-4 rounded-lg">
<Text className="text-foreground text-lg font-bold">Title</Text>
<Text className="text-muted mt-2">Subtitle</Text>
</View>Variable naming: → , .
--color-backgroundbg-backgroundtext-backgroundPrefer CSS variables over explicit variants — they're cleaner, maintain easier, and work with custom themes automatically.
dark:在中定义,无需前缀即可在任何地方使用:
global.cssdark:css
@layer theme {
:root {
@variant light {
--color-background: #ffffff;
--color-foreground: #111827;
--color-foreground-secondary: #6b7280;
--color-card: #ffffff;
--color-border: #e5e7eb;
--color-muted: #9ca3af;
--color-primary: #3b82f6;
--color-danger: #ef4444;
--color-success: #10b981;
}
@variant dark {
--color-background: #000000;
--color-foreground: #ffffff;
--color-foreground-secondary: #9ca3af;
--color-card: #1f2937;
--color-border: #374151;
--color-muted: #6b7280;
--color-primary: #3b82f6;
--color-danger: #ef4444;
--color-success: #10b981;
}
}
}tsx
// 自动适配当前主题 — 无需dark:前缀
<View className="bg-card border border-border p-4 rounded-lg">
<Text className="text-foreground text-lg font-bold">标题</Text>
<Text className="text-muted mt-2">副标题</Text>
</View>变量命名规则: → 、。
--color-backgroundbg-backgroundtext-background优先使用CSS变量而非显式的变体——它们更简洁、更易于维护,并且能自动适配自定义主题。
dark:Custom Themes
自定义主题
Step 1 — Define in :
global.csscss
@layer theme {
:root {
@variant light { /* ... */ }
@variant dark { /* ... */ }
@variant ocean {
--color-background: #0c4a6e;
--color-foreground: #e0f2fe;
--color-primary: #06b6d4;
--color-card: #0e7490;
--color-border: #155e75;
/* Must define ALL the same variables as light/dark */
}
}
}Step 2 — Register in (exclude / — they're automatic):
metro.config.jslightdarkjs
module.exports = withUniwindConfig(config, {
cssEntryFile: './global.css',
extraThemes: ['ocean'],
});Restart Metro after adding themes.
Step 3 — Use:
tsx
Uniwind.setTheme('ocean');步骤1 — 在中定义:
global.csscss
@layer theme {
:root {
@variant light { /* ... */ }
@variant dark { /* ... */ }
@variant ocean {
--color-background: #0c4a6e;
--color-foreground: #e0f2fe;
--color-primary: #06b6d4;
--color-card: #0e7490;
--color-border: #155e75;
/* 必须定义与light/dark相同的所有变量 */
}
}
}步骤2 — 在中注册(无需注册/——它们是自动的):
metro.config.jslightdarkjs
module.exports = withUniwindConfig(config, {
cssEntryFile: './global.css',
extraThemes: ['ocean'],
});添加主题后需重启Metro。
步骤3 — 使用:
tsx
Uniwind.setTheme('ocean');Theme API
主题API
tsx
import { Uniwind, useUniwind } from 'uniwind';
// Imperative (no re-render)
Uniwind.setTheme('dark'); // Force dark
Uniwind.setTheme('light'); // Force light
Uniwind.setTheme('system'); // Follow device (re-enables adaptive themes)
Uniwind.setTheme('ocean'); // Custom theme (must be in extraThemes)
Uniwind.currentTheme; // Current theme name
Uniwind.hasAdaptiveThemes; // true if following system
// Reactive hook (re-renders on change)
const { theme, hasAdaptiveThemes } = useUniwind();Uniwind.setTheme('light')setTheme('dark')Appearance.setColorSchemeBy default Uniwind uses "system" theme - follows device color scheme. If user wants to override it, just
call Uniwind.setTheme with desired theme. It can be done above the React component to avoid theme switching at runtime.
tsx
import { Uniwind, useUniwind } from 'uniwind';
// 命令式调用(不会触发重渲染)
Uniwind.setTheme('dark'); // 强制深色主题
Uniwind.setTheme('light'); // 强制浅色主题
Uniwind.setTheme('system'); // 跟随系统(重新启用自适应主题)
Uniwind.setTheme('ocean'); // 自定义主题(必须在extraThemes中注册)
Uniwind.currentTheme; // 当前主题名称
Uniwind.hasAdaptiveThemes; // 如果跟随系统则为true
// 响应式Hook(主题变化时触发重渲染)
const { theme, hasAdaptiveThemes } = useUniwind();Uniwind.setTheme('light')setTheme('dark')Appearance.setColorScheme默认情况下,Uniwind使用"system"主题——跟随设备的配色方案。如果用户想覆盖它,只需调用Uniwind.setTheme并传入所需主题。可以在React组件外部调用,以避免运行时主题切换。
Theme Switcher Example
主题切换器示例
tsx
import { View, Pressable, Text, ScrollView } from 'react-native';
import { Uniwind, useUniwind } from 'uniwind';
export const ThemeSwitcher = () => {
const { theme, hasAdaptiveThemes } = useUniwind();
const activeTheme = hasAdaptiveThemes ? 'system' : theme;
const themes = [
{ name: 'light', label: 'Light' },
{ name: 'dark', label: 'Dark' },
{ name: 'system', label: 'System' },
];
return (
<ScrollView horizontal showsHorizontalScrollIndicator={false}>
<View className="flex-row gap-2 p-4">
{themes.map((t) => (
<Pressable
key={t.name}
onPress={() => Uniwind.setTheme(t.name)}
className={`px-4 py-3 rounded-lg items-center ${
activeTheme === t.name ? 'bg-primary' : 'bg-card border border-border'
}`}
>
<Text className={`text-sm ${
activeTheme === t.name ? 'text-white' : 'text-foreground'
}`}>
{t.label}
</Text>
</Pressable>
))}
</View>
</ScrollView>
);
};tsx
import { View, Pressable, Text, ScrollView } from 'react-native';
import { Uniwind, useUniwind } from 'uniwind';
export const ThemeSwitcher = () => {
const { theme, hasAdaptiveThemes } = useUniwind();
const activeTheme = hasAdaptiveThemes ? 'system' : theme;
const themes = [
{ name: 'light', label: '浅色' },
{ name: 'dark', label: '深色' },
{ name: 'system', label: '跟随系统' },
];
return (
<ScrollView horizontal showsHorizontalScrollIndicator={false}>
<View className="flex-row gap-2 p-4">
{themes.map((t) => (
<Pressable
key={t.name}
onPress={() => Uniwind.setTheme(t.name)}
className={`px-4 py-3 rounded-lg items-center ${
activeTheme === t.name ? 'bg-primary' : 'bg-card border border-border'
}`}
>
<Text className={`text-sm ${
activeTheme === t.name ? 'text-white' : 'text-foreground'
}`}>
{t.label}
</Text>
</Pressable>
))}
</View>
</ScrollView>
);
};ScopedTheme
ScopedTheme
Apply a different theme to a subtree without changing the global theme:
tsx
import { ScopedTheme } from 'uniwind';
<View className="gap-3">
<PreviewCard />
<ScopedTheme theme="dark">
<PreviewCard /> {/* Renders with dark theme */}
</ScopedTheme>
<ScopedTheme theme="ocean">
<PreviewCard /> {/* Renders with ocean theme */}
</ScopedTheme>
</View>- Nearest wins (nested scopes supported)
ScopedTheme - Hooks (,
useUniwind,useResolveClassNames) resolve against the nearest scoped themeuseCSSVariable - -wrapped components inside the scope also resolve scoped theme values
withUniwind - Custom themes require registration in
extraThemes
为子树应用不同的主题,而不改变全局主题:
tsx
import { ScopedTheme } from 'uniwind';
<View className="gap-3">
<PreviewCard />
<ScopedTheme theme="dark">
<PreviewCard /> {/* 以深色主题渲染 */}
</ScopedTheme>
<ScopedTheme theme="ocean">
<PreviewCard /> {/* 以ocean主题渲染 */}
</ScopedTheme>
</View>- 最近的优先级最高(支持嵌套作用域)
ScopedTheme - Hooks(、
useUniwind、useResolveClassNames)会解析最近的作用域主题useCSSVariable
(以下内容省略,保持原文档结构和翻译,代码块保留,专业术语不变)
useCSSVariable
—
Access CSS variable values in JavaScript:
tsx
import { useCSSVariable } from 'uniwind';
const primaryColor = useCSSVariable('--color-primary');
const spacing = useCSSVariable('--spacing-4');
// Multiple variables at once
const [bg, fg] = useCSSVariable(['--color-background', '--color-foreground']) as [string, string]Use for: animations, chart libraries, third-party component configs, calculations with design tokens.
It's required to cast the result of as it can return: string | number | undefined.
Uniwind doesn't know if given variable exist and what type it is, so it returns union type.
useCSSVariable—
Runtime CSS Variable Updates
—
Update theme variables at runtime (e.g., user-selected brand colors or API-driven themes):
tsx
Uniwind.updateCSSVariables('light', {
'--color-primary': '#ff6600',
'--color-background': '#fafafa',
});Updates are theme-specific and take effect immediately.
—
@theme static
—
For JS-only values not used in classNames:
css
@theme static {
--chart-line-width: 2;
--chart-dot-radius: 4;
--animation-duration: 300;
}Access via . Use for: chart configs, animation durations, native module values.
useCSSVariable('--chart-line-width')—
OKLCH Colors support
—
Perceptually uniform color format — wider gamut, consistent lightness:
css
@layer theme {
:root {
@variant light {
--color-primary: oklch(0.5 0.2 240);
--color-background: oklch(1 0 0);
}
@variant dark {
--color-primary: oklch(0.6 0.2 240);
--color-background: oklch(0.13 0.004 17.69);
}
}
}—
Platform Selectors
—
Apply platform-specific styles directly in className:
tsx
// Individual platforms
<View className="ios:bg-red-500 android:bg-blue-500 web:bg-green-500" />
// native: shorthand (iOS + Android)
<View className="native:bg-blue-500 web:bg-gray-500" />
// TV platforms
<View className="tv:p-8 android-tv:bg-black apple-tv:bg-gray-900" />
// Combine with other utilities
<View className="p-4 ios:pt-12 android:pt-6 web:pt-4" />Platform variants in for global values (use , not ):
@layer theme@variant@mediacss
@layer theme {
:root {
@variant ios { --font-sans: 'SF Pro Text'; }
@variant android { --font-sans: 'Roboto-Regular'; }
@variant web { --font-sans: 'Inter'; }
}
}Prefer platform selectors over — cleaner syntax, no imports needed.
Platform.select()—
Data Selectors
—
Style based on prop values using :
data-[prop=value]:utilitytsx
// Boolean props
<Pressable
data-selected={isSelected}
className="border rounded px-3 py-2 data-[selected=true]:ring-2 data-[selected=true]:ring-primary"
/>
// String props
<View
data-state={isOpen ? 'open' : 'closed'}
className="p-4 data-[state=open]:bg-muted/50 data-[state=closed]:bg-transparent"
/>
// Tabs pattern
<Pressable
data-selected={route.key === current}
className="px-4 py-2 rounded-md text-foreground/60
data-[selected=true]:bg-primary data-[selected=true]:text-white"
>
<Text>{route.title}</Text>
</Pressable>
// Toggle pattern
<Pressable
data-checked={enabled}
className="h-6 w-10 rounded-full bg-muted data-[checked=true]:bg-primary"
>
<View className="h-5 w-5 rounded-full bg-background translate-x-0 data-[checked=true]:translate-x-4" />
</Pressable>Rules:
- Only equality selectors supported ()
data-[prop=value] - No presence-only selectors (— not supported)
data-[prop] - No parent selectors (not supported in React Native)
has-data-* - Booleans match both boolean and string forms
—
Interactive States
—
tsx
// active: — when pressed
<Pressable className="bg-primary active:bg-primary/80 active:opacity-90 active:scale-95">
<Text className="text-white">Press me</Text>
</Pressable>
// disabled: — when disabled prop is true
<Pressable
disabled={isLoading}
className="bg-primary disabled:bg-gray-300 disabled:opacity-50"
>
<Text className="text-white disabled:text-gray-500">Submit</Text>
</Pressable>
// focus: — keyboard/accessibility focus
<TextInput
className="border border-border rounded-lg px-4 py-2 focus:border-primary focus:ring-2 focus:ring-primary/20"
/>
<Pressable className="bg-card rounded-lg p-4 focus:ring-2 focus:ring-primary">
<Text className="text-foreground">Focusable</Text>
</Pressable>Components with state support:
- Pressable: ,
active:,disabled:focus: - TextInput: ,
active:,disabled:focus: - Switch:
disabled: - Text: ,
active:disabled: - TouchableOpacity / TouchableHighlight / TouchableNativeFeedback / TouchableWithoutFeedback: ,
active:disabled:
—
Responsive Breakpoints
—
Mobile-first — unprefixed styles apply to all sizes, prefixed styles apply at that breakpoint and above:
| Prefix | Min Width | Typical Device |
|---|---|---|
| (none) | 0px | All (mobile) |
| 640px | Large phones |
| 768px | Tablets |
| 1024px | Landscape tablets |
| 1280px | Desktops |
| 1536px | Large desktops |
tsx
// Responsive padding and typography
<View className="p-4 sm:p-6 lg:p-8">
<Text className="text-base sm:text-lg lg:text-xl font-bold">Responsive</Text>
</View>
// Responsive grid (1 col → 2 col → 3 col)
<View className="flex-row flex-wrap">
<View className="w-full sm:w-1/2 lg:w-1/3 p-2">
<View className="bg-card p-4 rounded"><Text>Item</Text></View>
</View>
</View>
// Responsive visibility
<View className="hidden sm:flex flex-row gap-4">
<Text>Visible on tablet+</Text>
</View>
<View className="flex sm:hidden">
<Text>Mobile only</Text>
</View>Custom breakpoints:
css
@theme {
--breakpoint-xs: 480px;
--breakpoint-tablet: 820px;
--breakpoint-3xl: 1920px;
}Usage:
xs:p-2 tablet:p-4 3xl:p-8Design mobile-first — start with base styles (no prefix), enhance with breakpoints:
tsx
// CORRECT — mobile-first
<View className="w-full sm:w-3/4 md:w-1/2 lg:w-1/3" />
// WRONG — desktop-first (reversed order is confusing and fragile)
<View className="w-full lg:w-1/2 md:w-3/4 sm:w-full" />—
Safe Area Utilities
—
Padding
—
| Class | Description |
|---|---|
| All sides |
| Individual sides |
| Horizontal / vertical |
—
Margin
—
| Class | Description |
|---|---|
| All sides |
| Individual sides |
| Horizontal / vertical |
—
Positioning
—
| Class | Description |
|---|---|
| All sides |
| Individual sides |
| Horizontal / vertical inset |
—
Compound Variants
—
| Pattern | Behavior | Example |
|---|---|---|
| | |
| | |
—
Setup
—
Uniwind Free (default) — requires to update insets.
Wrap your App component in and and call in the callback:
react-native-safe-area-contextSafeAreaProviderSafeAreaListenerUniwind.updateInsets(insets)onChangetsx
import { SafeAreaProvider, SafeAreaListener } from 'react-native-safe-area-context';
import { Uniwind } from 'uniwind';
export default function App() {
return (
<SafeAreaProvider>
<SafeAreaListener
onChange={({ insets }) => {
Uniwind.updateInsets(insets);
}}
>
<View className="pt-safe px-safe">{/* content */}</View>
</SafeAreaListener>
</SafeAreaProvider>
);
}Uniwind Pro — automatic, no setup needed. Insets injected from native layer.
—
CSS Functions
—
Uniwind provides CSS functions for device-aware and theme-aware styling. These can be used everywhere (custom CSS classes, , etc.) — but NOT inside (which only accepts static values). Use to create reusable Tailwind-style utility classes:
@utility@theme {}@utility—
hairlineWidth()
—
Returns the thinnest line width displayable on the device. Use for subtle borders and dividers.
css
@utility h-hairline { height: hairlineWidth(); }
@utility border-hairline { border-width: hairlineWidth(); }
@utility w-hairline { width: calc(hairlineWidth() * 10); }tsx
<View className="h-hairline bg-gray-300" />
<View className="border-hairline border-gray-200 rounded-lg p-4" />—
fontScale(multiplier?)
—
Multiplies a base value by the device's font scale accessibility setting. Ensures text respects user preferences for larger or smaller text.
- — uses multiplier 1 (device font scale × 1)
fontScale() - — smaller scale
fontScale(0.9) - — larger scale
fontScale(1.2)
css
@utility text-sm-scaled { font-size: fontScale(0.9); }
@utility text-base-scaled { font-size: fontScale(); }
@utility text-lg-scaled { font-size: fontScale(1.2); }tsx
<Text className="text-sm-scaled text-gray-600">Small accessible text</Text>
<Text className="text-base-scaled">Regular accessible text</Text>—
pixelRatio(multiplier?)
—
Multiplies a value by the device's pixel ratio. Creates pixel-perfect designs that scale across screen densities.
- — uses multiplier 1 (device pixel ratio × 1)
pixelRatio() - — double the pixel ratio
pixelRatio(2)
css
@utility w-icon { width: pixelRatio(); }
@utility w-avatar { width: pixelRatio(2); }tsx
<Image source={{ uri: 'avatar.png' }} className="w-avatar rounded-full" />—
light-dark(lightValue, darkValue)
—
Returns different values based on the current theme mode. Automatically adapts when the theme changes — no manual switching logic needed.
- First parameter: value for light theme
- Second parameter: value for dark theme
css
@utility bg-adaptive { background-color: light-dark(#ffffff, #1f2937); }
@utility text-adaptive { color: light-dark(#111827, #f9fafb); }
@utility border-adaptive { border-color: light-dark(#e5e7eb, #374151); }tsx
<View className="bg-adaptive border-adaptive border rounded-lg p-4">
<Text className="text-adaptive">Adapts to light/dark theme</Text>
</View>Also works in custom CSS classes (not just ):
@utilitycss
.adaptive-card {
background-color: light-dark(#ffffff, #1f2937);
color: light-dark(#111827, #f9fafb);
}—
Custom CSS & Utilities
—
Custom CSS Classes
—
Uniwind supports custom CSS class names defined in . They are compiled at build time — no runtime overhead. Use them when you need styles that are hard to express as Tailwind utilities (e.g., complex box-shadow, multi-property bundles).
global.csscss
/* global.css */
.card-shadow {
background-color: white;
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.adaptive-surface {
background-color: light-dark(#ffffff, #1f2937);
color: light-dark(#111827, #f9fafb);
}
.container {
flex: 1;
width: 100%;
max-width: 1200px;
}Apply via just like any Tailwind class:
classNametsx
<View className="card-shadow" />—
Mixing Custom CSS with Tailwind
—
You can combine custom CSS classes with Tailwind utilities in a single :
classNametsx
<View className="card-shadow p-4 m-2">
<Text className="adaptive-surface mb-2">{title}</Text>
<View className="container flex-row">{children}</View>
</View>WARNING: If a custom CSS class and a Tailwind utility set the same property, you MUST use to deduplicate. Without , both values apply and the result is unpredictable:
cn()cn()tsx
// WRONG — .container sets flex:1, and flex-1 also sets flex:1 (harmless but wasteful)
// WRONG — .container sets width:100%, and w-full also sets width:100% (redundant)
// DANGEROUS — .card-shadow sets border-radius:12px, and rounded-2xl sets border-radius:16px — CONFLICT!
<View className="card-shadow rounded-2xl" />
// CORRECT — cn ensures rounded-2xl wins
import { cn } from '@/lib/cn';
<View className={cn('card-shadow', 'rounded-2xl')} />Rule of thumb: If your custom CSS class sets properties that might overlap with Tailwind utilities you'll also use, always wrap with . See cn Utility section for full setup.
cn()—
Guidelines for Custom CSS
—
- Keep selectors flat — no deep nesting or child selectors
- Prefer Tailwind utilities for simple, single-property styles
- Use custom classes for complex or multi-property bundles that would be verbose in className
- Use for theme-aware custom classes
light-dark() - Custom classes are great for shared design tokens that don't fit Tailwind's naming (e.g., ,
.card,.chip).badge-dot
—
Custom Utilities (@utility)
—
The directive creates utility classes that work exactly like built-in Tailwind classes. Use for CSS functions and patterns Tailwind doesn't support natively:
@utilitycss
@utility h-hairline { height: hairlineWidth(); }
@utility text-scaled { font-size: fontScale(); }Usage like any Tailwind class:
<View className="h-hairline" />—
@theme Directive
—
Customize Tailwind design tokens in :
global.csscss
@theme {
/* Colors */
--color-primary: #3b82f6;
--color-brand-500: #3b82f6;
--color-brand-900: #1e3a8a;
/* Typography */
--font-sans: 'Roboto-Regular';
--font-sans-medium: 'Roboto-Medium';
--font-sans-bold: 'Roboto-Bold';
--font-mono: 'FiraCode-Regular';
/* Spacing & sizing */
--text-base: 15px;
--spacing-4: 16px;
--radius-lg: 12px;
/* Breakpoints */
--breakpoint-tablet: 820px;
}Usage: , , , , .
bg-brand-500text-brand-900font-sansfont-monorounded-lg—
Fonts
—
React Native requires a single font per family — no fallbacks:
css
@theme {
--font-sans: 'Roboto-Regular';
--font-sans-bold: 'Roboto-Bold';
--font-mono: 'FiraCode-Regular';
}Font name must exactly match the font file name (without extension).
Expo: Configure fonts in with the plugin, then reference in CSS.
app.jsonexpo-fontBare RN: Use to link fonts, same CSS config.
react-native-assetPlatform-specific fonts (use , not ):
@variant@mediacss
@layer theme {
:root {
@variant ios { --font-sans: 'SF Pro Text'; }
@variant android { --font-sans: 'Roboto-Regular'; }
@variant web { --font-sans: 'system-ui'; }
}
}—
Gradients
—
Built-in support — no extra dependencies:
tsx
<View className="bg-gradient-to-r from-red-500 via-yellow-500 to-green-500 p-4 rounded-lg">
<Text className="text-white font-bold">Gradient</Text>
</View>For , you can wrap it with for className-based layout and styling (padding, border-radius, flex, etc.), but the prop is an array that cannot be resolved via className — it must be provided explicitly. Use to get theme-aware colors:
expo-linear-gradientwithUniwindcolorsuseCSSVariabletsx
import { useCSSVariable } from 'uniwind';
import { withUniwind } from 'uniwind';
import { LinearGradient as RNLinearGradient } from 'expo-linear-gradient';
const LinearGradient = withUniwind(RNLinearGradient);
function GradientCard() {
// useCSSVariable returns string | number | undefined
const primary = useCSSVariable('--color-primary');
const secondary = useCSSVariable('--color-secondary');
// Guard against undefined — LinearGradient.colors requires valid ColorValues
if (!primary || !secondary) {
return null;
}
return (
<LinearGradient
className="flex-1 rounded-2xl p-6"
colors={[primary as string, secondary as string]}
>
<Text className="text-white font-bold">Themed gradient</Text>
</LinearGradient>
);
}Alternatively, export a wrapped component from a shared module for reuse:
tsx
// components/styled.ts
import { withUniwind } from 'uniwind';
import { LinearGradient as RNLinearGradient } from 'expo-linear-gradient';
export const LinearGradient = withUniwind(RNLinearGradient);tsx
// usage — className handles layout, colors still passed manually
import { LinearGradient } from '@/components/styled';
<LinearGradient className="rounded-xl p-4" colors={['#ff6b6b', '#4ecdc4']}>
<Text className="text-white">Static gradient</Text>
</LinearGradient>—
React Navigation Integration
—
Use for screen options that only accept objects:
useResolveClassNamesstyletsx
import { useResolveClassNames } from 'uniwind';
function Layout() {
const headerStyle = useResolveClassNames('bg-background');
const headerTitleStyle = useResolveClassNames('text-foreground font-bold');
return (
<Stack.Navigator
screenOptions={{
headerStyle,
headerTitleStyle,
}}
/>
);
}Keep React Navigation's if already in use — it manages navigation-specific theming.
<ThemeProvider>—
UI Kit Compatibility
—
- HeroUI Native: Works with Uniwind. Uses (tv) internally. Apply
tailwind-variantsdirectly on HeroUI components. Bun users: Bun uses symlinks forclassName, which can cause Tailwind's Oxide scanner to miss library classes in production builds. Fix: use the resolved path innode_modulesand hoist the package:@sourcecss@source "../../node_modules/heroui-native/lib";ini# .npmrc public-hoist-pattern[]=heroui-native - react-native-reusables: Compatible.
- Gluestack v4.1+: Compatible.
- Lucide React Native: Use with
withUniwind(LucideIcon)for icon color. Works for all Lucide icons.colorClassName="accent-blue-500" - @shopify/flash-list: Use for
withUniwind(FlashList)andclassNamesupport. Note:contentContainerClassNameloses generic type params onwithUniwind— cast manually if needed.ref
Use semantic color tokens (, ) for theme consistency across UI kits.
bg-primarytext-foreground—
Supported vs Unsupported Classes
—
React Native uses the Yoga layout engine. Key differences from web CSS:
- No CSS cascade/inheritance — styles don't inherit from parents
- Flexbox by default — all views use flexbox with
flexDirection: 'column' - Limited CSS properties — no floats, grid, pseudo-elements
—
Supported (all standard Tailwind)
—
Layout, spacing, sizing, typography, colors, borders, effects, flexbox, positioning, transforms, interactive states.
—
Unsupported (web-specific, silently ignored)
—
hover:— use Pressablevisited:insteadactive:before:after:— pseudo-elementsplaceholder:float-*clear-*columns-*print:screen:break-before-*break-after-*break-inside-*
—
Uniwind Pro
—
Paid upgrade with 100% API compatibility. Built on a 2nd-generation C++ engine for apps that demand the best performance. $99/seat (billed annually). Pricing and licensing: https://uniwind.dev/pricing
—
Pricing & Licensing
—
- $99/seat per year (VAT excluded unless applicable)
- Individual License: Personal Pro license per engineer
- Team License: Single key management — add or remove members instantly
- CI/CD License: Full support for automated and headless build environments
- Enterprise: Custom plans available (contact support@uniwind.dev)
- Priority Support: Critical issues resolved with priority response times
—
Overview
—
- C++ style engine: Forged on the 2nd-gen Unistyles C++ engine. Injects styles directly into the ShadowTree without triggering React re-renders — a direct, optimized highway between classNames and the native layer
- Performance: Benchmarked at ~55ms (vs StyleSheet 49ms, traditional Uniwind 81ms, NativeWind 197ms) — near-native speed
- 40+ className props update without re-renders (all component bindings listed above)
- Reanimated animations: and
animate-*via className (Reanimated v4)transition-* - Native insets & runtime values: Automatic safe area injection, device rotation, and font size updates — no setup needed
SafeAreaListener - Theme transitions: Native animated transitions when switching themes (fade, slide, circle mask)
- Priority support: Don't let technical hurdles slow your team down
Package: in .
"uniwind": "npm:uniwind-pro@rc"package.json—
Installation
—
-
Set dependency alias in:
package.jsonjson{ "dependencies": { "uniwind": "npm:uniwind-pro@rc" } } -
Install peer dependencies:bash
npm install react-native-nitro-modules react-native-reanimated react-native-worklets -
Authenticate:(interactive — select "Login with GitHub")
npx uniwind-pro -
Add Babel plugin:js
// babel.config.js module.exports = { presets: ['module:metro-react-native-babel-preset'], plugins: ['react-native-worklets/plugin'], }; -
Whitelist postinstall if needed:
- bun: Add to
"trustedDependencies": ["uniwind"]package.json - yarn v2+: Configure in
.yarnrc.yml - pnpm:
pnpm config set enable-pre-post-scripts true
- bun: Add
-
Rebuild native app:bash
npx expo prebuild --clean && npx expo run:ios
Pro does NOT work with Expo Go. Requires native rebuild.
Verify installation: Check for native modules (, files) in .
.cpp.mmnode_modules/uniwind—
Reanimated Animations (Requires Reanimated v4.0.0+)
—
tsx
<View className="size-32 bg-primary rounded animate-spin" />
<View className="size-32 bg-primary rounded animate-bounce" />
<View className="size-32 bg-primary rounded animate-pulse" />
<View className="size-32 bg-primary rounded animate-ping" />
// Loading spinner
<View className="size-8 border-4 border-gray-200 border-t-blue-500 rounded-full animate-spin" />Components auto-swap to Animated versions when animation classes detected:
| Component | Animated Version |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
—
Transitions
—
Smooth property changes when className or state changes:
tsx
// Color transition on press
<Pressable className="bg-primary active:bg-red-500 transition-colors duration-300" />
// Opacity transition
<View className={`transition-opacity duration-500 ${visible ? 'opacity-100' : 'opacity-0'}`} />
// Transform transition
<Pressable className="active:scale-95 transition-transform duration-150" />
// All properties
<Pressable className="bg-primary px-6 py-3 rounded-lg active:scale-95 active:bg-primary/80 transition-all duration-150">
<Text className="text-white font-semibold">Animated Button</Text>
</Pressable>| Class | Properties |
|---|---|
| No transition |
| All properties |
| Background, border, text colors |
| Opacity |
| Box shadow |
| Scale, rotate, translate |
Duration:
duration-75duration-100duration-150duration-200duration-300duration-500duration-700duration-1000Easing:
ease-linearease-inease-outease-in-outDelay:
delay-75delay-100delay-150delay-200delay-300delay-500delay-700delay-1000—
Using Reanimated Directly
—
Still works with Uniwind classes:
tsx
import Animated, { FadeIn, FlipInXUp, LinearTransition } from 'react-native-reanimated';
<Animated.Text entering={FadeIn.delay(500)} className="text-foreground text-lg">
Fading in
</Animated.Text>
<Animated.FlatList
data={data}
className="flex-none"
contentContainerClassName="px-2"
layout={LinearTransition}
renderItem={({ item }) => (
<Animated.Text entering={FlipInXUp} className="text-foreground py-2">
{item}
</Animated.Text>
)}
/>—
Shadow Tree Updates
—
No code changes needed — props connect directly to C++ engine, eliminating re-renders automatically.
—
Native Insets
—
Remove setup — insets injected from native layer:
SafeAreaListenertsx
// With Pro — just use safe area classes directly
<View className="pt-safe pb-safe">{/* content */}</View>—
Theme Transitions (Pro)
—
Native animated transitions when switching themes. Import and pass to :
ThemeTransitionPresetsetThemetsx
import { Uniwind, ThemeTransitionPreset } from 'uniwind';
// Fade transition
Uniwind.setTheme('dark', ThemeTransitionPreset.Fade);
// Slide transitions
Uniwind.setTheme('dark', ThemeTransitionPreset.SlideRightToLeft);
Uniwind.setTheme('light', ThemeTransitionPreset.SlideLeftToRight);
// Circle mask transitions (expand from a corner or center)
Uniwind.setTheme('ocean', ThemeTransitionPreset.CircleCenter);
Uniwind.setTheme('dark', ThemeTransitionPreset.CircleTopRight);
// No animation
Uniwind.setTheme('light', ThemeTransitionPreset.None);Available presets:
| Preset | Effect |
|---|---|
| Instant switch, no animation |
| Crossfade between themes |
| Slide new theme in from right |
| Slide new theme in from left |
| Circle mask expanding from top-right |
| Circle mask expanding from top-left |
| Circle mask expanding from bottom-right |
| Circle mask expanding from bottom-left |
| Circle mask expanding from center |
—
Setup Diagnostics
—
When styles aren't working, check in this order:
—
1. package.json
—
- (or
"uniwind") in dependencies"uniwind-pro" - at v4+ (
"tailwindcss")^4.0.0 - For Pro: ,
react-native-nitro-modules,react-native-reanimatedreact-native-worklets
—
2. metro.config.js
—
- imported from
withUniwindConfig'uniwind/metro' - is the outermost wrapper
withUniwindConfig - is a relative path string (e.g.,
cssEntryFile)'./global.css' - No or absolute paths
path.resolve()
—
3. global.css
—
- Contains AND
@import 'tailwindcss';@import 'uniwind'; - Imported in or root layout, NOT in
App.tsx/index.tsindex.js - Location determines app root for Tailwind scanning
—
4. babel.config.js (Pro only)
—
- in plugins array
'react-native-worklets/plugin'
—
5. TypeScript
—
- exists (generated after running Metro)
uniwind-types.d.ts - Included in or placed in
tsconfig.json/src/dirapp/
—
6. Build
—
- Metro server restarted after config changes
- Metro cache cleared (or
npx expo start --clear)npx react-native start --reset-cache - Native rebuild done (if Pro or after dependency changes)
—
Troubleshooting
—
| Symptom | Cause | Fix |
|---|---|---|
| Styles not applying | Missing imports in global.css | Add |
| Styles not applying | global.css imported in index.js | Move import to App.tsx or |
| Classes not detected | global.css in nested dir, components elsewhere | Add |
| TypeScript errors on className | Missing types file | Run Metro to generate |
| Wrong import | Use |
| Hot reload full-reloads | global.css imported in wrong file | Move to App.tsx or root layout |
| Absolute path used | Use relative: |
| Another wrapper wraps Uniwind | Swap order so Uniwind is outermost |
| Dark theme not working | Missing | Define dark variant in |
| Custom theme not appearing | Not registered in metro config | Add to |
| Fonts not loading | Font name mismatch | CSS font name must match file name exactly (no extension) |
| Wrong base rem | Set |
| Unsupported CSS warning | Web-specific CSS used | Enable |
| Complex CSS, circular refs, or stale cache | Clear caches: |
| Docs/markdown files with CSS classes in project dir get scanned by Tailwind | Move |
| App disables package exports | Use selective resolver for Uniwind and culori |
| Classes from monorepo package missing | Not included in Tailwind scan | Add |
Classes from | Bun uses symlinks; Tailwind's Oxide scanner can't follow them | Use resolved path: |
| | Only core RN |
| When manual mapping is provided, | Use auto mapping (no second arg) for |
| TypeScript limitation with HOCs | Cast the ref manually: |
Platform-specific fonts: | | Use |
| RN 0.82 changed Appearance API | Update to latest Uniwind (fixed). Avoid |
| Styles flash/disappear on initial load (Android) | | Fixed in recent versions. If persists, ensure Uniwind is latest |
| Uniwind module replacement interferes with tvOS exports | Fixed in v1.2.1+. Update Uniwind |
| Bug with RNW + Expo SDK 55 | Fixed in v1.4.1+. Update Uniwind |
| Calling for multiple themes back-to-back; last call wins on first render | Call |
| Pro: animations not working | Missing Babel plugin | Add |
| Pro: module not found | No native rebuild | Run |
| Pro: postinstall failed | Package manager blocks scripts | Add to |
| Pro: auth expired | Login session expired (180-day lifetime) | Run |
| Pro: download limit reached | Monthly download limit hit | Check Pro dashboard, limits reset monthly |
Pro: | Pro injects insets natively | |
| Pro: theme transition crash | Missing | Import from |
—
unstable_enablePackageExports Selective Resolver
—
If your app disables (common in crypto apps), use a selective resolver:
unstable_enablePackageExportsjs
config.resolver.unstable_enablePackageExports = false;
config.resolver.resolveRequest = (context, moduleName, platform) => {
if (['uniwind', 'culori'].some((prefix) => moduleName.startsWith(prefix))) {
return context.resolveRequest(
{ ...context, unstable_enablePackageExports: true },
moduleName,
platform
);
}
return context.resolveRequest(context, moduleName, platform);
};—
FAQ
—
Where to put global.css in Expo Router?
Project root. Import in . If placed in , add for sibling dirs.
app/_layout.tsxapp/@sourceDoes Uniwind work with Expo Go?
Free: Yes. Pro: No — requires native rebuild (development builds).
Can I use tailwind.config.js?
No. Uniwind uses Tailwind v4 — all config via in .
@themeglobal.cssHow to access CSS variables in JS?
. For variables not used in classNames, define with .
useCSSVariable('--color-primary')@theme staticCan I use Platform.select()?
Yes, but prefer platform selectors () — cleaner, no imports.
ios:pt-12 android:pt-6Next.js support?
Not officially supported. Community plugin: . For Next.js, use standard Tailwind CSS.
uniwind-plugin-nextVite support?
Yes, since v1.2.0. Use plugin alongside .
uniwind/vite@tailwindcss/viteFull app reloads on CSS changes?
Metro can't hot-reload files with many providers. Move import deeper in the component tree.
global.cssStyle specificity?
Inline always overrides . Use for static styles, inline only for truly dynamic values. Use from tailwind-merge for component libraries where classNames may conflict.
styleclassNameclassNamecn()How do I include custom fonts?
Load font files (Expo: plugin in ; Bare RN: ), then map in CSS: . Font name must exactly match the file name. See the Fonts section above.
expo-fontapp.jsonreact-native-asset@theme { --font-sans: 'Roboto-Regular'; }How can I style based on prop values?
Use data selectors: . Only equality checks supported. See the Data Selectors section above.
data-[selected=true]:ring-2How can I use gradients?
Built-in: . Also supports angle-based () and arbitrary values (). See the Gradients section above.
bg-gradient-to-r from-red-500 to-green-500bg-linear-90bg-linear-[45deg,#f00_0%,#00f_100%]How does className deduplication work?
Uniwind does NOT auto-deduplicate conflicting classNames. Use with a utility. See the cn Utility section above.
tailwind-mergecn()How to debug 'Failed to serialize javascript object'?
Clear caches: . Enable in metro config to identify the problematic CSS pattern. See the Troubleshooting table above.
watchman watch-del-all; rm -rf node_modules/.cache; npx expo start --cleardebug: trueHow do I enable safe area classNames?
Free: Install , wrap root with , call . Pro: Automatic — no setup. Then use , , etc. See the Safe Area Utilities section above.
react-native-safe-area-contextSafeAreaListenerUniwind.updateInsets(insets)pt-safepb-safeWhat UI kits work well with Uniwind?
React Native Reusables (shadcn philosophy, copy-paste components) and HeroUI Native (complete library, optimized for Uniwind). Any library works via wrapper. See the UI Kit Compatibility section above.
withUniwindCan I scope a theme to a single component?
Yes, use : . It forces a theme for the subtree without changing the global theme. See the Theming section.
ScopedTheme<ScopedTheme theme="dark"><Card /></ScopedTheme>Does work with Pressable?
No. does NOT support interactive state selectors (, , ). Only core RN , , and support them. For RNGH components, use / with state.
active:react-native-gesture-handlerwithUniwindactive:focus:disabled:PressableTextInputSwitchonPressInonPressOutCan I customize the default color?
Not via . The default from class is hardcoded to . Use explicitly or define in and use .
border@layer baseborderColorborder#000000border border-gray-300--color-border@themeborder-borderCan I use platform-specific fonts in ?
No. only accepts custom properties. Use instead. Note: use (not ) for platform selection in CSS.
@theme {}@theme {}@layer theme { :root { @variant ios { --font-sans: '...'; } } }@variant@mediaDoes Uniwind work with ESM metro config ( or )?
Yes since v1.3.0+. If you hit , update Uniwind or use CommonJS .
metro.config.mjsmetro.config.tsClass extends value is not a constructormetro.config.jsClasses from work in dev but not production (bun)?
Bun symlinks packages. Tailwind's Oxide scanner can't follow them. Use resolved paths and hoist the package. See UI Kit Compatibility for details.
node_modules@sourceHow to clear all caches when debugging?
. This clears Watchman, Babel/bundler caches, and Expo internal cache.
watchman watch-del-all 2>/dev/null; rm -rf node_modules/.cache && npx expo start --clear—
MCP Server
—
Uniwind provides an official MCP server for AI-assisted development. If the user's environment supports MCP, recommend setting it up: https://docs.uniwind.dev/mcp
—
Related Skills
—
NativeWind → Uniwind migration: Use the skill for migrating from NativeWind. It handles package removal, config migration, Tailwind v4 upgrade, removal, theme conversion, and all breaking changes. It is tested and production-ready.
migrate-nativewind-to-uniwindcssInteropIMPORTANT: Do NOT guess Uniwind APIs. If you are unsure about any Uniwind API, hook, component, or configuration option, fetch and verify against the official docs: https://docs.uniwind.dev/llms-full.txt
—