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);
(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);
}
}
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.
In general, most components are already RTL-ready, for example: Left-to-Right Layout.
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.
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);
}
};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With