Skip to content

fix(gestures): ensure default gestures are not overwritten by custom gestures #382

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

Merged
merged 1 commit into from
May 10, 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
56 changes: 40 additions & 16 deletions src/core/gestures/MdGestureConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,46 @@ import {HammerGestureConfig} from '@angular/platform-browser';
@Injectable()
export class MdGestureConfig extends HammerGestureConfig {
/* List of new event names to add to the gesture support list */
events: string[] = ['drag', 'longpress'];
events: string[] = [
'drag',
'dragstart',
'dragend',
'dragright',
'dragleft',
'longpress',
];

/*
* Overrides default recognizer event names and thresholds.
*
* Our gesture names come from the Material Design gestures spec:
* https://www.google.com/design/spec/patterns/gestures.html#gestures-touch-mechanics
*
* More information on default recognizers can be found in Hammer docs:
* http://hammerjs.github.io/recognizer-pan/
* http://hammerjs.github.io/recognizer-press/
*
* TODO: Confirm threshold numbers with Material Design UX Team
* */
overrides: {[key: string]: Object} = {
'pan': {event: 'drag', threshold: 6},
'press': {event: 'longpress', time: 500}
};
* Builds Hammer instance manually to add custom recognizers that match the Material Design spec.
*
* Our gesture names come from the Material Design gestures spec:
* https://www.google.com/design/spec/patterns/gestures.html#gestures-touch-mechanics
*
* More information on default recognizers can be found in Hammer docs:
* http://hammerjs.github.io/recognizer-pan/
* http://hammerjs.github.io/recognizer-press/
*
* TODO: Confirm threshold numbers with Material Design UX Team
* */
buildHammer(element: HTMLElement) {
var mc = new Hammer(element);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason you're using var instead of let? Just wondering because I've seen let being used in other places


// create custom gesture recognizers
var drag = new Hammer.Pan({event: 'drag', threshold: 6});
var longpress = new Hammer.Press({event: 'longpress', time: 500});

// ensure custom recognizers can coexist with the default gestures (i.e. pan, press, swipe)
var pan = new Hammer.Pan();
var press = new Hammer.Press();
var swipe = new Hammer.Swipe();
drag.recognizeWith(pan);
drag.recognizeWith(swipe);
pan.recognizeWith(swipe);
longpress.recognizeWith(press);

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

}
13 changes: 8 additions & 5 deletions src/demo-app/gestures/gestures-demo.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<div class="demo-gestures">
<div (longpress)="pressCount = pressCount + 1" (drag)="dragCount = dragCount + 1"
<div (drag)="dragCount = dragCount + 1" (pan)="panCount = panCount + 1"
(longpress)="longpressCount = longpressCount + 1" (press)="pressCount = pressCount + 1"
(swipe)="swipeCount = swipeCount + 1">
Drag or press me.
Drag, swipe, or press me.
</div>
drag: {{dragCount}}
swipe: {{swipeCount}}
longpress: {{pressCount}}
<p>Drag: {{dragCount}}</p>
<p>Pan: {{panCount}}</p>
<p>Longpress: {{longpressCount}}</p>
<p>Press: {{pressCount}}</p>
<p>Swipe: {{swipeCount}}</p>
</div>
2 changes: 2 additions & 0 deletions src/demo-app/gestures/gestures-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {Component} from '@angular/core';
})
export class GesturesDemo {
dragCount: number = 0;
panCount: number = 0;
pressCount: number = 0;
longpressCount: number = 0;
swipeCount: number = 0;
}
3 changes: 2 additions & 1 deletion typings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#26c98c8a9530c44f8c801ccc3b2057e2101187ee"
},
"ambientDependencies": {
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2"
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2",
"hammerjs": "github:DefinitelyTyped/DefinitelyTyped/hammerjs/hammerjs.d.ts#de8e80dfe5360fef44d00c41257d5ef37add000a"
}
}