Skip to content

Commit c9cec95

Browse files
committed
Document direction prop and useLocale
1 parent 57c00dc commit c9cec95

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

versioned_docs/version-7.x/navigation-container.md

+28
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,34 @@ Example:
911911
912912
Custom theme to use for the navigation components such as the header, tab bar etc. See [theming guide](themes.md) for more details and usage guide.
913913
914+
### `direction`
915+
916+
The direction of the text in the app. Defaults to `'rtl'` when `I18nManager.getConstants().isRTL` is `true`, otherwise `'ltr'`.
917+
918+
This is used in various navigators to adjust the content according to the text direction, for example, the drawer in the [drawer navigator](drawer-navigator.md) is positioned on the right side in RTL languages.
919+
920+
If you intend to support RTL languages, it's important to set this prop to the correct value. If it doesn't match the actual text direction, the layout might be incorrect.
921+
922+
On the Web, it may also be necessary to set the `dir` attribute on the root element of the app to ensure that the text direction is correct:
923+
924+
```html
925+
<html dir="rtl">
926+
<!-- App content -->
927+
</html>
928+
```
929+
930+
The `direction` will be available to use in your own components via the `useLocale` hook:
931+
932+
```js
933+
import { useLocale } from '@react-navigation/native';
934+
935+
function MyComponent() {
936+
const { direction } = useLocale();
937+
938+
// Use the direction
939+
}
940+
```
941+
914942
### `navigationInChildEnabled`
915943
916944
:::warning

versioned_docs/version-7.x/upgrading-from-6.x.md

+8
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,14 @@ const options = ({
539539
};
540540
```
541541

542+
### Improved RTL support
543+
544+
Previously, various UI elements used the `I18nManager` API to determine the writing direction. However, this API doesn't work well on the Web as the writing direction can be different for a specific subtree and hence can't be determined globally.
545+
546+
The `NavigationContainer` now accepts a `direction` prop to specify the direction of the layout instead of relying on the `I18nManager` API. It also exposes this value via `useLocale` hook for use in your own components.
547+
548+
See the [navigation container docs](navigation-container.md#direction) for usage.
549+
542550
### The `options` callback gets `theme`
543551

544552
The `options` callback now receives the `theme` object to allow customizing the UI elements specified in the options:

0 commit comments

Comments
 (0)