在安卓小米Note 3上,硬件返回按钮不能触发
我已经尝试了以下代码,但
导航代码:
handleBackPress
,当我点击返回键时,应用程序会退出。我已经尝试了以下代码,但
handleBackPress
没有被调用。 componentDidMount() {
BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
}
componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress);
}
handleBackPress = () => {
this.goBack(); // works best when the goBack is async
return true;
}
导航代码:
const ModalSignUp = createStackNavigator(
{
Signup: { screen: Signup, key: 'Signup' },
PartyList: { screen: PartyList, key: 'PartyList' },
StatesList: { screen: StatesList, key: 'StatesList' },
},
{
initialRouteName: 'Signup',
headerMode: 'none',
mode: 'card',
}
);
导航:
this.props.navigation.push("StatesList")
预期结果:
点击硬件按钮返回上一个屏幕。