在React-Native中动态设置RTL / LTR
发布时间:2020-12-15 20:30:07 所属栏目:百科 来源:网络整理
导读:我想通过属性动态设置我的app’a方向. React Native允许根据设备的默认语言设置方向,但我想根据我对用户数据的locale属性选择方向. 到目前为止,我在MainApplication.java中使用此代码仅强制所有用户使用LTR: I18nUtil sharedI18nUtilInstance = I18nUtil.ge
我想通过属性动态设置我的app’a方向.
React Native允许根据设备的默认语言设置方向,但我想根据我对用户数据的locale属性选择方向. 到目前为止,我在MainApplication.java中使用此代码仅强制所有用户使用LTR: I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance(); sharedI18nUtilInstance.allowRTL(getApplicationContext(),false); 我现在正在寻找一种方法来将代码中的’false’切换为根据我用户的语言环境更改的布尔值. 额外信息: > Android设备 解决方法
你可以用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(); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |