Skip to content

Commit

Permalink
fix(gestures): ensure drag and pan are recognized with slide (#901)
Browse files Browse the repository at this point in the history
  • Loading branch information
kara authored and robertmesserle committed Jul 22, 2016
1 parent 14805fe commit 3179fec
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
42 changes: 21 additions & 21 deletions src/core/gestures/MdGestureConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,34 @@ export class MdGestureConfig extends HammerGestureConfig {
* TODO: Confirm threshold numbers with Material Design UX Team
* */
buildHammer(element: HTMLElement) {
var mc = new Hammer(element);
const mc = new Hammer(element);

// Create custom gesture recognizers
let drag = this._createRecognizer(Hammer.Pan, {event: 'drag', threshold: 6}, Hammer.Swipe);
let slide = this._createRecognizer(Hammer.Pan, {event: 'slide', threshold: 0}, Hammer.Swipe);
let longpress = this._createRecognizer(Hammer.Press, {event: 'longpress', time: 500});
// create custom gesture recognizers
const drag = new Hammer.Pan({event: 'drag', threshold: 6});
const longpress = new Hammer.Press({event: 'longpress', time: 500});
const slide = new Hammer.Pan({event: 'slide', threshold: 0});

let pan = new Hammer.Pan();
let swipe = new Hammer.Swipe();
// ensure custom recognizers can coexist with the default gestures (i.e. pan, press, swipe)
// custom recognizers can overwrite default recognizers if they aren't configured to
// "recognizeWith" others that listen to the same base events.
const pan = new Hammer.Pan();
const press = new Hammer.Press();
const swipe = new Hammer.Swipe();

// Overwrite the default `pan` event to use the swipe event.
pan.recognizeWith(swipe);

// Add customized gestures to Hammer manager
mc.add([drag, slide, pan, longpress]);
drag.recognizeWith(pan);
drag.recognizeWith(swipe);
drag.recognizeWith(slide);

return mc;
}
pan.recognizeWith(swipe);
pan.recognizeWith(slide);

/** Creates a new recognizer, without affecting the default recognizers of HammerJS */
private _createRecognizer(type: RecognizerStatic, options: any, ...extra: RecognizerStatic[]) {
let recognizer = new type(options);
slide.recognizeWith(swipe);

// Add the default recognizer to the new custom recognizer.
extra.push(type);
extra.forEach(entry => recognizer.recognizeWith(new entry()));
longpress.recognizeWith(press);

return recognizer;
// add customized gestures to Hammer manager
mc.add([drag, pan, swipe, press, longpress, slide]);
return mc;
}

}
3 changes: 2 additions & 1 deletion src/demo-app/gestures/gestures-demo.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<div class="demo-gestures">
<div (drag)="dragCount = dragCount + 1" (pan)="panCount = panCount + 1"
(longpress)="longpressCount = longpressCount + 1" (press)="pressCount = pressCount + 1"
(swipe)="swipeCount = swipeCount + 1">
(swipe)="swipeCount = swipeCount + 1" (slide)="slideCount = slideCount + 1">
Drag, swipe, or press me.
</div>
<p>Drag: {{dragCount}}</p>
<p>Pan: {{panCount}}</p>
<p>Longpress: {{longpressCount}}</p>
<p>Press: {{pressCount}}</p>
<p>Swipe: {{swipeCount}}</p>
<p>Slide: {{slideCount}}</p>
</div>
1 change: 1 addition & 0 deletions src/demo-app/gestures/gestures-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export class GesturesDemo {
pressCount: number = 0;
longpressCount: number = 0;
swipeCount: number = 0;
slideCount: number = 0;
}

0 comments on commit 3179fec

Please sign in to comment.