react-native 连续两次点击后退退出应用
作者:
暗木幽浅 | 来源:发表于
2017-11-09 14:11 被阅读0次import {
BackHandler,
ToastAndroid
} from 'react-native'
let lastTime = 0
let handler = null
const bindBackExitApp = () => {
handler = BackHandler.addEventListener('hardwareBackPress', () => {
let time = Date.now()
if (time - lastTime <= 2000) {
BackHandler.exitApp()
return false
} else {
ToastAndroid.show('再按一次退出应用', ToastAndroid.SHORT)
lastTime = time
return true
}
})
}
const removeBackExitApp = () => {
handler && handler.remove()
}
export {
bindBackExitApp,
removeBackExitApp
}
本文标题:react-native 连续两次点击后退退出应用
本文链接:https://www.haomeiwen.com/subject/dbipmxtx.html
网友评论