biodiv / contactjs

Pointer gestures for your webapp
MIT License
77 stars 6 forks source link

Add support for double tap and drag for zooming #34

Open cdrini opened 1 year ago

cdrini commented 1 year ago

This has become a very common interaction in mobile devices: Google maps, Apple.

The way it works:

It would be great if this was included in the library and easy to add!

biodiv commented 1 year ago

Thanks for bringing attention to this. I tried what you described in Apple maps and it worked as you described.

I will implement support for multiple taps. eg

const tap = new Tap(domElement, {
  taps: 2
});

The latter of what you described is a Tap followed by a Pan. A Tap requires the finger to be lifted from the surface. We could create something like a TapPan gesture, which then also would support tappanleft, tappanright tappanup and tappandown events.

cdrini commented 1 year ago

That seems good to me! I think a tappan would be enough for me, and then I could use the x/y coordinates to determine the amount of zoom. But tappan{left,right,up,down} would also work!

Thank you for the prompt reply!

biodiv commented 1 year ago

Meanwhile, you could try something like the following approach:

var TAP_ACTIVE = false;

function onTap(event){
    TAP_ACTIVE = true;
    setTimeout(function(){
        TAP_ACTIVE = false;
    }, 500);
}

pointerListener.on("tap", onTap);

function onPan(event){
    if (TAP_ACTIVE == true){
        if (event.detail.live.direction == "up") {
            // do something
        }
    }
}

pointerListener.on("pan", onPan);