React-Hybrid App realizes long press event

1. Requirements:
Long press to delete comments
Insert picture description here

2.
Binding events in the corresponding structure

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

Note that the timed event must be cancelled at the end of the event to prevent resource occupation and waste.

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

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

Guess you like

Origin blog.csdn.net/weixin_45416217/article/details/107703145