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.
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
Common Patterns
Side-by-Side Direction Previews
Nested Scopes
Hooks and withUniwind in a Layout Direction Scope
Hooks and HOCs resolve against the closest LayoutDirection boundary:
useResolveClassNames()resolvesrtl:/ltr:variants using the scoped directionwithUniwind()mappings use values resolved from the scoped direction
API Reference
Component Signature
Props
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.Behavior Notes
LayoutDirectionaffects only its descendants- It does not change the global RTL state (
I18nManageron native, the documentdiron web) - Nested scopes override parent scopes for their own subtree
- The wrapper renders with
display: contents, so it does not affect your layout - Prefer
LayoutDirectionover inlinestyle={{ direction: 'rtl' }}- only the component scopes thertl:/ltr:variants
Related Direction-Aware Utilities
Some utilities follow the reading direction on their own, withoutrtl: / ltr: pairs:
- Logical text alignment (Uniwind 1.12.1+, Pro 1.8.0+):
text-startandtext-endalign text to the start or end edge. See 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-safeandend-safeapply the inset of the logical start or end edge. See Safe Area Classes
Related
Class Names
All supported variants, including
rtl: and ltr:Scoped Themes
Apply a different theme to a subtree
useResolveClassNames
Resolve class names into style objects at runtime
withUniwind
Add className support to third-party components