简体   繁体   English

在Android上反应原生RTL

[英]React native RTL on Android

Trying to get these few steps here so I can support RTL: Making an App RTL-ready 试图在这里完成这几个步骤,这样我就可以支持RTL: 使应用程序RTL就绪
I am trying to add these lines to MainActivity.java according to the instructions: 我试图根据说明将这些行添加到MainActivity.java

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

在此输入图像描述

(I am not a native Android developer, but trying to use react native and occasionally accessing the Android source to modify deeper changes - this one won't compile.) (我不是原生Android开发人员,但尝试使用本机反应并偶尔访问Android源来修改更深层次的更改 - 这个不会编译。)

First , where do they think context should be defined? First ,他们认为应该在哪里定义context I can't imagine it's any sort of a global..? 我无法想象这是一种全球性的......?

Second , setAllowRTL shows in red... which seems like a compilation error. Second ,setAllowRTL以红色显示...这似乎是编译错误。 Any idea what they meant? 知道他们的意思吗? am I even defining this in the right place? 我甚至在正确的地方定义了这个吗?

My code looks like this: 我的代码看起来像这样:

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

import android.content.Intent;

public class MainActivity extends ReactActivity {

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "myApp";
    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
        sharedI18nUtilInstance.setAllowRTL(context, true);
        MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
    }
}

Add this import in MainApplication.java : 在MainApplication.java中添加此导入:

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

and add 并添加

@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
    sharedI18nUtilInstance.allowRTL(getApplicationContext(), true);
}

Add this import in MainActivity.java : 在MainActivity.java中添加此导入:

import com.facebook.react.modules.i18nmanager.I18nUtil;
I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
sharedI18nUtilInstance.allowRTL(getApplicationContext(), true);

add these line in ReactActivityDelegate 在ReactActivityDelegate中添加这些行

  protected ReactActivityDelegate createReactActivityDelegate() {
            return new ReactActivityDelegate(this, getMainComponentName()) {
      @Override
      protected ReactRootView createRootView() {
          I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
          sharedI18nUtilInstance.allowRTL(getApplicationContext(), true);
                       return new RNGestureHandlerEnabledRootView(MainActivity.this);
                      }
    };
          }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM