Direction
stablefunction Direction({ value, children }: DirectionProps): JSX.ElementWriting direction applied to the subtree. Logical style props and row layouts resolve against it.
Subtree the direction applies to.
Description
Sets the writing direction for a subtree. Logical style props — px / mx, the ps / pe /
ms / me shorthands, the start / end insets, and the paddingInline* / marginInline* /
insetInline* long forms — resolve against it, as does the inline axis of a row flex layout.
A Direction boundary nests: wrap an inner subtree in another <Direction> to override.
The two renderers reach the same result by different routes:
- Web —
<Direction>renders adir-carrying boundary withdisplay: contents(so it adds no box of its own). The browser flips CSS logical properties androwlayouts from thedirattribute. - Native —
<Direction>provides the value through context;BoxandTextread it and inject the Yogadirectionstyle, so logical props androwflip for every motif primitive below. With no provider in scope, the direction follows React Native's globalI18nManager.isRTL.
The directional primitives (Stack, HStack, VStack) need no special prop — row is already
writing-direction-relative on both platforms, so they mirror automatically.
useDirection
useDirection
stablefunction useDirection(): 'ltr' | 'rtl'
Returns the writing direction of the nearest <Direction> provider. With no provider in scope it
returns 'ltr' on web, and follows I18nManager.isRTL on native. Use it when component logic —
not just layout — has to branch on direction (picking an arrow glyph, choosing an animation
offset).
Example
DirectionContext
For lower-level access — wiring a custom provider or a test harness — DirectionContext is
exported. Prefer the <Direction> / useDirection surface in application code.
DirectionContext
stableconst DirectionContext: React.Context<Direction | undefined>
Its value type is the Direction union ('ltr' | 'rtl'). The web export defaults the context
to 'ltr'; the native export defaults it to undefined, which useDirection treats as the
no-provider case and resolves against I18nManager.isRTL.
Related
- Style props — the logical props that resolve against the direction.
HStack— a row stack; mirrors automatically under RTL.