1

I want to detect swipe up/down/left/right on a div(touchableOpacity) after long-press in react native. Just swipe up will do, for now, as I can make the others on my own using that. So the process would be

  1. long press a container

  2. call a function that starts tracking the touches and uses if/else to decide if swipe up or not

    <TouchableOpacity onLongPress={()=>swipeUp()}/>

where swipe will be something like this

 const swipeUp = () => {
    //track touch start y axis
    //track touch end y axis
    //if difference greater than 10, it's swipe up
    // randomFunctionCalled
    //else no response
}

I don't want to use any complicated library and I already tried the simple ones which didn't give optimal performance

Karan
  • 141
  • 2
  • 13

1 Answers1

1

Check when the press is on using onPressIn, Then get the coordinates of your press, (put it on the main View, this might help React native get the coordinates of my touch event ) Then when the press is out and see it's coordinates Then get the difference between them