RTL在RTL设备中被强制使用

atl*_*teh 25 android right-to-left react-native

本机作出反应的新版本已经发布了RTL设备的支持: https://facebook.github.io/react-native/blog/2016/08/19/right-to-left-support-for-react-native-apps .html
然而,似乎在RTL安卓设备中,RTL布局是强制的,并且没有办法改变它,所以现在所有的应用程序都被破坏了RTL设备.如何强制我的应用程序使用LTR?

atl*_*teh 42

我设法通过添加到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);
        ....
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 这很棒!...(在清单中设置supportsRtl =“ false”对我没有任何作用)。 (2认同)

mas*_*ali 6

在manifest.xml文件中添加android:supportsRtl="false"到您的应用程序标记

  • 是的,这个答案以及上面的答案(allowRTL-false)起到了神奇的作用。 (2认同)

Ahm*_*mam 6

如果您使用的是世博会

import { I18nManager} from 'react-native';
I18nManager.allowRTL(false);

export default class <className> extends Component {



}
Run Code Online (Sandbox Code Playgroud)

  • 添加这两个对我有用:“I18nManager.forceRTL(false);”和“I18nManager.allowRTL(false);” (2认同)

Bis*_*mad 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);
}
Run Code Online (Sandbox Code Playgroud)

更新

克服“现在”的当前情况,因为即使使用这些设置,rtl 仍然是强制的!

你必须改变每flexDirection: "row"一个

flexDirection: I18nManager.isRTL ? 'row-reverse' : 'row',
Run Code Online (Sandbox Code Playgroud)