1 回答
TA贡献1875条经验 获得超3个赞
抱歉,您以为您使用的是 Typescript,您有这个选项,或者直接在您想要的地方使用 this.props.afterChange()。
interface LanguageSelectorProps{
afterChange: () => void;
}
export class LanguageSelector extends Component<LanguageSelectorProps> {
constructor(props) {
super(props);
this.afterChange = this.afterChange.bind(this);
}
afterChange() {
this.props.afterChange(); // callback ,use whatever you want
}
changeLang(lang: string) {
Global.localizedStrings.setLanguage(lang);
//this.setState({});
}
render() {
return (
<View style={{ paddingBottom: 10, flexDirection: "row", alignSelf: "flex-end" }}>
<TouchableOpacity onPress={() => this.changeLang('de')}>
<Flag code="DE" size={32} />
</TouchableOpacity>
<TouchableOpacity onPress={() => {
this.changeLang('de')
this.afterChange();
}>
<Flag code="GB" size={32} />
</TouchableOpacity>
</View>
)
}
添加回答
举报