react-Hybrid App实现长按事件

1、需求:
长按可以删除评论
在这里插入图片描述

2、
在相应的结构中绑定事件

 <span onTouchStart={
    
    this.touchStart.bind(this, index)} onTouchEnd={
    
    this.handleTouchEnd}>

注意一定需要在事件结束的时候解除定时事件,防止资源占用浪费。

  // 长按事件
  handleTouchEnd = () => {
    
    
    clearTimeout(this.pressTime);
  }

  touchStart = (index) => {
    
    
    this.pressTime = setTimeout(() => {
    
    
     //  你要todo的事
    }, '1000');
  }

猜你喜欢

转载自blog.csdn.net/weixin_45416217/article/details/107703145
今日推荐