如何在 React Native 中将视图的方向属性设置为 RTL

Hen*_*hli 2 reactjs react-native

如何View在react-native中设置a的方向属性...类似:

<View direction="rtl" />

或者

在使我的应用程序 RTL 就绪后,无论当前的设备语言如何,如何强制整个应用程序的方向从右到左

Hen*_*hli 6

我通过调用forceRTLMainApplication.java 解决了这个问题,如下所示:

MainApplication.java 导入 com.facebook.react.modules.i18nmanager.I18nUtil;

 @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);

    I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
    sharedI18nUtilInstance.forceRTL(this,true);
    sharedI18nUtilInstance.allowRTL(this, true);
  }
Run Code Online (Sandbox Code Playgroud)

AndroidManifest.xml

<Application
...
android:supportsRtl="true"
...
/>
Run Code Online (Sandbox Code Playgroud)

因为调用forceRTLApp.js确实需要重新启动应用程序才能工作。

I18nManager.forceRTL(true); // Work on second-load of the app

现在当我设置时flexDirection: 'row'它将是从右到左