当用户按下changeLocale按钮时,会发生此错误,并且应用程序崩溃。
任何帮助将不胜感激。谢谢。
Homepage.js
constructor(props) {
super(props);
this.state = {
locale: {},
token: '',
};
this._changeLocale = this._changeLocale.bind(this);
}
_changeLocale() {
if(this.state.locale.short === 'TR') {
changeLocale({id: 2, short: 'EN'}, this.state.token);
this.setState({
locale: {id: 2, short: 'EN'}
})
} else {
changeLocale({id: 1, short: 'TR'}, this.state.token);
this.setState({
locale: {id: 1, short: 'TR'}
})
}
}
renderContent() {
return(
<Container style={styles.container}>
<HomepageHeader _changeLocale={this._changeLocale} locale={this.state.locale} />
...
</Container>
}
HomepageHeader.js
render() {
return(
<Header style={styles.header} androidStatusBarColor={'#243f65'}>
...
<Right style={styles.right}>
<TouchableOpacity style={styles.loginButton} onPress={() => {this.props._changeLocale()}}>
<Text style={styles.loginText}>{this.props.locale.short}</Text>
</TouchableOpacity>
</Right>
</Header>
);
}
Function.js
export function changeLocale(locale, token) {
Variables.LOCALE.setLanguage(locale.short);
AsyncStorage.setItem('locale', JSON.stringify(locale));
return axios({
method: 'POST',
url: Variables.API_URL + 'auth/changeLocale',
data: {
locale_id: locale.id
},
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer ' + token
},
});
}
Variables.js
static LOCALE = new LocalizedStrings({
TR: {
pages: {
invitation: 'Davet',
boards: 'Kurullar',
program: 'Bilimsel Program',
accommodation: 'Kayıt & Konaklama',
courses: 'Kurslar',
general: 'Genel Bilgiler',
contact: 'İletişim',
live: 'Canlı',
papers: 'Bildiriler',
search: 'Ara',
speakers: 'Konuşmacılar',
favorites: 'Favoriler'
},
},
EN: {
pages: {
invitation: 'Invitation',
boards: 'Boards',
program: 'Scientific Program',
accommodation: 'Registration & Accommodation',
courses: 'Courses',
general: 'General Information',
contact: 'Contact',
live: 'Live',
papers: 'Papers',
search: 'Search',
speakers: 'Speakers',
favorites: 'Favorites'
}
}
});
所以基本上我想按一个按钮来更改Variables.js文件中项目的本地化。
我能够完成以前的项目,但是在此我无法管理。
我认为该问题可能是由于Android API级别引起的。我刚刚读了这个https://facebook.github.io/react-native/docs/improvingux#use-android-ripple
但我仍然没有解决办法。