# CSS Parser Source: https://docs.uniwind.dev/api/css Write custom CSS classes alongside Tailwind in your React Native app ## Overview Uniwind includes a built-in CSS parser that allows you to use traditional CSS alongside Tailwind utilities. While our primary focus is on Tailwind syntax, you can write custom CSS classes and use them directly in your React Native components. > [!NOTE] > > We're actively seeking feedback to identify missing features and limitations. Your input helps us improve CSS support in Uniwind! ## Why Use Custom CSS? While Tailwind provides utility classes for most styling needs, custom CSS can be useful for: * Complex, reusable component styles that would be verbose with utilities * Migrating existing web codebases to React Native * Defining design system components with consistent styling * Advanced animations and transitions ## Basic Usage Define custom CSS classes in your `global.css` file and use them with the `className` prop: ### CSS Definition ```css global.css theme={null} .container { flex: 1; background-color: red; width: 50px; height: 50px; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1); } ``` ### Using in Components ```tsx theme={null} import { View } from 'react-native' export const MyComponent = () => ( ) ``` ## Combining CSS Classes with Tailwind You can seamlessly mix custom CSS classes with Tailwind utilities: ### CSS Definition ```css global.css theme={null} .card { background-color: white; border-radius: 8px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); } .card-header { font-size: 18px; font-weight: bold; color: #333; } ``` ### Usage with Tailwind ```tsx theme={null} import { View, Text } from 'react-native' export const Card = ({ title, children }) => ( {title} {children} ) ``` ### Overriding Custom Classes with Utilities Custom classes written directly in `global.css` are outside any cascade layer, while Tailwind generates utilities inside `@layer utilities`. When both set the same property, the custom class wins, the same as in a browser: ```tsx theme={null} {/* background stays white from .card */} ``` To let utilities override a custom class, define it inside `@layer components`: ```css global.css theme={null} @layer components { .card { background-color: white; border-radius: 8px; } } ``` Now `card bg-blue-500` renders a blue background. See [Style Specificity](/style-specificity) for the full set of rules. > [!NOTE] > > On native, this cascade order requires Uniwind 1.13.0 or Uniwind Pro 1.9.0 or later. ### Using light-dark() Function Uniwind supports the CSS [`light-dark()`](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/light-dark) function, which provides a convenient way to define different values for light and dark themes: ```css theme={null} .adaptive-card { background-color: light-dark(#ffffff, #1f2937); color: light-dark(#111827, #f9fafb); border-color: light-dark(#e5e7eb, #374151); } ``` The first value is used in light mode, and the second value is used in dark mode. This automatically adapts when the theme changes. ```tsx theme={null} {/* Colors automatically switch between light and dark themes */} ``` > [!TIP] > > The `light-dark()` function is particularly useful for maintaining color consistency across themes without needing separate CSS variables for each theme. ## Best Practices > [!TIP] > > **Prefer Tailwind utilities for simple styles.** Use custom CSS classes for complex, reusable component patterns that would be verbose or repetitive with utility classes. > [!WARNING] > > **Avoid deeply nested selectors.** React Native's styling model is simpler than web CSS. Keep your selectors flat and component-scoped for best results. ### Recommended Pattern ```css theme={null} /* ✅ Good: Component-scoped classes */ .product-card { background-color: white; border-radius: 12px; padding: 16px; } .product-card-image { width: 100%; aspect-ratio: 16/9; border-radius: 8px; } .product-card-title { font-size: 18px; font-weight: bold; margin-top: 12px; } ``` ```css theme={null} /* ❌ Avoid: Complex nested selectors */ .product-card .image-container .image .overlay .title { /* This is too complex for React Native */ } ``` ## Performance Considerations * **Compile-time parsing**: CSS is parsed at build time, not runtime, for optimal performance * **No runtime overhead**: Custom CSS classes are converted to React Native styles during compilation ## Feedback & Feature Requests > [!NOTE] > > The CSS parser is continuously evolving. We're actively looking for feedback to help identify missing features and limitations. > [card] [Share Your Feedback](https://github.com/uni-stack/uniwind/discussions) > > Let us know what CSS features you need or issues you've encountered! ## Related > [card] [Tailwind Basics](/tailwind-basics) > > Learn how to use Tailwind utilities in Uniwind > [card] [Theming](/theming/basics) > > Discover theming and CSS variables in Uniwind # CSS Functions Source: https://docs.uniwind.dev/api/css-functions Use CSS functions to create dynamic styles ## Overview Uniwind provides device-specific CSS functions that automatically adapt to platform characteristics. These functions help you create responsive styles that work seamlessly across different devices and screen densities. > [!NOTE] > > CSS functions must be defined as utilities in your `global.css` file before use. You cannot use them directly in className props with arbitrary values. ## Available Functions ### hairlineWidth() Returns the thinnest line width that can be displayed on the device. Perfect for creating subtle borders and dividers. **Define in global.css** ```css theme={null} @utility h-hairline { height: hairlineWidth(); } @utility w-hairline { width: calc(hairlineWidth() * 10); /* 10 * device hairline width */ } ``` **Usage Example** ```tsx theme={null} import { View } from 'react-native' ``` ### fontScale() Multiplies a base font size by the device's font scale setting (accessibility setting). This ensures your text respects user preferences for larger or smaller text. **Define in global.css** ```css theme={null} @utility text-sm-scaled { font-size: fontScale(0.9); } @utility text-base-scaled { font-size: fontScale(); } ``` You can pass a numeric argument directly to `fontScale()` instead of wrapping it in `calc()`: ```css theme={null} /* Equivalent, prefer the first form */ font-size: fontScale(0.9); font-size: calc(fontScale() * 0.9); ``` **Usage Example** ```tsx theme={null} import { Text } from 'react-native' // Multiple text sizes Small text Regular text ``` ### pixelRatio() Multiplies a value by the device's pixel ratio. Useful for creating pixel-perfect designs that scale appropriately across different screen densities. **Define in global.css** ```css theme={null} @utility w-icon { width: pixelRatio(); } @utility w-avatar { width: pixelRatio(2); } ``` You can pass a numeric argument directly to `pixelRatio()` instead of wrapping it in `calc()`: ```css theme={null} /* Equivalent, prefer the first form */ width: pixelRatio(2); width: calc(pixelRatio() * 2); ``` **Usage Example** ```tsx theme={null} import { View, Image } from 'react-native' ``` ### light-dark() Returns different values based on the current theme mode (light or dark). This function automatically adapts when the theme changes, making it perfect for creating theme-aware styles without manual theme switching logic. **Define in global.css** ```css theme={null} @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); } ``` **Usage Example** ```tsx theme={null} import { View, Text } from 'react-native' This text and background automatically adapt to light/dark theme ``` > [!TIP] > > The `light-dark()` function is particularly useful for maintaining color consistency across themes without needing separate CSS variables for each theme. ### min() Available in Uniwind 1.10.0+ and Uniwind Pro 1.5.0+ Returns the smallest of its arguments. Use it to cap a size, for example a width that follows the screen but never grows past a fixed value. **Define in global.css** ```css theme={null} @utility w-card { width: min(90vw, 480px); } @utility h-header { height: min(25vh, 12rem); } ``` Arguments can be `px`, `rem`, `vw` and `vh` lengths, plain numbers, and other functions such as `max()`, `calc()`, `pixelRatio()` and `fontScale()`. Percentages are not supported inside `min()`. `min()` is a standard CSS function, so it also works in arbitrary values: ```tsx theme={null} import { View } from 'react-native' ``` > [!TIP] > > `max()` works the same way and returns the largest of its arguments, for example `min-h-[max(50vh,320px)]`. ## Related > [card] [CSS Parser](/api/css) > > Learn about CSS variable support and custom CSS classes > [card] [Theming](/theming/basics) > > Combine with themes for powerful styling # Data Selectors Source: https://docs.uniwind.dev/api/data-selectors Style components based on prop values using data-[...] variants Available in Uniwind 1.3.0+ ## Overview Data selectors let you conditionally apply styles based on a component’s props using Tailwind-style variants. This mirrors the familiar `data-[state=open]:...` pattern from Tailwind v4 and allows React Native components to react to their own prop values. ## Basic Usage Use the `data-[prop=value]` variant with your classes. The name inside the brackets maps to a `data-` prop on the same component. ```tsx theme={null} import { View } from 'react-native' // Use your own data-* props on React Native components ``` * Inside brackets, use the name without the `data-` prefix (e.g., `state` targets the `data-state` prop) * The utility applies only when the prop equals the given value ## Boolean Props For boolean props, compare to `true` or `false`: ```tsx theme={null} import { View } from 'react-native' ``` > [!TIP] > > Booleans match both the boolean and string forms. For example, `data-[selected=true]` matches `data-selected={true}` and `data-selected="true"`. ## String Props You can match arbitrary string values: ```tsx theme={null} import { View } from 'react-native' // Match a specific value on your own data-* prop ``` ## Multiple Variants Chain multiple data selectors to target different prop states: ```tsx theme={null} import { View } from 'react-native' ``` ## How It Works * During build, Uniwind recognizes attribute selectors generated by variants like `data-[prop=value]:...` and records them as data constraints for the corresponding class * At runtime, when resolving a component’s `className`, Uniwind compares the component’s props against those constraints and only applies the matching styles * Styles that depend on data selectors are evaluated against props and are not cached across prop changes ## Supported Syntax * Equality checks: `data-[prop=value]:utility` * Boolean checks: `data-[prop=true]` and `data-[prop=false]` * Multiple different data selectors can be used on the same className string > [!WARNING] > > Only equality selectors are supported (e.g., `data-[prop=value]`). Presence-only selectors like `data-[prop]` or other operators are not supported. > [!NOTE] > > Tailwind 4.3.3 and newer emit flattened variant selectors instead of nested ones. Data selectors compiled by these Tailwind versions need Uniwind 1.12.0+ or Uniwind Pro 1.7.0+. On older Uniwind versions, the variant is ignored and the style applies unconditionally. ## Best Practices * Prefer semantic prop names (e.g., `state`, `status`, `variant`, `disabled`) to keep selectors readable * Keep variant logic close to the component whose props drive the state * Use data selectors for prop-driven state; use interactive variants for interaction states when available ## Examples ### Tabs ```tsx theme={null} import { Pressable, Text } from 'react-native' {route.title} ``` ### Toggle ```tsx theme={null} import { Pressable, View } from 'react-native' ``` ## Related > [card] [Supported Class Names](/class-names) > > Learn which utilities and variants are supported > [card] [Platform Selectors](/api/platform-select) > > Combine data selectors with platform variants # generate-artifacts Source: https://docs.uniwind.dev/api/generate-artifacts Generate Uniwind artifacts from your CSS entry file Available in Uniwind 1.8.0+ (Free) and 1.2.1+ (Pro) ## Overview The `generate-artifacts` command generates Uniwind artifacts from your CSS entry file. Use it when you need to run artifact generation manually from a script or CI step. This is useful in CI actions when you run tools that need generated Uniwind types before Metro or Vite starts, for example a linter or formatter for Tailwind classes. ## Basic Usage ```bash theme={null} uniwind generate-artifacts --css ./global.css ``` Pass extra themes with repeated `--theme` flags and set the TypeScript declarations path with `--dts`: ```bash theme={null} uniwind generate-artifacts --css ./global.css --theme premium --theme ocean --dts ./src/uniwind-types.d.ts ``` ## Generated Files The command writes the same artifacts that Metro and Vite generate during a build: | File | Location | Contents | | - | - | - | | `uniwind.css` | Inside the installed `uniwind` package | The CSS that `@import 'uniwind'` loads, including the variants and theme setup for your themes | | `uniwind-types.d.ts` | Project root, or the path passed to `--dts` | TypeScript declarations for your themes | > [!NOTE] > > **Uniwind 1.12.1+ and Uniwind Pro 1.8.0+:** Both files are written atomically: Uniwind writes a temporary file next to the target and renames it into place. A process that reads the file at the same time sees either the old or the new version, never a partially written one. This fixes random `Missing closing } at @theme` errors in CI when several Metro workers, or Metro and the CLI, generate artifacts at the same time. ## Options ### --css **--css** `string` *required* CSS entry file path, for example `./global.css`. This should point to the CSS file where you import Tailwind and Uniwind: ```css global.css theme={null} @import 'tailwindcss'; @import 'uniwind'; ``` ### --theme **--theme** `string` Extra theme name. Pass this option multiple times to match the custom themes from `extraThemes`. ```bash theme={null} uniwind generate-artifacts --css ./global.css --theme premium --theme ocean ``` Define these themes in your Metro or Vite config with `extraThemes`: ```js metro.config.js theme={null} module.exports = withUniwindConfig(config, { cssEntryFile: './global.css', extraThemes: ['premium', 'ocean'], }); ``` ```ts vite.config.ts theme={null} uniwind({ cssEntryFile: './global.css', extraThemes: ['premium', 'ocean'], }) ``` ### --dts **--dts** `string` Generated TypeScript declarations path. ```bash theme={null} uniwind generate-artifacts --css ./global.css --dts ./src/uniwind-types.d.ts ``` > [!NOTE] > > Place the `.d.ts` file in your `src` or `app` directory for automatic TypeScript inclusion. For custom paths outside these directories, add the file to your `tsconfig.json`. ### --help **--help** `boolean` Show help for the command. ```bash theme={null} uniwind generate-artifacts --help ``` ## Usage Reference ```bash theme={null} uniwind generate-artifacts --css [--theme ...] [--dts ] ``` ## Related > [card] [Metro Config](/api/metro-config) > > Configure automatic artifact generation in Metro > [card] [Global CSS](/theming/global-css) > > Learn more about configuring your CSS entry file > [card] [Custom Themes](/theming/custom-themes) > > Create and register extra themes # getCSSVariable Source: https://docs.uniwind.dev/api/get-css-variable Read CSS variable values from outside of React components Available in Uniwind 1.6.4+ ## Overview `Uniwind.getCSSVariable` returns the value of one or more CSS variables on demand. Unlike [`useCSSVariable`](/api/use-css-variable), it isn't a hook, doesn't subscribe to theme changes, and can be called from anywhere: event handlers, async functions, utility modules, or third-party callbacks where hooks aren't allowed. > [!WARNING] > > This function reads the value once. It will not update when the theme switches. If you need a reactive value inside a component, use [`useCSSVariable`](/api/use-css-variable) instead. ## When to Use This Function Reach for `getCSSVariable` when you need to: * Read a token from outside a React component (utility files, services, event handlers) * Resolve a value lazily inside an `onPress`, `onLayout`, or async callback * Pass a token into an imperative API that runs once (native module, animation driver, logger) * Access theme values from worklets or initialization code where hooks aren't available > [!TIP] > > **Prefer these alternatives when possible:** > > * For styling components: Use the `className` prop directly > * For reactive values inside components: Use [`useCSSVariable`](/api/use-css-variable) > * For multiple style properties at once: Use [`useResolveClassNames`](/api/use-resolve-class-names) ## Usage ### Basic Example ```tsx theme={null} import { Uniwind } from 'uniwind' import { Pressable, Text } from 'react-native' export const MyButton = () => ( { const primaryColor = Uniwind.getCSSVariable('--color-primary') console.log('Primary color is', primaryColor) }} > Press me ) ``` ### Multiple Variables at Once Pass an array to read several variables in a single call: ```tsx theme={null} import { Uniwind } from 'uniwind' const reportTheme = () => { const [primaryColor, spacing, backgroundColor] = Uniwind.getCSSVariable([ '--color-primary', '--spacing-4', '--color-background', ]) analytics.track('theme_snapshot', { primaryColor, spacing, backgroundColor }) } ``` ### Outside of React Because `getCSSVariable` is a plain function, you can call it from any module: ```ts theme={null} // utils/colors.ts import { Uniwind } from 'uniwind' export const getAccentColor = () => Uniwind.getCSSVariable('--color-accent') ``` ```tsx theme={null} import { getAccentColor } from './utils/colors' const color = getAccentColor() ``` ## Making Variables Available For `getCSSVariable` to resolve a value, the variable must be either: ### Option 1: Used in a className (Recommended) Use the variable at least once anywhere in your app's `className` props: ```tsx theme={null} ``` This makes `--color-primary` available to `getCSSVariable`: ```tsx theme={null} const primaryColor = Uniwind.getCSSVariable('--color-primary') // ✅ Works ``` ### Option 2: Define in Static Theme If a variable is never used in any `className` but you still need it from JavaScript, define it in a static theme block in your `global.css`: ```css global.css theme={null} @import 'tailwindcss'; @import 'uniwind'; @theme static { --color-al-teal-75: #607d81; --chart-line-width: 2; } ``` Then read it anywhere: ```ts theme={null} const tealColor = Uniwind.getCSSVariable('--color-al-teal-75') // ✅ Works const lineWidth = Uniwind.getCSSVariable('--chart-line-width') // ✅ Works ``` > [!NOTE] > > Variables defined in `@theme static` are always available, even if they're never used in any `className`. ## Development Warnings In development mode, Uniwind warns if you try to read a variable that isn't available: ```tsx theme={null} const unknownColor = Uniwind.getCSSVariable('--color-unknown') // Console warning: // "We couldn't find your variable --color-unknown. Make sure it's used // at least once in your className, or define it in a static theme as // described in the docs." ``` ## API Reference ### Arguments **name** `string | string[]` *required* The name of the CSS variable(s) to read, including the `--` prefix. * **Single variable**: Pass a string (e.g., `'--color-primary'`) * **Multiple variables**: Pass an array of strings (e.g., `['--color-primary', '--spacing-4']`) ### Return Value The return type depends on the input: **single value** `string | number | undefined` When passing a **single string**, returns the resolved value of the CSS variable: * **Web**: Always returns a `string` (e.g., `"16px"`, `"#ff0000"`) * **Native**: Returns `string` or `number` depending on the value type (e.g., `16`, `"#ff0000"`) * **Undefined**: If the variable cannot be found **array of values** `Array\` When passing an **array of strings**, returns an array of resolved values in the same order: ```tsx theme={null} const [color, spacing, radius] = Uniwind.getCSSVariable([ '--color-primary', // Returns: "#3b82f6" '--spacing-4', // Returns: 16 (on native) or "16px" (on web) '--radius-lg' // Returns: 12 (on native) or "12px" (on web) ]) ``` ## Platform Differences > [accordion] Web Platform > > On web, `getCSSVariable` uses `getComputedStyle()` to retrieve values from the DOM. All values are returned as strings: > > ```tsx theme={null} > const color = Uniwind.getCSSVariable('--color-primary') > // Web: "#3b82f6" (string) > > const [color, spacing] = Uniwind.getCSSVariable(['--color-primary', '--spacing-4']) > // Web: ["#3b82f6", "16px"] (strings) > ``` > [accordion] Native Platform > > On React Native, `getCSSVariable` accesses the internal variable store. Numeric values are returned as numbers: > > ```tsx theme={null} > const spacing = Uniwind.getCSSVariable('--spacing-4') > // Native: 16 (number) > > const color = Uniwind.getCSSVariable('--color-primary') > // Native: "#3b82f6" (string) > > const [color, spacing] = Uniwind.getCSSVariable(['--color-primary', '--spacing-4']) > // Native: ["#3b82f6", 16] (mixed types) > ``` ## getCSSVariable vs useCSSVariable | | `getCSSVariable` | `useCSSVariable` | | - | - | - | | Where you can call it | Anywhere | Inside React components only | | Reactive to theme changes | No | Yes | | Triggers re-renders | No | Yes, when the theme changes | | Best for | One-off reads, callbacks, utilities | Values rendered in JSX | > [!TIP] > > If you only need a value once (e.g., inside an `onPress` handler), `getCSSVariable` avoids the extra subscription and re-render cost of `useCSSVariable`. ## Related > [card] [useCSSVariable](/api/use-css-variable) > > Reactive CSS variable access inside components > [card] [useResolveClassNames](/api/use-resolve-class-names) > > Convert full className strings to style objects > [card] [Global CSS](/theming/global-css) > > Learn how to define CSS variables in your theme > [card] [Theming Basics](/theming/basics) > > Understand how themes work in Uniwind # Layout Direction Source: https://docs.uniwind.dev/api/layout-direction Force RTL or LTR for a subtree with `LayoutDirection` Available in Uniwind 1.9.0+ (Free) and 1.4.0+ (Pro) ## Overview `LayoutDirection` lets you force right-to-left or left-to-right layout for a specific subtree without changing the global device RTL state. This is useful for previews, mixed-direction layouts (for example, an RTL chat bubble inside an LTR app), and testing RTL designs side by side. The nearest `LayoutDirection` wins, so nested scopes work naturally. > [!NOTE] > > `LayoutDirection` is a runtime direction boundary. The `rtl:` and `ltr:` variants, hooks, and `withUniwind` wrapped components inside the boundary resolve against the scoped direction instead of the global RTL state. ## Usage ### Basic Example ```tsx theme={null} import { LayoutDirection } from 'uniwind' import { Text, View } from 'react-native' export function Example() { return ( Uses the global RTL state Forced RTL subtree Forced LTR subtree ) } ``` ## Common Patterns ### Side-by-Side Direction Previews ```tsx theme={null} import { LayoutDirection } from 'uniwind' import { Text, View } from 'react-native' export function DirectionPreviewRow() { return ( LTR Scoped to left-to-right RTL Scoped to right-to-left ) } ``` ### Nested Scopes ```tsx theme={null} import { LayoutDirection } from 'uniwind' import { Text, View } from 'react-native' export function NestedScopes() { return ( RTL (outer) LTR (inner) ) } ``` > [!TIP] > > Omit the `rtl` prop to inherit the direction from the nearest parent `LayoutDirection`. Outside of any scope, it falls back to the global RTL state. ## Hooks and `withUniwind` in a Layout Direction Scope Hooks and HOCs resolve against the closest `LayoutDirection` boundary: * `useResolveClassNames()` resolves `rtl:`/`ltr:` variants using the scoped direction * `withUniwind()` mappings use values resolved from the scoped direction ## API Reference ### Component Signature ```tsx theme={null} import { LayoutDirection } from 'uniwind' {/* direction-scoped subtree */} ``` ### Props **rtl** `boolean` `true` forces right-to-left, `false` forces left-to-right. When omitted, the subtree inherits the direction from the nearest parent `LayoutDirection`, or the global RTL state if there is none. **children** `React.ReactNode` *required* React children rendered inside the layout direction boundary. ## Behavior Notes * `LayoutDirection` affects only its descendants * It does not change the global RTL state (`I18nManager` on native, the document `dir` on web) * Nested scopes override parent scopes for their own subtree * The wrapper renders with `display: contents`, so it does not affect your layout * Prefer `LayoutDirection` over inline `style={{ direction: 'rtl' }}` - only the component scopes the `rtl:`/`ltr:` variants ## Related Direction-Aware Utilities Some utilities follow the reading direction on their own, without `rtl:` / `ltr:` pairs: * **Logical text alignment** (Uniwind 1.12.1+, Pro 1.8.0+): `text-start` and `text-end` align text to the start or end edge. See [Logical Text Alignment](/class-names#logical-text-alignment) * **RTL-aware safe area classes** (Uniwind 1.10.0+, Pro 1.5.0+): `ps-safe`, `pe-safe`, `ms-safe`, `me-safe`, `start-safe` and `end-safe` apply the inset of the logical start or end edge. See [Safe Area Classes](/class-names#safe-area-classes) ## Related > [card] [Class Names](/class-names) > > All supported variants, including `rtl:` and `ltr:` > [card] [Scoped Themes](/api/scoped-themes) > > Apply a different theme to a subtree > [card] [useResolveClassNames](/api/use-resolve-class-names) > > Resolve class names into style objects at runtime > [card] [withUniwind](/api/with-uniwind) > > Add className support to third-party components # metro.config.js Source: https://docs.uniwind.dev/api/metro-config Configure Uniwind in your Metro bundler for React Native ## Overview The `withUniwindConfig` function configures Uniwind in your Metro bundler. This is required to enable CSS processing, type generation, and theme support in your React Native application. > [!NOTE] > > All Metro configuration changes require a Metro bundler restart to take effect. Clear the cache with `npx expo start --clear` if you encounter issues. ## Basic Usage Import and wrap your Metro config with `withUniwindConfig`: ```js metro.config.js theme={null} const { getDefaultConfig } = require('expo/metro-config'); const { withUniwindConfig } = require('uniwind/metro'); const config = getDefaultConfig(__dirname); module.exports = withUniwindConfig(config, { cssEntryFile: './src/global.css', }); ``` ## Configuration Options ### cssEntryFile **cssEntryFile** `string` *required* The relative path to your CSS entry file from the project root. This file should contain your Tailwind imports and custom CSS. > [!WARNING] > > **Important:** The location of your CSS entry file determines the app root - Tailwind will automatically scan for classNames starting from this directory. Files outside this directory require the `@source` directive in your CSS file. > [!WARNING] > > `cssEntryFile` must be a **relative path string** from project root (for example, `./src/global.css`).\ > Do not pass an absolute path or `path.resolve(...)`. **Example:** ```js metro.config.js theme={null} module.exports = withUniwindConfig(config, { cssEntryFile: './src/global.css', }); ``` Your CSS entry file should follow this structure: ```css global.css theme={null} @import 'tailwindcss'; @import 'uniwind'; /* Your custom CSS and themes */ ``` > [!TIP] > > Keep your CSS entry file in the root of your application folder (e.g., `src`, `app`). If you have components outside this folder, use `@source` to include them. See the [monorepo guide](/monorepos) for details. ### extraThemes **extraThemes** `Array\` An array of custom theme names beyond the default `light` and `dark` themes. Each theme must be defined in your CSS using the `@variant` directive. **Example:** ```js metro.config.js theme={null} module.exports = withUniwindConfig(config, { cssEntryFile: './src/global.css', extraThemes: ['ocean', 'sunset', 'premium'], }); ``` Define these themes in your CSS: ```css global.css theme={null} @layer theme { :root { @variant ocean { --color-background: #0c4a6e; --color-foreground: #e0f2fe; } @variant sunset { --color-background: #7c2d12; --color-foreground: #fed7aa; } @variant premium { --color-background: #1e1b4b; --color-foreground: #fef3c7; } } } ``` > [!WARNING] > > After adding new themes, restart your Metro bundler for changes to take effect. > [card] [Custom Themes](/theming/custom-themes) > > Learn more about creating and managing custom themes ### dtsFile **dtsFile** `string` The path where Uniwind will auto-generate TypeScript type definitions for your CSS classes and themes. Defaults to `./uniwind-types.d.ts` in your project root. **Example:** ```js metro.config.js theme={null} module.exports = withUniwindConfig(config, { cssEntryFile: './src/global.css', dtsFile: './src/uniwind-types.d.ts', }); ``` > [!NOTE] > > Place the `.d.ts` file in your `src` or `app` directory for automatic TypeScript inclusion. For custom paths outside these directories, add the file to your `tsconfig.json`. **TypeScript configuration:** ```json tsconfig.json theme={null} { "compilerOptions": { // ... }, "include": [ // ... "./uniwind-types.d.ts" // If placed in project root ] } ``` ### polyfills **polyfills** `Polyfills` Configuration for CSS unit polyfills and adjustments to ensure cross-platform consistency. #### polyfills.rem **polyfills.rem** `number` (default: 16) The base font size (in pixels) used for rem unit calculations. Defaults to `16`, which is the standard browser default. **Example:** ```js metro.config.js theme={null} module.exports = withUniwindConfig(config, { cssEntryFile: './src/global.css', polyfills: { rem: 14, // Change rem base to 14px }, }); ``` **Use case:** Adjusting the rem base is useful when: * Your design system uses a different base font size * You need to scale your entire UI proportionally * You're migrating from a web app with a custom rem base * You're migrating from Nativewind ### isTV Available in Uniwind 1.5.0+ **isTV** `boolean` (default: false) Enable TV platform support for Apple TV and Android TV. When enabled, Uniwind recognizes `tv:`, `apple-tv:`, and `android-tv:` platform selectors and `@variant` directives. **Example:** ```js metro.config.js theme={null} module.exports = withUniwindConfig(config, { cssEntryFile: './src/global.css', isTV: true, }); ``` > [!NOTE] > > When `isTV` is enabled, Uniwind maps `ios` to `apple-tv` and `android` to `android-tv` at build time. The `tv:` selector targets both TV platforms, similar to how `native:` targets both iOS and Android. > [card] [Platform Selectors](/api/platform-select) > > Learn about TV platform selectors and focus-based styling ### debug **debug** `boolean` (default: false) Enable debug mode to identify unsupported CSS properties and classNames. When enabled, Uniwind will log errors for web-specific CSS that doesn't work in React Native. **Example:** ```js metro.config.js theme={null} module.exports = withUniwindConfig(config, { cssEntryFile: './src/global.css', debug: true, }); ``` **Debug output example:** ``` Uniwind Warning [Units Processor] - Unsupported unit - ch ``` This warning is printed for a class like `w-[10ch]`, because React Native has no equivalent for the `ch` unit. > [!TIP] > > Enable debug mode during development if you're experiencing styling issues or migrating from web. It helps catch web-specific CSS properties that aren't supported in React Native. > [!WARNING] > > Disable it in production builds. ### experimental.defaultStyles Available in Uniwind Pro 1.2.0+ **experimental.defaultStyles** `boolean` (default: false) Enable default styles for built-in React Native components, defined with component selectors like `View { ... }` in your CSS entry file. This feature is experimental. **Example:** ```js metro.config.js theme={null} module.exports = withUniwindConfig(config, { cssEntryFile: './src/global.css', experimental: { defaultStyles: true, }, }); ``` > [card] [Default Styles](/pro/default-styles) > > Learn which components support default styles and how to define them ## Complete Configuration Example Here's a full example with all options configured: ```js metro.config.js theme={null} const { getDefaultConfig } = require('expo/metro-config'); const { withUniwindConfig } = require('uniwind/metro'); const config = getDefaultConfig(__dirname); // Your custom Metro modifications // ... module.exports = withUniwindConfig(config, { // Required: Path to your CSS entry file cssEntryFile: './src/global.css', // Optional: Custom themes beyond light/dark extraThemes: ['ocean', 'sunset', 'premium', 'high-contrast'], // Optional: TypeScript definitions path dtsFile: './src/uniwind-types.d.ts', // Optional: CSS polyfills polyfills: { rem: 14, // Custom rem base size }, // Optional: Enable TV platform support isTV: false, // Optional: Enable debug mode for troubleshooting debug: true, }); ``` ## Bare React Native For bare React Native projects (non-Expo), use the `@react-native/metro-config` package: ```js metro.config.js theme={null} const { getDefaultConfig } = require('@react-native/metro-config'); const { withUniwindConfig } = require('uniwind/metro'); const config = getDefaultConfig(__dirname); module.exports = withUniwindConfig(config, { cssEntryFile: './src/global.css', dtsFile: './src/uniwind-types.d.ts', }); ``` ## Related > [card] [Quickstart](/quickstart) > > Get started with Uniwind in 3 minutes > [card] [Monorepos & @source](/monorepos) > > Learn how to include components from multiple directories > [card] [Custom Themes](/theming/custom-themes) > > Create and manage custom themes beyond light and dark > [card] [Global CSS](/theming/global-css) > > Configure global styles and CSS variables > [card] [Theming Basics](/theming/basics) > > Learn the fundamentals of theming in Uniwind # Platform Selectors Source: https://docs.uniwind.dev/api/platform-select Apply platform-specific styles with built-in selectors for iOS, Android, Web, and TV platforms ## Overview Uniwind provides built-in platform selectors that allow you to apply styles conditionally based on the platform your app is running on. This is essential for creating platform-specific user experiences in React Native. > [!NOTE] > > Platform selectors are resolved at runtime and automatically apply the correct styles for the current platform. ## Basic Usage Use platform selectors directly in your `className` prop with the syntax `platform:utility`: ```tsx theme={null} import { View, Text } from 'react-native' export const PlatformExample = () => ( This component has different styles on each platform ) ``` ## Why Use Platform Selectors? Platform selectors are superior to React Native's `Platform.select()` API for several reasons: ### ❌ Not Recommended: Platform.select() ```tsx theme={null} import { Platform } from 'react-native' import { View } from 'react-native' ``` **Downsides:** * Requires importing `Platform` API * More verbose syntax * Cannot combine with other utilities easily * Less readable when multiple platform conditions are needed ### ✅ Recommended: Platform Selectors ```tsx theme={null} import { View } from 'react-native' ``` **Benefits:** * Clean, declarative syntax * No extra imports needed * Easy to combine with other Tailwind utilities * Better readability and maintainability * Works seamlessly with theme variants ## Supported Platforms **ios** `selector` Targets iOS devices (iPhone, iPad). Styles are applied only when running on iOS. **android** `selector` Targets Android devices. Styles are applied only when running on Android. **web** `selector` Targets web browsers. Styles are applied only when running in a web environment (e.g., React Native Web). **native** `selector` Targets both iOS and Android platforms. Styles are applied on mobile platforms but not on web. This is a convenient shorthand when you want to apply the same styles to both iOS and Android. **tv** `selector` Targets all TV platforms (Apple TV and Android TV). Styles are applied only when running on a TV device. Requires `isTV: true` in your [metro.config.js](/api/metro-config). **apple-tv** `selector` Targets Apple TV only. Styles are applied only when running on tvOS. Requires `isTV: true` in your [metro.config.js](/api/metro-config). **android-tv** `selector` Targets Android TV only. Styles are applied only when running on Android TV. Requires `isTV: true` in your [metro.config.js](/api/metro-config). ## Native Selector The `native:` selector is a convenient shorthand for targeting both iOS and Android platforms simultaneously. Instead of writing duplicate styles for both platforms, you can use `native:` to apply styles to all mobile platforms at once. ### ❌ Verbose: Duplicate platform styles ```tsx theme={null} import { View, Text } from 'react-native' Mobile vs Web styling ``` ### ✅ Concise: Using native: selector ```tsx theme={null} import { View, Text } from 'react-native' Mobile vs Web styling ``` > [!TIP] > > Use `native:` when your iOS and Android styles are identical, and only web differs. This reduces duplication and improves maintainability. ## TV Selectors Available in Uniwind 1.5.0+ Uniwind supports TV platforms with dedicated selectors. To enable TV support, set `isTV: true` in your [metro.config.js](/api/metro-config). ```tsx theme={null} import { View, Text } from 'react-native' // Target all TV platforms Larger text and spacing on TV // Target specific TV platforms Platform-specific TV styling ``` The `tv:` selector targets both Apple TV and Android TV, similar to how `native:` targets both iOS and Android. Use `apple-tv:` or `android-tv:` when you need platform-specific TV styles. > [!TIP] > > On TV platforms, navigation is focus-based rather than touch-based. Use the `focus:` state selector on `Pressable`, `TouchableOpacity`, and `TouchableHighlight` to style the currently focused element. ## Examples ### Platform-Specific Colors ```tsx theme={null} import { View, Text } from 'react-native' export const PlatformColors = () => ( Different background color on each platform ) ``` ### Platform-Specific Spacing ```tsx theme={null} import { View, Text } from 'react-native' export const PlatformSpacing = () => ( Platform-specific top padding ) ``` ## Platform Variants in @layer theme While platform selectors like `ios:`, `android:`, `native:`, and `web:` are great for component-level styling, Uniwind also supports platform-specific `@variant` directives within `@layer theme`. This allows you to define platform-specific design tokens and CSS variables that affect your entire theme. > [!NOTE] > > Platform `@variant` directives in `@layer theme` are processed at build time and define global theme values, while platform selectors are resolved at runtime for component-specific styles. ### Theme Configuration Use `@media` queries inside `@theme` to define platform-specific CSS variables in your `global.css`: ```css theme={null} @import 'tailwindcss'; @import 'uniwind'; @layer theme { :root { /* Base configuration applies to all platforms */ --font-sans: "Inter"; --spacing-4: 16px; /* iOS-specific overrides */ @variant ios { --font-sans: "system-ui"; --spacing-4: 20px; } /* Android-specific overrides */ @variant android { --font-sans: "sans-serif"; --spacing-4: 18px; } /* Web-specific overrides */ @variant web { --font-sans: "Inter"; --spacing-4: 16px; } } } ``` ### When to Use Each Approach Understanding when to use platform selectors vs platform `@variant` directives helps you build better cross-platform apps: > [accordion] Platform Selectors (ios:, android:, native:, web:) > > **Use for component-specific styling** > > ```tsx theme={null} > > > ``` > > * High flexibility - mix and match on any component > * Best for: Different padding, colors, or layouts for specific UI elements > * Use `native:` for shared mobile styles > [accordion] Platform Variants in @layer theme > > **Use for global theme configuration** > > ```css theme={null} > @layer theme { > :root { > --font-sans: "Inter"; > > @variant ios { > --font-sans: "system-ui"; > } > } > } > ``` > > * Affects entire design system > * Best for: Platform-specific fonts, spacing scales, or brand colors ### Platform-Specific Typography One of the most common use cases is defining platform-appropriate font families: ```css theme={null} @layer theme { :root { --font-sans: "Inter"; --text-base: 16px; @variant ios { --font-sans: "-apple-system", "SF Pro Text"; --text-base: 17px; /* iOS prefers slightly larger text */ } @variant android { --font-sans: "Roboto"; --text-base: 14px; /* Material Design standard */ } @variant web { --font-sans: "Inter", "system-ui", sans-serif; --text-base: 16px; } } } ``` Then use the font variables in your components: ```tsx theme={null} import { Text } from 'react-native' export const PlatformText = () => ( This text automatically uses the platform-appropriate font ) ``` ### Platform-Specific Spacing Adjust spacing scales to match platform design guidelines: ```css theme={null} @layer theme { :root { @variant ios { /* iOS prefers more generous spacing */ --spacing-4: 20px; --spacing-6: 28px; } @variant android { /* Material Design spacing */ --spacing-4: 16px; --spacing-6: 24px; } } } ``` ### Combining with Theme Variants Platform `@variant` directives work seamlessly with theme variants like `dark`: ```css theme={null} @layer theme { :root { --font-sans: "Inter"; @variant dark { --color-background: #000000; --color-foreground: #ffffff; } @variant light { --color-background: #ffffff; --color-foreground: #000000; } @variant ios { --font-sans: "SF Pro Text"; } @variant android { --font-sans: "Roboto"; } } } ``` ```tsx theme={null} import { View, Text } from 'react-native' export const ThemedText = () => ( Platform and theme-aware text ) ``` > [!WARNING] > > Platform `@variant` directives can only be used inside `@layer theme` in your `global.css` file. They define global theme values, not component-specific styles. ## Related > [card] [Supported Class Names](/class-names) > > Learn about all supported Tailwind classes in Uniwind > [card] [Theming](/theming/basics) > > Combine platform selectors with theme variants # Scoped Themes Source: https://docs.uniwind.dev/api/scoped-themes Apply a different theme to a subtree with `ScopedTheme` Available in Uniwind 1.4.0+ ## Overview `ScopedTheme` lets you apply a theme to a specific subtree without changing the global app theme. This is useful for previews, isolated surfaces (cards, modals, panels), and mixed-theme layouts where multiple themes need to exist on screen at the same time. The nearest `ScopedTheme` wins, so nested scopes work naturally. > [!NOTE] > > `ScopedTheme` is a runtime theme boundary. Components, hooks, and `withUniwind` wrapped components inside the boundary resolve styles against the scoped theme. ## Usage ### Basic Example ```tsx theme={null} import { ScopedTheme } from 'uniwind' import { Text, View } from 'react-native' export function Example() { return ( Uses the current app theme This subtree uses the dark theme ) } ``` ## Common Patterns ### Side-by-Side Theme Previews ```tsx theme={null} import { ScopedTheme } from 'uniwind' import { Text, View } from 'react-native' export function ThemePreviewRow() { return ( Light Scoped to light Dark Scoped to dark Coffee Scoped to coffee (custom theme) ) } ``` ### Nested Scoped Themes ```tsx theme={null} import { ScopedTheme } from 'uniwind' import { Text, View } from 'react-native' export function NestedScopes() { return ( Coffee (outer custom theme) Dark (middle) Light (inner) ) } ``` > [!TIP] > > Nested scopes are great for documentation previews and component galleries where you want to compare variants without changing global theme state. ## Hooks and `withUniwind` in a Scoped Theme Hooks and HOCs resolve against the closest `ScopedTheme` boundary. * `useUniwind()` returns the scoped theme name * `useResolveClassNames()` resolves class names using scoped theme variables * `useCSSVariable()` reads CSS variables from the scoped theme * `withUniwind()` mappings use values resolved from the scoped theme ### Example ```tsx theme={null} import { Feather } from '@expo/vector-icons' import { Pressable, Text, View } from 'react-native' import { ScopedTheme, useCSSVariable, useResolveClassNames, useUniwind, withUniwind, } from 'uniwind' const StyledFeather = withUniwind(Feather, { size: { fromClassName: 'className', styleProperty: 'width', }, color: { fromClassName: 'className', styleProperty: 'color', }, }) function UseUniwindExample() { const { theme } = useUniwind() return ( useUniwind Current theme: {theme} ) } function UseResolveClassNamesExample() { const styles = useResolveClassNames('text-primary') return ( useResolveClassNames Resolved from 'text-primary' ) } function UseCSSVariableExample() { const primaryColor = useCSSVariable('--color-primary') return ( useCSSVariable --color-primary: {String(primaryColor)} ) } function WithUniwindExample() { return ( withUniwind Icons via withUniwind ) } function ThemedButton({ title }: { title: string }) { return ( {title} ) } export function ScopedThemeHooksExample() { return ( ) } ``` ## API Reference ### Component Signature ```tsx theme={null} import { ScopedTheme } from 'uniwind' {/* themed subtree */} ``` ### Props **theme** `string` *required* Theme name to apply to this subtree. The theme must exist in your configured Uniwind theme definitions (for example, `light`, `dark`, or a custom theme like `coffee`). **children** `React.ReactNode` *required* React children rendered inside the scoped theme boundary. ## Behavior Notes * `ScopedTheme` affects only its descendants * It does not change the global app theme * Nested scopes override parent scopes for their own subtree * Multiple scopes can render side by side on the same screen ## Related > [card] [Theming Basics](/theming/basics) > > Learn how to set up themes in Uniwind > [card] [Custom Themes](/theming/custom-themes) > > Define custom themes like `coffee` > [card] [useUniwind](/api/use-uniwind) > > Read the current theme and adaptive theme state > [card] [useCSSVariable](/api/use-css-variable) > > Read theme variables directly in JavaScript > [card] [Scoped Variables](/api/scoped-variables) > > Override CSS variables for a subtree > [card] [Layout Direction](/api/layout-direction) > > Scope RTL and LTR variants to a subtree > [card] [useResolveClassNames](/api/use-resolve-class-names) > > Resolve class names into style objects at runtime > [card] [withUniwind](/api/with-uniwind) > > Add className support to third-party components # Scoped Variables Source: https://docs.uniwind.dev/api/scoped-variables Override CSS variables for a component subtree with `ScopedVariables` Available in Uniwind 1.11.0+ (Free) and 1.6.0+ (Pro) ## Overview `ScopedVariables` overrides CSS variables for a specific subtree without changing the active theme or global variable values. Use it for component previews, branded sections, and local design-token overrides. The nearest `ScopedVariables` value wins, so nested scopes inherit parent values and can override only what they need. > [!NOTE] > > `ScopedVariables` is a runtime variable boundary. Class names, hooks, and `withUniwind`-wrapped components inside the boundary resolve variables from the scoped values first. ## Usage ### Basic Example ```tsx theme={null} import { ScopedVariables } from 'uniwind' import { Text, View } from 'react-native' export function Example() { return ( Uses the active theme primary color Uses a scoped purple primary color ) } ``` ### Nested Scoped Variables Nested scopes merge with their parents. The closest value for each variable wins. ```tsx theme={null} import { ScopedVariables } from 'uniwind' import { Text, View } from 'react-native' export function NestedScopes() { return ( Purple primary from the outer scope Green primary from the inner scope Still inherits the amber secondary color ) } ``` ### Reading a Scoped Variable in JavaScript `useCSSVariable` reads the nearest scoped value and updates when the scope changes. ```tsx theme={null} import { ScopedVariables, useCSSVariable } from 'uniwind' import { Text, View } from 'react-native' function PrimaryValue() { const primary = useCSSVariable('--color-primary') return Primary: {String(primary)} } export function Example() { return ( ) } ``` ## API Reference ### Component Signature ```tsx theme={null} import { ScopedVariables } from 'uniwind' {/* scoped subtree */} ``` ### Props **variables** `Record\` *required* CSS variable overrides for this subtree. Every variable name must start with `--`; invalid names are ignored. **children** `React.ReactNode` *required* React children rendered inside the scoped variable boundary. ## Behavior Notes * `ScopedVariables` affects only its descendants and never mutates global theme variables. * Nested scopes merge with parent scopes; the nearest value for a variable wins. * Scoped values are used by `className`, `useCSSVariable`, `useResolveClassNames`, and `withUniwind`-wrapped components. * On web, numeric values become pixel values. For example, `16` is applied as `16px`. * The overridden variable should be defined in your theme or used by a class name, just like other CSS variables. ## Scoped Variables vs Other Theme APIs * Use `ScopedVariables` to override one or more values for a subtree. * Use [`ScopedTheme`](/api/scoped-themes) to apply an existing theme to a subtree. * Use [`Uniwind.updateCSSVariables`](/theming/update-css-variables) to persistently update values for an entire theme at runtime. ## Related > [card] [Scoped Themes](/api/scoped-themes) > > Apply an existing theme to a subtree > [card] [useCSSVariable](/api/use-css-variable) > > Read CSS variables in JavaScript > [card] [Update CSS Variables](/theming/update-css-variables) > > Update variables for an entire theme at runtime > [card] [Global CSS](/theming/global-css) > > Define CSS variables in your theme configuration # useCSSVariable Source: https://docs.uniwind.dev/api/use-css-variable Access CSS variable values in JavaScript with automatic theme updates Available in Uniwind 1.0.5+ ## Overview The `useCSSVariable` hook allows you to retrieve one or more CSS variable values directly in JavaScript. It's particularly useful when you need to access theme colors, spacing values, or other design tokens programmatically for calculations, animations, or third-party library configurations. > [!WARNING] > > This hook should be used sparingly. For most styling use cases, prefer using the `className` prop with Tailwind utilities. ## When to Use This Hook Use `useCSSVariable` when you need to: * Access theme colors for third-party libraries (e.g., chart libraries, map markers) * Perform calculations with design tokens (e.g., dynamic positioning based on spacing values) * Configure native modules that require color/size values * Pass theme values to JavaScript animation libraries * Access design tokens for runtime logic > [!TIP] > > **Prefer these alternatives when possible:** > > * For styling components: Use the `className` prop directly > * For multiple style properties: Use [`useResolveClassNames`](/api/use-resolve-class-names) > * For third-party components: Wrap them with [`withUniwind`](/api/with-uniwind) ## Usage ### Basic Example ```tsx theme={null} import { useCSSVariable } from 'uniwind' import { View, Text } from 'react-native' export const MyComponent = () => { const primaryColor = useCSSVariable('--color-primary') const spacing = useCSSVariable('--spacing-4') return ( Primary color: {primaryColor} Spacing: {spacing} ) } ``` ### Multiple Variables at Once You can also retrieve multiple CSS variables at once by passing an array: ```tsx theme={null} import { useCSSVariable } from 'uniwind' import { View, Text } from 'react-native' export const MyComponent = () => { const [primaryColor, spacing, backgroundColor] = useCSSVariable([ '--color-primary', '--spacing-4', '--color-background' ]) return ( Primary color: {primaryColor} Spacing: {spacing} ) } ``` > [!TIP] > > Using the array syntax is more efficient than calling `useCSSVariable` multiple times, as it only subscribes to theme changes once. ### With Chart Libraries ```tsx theme={null} import { useCSSVariable } from 'uniwind' import { LineChart } from 'react-native-chart-kit' export const ThemedChart = () => { const [primaryColor, backgroundColor, textColor] = useCSSVariable([ '--color-primary', '--color-background', '--color-foreground' ]) return ( primaryColor, labelColor: () => textColor, }} /> ) } ``` ### Accessing Custom Theme Variables ```tsx theme={null} import { useCSSVariable } from 'uniwind' import MapView, { Marker } from 'react-native-maps' export const ThemedMap = () => { const markerColor = useCSSVariable('--color-accent') return ( ) } ``` ## Making Variables Available For the hook to resolve a CSS variable, the variable must be either: ### Option 1: Used in a className (Recommended) Use the variable at least once anywhere in your app's `className` props: ```tsx theme={null} // Somewhere in your app ``` This makes `--color-primary` available to `useCSSVariable`: ```tsx theme={null} const primaryColor = useCSSVariable('--color-primary') // ✅ Works ``` ### Option 2: Define in Static Theme If you have CSS variables that are never used in classNames but need to be accessed in JavaScript, define them in a static theme block in your `global.css`: ```css global.css theme={null} @import 'tailwindcss'; @import 'uniwind'; @theme static { --color-al-teal-10: #eaeeee; --color-al-teal-25: #cad4d5; --color-al-teal-75: #607d81; --color-al-teal-100: #2b5257; --color-custom-teal-10: #eaeeee; --color-custom-teal-25: #cad4d5; --color-custom-teal-75: #607d81; --color-custom-teal-100: #2b5257; --chart-line-width: 2; --chart-dot-radius: 4; } ``` Then access them anywhere: ```tsx theme={null} const tealColor = useCSSVariable('--color-al-teal-75') // ✅ Works const lineWidth = useCSSVariable('--chart-line-width') // ✅ Works ``` > [!NOTE] > > Variables defined in `@theme static` are always available, even if they're never used in any `className`. ## Development Warnings In development mode, Uniwind will warn you if you try to access a variable that hasn't been made available: ```tsx theme={null} const unknownColor = useCSSVariable('--color-unknown') // Console warning: // "We couldn't find your variable --color-unknown. Make sure it's used // at least once in your className, or define it in a static theme as // described in the docs." ``` > [!TIP] > > If you see this warning, either use the variable in a `className` somewhere or add it to `@theme static` in your `global.css`. ## API Reference ### Arguments **name** `string | string[]` *required* The name of the CSS variable(s) to retrieve, including the `--` prefix. * **Single variable**: Pass a string (e.g., `'--color-primary'`) * **Multiple variables**: Pass an array of strings (e.g., `['--color-primary', '--spacing-4']`) ### Return Value The return type depends on the input: **single value** `string | number | undefined` When passing a **single string**, returns the resolved value of the CSS variable: * **Web**: Always returns a `string` (e.g., `"16px"`, `"#ff0000"`) * **Native**: Returns `string` or `number` depending on the value type (e.g., `16`, `"#ff0000"`) * **Undefined**: If the variable cannot be found **array of values** `Array\` When passing an **array of strings**, returns an array of resolved values in the same order: ```tsx theme={null} const [color, spacing, radius] = useCSSVariable([ '--color-primary', // Returns: "#3b82f6" '--spacing-4', // Returns: 16 (on native) or "16px" (on web) '--radius-lg' // Returns: 12 (on native) or "12px" (on web) ]) ``` ## Platform Differences > [accordion] Web Platform > > On web, `useCSSVariable` uses `getComputedStyle()` to retrieve values from the DOM. All values are returned as strings: > > ```tsx theme={null} > // Single variable > const color = useCSSVariable('--color-primary') > // Web: "#3b82f6" (string) > > // Multiple variables > const [color, spacing] = useCSSVariable(['--color-primary', '--spacing-4']) > // Web: ["#3b82f6", "16px"] (strings) > ``` > [accordion] Native Platform > > On React Native, `useCSSVariable` accesses the internal variable store. Numeric values are returned as numbers: > > ```tsx theme={null} > // Single variable > const spacing = useCSSVariable('--spacing-4') > // Native: 16 (number) > > const color = useCSSVariable('--color-primary') > // Native: "#3b82f6" (string) > > // Multiple variables > const [color, spacing] = useCSSVariable(['--color-primary', '--spacing-4']) > // Native: ["#3b82f6", 16] (mixed types) > ``` ## Performance Considerations > [!NOTE] > > The `useCSSVariable` hook is reactive and will automatically update when the theme changes, ensuring your values stay in sync with the active theme. Keep in mind: * The hook subscribes to theme changes, so components will re-render when themes switch * **Use array syntax for multiple variables**: When you need multiple CSS variables, pass an array instead of calling the hook multiple times. This creates only one subscription instead of multiple. * For static values that don't need theme reactivity, consider storing them outside the component **Example of efficient usage:** ```tsx theme={null} // ✅ Good: Single subscription const [color, spacing, radius] = useCSSVariable([ '--color-primary', '--spacing-4', '--radius-lg' ]) // ❌ Less efficient: Multiple subscriptions const color = useCSSVariable('--color-primary') const spacing = useCSSVariable('--spacing-4') const radius = useCSSVariable('--radius-lg') ``` ## Related > [card] [useResolveClassNames](/api/use-resolve-class-names) > > Convert full className strings to style objects > [card] [Global CSS](/theming/global-css) > > Learn how to define CSS variables in your theme > [card] [Theming Basics](/theming/basics) > > Understand how themes work in Uniwind > [card] [withUniwind](/api/with-uniwind) > > Wrap third-party components to add className support > [card] [Scoped Variables](/api/scoped-variables) > > Override variables for a component subtree > [card] [Scoped Themes](/api/scoped-themes) > > Apply an existing theme to a component subtree # useResolveClassNames Source: https://docs.uniwind.dev/api/use-resolve-class-names Convert Tailwind class names to React Native style objects at runtime ## Overview The `useResolveClassNames` hook converts Tailwind class names into valid React Native `style` objects. This is useful when working with components or libraries that don't support the `className` prop directly, such as `react-navigation` theme configuration or third-party components that can't be wrapped in `withUniwind`. > [!WARNING] > > This hook should be used rarely. For most use cases, prefer using the `className` prop on Uniwind-wrapped components. ## When to Use This Hook Use `useResolveClassNames` when you need to: * Configure libraries that accept style objects (e.g., `react-navigation` themes) * Pass styles to third-party components that only accept `style` props (and can't be wrapped in `withUniwind`) * Generate style objects dynamically for special use cases * Work with legacy code that requires style objects > [!TIP] > > **Prefer these alternatives when possible:** > > * For React Native components: Use the `className` prop directly. See [Components](/components/activity-indicator). > * For third-party components: Wrap them with [`withUniwind`](/api/with-uniwind) to add `className` support. ## Usage ### Basic Example ```tsx theme={null} import { useResolveClassNames } from 'uniwind' import { View } from 'react-native' export const MyComponent = () => { const styles = useResolveClassNames('bg-red-500 p-4 rounded-lg') return Content } ``` ### With react-navigation ```tsx theme={null} import { useResolveClassNames } from 'uniwind' import { NavigationContainer } from '@react-navigation/native' export const App = () => { const headerStyle = useResolveClassNames('bg-blue-500') const cardStyle = useResolveClassNames('bg-white dark:bg-gray-900') const theme = { colors: { background: 'transparent', }, // Use resolved styles for navigation theme dark: false, } return ( {/* Your screens */} ) } ``` ### Dynamic Class Names ```tsx theme={null} import { useResolveClassNames } from 'uniwind' export const DynamicCard = ({ variant }: { variant: 'primary' | 'secondary' }) => { const cardClasses = variant === 'primary' ? 'bg-blue-500 text-white' : 'bg-gray-200 text-black' const styles = useResolveClassNames(cardClasses) return Card content } ``` ### Combining Multiple Style Objects ```tsx theme={null} import { useResolveClassNames } from 'uniwind' import { View, StyleSheet } from 'react-native' export const CombinedStyles = () => { const tailwindStyles = useResolveClassNames('p-4 rounded-lg') const customStyles = StyleSheet.create({ shadow: { shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.25, shadowRadius: 3.84, elevation: 5, }, }) return Content } ``` ## API Reference ### Arguments **classNames** `string` *required* A string containing Tailwind class names to be resolved at runtime. Supports all standard Tailwind utilities and theme-based variants (e.g., `dark:bg-gray-900`). ### Return Value **styles** `object` A valid React Native `style` object containing the resolved styles. This object can be passed directly to any component's `style` prop or combined with other style objects. ## Performance Considerations > [!NOTE] > > The `useResolveClassNames` hook is reactive and will automatically update when the theme changes, ensuring your styles stay in sync with the active theme. While `useResolveClassNames` is optimized for performance, be aware that: * It processes class names at runtime, which is slightly less performant than compile-time resolution * For frequently re-rendered components, consider memoizing the result if the class names don't change * Using the `className` prop directly is more performant when possible ## Related > [card] [withUniwind](/api/with-uniwind) > > Wrap third-party components to add className support > [card] [Components](/components/activity-indicator) > > Learn about Uniwind-wrapped React Native components > [card] [useCSSVariable](/api/use-css-variable) > > Access individual CSS variable values in JavaScript > [card] [Global CSS](/theming/global-css) > > Define CSS variables in your theme # useUniwind Source: https://docs.uniwind.dev/api/use-uniwind React hook for accessing the current theme and reacting to theme changes ## Overview The `useUniwind` hook provides access to the current theme name and adaptive theme status. It automatically triggers a re-render when the theme changes or when adaptive themes are toggled. This is useful when you need to conditionally render components or apply logic based on the active theme. ## Usage ```tsx theme={null} import { useUniwind } from 'uniwind' export const MyComponent = () => { const { theme, hasAdaptiveThemes } = useUniwind() return ( Current theme: {theme} Adaptive themes: {hasAdaptiveThemes ? 'enabled' : 'disabled'} ) } ``` ## When to Use This Hook The `useUniwind` hook is ideal for scenarios where you need to: * Display the current theme name in your UI * Check if adaptive themes (system theme) are enabled * Conditionally render different components based on the active theme * Execute side effects when the theme changes * Access theme information for logging or analytics > [!TIP] > > For most styling use cases, you don't need this hook. Use theme-based className variants instead (e.g., `dark:bg-gray-900`). ## Return Values **theme** `string` The name of the currently active theme (e.g., `"light"`, `"dark"`, `"system"`, or any custom theme name you've defined). **hasAdaptiveThemes** `boolean` Indicates whether adaptive themes are currently enabled. When `true`, the app automatically follows the device's system color scheme. When `false`, the app uses a fixed theme. ## Examples ### Conditional Rendering Based on Theme ```tsx theme={null} import { useUniwind } from 'uniwind' import { View, Text } from 'react-native' export const ThemedIcon = () => { const { theme } = useUniwind() return ( {theme === 'dark' ? ( ) : ( )} ) } ``` ### Using Theme in Side Effects ```tsx theme={null} import { useUniwind } from 'uniwind' import { useEffect } from 'react' export const ThemeLogger = () => { const { theme } = useUniwind() useEffect(() => { console.log('Theme changed to:', theme) // You could also: // - Update analytics // - Store preference in MMKV storage // - Trigger additional theme-related logic }, [theme]) return null } ``` ### Displaying Current Theme ```tsx theme={null} import { useUniwind } from 'uniwind' import { View, Text } from 'react-native' export const ThemeIndicator = () => { const { theme, hasAdaptiveThemes } = useUniwind() return ( Active theme: {theme} {hasAdaptiveThemes ? 'Following system theme' : 'Fixed theme'} ) } ``` ### Reacting to Adaptive Theme Changes ```tsx theme={null} import { useUniwind } from 'uniwind' import { useEffect } from 'react' export const AdaptiveThemeMonitor = () => { const { theme, hasAdaptiveThemes } = useUniwind() useEffect(() => { if (hasAdaptiveThemes) { console.log('System theme changed to:', theme) // Handle system theme change // - Update status bar style // - Log analytics event // - Sync with backend preferences } }, [theme, hasAdaptiveThemes]) return null } ``` ## Related > [card] [Theming Basics](/theming/basics) > > Learn how to set up and configure themes in Uniwind > [card] [Custom Themes](/theming/custom-themes) > > Create and manage custom theme configurations # withUniwind Source: https://docs.uniwind.dev/api/with-uniwind Add `className` support to any React Native component ## Overview The `withUniwind` higher-order component (HOC) wraps any React Native component to add `className` prop support. This is essential for using third-party components with Uniwind's Tailwind-based styling system. ## Why Use withUniwind? Many popular React Native libraries export components that don't natively support the `className` prop. Instead, they accept the traditional `style` prop. The `withUniwind` wrapper bridges this gap, allowing you to use Tailwind classes with any component. > [!TIP] > > **Some third-party components work out of the box!** Libraries like React Native Reanimated that are built on top of React Native's core components (View, Text, etc.) automatically support `className` without wrapping. You only need `withUniwind` when the underlying implementation uses custom native components or doesn't forward the `style` prop properly. ### Problem ```tsx theme={null} import { SafeAreaView } from 'react-native-safe-area-context'; // ❌ This won't work - SafeAreaView is a third-party component {/* content */} ``` ### Solution ```tsx theme={null} import { withUniwind } from 'uniwind' import { SafeAreaView } from 'react-native-safe-area-context'; const StyledSafeAreaView = withUniwind(SafeAreaView); // ✅ This works - we've wrapped the component with withUniwind {/* content */} ``` ## Automatic Prop Mapping `withUniwind` automatically maps props based on their names. Any prop containing `style` or `color` in its name is automatically mapped. > [!NOTE] > > **No manual mapping needed!** The `style` prop is automatically mapped to `className`, and color-related props get their own `*ClassName` variants. ### Automatic Mappings Here are some examples of how props are automatically mapped: | Original Prop | Mapped ClassName Prop | Example Usage | | - | - | - | | `style` | `className` | `` | | `color` | `colorClassName` | `` | | `backgroundColor` | `backgroundColorClassName` | `` | | `borderColor` | `borderColorClassName` | `` | | `tintColor` | `tintColorClassName` | `` | ### Example: Using Auto-Mapped Color Props ```tsx theme={null} import { withUniwind } from 'uniwind' import { ActivityIndicator } from 'react-native-activity-indicator' const StyledActivityIndicator = withUniwind(ActivityIndicator) // Use colorClassName instead of the color prop ``` ## Custom Prop Mapping For advanced use cases, you can define custom mappings to map className props to component props. This is useful for components with non-standard prop names like `width`, `size`, `fill`, or `stroke`. ### How Mapping Works The mapping object structure is: ```tsx theme={null} withUniwind(Component, { targetProp: { // The component's original prop name fromClassName: 'myClassName', // The className prop you'll use in JSX styleProperty: 'width', // (Optional) Which CSS property to extract }, }) ``` > [!NOTE] > > **Understanding the structure:** > > * **Object key** (`targetProp`) → The prop that the component actually receives > * **`fromClassName`** → The new className prop you'll write in your JSX > * **`styleProperty`** → Which CSS property value to extract and pass to the target prop ### Example: Mapping a Width Prop Some components accept a `width` prop as a number or string, not a style object. Here's how to map it: ```tsx theme={null} import { withUniwind } from 'uniwind' import { ProgressBar } from 'some-library' const StyledProgressBar = withUniwind(ProgressBar, { width: { fromClassName: 'widthClassName', styleProperty: 'width', }, }) // Usage: pass Tailwind width classes via widthClassName // The component receives: width={256} ``` ### Example: Mapping a Size Prop ```tsx theme={null} import { withUniwind } from 'uniwind' import { Avatar } from 'some-library' const StyledAvatar = withUniwind(Avatar, { size: { fromClassName: 'sizeClassName', styleProperty: 'width', // Extract width value for the size prop }, }) // Usage: use width classes to control size // The component receives: size={48} ``` ### Example: SVG Stroke and Fill SVG components often use `stroke` and `fill` props that accept color values: ```tsx theme={null} import { withUniwind } from 'uniwind' import { Path } from 'react-native-svg' export const StyledPath = withUniwind(Path, { stroke: { fromClassName: 'strokeClassName', styleProperty: 'accentColor', }, fill: { fromClassName: 'fillClassName', styleProperty: 'accentColor', }, }) // Usage: use accent-* classes to set colors ``` > [!TIP] > > Use `accent-*` classes when you need to extract a color value. The `accentColor` style property is specifically designed for this purpose in Uniwind. ### Mapping Entire Style Objects If you omit `styleProperty`, the entire resolved style object is passed to the target prop: ```tsx theme={null} import { withUniwind } from 'uniwind' import { CustomComponent } from 'some-library' export const StyledCustomComponent = withUniwind(CustomComponent, { containerStyle: { fromClassName: 'containerClassName', // No styleProperty - maps the entire style object }, }) // Usage: all styles are passed as an object to containerStyle // The component receives: containerStyle={{ padding: 16, backgroundColor: '...', borderRadius: 8 }} ``` ### Third-Party UI Components ```tsx theme={null} import { withUniwind } from 'uniwind' import { Button } from 'react-native-paper' const StyledButton = withUniwind(Button) export const MyButton = () => ( Press me ) ``` ## API Reference ### Function Signature ```tsx theme={null} withUniwind(Component: T, mappings?: PropMappings): T ``` ### Parameters **Component** `React.ComponentType` *required* The React component to wrap with className support. **mappings** `PropMappings` Optional custom prop mappings. Each mapping defines how to convert a className prop to a component prop. **Mapping structure:** ```tsx theme={null} { [targetProp: string]: { fromClassName: string, // The className prop name to create styleProperty?: string // Optional CSS property to extract (omit to use entire style) } } ``` ### Return Value **StyledComponent** `React.ComponentType` A wrapped component that accepts `className` and auto-generated `*ClassName` props, in addition to all original component props. ## Best Practices > [!TIP] > > **Create reusable styled components:** Define your wrapped components in a separate file and export them for reuse throughout your app. ```tsx theme={null} // components/styled.ts import { withUniwind } from 'uniwind' import { SafeAreaView } from 'react-native-safe-area-context' import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view' export const StyledSafeAreaView = withUniwind(SafeAreaView) export const StyledKeyboardAwareScrollView = withUniwind(KeyboardAwareScrollView) ``` > [!WARNING] > > **Performance consideration:** Wrap components at the module level (outside your component functions) to avoid recreating the wrapper on every render. ## Related > [card] [useResolveClassNames](/api/use-resolve-class-names) > > Convert classNames to style objects at runtime > [card] [Third-Party Components](/components/other-components) > > Learn about styling third-party component libraries # Responsive Breakpoints Source: https://docs.uniwind.dev/breakpoints Use Tailwind's responsive breakpoints to build adaptive layouts in React Native ## Overview Uniwind supports Tailwind's responsive breakpoint system out of the box, allowing you to create adaptive layouts that respond to different screen sizes. Use breakpoint prefixes like `sm:`, `md:`, `lg:`, and `xl:` to apply styles conditionally based on screen width. > [!NOTE] > > Uniwind uses the same breakpoint syntax as Tailwind CSS. If you're familiar with Tailwind on the web, you already know how to use breakpoints in React Native! ## Default Breakpoints Uniwind includes five default breakpoints based on common device sizes: | Breakpoint | Minimum Width | CSS | | - | - | - | | `sm` | 640px | `@media (min-width: 640px)` | | `md` | 768px | `@media (min-width: 768px)` | | `lg` | 1024px | `@media (min-width: 1024px)` | | `xl` | 1280px | `@media (min-width: 1280px)` | | `2xl` | 1536px | `@media (min-width: 1536px)` | > [!TIP] > > All breakpoints use a **mobile-first** approach. This means unprefixed utilities (like `p-4`) apply to all screen sizes, and prefixed utilities (like `md:p-8`) apply at the specified breakpoint and above. ## Basic Usage Apply different styles at different breakpoints using the breakpoint prefix: ```tsx theme={null} import { View, Text } from 'react-native' export const ResponsiveCard = () => ( Responsive Typography This text size adapts to screen width ) ``` **How it works:** * On screens `< 640px`: Uses `p-4` and `text-base` * On screens `≥ 640px`: Uses `p-6` and `text-lg` * On screens `≥ 1024px`: Uses `p-8` and `text-xl` ## Mobile-First Design Uniwind uses a mobile-first breakpoint system, meaning you style for mobile first, then add styles for larger screens: ### ❌ Don't style desktop-first ```tsx theme={null} import { View } from 'react-native' // Desktop-first approach (not recommended) {/* Content */} ``` ### ✅ Do style mobile-first ```tsx theme={null} import { View } from 'react-native' // Mobile-first approach (recommended) {/* Content */} ``` > [!TIP] > > Start with the mobile layout (no prefix), then use `sm:`, `md:`, `lg:` to progressively enhance for larger screens. ## Common Patterns ### Responsive Layouts Create layouts that adapt to screen size: ```tsx theme={null} import { View, Text } from 'react-native' export const ResponsiveGrid = () => ( {/* Mobile: 1 column, Tablet: 2 columns, Desktop: 3 columns */} Item 1 Item 2 Item 3 ) ``` ### Responsive Spacing Adjust padding and margins based on screen size: ```tsx theme={null} import { View, Text } from 'react-native' export const ResponsiveContainer = () => ( Responsive Heading Content with responsive spacing ) ``` ### Responsive Visibility Show or hide elements at different breakpoints: ```tsx theme={null} import { View, Text } from 'react-native' export const ResponsiveNav = () => ( {/* Always visible */} Logo {/* Hidden on mobile, visible on tablet and up */} Home About Contact {/* Visible on mobile, hidden on tablet and up */} ☰ ) ``` ## Max-width and Range Breakpoints Use the `max-*` variants to apply styles **below** a breakpoint, and stack a breakpoint with a `max-*` variant to target a range: ```tsx theme={null} import { View, Text } from 'react-native' export const RangeExample = () => ( {/* Only between md (768px) and lg (1024px) */} Tablet only ) ``` | Variant | CSS | | - | - | | `max-md:` | `@media (width < 768px)` | | `md:max-lg:` | `@media (width >= 768px)` and `@media (width < 1024px)` | ## Height Media Queries > [!NOTE] > > Height media queries on native require Uniwind 1.13.0 or Uniwind Pro 1.9.0 or later. Tailwind's breakpoints only check screen width. To style based on screen height, define a custom variant with a `height` media query in your `global.css`: ```css global.css theme={null} @import 'tailwindcss'; @import 'uniwind'; @custom-variant tall (@media (height >= 800px)); @custom-variant short (@media (height < 600px)); ``` Then use it like any other variant: ```tsx theme={null} import { View, Text } from 'react-native' export const Hero = () => ( Adapts to screen height ) ``` For one-off cases, use an arbitrary variant instead: `[@media(height>=800px)]:p-8`. Height queries support `min-height` / `max-height`, ranges like `(300px <= height < 500px)`, and combinations with `width` and `orientation`: ```css global.css theme={null} @custom-variant compact-landscape (@media (orientation: landscape) and (height < 500px)); ``` Styles update automatically when the screen size changes, for example after rotation or a Split View resize. ## Custom Breakpoints You can customize breakpoints to match your specific design needs using the `@theme` directive in your `global.css`: ```css global.css theme={null} @import 'tailwindcss'; @import 'uniwind'; @theme { /* Override default breakpoints */ --breakpoint-sm: 576px; --breakpoint-md: 768px; --breakpoint-lg: 992px; --breakpoint-xl: 1200px; --breakpoint-2xl: 1400px; } ``` ### Adding Custom Breakpoints You can also add entirely new breakpoints: ```css global.css theme={null} @theme { /* Keep default breakpoints */ --breakpoint-sm: 640px; --breakpoint-md: 768px; --breakpoint-lg: 1024px; --breakpoint-xl: 1280px; --breakpoint-2xl: 1536px; /* Add custom breakpoints */ --breakpoint-xs: 480px; /* Extra small devices */ --breakpoint-3xl: 1920px; /* Ultra-wide screens */ --breakpoint-tablet: 820px; /* iPad-specific */ } ``` Usage: ```tsx theme={null} import { View, Text } from 'react-native' Responsive with custom breakpoints ``` ## Best Practices > [!TIP] > > **Design mobile-first:** Start with mobile styles and progressively enhance for larger screens. This ensures a solid foundation for all devices. > [!TIP] > > **Use semantic breakpoint names:** When adding custom breakpoints, use meaningful names like `tablet`, `desktop`, or `ultrawide` instead of arbitrary values. > [!WARNING] > > **Avoid too many breakpoints:** Stick to 3-5 breakpoints maximum. Too many breakpoints make your code harder to maintain and can lead to inconsistent designs. ## Related > [card] [Tailwind Basics](/tailwind-basics) > > Learn the fundamentals of using Tailwind with Uniwind > [card] [Platform Selectors](/api/platform-select) > > Combine breakpoints with platform-specific styles > [card] [Global CSS](/theming/global-css) > > Customize breakpoints in your global.css file > [card] [Supported Class Names](/class-names) > > See all supported Tailwind utilities > [!NOTE] > > For more details on Tailwind's responsive design system, check the [official Tailwind documentation](https://tailwindcss.com/docs/responsive-design). # Supported classNames Source: https://docs.uniwind.dev/class-names Comprehensive guide to Tailwind class names supported in Uniwind ## Overview > [!WARNING] > > React Native uses the Yoga layout engine, not browser CSS. Key differences to be aware of: > > * **No CSS cascade/inheritance**: Styles don't inherit from parent components > * **Flexbox by default**: All views use `flexbox` with `flexDirection: 'column'` by default > * **Limited CSS properties**: Only a subset of CSS is supported (no floats, grid, pseudo-elements, etc.) > * **Different units**: No `em`, `rem`, or percentage-based units for most properties Uniwind supports the vast majority of Tailwind CSS utility classes out of the box. This page documents special cases, platform-specific classes, and differences between the free and pro versions. > [!NOTE] > > **Most Tailwind classes just work!** If a class name isn't listed below as unsupported or with special behavior, you can assume Uniwind fully supports it. > [!TIP] > > Found a class name that doesn't work as expected? Please [open an issue on GitHub](https://github.com/uni-stack/uniwind/issues) to help us improve this documentation. ## Standard Tailwind Classes All standard Tailwind utility classes are supported, including: * **Layout**: `container`, `flex`, `block`, `hidden`, etc. * **Spacing**: `p-*`, `m-*`, `space-*`, `gap-*` * **Sizing**: `w-*`, `h-*`, `min-w-*`, `max-w-*`, etc. * **Typography**: `text-*`, `font-*`, `leading-*`, `tracking-*`, etc. * **Colors**: `bg-*`, `text-*`, `border-*`, `shadow-*`, etc. * **Borders**: `border-*`, `rounded-*`, `ring-*` * **Effects**: `shadow-*`, `opacity-*` * **Filters**: `blur-*`, `drop-shadow-*`, `grayscale`, `saturate-*`, etc. (see [platform notes](/faq#how-do-i-enable-filters-blur-grayscale-on-native)) * **Flexbox**: `justify-*`, `items-*`, `content-*`, etc. * **Positioning**: `absolute`, `relative`, `top-*`, `left-*`, etc. * **Transforms**: `translate-*`, `rotate-*`, `scale-*`, `skew-*` * **State selectors**: `active:`, `disabled:`, `focus:` (with Tailwind 4.3.3+, which emits flattened variant selectors, these need Uniwind 1.12.0+ or Uniwind Pro 1.7.0+) ## Platform-Specific Variants Uniwind extends Tailwind with platform-specific variants for React Native: ```tsx theme={null} // Style only on iOS // Style only on Android // Style only on Web // TV platforms (requires isTV: true in metro.config.js) ``` Learn more about platform variants in the [Platform Selectors](/api/platform-select) documentation. ## Direction Variants (`rtl:` / `ltr:`) Style based on the layout direction: ```tsx theme={null} Aligned with the reading direction ``` By default, the variants follow the global RTL state. To force a direction for a specific subtree, wrap it in [`LayoutDirection`](/api/layout-direction) (available in Uniwind 1.9.0+, Pro 1.4.0+): ```tsx theme={null} import { LayoutDirection } from 'uniwind' Forced RTL ``` ## Logical Text Alignment Available in Uniwind 1.12.1+ and Uniwind Pro 1.8.0+ `text-start` and `text-end` pass through as `textAlign: 'start'` and `textAlign: 'end'`, so text aligns with the reading direction without separate `ltr:` / `rtl:` classes: ```tsx theme={null} Aligned to the start edge Aligned to the end edge ``` > [!NOTE] > > React Native resolves `end` from 0.87. On older versions, both values fall back to natural alignment. ## Variable Fonts Available in Uniwind 1.12.1+ and Uniwind Pro 1.8.0+ Tailwind has no built-in `font-variation-settings` utility, so use an arbitrary property. Quote the axis tag and use `_` for spaces: ```tsx theme={null} // Single axis Variable weight // Multiple axes Weight and slant // Axis value from a CSS variable From a variable ``` Uniwind maps the value to the `fontVariationSettings` style and keeps the axis tags quoted, which React Native requires on both iOS and Android. > [!NOTE] > > React Native applies `fontVariationSettings` from 0.88. The font must be a variable font that exposes the axes you set. ## Viewport Units Arbitrary values with `vw` and `vh` resolve against the screen size: ```tsx theme={null} ``` ## The `accent-*` Prefix React Native components often have color props that are separate from the `style` prop (like `color`, `tintColor`, `underlayColor`). These props expect a plain color string, not a style object. Uniwind uses the `accent-*` prefix to handle these cases. ### Why Use `accent-*`? When you use a `*ClassName` prop that maps to a color prop (e.g., `colorClassName`, `tintColorClassName`), you must use the `accent-*` prefix to indicate that you want to extract a color value, not a style object. > [!NOTE] > > **For style props:** Use regular Tailwind classes directly (e.g., `className="bg-blue-500"`). > > **For non-style color props:** Use the `accent-` prefix (e.g., `colorClassName="accent-blue-500"`). ### How It Works Under the hood, Uniwind resolves `accent-*` classes to the `accentColor` style property, then extracts the raw color value and passes it as a string to the native prop. ### Common Color Props Requiring `accent-*` | Prop | Component Examples | | - | - | | `colorClassName` | ActivityIndicator, Button, Image | | `tintColorClassName` | Image, RefreshControl | | `underlayColorClassName` | TouchableHighlight | | `selectionColorClassName` | TextInput, Text | | `cursorColorClassName` | TextInput | | `placeholderTextColorClassName` | TextInput | | `thumbColorClassName` | Switch | | `trackColorOnClassName` / `trackColorOffClassName` | Switch | | `backdropColorClassName` | Modal | | `endFillColorClassName` | ScrollView, FlatList, SectionList | ### Selector Support `accent-*` classes support all the same selectors as regular Tailwind classes, including theme variants, platform variants, and state selectors: ```tsx theme={null}