Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native RTL on Android

Trying to get these few steps here so I can support RTL: Making an App RTL-ready
I am trying to add these lines to MainActivity.java according to the instructions:

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

enter image description here

(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.)

First, where do they think context should be defined? I can't imagine it's any sort of a global..?

Second, setAllowRTL shows in red... which seems like a compilation error. 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);
    }
}
like image 853
Ted Avatar asked Jan 14 '17 22:01

Ted


People also ask

Can React Native run on Android?

Overview. React Native is an open-source mobile application framework created by Facebook. It is used to develop applications for Android, iOS, Web and UWP (Windows) providing native UI controls and full access to the native platform. Working with React Native requires an understanding of JavaScript fundamentals.

Does React Native support RTL?

In general, most components are already RTL-ready, for example: Left-to-Right Layout.

What is RTL support in Android?

A class for defining layout directions. A layout direction can be left-to-right (LTR) or right-to-left (RTL). It can also be inherited (from a parent) or deduced from the default language script of a locale.


1 Answers

Add this import in MainActivity.java :

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

add these line in 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);
                      }
    };
          }
like image 159
Muhammad Numan Avatar answered Sep 20 '22 10:09

Muhammad Numan