Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native - rtl in ios

firstly i worked on android and the RTL working good, i added the following code:

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

to MainActivity.java and

android:supportsRtl="true"

to AndroidManifest.xml

and in the js code:

I18nManager.forceRTL(true);

Now is the problem: i tried to set rtl on ios but its not working i added

 // in AppDelegate.m
   [[RCTI18nUtil sharedInstance] allowRTL:YES];

and

I18nManager.forceRTL(true);

in js code but all the text and flex are still ltr... what can i do?

like image 282
gregory Avatar asked Apr 09 '17 09:04

gregory


People also ask

Does react native support RTL?

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

Is react native compatible with iOS?

React Native combines the best parts of native development with React, a best-in-class JavaScript library for building user interfaces. Use a little—or a lot. You can use React Native today in your existing Android and iOS projects or you can create a whole new app from scratch.

How do you force RTL in react native?

How do I force RTL on Android? Go to Settings and open the Developer Options settings. Under the Drawing settings, make sure to makr the "Force RTL layout direction" option. Now enjoy using the big screen of your Android device with your left hand.

Can react native used for both iOS and Android?

React Native is a JavaScript library based on ReactJS, which we use to build mobile apps using iOS and Android platforms. The advantage of React Native is that a single code allows you to create an application at once for two systems, iOS and Android. This is suitable for small applications or MVPs.


2 Answers

No need to add an RTL language to your project. just open your AppDelegate.m file in yourProject/ios/YourProject/AppDelegate.m

take care not to open another file that similar to this with .h extension

Now, add #import <React/RCTI18nUtil.h> to the top of code like this:

#import "AppDelegate.h"

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <React/RCTI18nUtil.h>      <-- added here

Now restart and rebuild your application.

Now you can change the RTL direction of the whole app with I18nManager easily.

import {I18nManager} from "react-native"


I18nManager.forceRTL(true) // false for LTR direction
like image 71
nima Avatar answered Sep 28 '22 05:09

nima


You must add an RTL Language beside default one and it'll work , more info can be found here

like image 34
Ahmed Ali Avatar answered Sep 28 '22 03:09

Ahmed Ali