这个动作判断比较简单,单击和长按都可以调用相应的API,双击就要做点判断
单击:判断是否点击, 通过 onTouchStart 触发
双击:判断两次点击的时间间隔,通过 onTouchStart触发+自定义函数实现
长按:手指触摸后,超过350ms再离开,通过 onLongPress 触发
<View className='col'
key={index}
onTouchStart={this.touchStart.bind(this, el, index)}
onLongPress={this.longTap}
></View>
touchStart(item, index, e){
const { touchStartTime } = this.state;
const that = this;
if(!touchStartTime) {
this.setState({
touchStartTime: e.timeStamp
})
t = setTimeout(function timer() {
that.setState({
touchStartTime: 0
})
},500)
} else {
if (e.timeStamp - touchStartTime < 350) {
const newData = {
index,
...item
};
this.setState({
touchStartTime: 0
})
clearTimeout(t);
}
}
}