如何View
在 react-native 中设置 a 的方向属性......类似于:
<View direction="rtl" />
或者
如何强制整个应用程序的方向为从右到左...使我的应用程序 RTL 就绪后,无论当前的设备语言如何
如何View
在 react-native 中设置 a 的方向属性......类似于:
<View direction="rtl" />
或者
如何强制整个应用程序的方向为从右到左...使我的应用程序 RTL 就绪后,无论当前的设备语言如何
我通过调用forceRTL
MainApplication.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);
}
AndroidManifest.xml
<Application
...
android:supportsRtl="true"
...
/>
原因调用 forceRTLApp.js
确实需要重新启动应用程序才能工作。
I18nManager.forceRTL(true); // Work on second-load of the app
现在,当我设置时flexDirection: 'row'
,它将从右到左
您可以简单地使用flex-direction
. 请看下面的代码片段
<View style={{ flexDirection: language === ARABIC_LANGUAGE ? 'row-reverse' : 'row' }}/>
在文本前添加 '\u{200F}' 以将方向更改为 rtl。
_rtlcheck = (language, data) => {
if (rtlLanguages.includes(language)) {
return '\u{200F}' + data
}else{
return data
}
};