Commit e46189e
fix(android): use the active locale to detect RTL direction (#57635)
Summary:
On Android, RTL detection read the wrong locale. `isDevicePreferredLanguageRTL` use `Locale.getAvailableLocales()[0]`, which returns an arbitrary entry from the unordered list of **all runtime locales** (so, all locales that the current Android version supports), not the user's current system / app language. So layout direction was resolved from whatever locale happened to be first in that list, unrelated to the device (or per-app) language.
This fixes it to read the active locale from `context.resources.configuration.locales[0]`, the resolved preferred locale for the app.
See the screenshots below: `Locale.getAvailableLocales()[0]` returns all locales supported by Android, so the first one is **always** `af`, and `isRTL` is always `false`:
<img width="1862" height="383" alt="Locale getAvailableLocales" src="https://github.com/user-attachments/assets/7340959f-67bd-4537-a074-849a76f345f8" />
---
vs `context.resources.configuration.locales[0]` for the same device language (I chose `ar-JO` in app settings), `isRTL` is `true`:
<img width="1258" height="396" alt="app locales" src="https://github.com/user-attachments/assets/55159b65-a90c-40b7-9941-e5339c73d44c" />
## Changelog:
[ANDROID] [FIXED] - Detect RTL from the active locale instead of an arbitrary installed one
Pull Request resolved: #57635
Test Plan:
Switch the device (or per-app) language to an RTL language (e.g. Arabic) and confirm the app lays out RTL.
**`Locale.getAvailableLocales()[0]` (before, arbitrary):**
<img width="238" height="467" alt="android - before" src="https://github.com/user-attachments/assets/3f69e933-22b1-4d31-824a-b5e96057a76d" />
---
**`context.resources.configuration.locales[0]` (after, active locale):**
<img width="238" height="467" alt="android - after" src="https://github.com/user-attachments/assets/9c86ff1a-b0ab-489f-a84e-76e3b7507da8" />
Reviewed By: christophpurrer
Differential Revision: D113244807
Pulled By: Abbondanzo
fbshipit-source-id: d1c884dcdbf5d1d0882fb12bc63644fc415596351 parent e0d8e63 commit e46189e
1 file changed
Lines changed: 7 additions & 9 deletions
File tree
- packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager
Lines changed: 7 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
| |||
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
24 | | - | |
| 23 | + | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
| |||
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
70 | 68 | | |
71 | 69 | | |
72 | 70 | | |
| |||
0 commit comments