RTL在RTL设备中被强制执行。

35
5个回答

57

我通过在MainApplication.java中添加以下内容成功修复了这个问题:

import com.facebook.react.modules.i18nmanager.I18nUtil;

public class MainApplication extends Application implements ReactApplication {
    @Override
    public void onCreate() {
        super.onCreate();

        // FORCE LTR
        I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
        sharedI18nUtilInstance.allowRTL(getApplicationContext(), false);
        ....
    }
}

1
在 MainApplication.java 文件中 - atlanteh
3
这很有效!(在清单中设置supportsRtl="false"对我没有任何作用) - Yaron Levi
我写了一个小的代码片段来帮助解决这个问题,网址是https://medium.com/@nirlevy/rtl-support-in-react-native-even-for-non-rtl-applications-981359ee7c46 - Nir Levy
1
太棒了。对我非常有效。 - Hadi Nahavandi
I18nUtil 是从 'import com.facebook.react.modules.i18nmanager.I18nUtil;' 导入的。 - SAM
显示剩余3条评论

9
如果你在使用Expo或原生React Native,将以下代码放入你的App.js/tsx文件中:
import { I18nManager} from 'react-native';

I18nManager.allowRTL(false);
I18nManager.forceRTL(false);
I18nManager.swapLeftAndRightInRTL(false);

const App = () => {

   ~ ~ ~

}

2
将这两个添加进去对我有用:I18nManager.forceRTL(false);I18nManager.allowRTL(false); - Ahmad Yousef

8
在manifest.xml文件中,将 android:supportsRtl="false" 添加到您的应用程序标签中。

3
是的,这个答案以及上面的那个答案(allowRTL-false)起到了奇效。 - dod_basim
你需要添加 android:tools:`<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.*.*" xmlns:tools="http://schemas.android.com/tools">......` - S.M_Emamian
1
我的项目中没有 manifest.xml 文件。我应该在哪里搜索它? - PurTahan

5
只需在项目入口点添加以下代码,例如App.tsx
import { I18nManager } from "react-native";

// disable RTL
try {
  I18nManager.allowRTL(false);
  I18nManager.forceRTL(false);
  // the next line is the most effective one
  I18nManager.swapLeftAndRightInRTL(false);
} catch (e) {
  console.log(e);
}

3

@atlanteh的答案是正确的。我为那些有iOS背景但对Android不太了解的人提供了详细的答案。

首先,尝试第一个方法。如果第一个方法不起作用,则尝试第二个方法。如果还没有起作用,则尝试两个方法。然后它将显示预期的输出。

答案1

MainApplication.java

public class MainApplication extends Application implements ReactApplication {
    @Override
    public void onCreate() {
        super.onCreate();

        // FORCE LTR
        I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
        sharedI18nUtilInstance.allowRTL(getApplicationContext(), false);
        ....
    }
}

答案 2

AndroidManifest.xml

我已经在application标签中添加了android:supportsRtl="false"

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.appname">
    ........
    <application 
      android:supportsRtl="false"
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      android:name="com.facebook.react.devsupport.DevSettingsActivity" />
       ....
    </application>

</manifest>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接