I18nManager.allowRTL(false);
I18nManager.forceRTL(false);
on first boot, however, it did not help these people and their apps layout is still shown in reverse the first time they use它..作为一个快速解决方案,我们决定显示一条错误消息,该消息提示用户退出应用程序并重新输入,如果这是应用程序第一次加载(这是一个令人讨厌的解决方案)
有人对为什么会发生这种情况以及如何解决它有一个想法吗?
tongrestart您的应用程序,以防您检测到i18nmanager.isrtl
如何做? 安装:
Util.reload()
在app.js 导入:
npm i fiction-expo-restart
和
import {Restart} from 'fiction-expo-restart';
然后在componentDidmount()函数中:
import {I18nManager} from 'react-native';
我使用的纤维可以在此处找到:
https://www.npmjs.com/package/fiction-expo-restart您可以在AndroidManifest.xml中添加代码到默认情况下禁用RTL,并且您不必重新启动App
componentDidMount()
{
if(I18nManager.isRTL)
{
I18nManager.allowRTL(false);
I18nManager.forceRTL(false);
Restart();
}
}
检查这个
link也是
<!-- AndroidManifest.xml -->
<application
android:supportsRtl="false"
....
类之外。这是测试的示例。
App
对于2023年2月答复时的博览会,此代码有效: 首先安装此软件包:
import React, { Component } from 'react';
import { Switch, I18nManager, Text, View, StyleSheet } from 'react-native';
import Constants from 'expo-constants';
// I18nManager.forceRTL(false);
I18nManager.allowRTL(false);
export default class App extends Component {
state = {
isRTL: I18nManager.isRTL,
};
render() {
return (
<View style={styles.container}>
<View style={styles.directionBox}>
<Text style={styles.directionText}>
{this.state.isRTL ? 'Right-to-Left' : 'Left-to-Right'}
</Text>
</View>
<View style={styles.flexDirectionRow}>
<Text style={styles.switchRowTextView}>
forceRTL
</Text>
<View style={styles.switchRowSwitchView}>
<Switch
onValueChange={this._onDirectionChange}
style={styles.rightAlignStyle}
value={this.state.isRTL}
/>
</View>
</View>
</View>
);
}
_onDirectionChange = () => {
I18nManager.forceRTL(!this.state.isRTL);
this.setState({ isRTL: !this.state.isRTL });
};
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
},
directionBox: {
backgroundColor: '#f8f8f8',
borderWidth: 0.5,
borderColor: 'black',
},
directionText: {
padding: 10,
fontSize: 16,
textAlign: 'center',
fontWeight: 'bold',
},
flexDirectionRow: {
flexDirection: 'row',
},
switchRowTextView: {
flex: 1,
marginBottom: 5,
marginTop: 5,
textAlign: 'center',
},
switchRowSwitchView: {
flex: 3,
},
});
以这样的方式进行:
npm install expo-updates
重新启动:
import * as Updates from "expo-updates";
这是这样做的正确方法 -
https://geekyants.com/blog/implementing-right-to-to-left-rtl-support-in-expo-without-without-without-without-without-the-app
这是我自己的实施没有AI。
Updates.reloadAsync();