fix: use the first language from context to decide Android directionality #54986
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
In #53417 I used
Locale.getAvailableLocales()[0]to obtain the prioritized locale, which is incorrect according to @mukti107's comment. This returns "an array of all installed locales". However, what we want is the preferred locale specified by users, so it should becontext.resources.configuration.locales[0].I also renamed this from
isDevicePreferredLanguageRTLtoisApplicationPreferredLanguageRTLso it aligns with iOS's implementation (isDevicePreferredLanguageRTLis not used anywhere in iOS, andisApplicationPreferredLanguageRTLis the one that actually get used) and reflects the usage of this function more accurately (context.resources.configuration.locales[0]would also respect per app's language settings, in addition to system language settings).Note: since 0.76 React Native's minimum Android support SDK version becomes 24, so using
localeswhich is added in API level 24 should be safe.Changelog:
Same as in #53417, I used
Then I tried to set system's language to English and Hebrew, then set app's language settings to English and Hebrew. The directionality always conforms to the per app settings. If per app settings not set (use "System Default") then it would conform to the system language.