如何在react-native中获取上下文

时间:2017-08-20 12:11:58

标签: android react-native

我想让我的反应原生应用程序RTL。

https://facebook.github.io/react-native/blog/2016/08/19/right-to-left-support-for-react-native-apps.html所述,这可以胜任:

Setup.hs

如何获得我在下面使用的上下文:

I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
sharedI18nUtilInstance.setAllowRTL(context, true);

但是我得到sharedI18nUtilInstance.allowRTL(getApplicationContext(),true);

NullPointerException

1 个答案:

答案 0 :(得分:4)

您可以在MainActivety.java文件中使用此代码强制您的应用为RTL或LTR。我用它,它对我有用。

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

@Override
public void onCreate() {
    super.onCreate();

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