天天看点

react native 中android物理返回键BackHandler

在生命周期componentDidMount中(必须要写在生命周期中):
componentDidMount() {
    if (Platform.OS === 'android') {
        BackHandler.addEventListener('hardwareBackPress', () => {
            if ('可以返回的条件') {
                console.log('可以返回')
                return false;
            }
            console.log('不能返回')
            return true;
        });
    } 
}
      

继续阅读