# 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. 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} ) ``` ### 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 */} ``` The `light-dark()` function is particularly useful for maintaining color consistency across themes without needing separate CSS variables for each theme. ## Best Practices **Prefer Tailwind utilities for simple styles.** Use custom CSS classes for complex, reusable component patterns that would be verbose or repetitive with utility classes. **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 The CSS parser is continuously evolving. We're actively looking for feedback to help identify missing features and limitations. Let us know what CSS features you need or issues you've encountered! ## Related Learn how to use Tailwind utilities in Uniwind 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. 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} @layer utilities { .h-hairline { height: hairlineWidth(); } .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} @layer utilities { .text-sm-scaled { font-size: calc(fontScale() * 0.9); } .text-base-scaled { font-size: fontScale(); } } ``` **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} @layer utilities { .w-icon { width: pixelRatio(); } .w-avatar { 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} @layer utilities { .bg-adaptive { background-color: light-dark(#ffffff, #1f2937); } .text-adaptive { color: light-dark(#111827, #f9fafb); } .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 ``` The `light-dark()` function is particularly useful for maintaining color consistency across themes without needing separate CSS variables for each theme. ## Related Learn about CSS variable support and custom CSS classes Combine with themes for powerful styling # 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. 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 The relative path to your CSS entry file from the project root. This file should contain your Tailwind imports and custom CSS. **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 */ ``` Keep your CSS entry file in the root, `app`, or `src` directory for easier path management. ### extraThemes 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; } } } ``` After adding new themes, restart your Metro bundler for changes to take effect. Learn more about creating and managing custom themes ### dtsFile 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', }); ``` 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 Configuration for CSS unit polyfills and adjustments to ensure cross-platform consistency. #### polyfills.rem 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 ## 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 }, }); ``` ## 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 Get started with Uniwind in 3 minutes Create and manage custom themes beyond light and dark Configure global styles and CSS variables 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, and Web ## 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. 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 Targets iOS devices (iPhone, iPad). Styles are applied only when running on iOS. Targets Android devices. Styles are applied only when running on Android. Targets web browsers. Styles are applied only when running in a web environment (e.g., React Native Web). ## 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 Media Queries in @theme While platform selectors like `ios:`, `android:`, and `web:` are great for component-level styling, Uniwind also supports platform-specific media queries within the `@theme` directive. This allows you to define platform-specific design tokens and CSS variables that affect your entire theme. Platform media queries in `@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 */ @media ios { --font-sans: "system-ui"; --spacing-4: 20px; } /* Android-specific overrides */ @media android { --font-sans: "sans-serif"; --spacing-4: 18px; } /* Web-specific overrides */ @media web { --font-sans: "Inter"; --spacing-4: 16px; } } } ``` ### When to Use Each Approach Understanding when to use platform selectors vs platform media queries helps you build better cross-platform apps: **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 for global theme configuration** ```css theme={null} @layer theme { :root { --font-sans: "Inter"; @media 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"; --font-base: 16px; @media ios { --font-sans: "-apple-system", "SF Pro Text"; --font-base: 17px; /* iOS prefers slightly larger text */ } @media android { --font-sans: "Roboto"; --font-base: 14px; /* Material Design standard */ } @media web { --font-sans: "Inter", "system-ui", sans-serif; --font-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 { @media ios { /* iOS prefers more generous spacing */ --spacing-4: 20px; --spacing-6: 28px; } @media android { /* Material Design spacing */ --spacing-4: 16px; --spacing-6: 24px; } } } ``` ### Combining with Theme Variants Platform media queries 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; } @media ios { --font-sans: "SF Pro Text"; } @media android { --font-sans: "Roboto"; } } } ``` ```tsx theme={null} import { View, Text } from 'react-native' export const ThemedText = () => ( Platform and theme-aware text ) ``` Platform media queries can only be used inside the `@theme` directive in your `global.css` file. They define global theme values, not component-specific styles. ## Related Learn about all supported Tailwind classes in Uniwind Combine platform selectors with theme variants # 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`. 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 **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 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 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 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 Wrap third-party components to add className support Learn about Uniwind-wrapped React Native components # 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 automatically triggers a re-render when the theme changes. 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 } = useUniwind() return ( Current theme: {theme} ) } ``` ## When to Use This Hook The `useUniwind` hook is ideal for scenarios where you need to: * Display the current theme name in your UI * Conditionally render different components based on the active theme * Execute side effects when the theme changes * Access theme information for logging or analytics 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 The name of the currently active theme (e.g., `"light"`, `"dark"`, or any custom theme name you've defined). ## 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 } = useUniwind() return ( Active theme: {theme} ) } ``` ## Related Learn how to set up and configure themes in Uniwind 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. **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. **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 specific props to style properties. This is particularly useful for SVG components or components with non-standard prop names. ### Mapping with Style Properties Map a custom className prop to a specific CSS property: ```tsx theme={null} import { withUniwind } from 'uniwind' import { Path } from 'react-native-svg' export const StyledPath = withUniwind(Path, { stroke: { fromClassName: 'strokeClassName', styleProperty: 'accentColor', }, }) // Usage: strokeClassName maps to stroke, using accentColor from the class ``` In this example: * `strokeClassName` is the new prop you'll use in JSX * `stroke` is the original component prop being mapped * `accentColor` is the CSS property to extract from the className ### Mapping Background Colors You can map any style property, including background colors: ```tsx theme={null} import { withUniwind } from 'uniwind' import { Path } from 'react-native-svg' export const StyledPath = withUniwind(Path, { stroke: { fromClassName: 'strokeClassName', styleProperty: 'backgroundColor', }, }) // Usage: strokeClassName maps to stroke, using backgroundColor ``` ### Mapping Entire Style Objects If you omit the `styleProperty`, `withUniwind` will map the entire resolved style object instead of a single property: ```tsx theme={null} import { withUniwind } from 'uniwind' import { CustomComponent } from 'some-library' export const StyledCustomComponent = withUniwind(CustomComponent, { customProp: { fromClassName: 'customClassName', // No styleProperty - maps the entire style object }, }) // Usage: All styles from customClassName are applied to customProp ``` ### 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 The React component to wrap with className support. 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 A wrapped component that accepts `className` and auto-generated `*ClassName` props, in addition to all original component props. ## Best Practices **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) ``` **Performance consideration:** Wrap components at the module level (outside your component functions) to avoid recreating the wrapper on every render. ## Related Convert classNames to style objects at runtime Learn about styling third-party component libraries # Supported classNames Source: https://docs.uniwind.dev/class-names Comprehensive guide to Tailwind class names supported in Uniwind ## Overview 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. **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. Found a class name that doesn't work as expected? Please [open an issue on GitHub](https://github.com/Unistyles-OSS/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-*` * **Flexbox**: `justify-*`, `items-*`, `content-*`, etc. * **Positioning**: `absolute`, `relative`, `top-*`, `left-*`, etc. * **Transforms**: `translate-*`, `rotate-*`, `scale-*`, `skew-*` * **Pseudo-elements**: `focus:`, `active:`, `disabled:` ## 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 ``` Learn more about platform variants in the [Platform Selectors](/api/platform-select) documentation. ## Unsupported Classes | Class Name | Free Version | Pro Version | Description | | -------------------------------------------------------------- | ------------ | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | **p-safe**, **pt-safe**, **pb-safe**, **pl-safe**, **pr-safe** | ❌ | ✅ | Applies safe area padding. The free version doesn't depend on `react-native-safe-area-context`. The pro version injects safe area values directly from C++ for better performance. | | **m-safe**, **mt-safe**, **mb-safe**, **ml-safe**, **mr-safe** | ❌ | ✅ | Applies safe area margins. Similar to padding variants, pro version provides optimized C++ implementation. | | **grid** | ❌ | ❌ | Not supported by Yoga (React Native) | Some Tailwind classes are not applicable to React Native and are not supported: The following web-specific classes have no React Native equivalent and will be ignored: * **Pseudo-classes**: `hover:*`, `visited:*` (use Pressable states instead) * **Pseudo-elements**: `before:*`, `after:*`, `placeholder:*` * **Media queries**: `print:*`, `screen:*` * **Float & Clear**: `float-*`, `clear-*` * **Break**: `break-before-*`, `break-after-*`, `break-inside-*` * **Columns**: `columns-*`, `break-*` * **Aspect Ratio**: Some variants may have limited support For interactive states like hover and press, use the `Pressable` component's built-in state management and apply classes conditionally. ## Need More Information? This page is continuously updated as we expand Uniwind's capabilities. Help us improve this documentation by reporting missing or incorrect information. # ActivityIndicator Source: https://docs.uniwind.dev/components/activity-indicator Learn how to use ActivityIndicator with Uniwind className props ## Overview The `ActivityIndicator` component displays a circular loading indicator. Uniwind provides className prop support for styling this component. ## Styling Convention **For `style` props:** Use regular Tailwind classes directly (e.g., `className="p-4"`). **For non-style props** (like `color`): Use the `accent-` prefix (e.g., `colorClassName="accent-bg-blue-500"`). ## Uniwind Bindings Maps to the `style` prop. Use any Tailwind utility classes. Maps to the `color` prop. Requires `accent-` prefix for color values. ## Usage Example ```tsx theme={null} import { ActivityIndicator, View } from 'react-native' ``` # Button Source: https://docs.uniwind.dev/components/button Learn how to use Button with Uniwind className props ## Overview The `Button` component is a basic button with a simple platform-specific appearance. Uniwind provides className prop support for styling this component. ## Styling Convention **For `style` props:** Use regular Tailwind classes directly (e.g., `className="p-4"`). **For non-style props** (like `color`): Use the `accent-` prefix (e.g., `colorClassName="accent-bg-blue-500"`). ## Uniwind Bindings Maps to the `color` prop. Requires `accent-` prefix for color values. ## Usage Example ```tsx theme={null} import { Button } from 'react-native'