From e46189e1e1cb07ced47afbeb4a3cbdc361417b01 Mon Sep 17 00:00:00 2001 From: Mathieu Acthernoene Date: Wed, 22 Jul 2026 17:24:35 -0700 Subject: [PATCH] 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`: Locale getAvailableLocales --- vs `context.resources.configuration.locales[0]` for the same device language (I chose `ar-JO` in app settings), `isRTL` is `true`: app locales ## Changelog: [ANDROID] [FIXED] - Detect RTL from the active locale instead of an arbitrary installed one Pull Request resolved: https://github.com/react/react-native/pull/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):** android - before --- **`context.resources.configuration.locales[0]` (after, active locale):** android - after Reviewed By: christophpurrer Differential Revision: D113244807 Pulled By: Abbondanzo fbshipit-source-id: d1c884dcdbf5d1d0882fb12bc63644fc41559635 --- .../react/modules/i18nmanager/I18nUtil.kt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nUtil.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nUtil.kt index 38df17ec8cc..1048e0b4006 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nUtil.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nUtil.kt @@ -11,7 +11,6 @@ import android.content.Context import android.content.pm.ApplicationInfo import android.view.View import androidx.core.text.TextUtilsCompat -import java.util.Locale public class I18nUtil private constructor() { /** @@ -21,7 +20,7 @@ public class I18nUtil private constructor() { */ public fun isRTL(context: Context): Boolean = applicationHasRtlSupport(context) && - (isRTLForced(context) || (isRTLAllowed(context) && isDevicePreferredLanguageRTL)) + (isRTLForced(context) || (isRTLAllowed(context) && isDevicePreferredLanguageRTL(context))) /** * Android relies on the presence of `android:supportsRtl="true"` being set in order to resolve @@ -60,13 +59,12 @@ public class I18nUtil private constructor() { setPref(context, KEY_FOR_PREFS_FORCERTL, forceRTL) } - private val isDevicePreferredLanguageRTL: Boolean - // Check if the current device language is RTL - get() { - val directionality = - TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getAvailableLocales()[0]) - return directionality == View.LAYOUT_DIRECTION_RTL - } + // Check if the current device language is RTL + private fun isDevicePreferredLanguageRTL(context: Context): Boolean { + val directionality = + TextUtilsCompat.getLayoutDirectionFromLocale(context.resources.configuration.locales[0]) + return directionality == View.LAYOUT_DIRECTION_RTL + } private fun isPrefSet(context: Context, key: String, defaultValue: Boolean): Boolean = context