Skip to content

Commit a03780d

Browse files
Kaining Zhongfacebook-github-bot
authored andcommitted
fix: use the first available locale to decide directionality on Android (#53417)
Summary: On iOS, if the default locale is not supported in the app, it will fall back to the first available locale to decide if RTL layout should be enabled or not; however on Android, we use the default locale. So if the first locale is a RTL locale and not supported by the app on Android, the app will fall back to the first available locale which might not be RTL, but the layout would be decided as RTL according to the default locale. ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID] [FIXED] - use the first available locale instead of the default one to decide `isDevicePreferredLanguageRTL` For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [ANDROID] [FIXED] - use the first available locale instead of the default one to decide `isDevicePreferredLanguageRTL` Pull Request resolved: #53417 Test Plan: I set my phone's locale to this order: Hebrew, English and enabled RTL layout: ``` import { I18nManager } from 'react-native'; I18nManager.allowRTL(true); I18nManager.swapLeftAndRightInRTL(true); ``` Prior to my PR, the app would use RTL layout with English on Android which doesn't make much sense (iOS is LTR + English). With my PR Android app will behave exactly the same as the iOS app. Reviewed By: rshest Differential Revision: D80821903 Pulled By: zeyap fbshipit-source-id: c1bd9b45341c344833a8fdfacc2c786ee8437415
1 parent 0931202 commit a03780d

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nUtil.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public class I18nUtil private constructor() {
6363
private val isDevicePreferredLanguageRTL: Boolean
6464
// Check if the current device language is RTL
6565
get() {
66-
val directionality = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault())
66+
val directionality =
67+
TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getAvailableLocales()[0])
6768
return directionality == View.LAYOUT_DIRECTION_RTL
6869
}
6970

0 commit comments

Comments
 (0)