-
I would love to know if/how it is possible to detect multi-touch gestures, like a four-finger swipe down. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
v10 should make it more reliable for that kind of stuff, but no it's not built-in. const fourFingersTimeStamp = React.useRef(0)
const bind = useDrag(({ touches, swipe, timeStamp }) => {
if (touches === 4) fourFingersTimeStamp.current = timeStamp
if (swipe[1] && timeStamp - fourFingersTimeStamp.current < 50) alert('4 FINGERS SWIPE')
}) Swipe is detected based on velocity, distance and duration of the first finger that pressed the screen. The code above should work if at one point of the gesture, four fingers were pressing the screen and between the time the gesture ends and the last time 4 fingers were pressing the screen, there was a lapse of time smaller than 50ms. What this code doesn't do though is checking if the other three fingers were actually swiping: the code above would still trigger an alert if the first finger pressing the screen did the swipe while the other 3 were just still on the screen. But that's some unusual gymnastic to be honest so I think this is a valid implementation of what you're trying to achieve. |
Beta Was this translation helpful? Give feedback.
v10 should make it more reliable for that kind of stuff, but no it's not built-in.
You can try this in v9 though and see if it works.
Swipe is detected based on velocity, distance and duration of the first finger that pressed the screen. The code above should work if at one point of the gesture, four fingers were pressing the screen and between the time the gesture ends and the last time 4 fingers were pressing the screen, there was a …