天天看點

react native 中android實體傳回鍵BackHandler

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

繼續閱讀