react long press event

前端 未结 9 1190
一个人的身影
一个人的身影 2020-12-13 02:01

Is there a way to add long press event in react-web application?

I have list of addresses. On long press on any address, I want to

9条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 02:46

    Ionic React LongPress Example I use it with Ionic React, it works well.

    import React, {useState}  from 'react';
    import { Route, Redirect } from 'react-router';
    
    interface MainTabsProps { }
    const MainTabs: React.FC = () => {
    
    // timeout id  
    var initial: any;
    
    // setstate
    const [start, setStart] = useState(false);
    
    const handleButtonPress = () => {
      initial = setTimeout(() => {
        setStart(true); // start long button          
        console.log('long press button');
        }, 1500);
    }
    
    const handleButtonRelease = () => {
      setStart(false); // stop long press   
      clearTimeout(initial); // clear timeout  
      if(start===false) { // is click
        console.log('click button');
      }  
    }
    
      return (
        
          
            Ionic React LongPress
              
          
            LongPress    
          
        
      );
    };
    
    export default MainTabs;
    

提交回复
热议问题