RyanMullins / angular-hammer

Hammer.js v2 support for AngularJS
http://ryanmullins.github.io/angular-hammer/
MIT License
188 stars 55 forks source link

[Question] How to recognize swipe from the edge #20

Closed DmitryEfimenko closed 9 years ago

DmitryEfimenko commented 9 years ago

Hello,

I'm trying to implement some custom functionality when user swipes from the left edge of the display in the right direction.

It's probably my misunderstanding of hummer.js, which is the biggest problem, but here is what I tried:

html:

<div class="my-main-container" hm-panright="onHammer" hm-recognizer-options='[{"deltaX":"1"}]'>
</div>

js:

$scope.onHammer = function() {
   console.log('hit'); // never gets hit
}

if I replace hm-panright with hm-pan, it get's hit, but it gets hit on any swipe, not just from the edge. Do you see anything obvious that I'm doing wrong? Any help is appreciated!

RyanMullins commented 9 years ago

I'm actually working through a related in (see #16 and #19) where the default recognizers were not being initialized properly. It's part of a pretty big suite of bug and performance fixes coming in v2.1.3. I'll keep this open until I finalize those changes (target for that is Monday).

In the meantime, you're missing a couple of things in your recognizer options, namely a type and an explicit directions value. Without a type, Angular Hammer won't associate the options with a recognizer. The directions value is only necessary because of the issue I mentioned above. The deltaX value may not do anything, or at least I wouldn't expect it to given the Hammer docs for Pan. Try this and let me know if it works.

<div class="my-main-container" 
    hm-panright="onHammer"
    hm-recognizer-options='[{"type":"pan","directions":"DIRECTIONS_RIGHT"}]'>
</div>

One more thing to keep in mind. Pan, Press, Swipe, and Tap gestures are all pretty much universally supported, but other gestures may not be depending on the browser. If you run into issues check the Hammer Compatibility page to make sure your browser supports that gesture type.

DmitryEfimenko commented 9 years ago

Thanks for the info and a suggestion. Though It still never gets hit. I'm testing on latest Chrome locally.

RyanMullins commented 9 years ago

Interesting. I recommended this fix to another person and they reported the same thing. Maybe it's a bigger problem with the pan right gesture. I'll look into it.