hammerjs / hammer.js

A javascript library for multi-touch gestures :// You can touch this
http://hammerjs.github.io
MIT License
24.08k stars 2.63k forks source link

Only swipe recognizer set, yet it prevents standard zoomin from working #1236

Open teo1978 opened 4 years ago

teo1978 commented 4 years ago

Example code:

var hamman = new Hammer.Manager(myElement, {
    recognizers: [
        [Hammer.Swipe, {
            direction: Hammer.DIRECTION_HORIZONTAL
        }]
    ]
});
hamman.on('swipe', function(e) {
        console.log("Swipe detected");
});

EXPECTED I expect to be able to pinch to zoom, the default behavior that the mobile browser exhibits on the same page without the above code. I explicitly set only a swipe recognizer, so I expect Hammer to only recognize and react to swipe events and not interfere with anything else. I know that's not trivial, but it's possible and it's Hammer's entire job.

I haven't yet researched if I can accomplish that by tinkering with some parameter, but if that is the case, then there's a wrong default somewhere. That is the out-of-the-box behavior that I expect in this situation. I have set Hammer to only listen for swipes, hence I expect it to do by default whatever is needed to avoid interfering with other events.

OBSERVED If I pinch to zoom (which works if the above code is removed), nothing happens.

teo1978 commented 4 years ago

And I tried setting touchAction: 'pan-y pinch-zoom': then I can pinch-zoom, but Hammer doesn't detect the swipe gestures anymore.

There should be no conflict between detecting a horizontal (or vertical, for that matter) swipe gesture and being able to pinch-zoom. Pinch-zoom is done with two fingers. A requirement for a pinch zoom to happen is that there are two fingers touching and dragging. Horizontal swipe can only happen if there is one and only one finger dragging. The two scenarios are non-overlapping, so it is possible to have both work without interfering with one another.

More complex scenarios might be tricky, but one as simple as this one is achievable. It's the simplest thing and I expected it to work out of the box.

collimarco commented 4 years ago

Same problem here. I use Hammer.js to detect left / right swipe and native zoom doesn't work anymore on that pages. This is unacceptable for usability.

Is there any workaround at least? Otherwise I will have to build a swipe detection from scratch.

materemias commented 5 months ago

Defining an explicit inputClass on the HammerManager's configuration solved this issue, native pinch to zoom and pull to refresh started to work. eg inputClass: Hammer.TouchInput