Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gestures): ensure drag and pan are recognized with slide #901

Merged
merged 1 commit into from
Jul 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}