如何在手机语言更改时禁用 rtl?

Moh*_*lah 6 reactjs react-router react-native

我在 react-native 中创建了一个应用程序,当电话语言为 En 时一切正常,但是当我更改电话语言时,UI 崩溃并且一切都向后我正在使用

"react": "16.6.3",
    "react-native": "0.58.5",
Run Code Online (Sandbox Code Playgroud)

Roo*_*deh 16

您应该在您的应用程序中禁用 rtl 视图

将此代码放在 app.js 中:-

const ReactNative = require('react-native');
try {
  ReactNative.I18nManager.allowRTL(false);
} catch (e) {
  console.log(e);
}
Run Code Online (Sandbox Code Playgroud)

你应该没事的。


小智 7

I18nManager.allowRTL(false);当我第一次打开应用程序时,它不起作用,但下次我打开应用程序时,它就起作用了。相反,我做了这些更改MainApplication.java,它工作得很好:

import com.facebook.react.modules.i18nmanager.I18nUtil;
....
@Override
public void onCreate() {
    super.onCreate();
    // FORCE LTR
    I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
    sharedI18nUtilInstance.allowRTL(getApplicationContext(), false);
    .....
}
.....
Run Code Online (Sandbox Code Playgroud)

资源


Tal*_*l C 6

与@Roozbeh类似,但你可以这样做:

import { I18nManager} from 'react-native';
Run Code Online (Sandbox Code Playgroud)

然后

 try { 
    I18nManager.allowRTL(false);
} 
catch (e) {
    console.log(e);
}
Run Code Online (Sandbox Code Playgroud)