我正在尝试触发函数onPress {()=> someFunction()}但我需要点击两次才能触发函数。在这种情况下,有人可以帮助我吗?我在本机中使用Native Base Framework for UI组件。这是一个错误吗?
按压方法可以是这样的:
onPressFunction () {
if (this.state.wasPressedOnce) {
// do here what you want to do in double press <---
} else {
this.setState({ wasPressedOnce: true });
setTimeout(
() => {
this.setState({ wasPressedOnce: false });
}, 1000); // 1000 is the time the user have to double press the button
}
}
如果在最后1秒之前按下按钮,则按下按钮时基本计算。