efr*_*tyo 5 right-to-left react-native react-native-android
我想通过属性动态设置我的app'a方向.React Native允许根据设备的默认语言设置方向,但我想根据我对用户数据的locale属性选择方向.
到目前为止,我在MainApplication.java中使用此代码仅强制所有用户使用LTR:
I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
sharedI18nUtilInstance.allowRTL(getApplicationContext(), false);
Run Code Online (Sandbox Code Playgroud)
我现在正在寻找一种方法来将代码中的'false'切换为根据我用户的语言环境更改的布尔值.不知道如何实现......
额外信息:
你可以用来I18nManager
强制语言方向
constructor() {
super();
//set user language b default english
this.state = {
lang: 'en'
}
}
componentWillMount() {
//get user lang form AsyncStorage
AsyncStorage.getItem('lang').then((value) => {
//now you should forceRTL by Language and set Language in your states
if ((value === 'ar' || value === 'fa' )) {
I18nManager.forceRTL(true);
} else {
I18nManager.forceRTL(false);
}
return this.setState({
lang: value
});
}).done();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1471 次 |
最近记录: |