Skip to content

feat: add direction prop to PaperProvider and useLocale hook for RTL support#4921

Open
hristototov wants to merge 2 commits intov6from
@hristototov/feat/improve_RTL_handling
Open

feat: add direction prop to PaperProvider and useLocale hook for RTL support#4921
hristototov wants to merge 2 commits intov6from
@hristototov/feat/improve_RTL_handling

Conversation

@hristototov
Copy link
Copy Markdown
Collaborator

Motivation

Components in react-native-paper read RTL state directly from
I18nManager.getConstants().isRTL. This has two issues:

  • I18nManager is a no-op on React Native Web, so RTL breaks entirely on Web
  • The value is read at module load or render time with no way to override it reactively

Solution

New: useLocale() hook

import { useLocale } from 'react-native-paper';

const { direction } = useLocale(); // 'ltr' | 'rtl'

<PaperProvider direction="rtl">
  {children}
</PaperProvider>

Defaults to I18nManager.getConstants().isRTL when not provided, so existing apps are unaffected. Setting the prop does not call I18nManager.forceRTL or modify any native state; it only tells Paper which direction to use for rendering.

Related issue

N/A
Notion link

Test plan

  • Add direction="rtl" to PaperProvider in the example app and verify RTL layout renders correctly across components
    Remove the prop and verify the app falls back to I18nManager (default behaviour unchanged)
  • On React Native Web, set direction="rtl" and verify RTL layout works
  • All existing tests pass (yarn test)

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

The mobile version of example app from this branch is ready! You can see it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants