Skip to content

Commit 82c6f8a

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Set and require android:supportsRtl="true" for RTL layout (#44538)
Summary: Pull Request resolved: #44538 Android originated without RTL support. When RTL support was added, Applications needed to set `android:supportsRtl="true"` in their manifest, to allow Android to do RTL specific layout and drawing. This became the default for new projects created by Android Studio at some point. React Native was not setting this in template, which means apps created from it do not do any of Android's RTL layout, text alignment, or drawing (e.g. in D3652980 8 years ago, a native drawer component came from the wrong side of the screen). RN would still layout the app using Yoga in RTL if in RTL locale though. This change sets `android:supportsRtl` in template matching default new Android projects, and to avoid mismatched states in the future, will only tell I18NManager that RTL is allowed if `android:supportsRtl` is also set. This is breaking, since existing apps may not get Yoga RTL support unless telling Android that the application should support RTL layout. Changelog: [Android][Breaking] - Set and require `android:supportsRtl="true"` for RTL layout Reviewed By: joevilches Differential Revision: D57248205 fbshipit-source-id: 3f60c9f855db26f8d34a2e05d460f95961f5ffeb
1 parent 258b481 commit 82c6f8a

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package com.facebook.react.modules.i18nmanager
99

1010
import android.content.Context
11+
import android.content.pm.ApplicationInfo
1112
import androidx.core.text.TextUtilsCompat
1213
import androidx.core.view.ViewCompat
1314
import java.util.Locale
@@ -23,6 +24,19 @@ public class I18nUtil private constructor() {
2324
true
2425
} else isRTLAllowed(context) && isDevicePreferredLanguageRTL
2526

27+
/**
28+
* Android relies on the presence of `android:supportsRtl="true"` being set in order to resolve
29+
* RTL as a layout direction for native Android views. RTL in React Native relies on this being
30+
* set.
31+
*/
32+
private fun applicationHasRtlSupport(context: Context): Boolean {
33+
return (context.getApplicationInfo().flags and ApplicationInfo.FLAG_SUPPORTS_RTL) != 0
34+
}
35+
36+
public fun hasRtlSupport(context: Context): Boolean {
37+
return applicationHasRtlSupport(context) || isRTLAllowed(context)
38+
}
39+
2640
/**
2741
* Should be used very early during app start up Before the bridge is initialized
2842
*

packages/react-native/template/android/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
android:icon="@mipmap/ic_launcher"
99
android:roundIcon="@mipmap/ic_launcher_round"
1010
android:allowBackup="false"
11-
android:theme="@style/AppTheme">
11+
android:theme="@style/AppTheme"
12+
android:supportsRtl="true">
1213
<activity
1314
android:name=".MainActivity"
1415
android:label="@string/app_name"

packages/rn-tester/android/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
android:icon="@mipmap/ic_launcher"
3838
android:roundIcon="@mipmap/ic_launcher_round"
3939
android:label="@string/app_name"
40-
android:theme="@style/AppTheme">
40+
android:theme="@style/AppTheme"
41+
android:supportsRtl="true">
4142
<activity
4243
android:name=".RNTesterActivity"
4344
android:label="@string/app_name"

0 commit comments

Comments
 (0)