Reputation: 771
I use I18nManager.forceRTL(true)
in initialState
or componentDidMount
life cycle but it does't work and if I reload my App, it works.
I mean I have to reload the App to see the effect, what is the reason?
Thanks in advance
Upvotes: 3
Views: 4697
Reputation: 884
Android: Inside MainApplication:
import com.facebook.react.modules.i18nmanager.I18nUtil;
I18nUtil.getInstance().allowRTL(this, true);
I18nUtil.getInstance().forceRTL(this, true);
iOS: Inside AppDelegate:
#import <React/RCTI18nUtil.h>
[[RCTI18nUtil sharedInstance] allowRTL:YES];
[[RCTI18nUtil sharedInstance] forceRTL:YES];
Upvotes: 10
Reputation: 2784
For reloading the App you can use react-native-restart
After installing the module, you can use it like here:
// Add these at the top of your component file
import RNRestart from 'react-native-restart';
import {I18nManager} from 'react-native';
// Then use it
...
I18nManager.forceRTL(true);
RNRestart.Restart();
If you want to use it inside of componentDidMount function of your component, You need to run this code exactly once, not more:
// Inside of your component class
componentDidMount() {
if(!I18nManager.isRTL) {
I18nManager.forceRTL(true);
RNRestart.Restart();
}
}
Upvotes: 4
Reputation: 1
You can use RNRestart.Restart()
after I18nManager.forceRTL(true)
. It will not close your app.
Upvotes: 0