【发布时间】:2018-06-21 16:35:39
【问题描述】:
我已启用 backandroid 以在主屏幕中显示注销警报。问题是即使屏幕导航离开主屏幕。仍然要注销警报。基本的后退导航也被禁用。
HomeScreen.js
componentWillMount() {
BackHandler.addEventListener('hardwareBackPress', this._handleback);
}
componentWillUnmount() {
//Forgetting to remove the listener will cause pop executes multiple times
BackHandler.removeEventListener('hardwareBackPress', this._handleback);
}
_handleback = () => {
Alert.alert(i18N.t('alertHeader'), i18N.t('logoutqHeader'), [
{
text: i18N.t('yes'), onPress: () => { this.props.navigation.navigate('login'); }
},
{ text: i18N.t('cancel'), onPress: () => { return true; }, style: 'cancel' },
], { cancelable: false });
return true;
};
我只想在主屏幕中显示注销警报。在其他屏幕中,我想遵循基本的后退导航。请告诉我如何解决这个问题。
【问题讨论】:
标签: android reactjs react-native ecmascript-6