diff --git a/src/core/gestures/MdGestureConfig.ts b/src/core/gestures/MdGestureConfig.ts index 85d35437485a..e80493152d37 100644 --- a/src/core/gestures/MdGestureConfig.ts +++ b/src/core/gestures/MdGestureConfig.ts @@ -33,34 +33,32 @@ 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) + 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; } } diff --git a/src/demo-app/gestures/gestures-demo.html b/src/demo-app/gestures/gestures-demo.html index d13beb1914c4..9f2467659efb 100644 --- a/src/demo-app/gestures/gestures-demo.html +++ b/src/demo-app/gestures/gestures-demo.html @@ -1,7 +1,7 @@
Drag: {{dragCount}}
@@ -9,4 +9,5 @@Longpress: {{longpressCount}}
Press: {{pressCount}}
Swipe: {{swipeCount}}
+Slide: {{slideCount}}