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
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.React.ReactNode
required
React children rendered inside the layout direction boundary.
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
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