@@ -5,22 +5,46 @@ import {HammerGestureConfig} from '@angular/platform-browser';
5
5
@Injectable ( )
6
6
export class MdGestureConfig extends HammerGestureConfig {
7
7
/* List of new event names to add to the gesture support list */
8
- events : string [ ] = [ 'drag' , 'longpress' ] ;
8
+ events : string [ ] = [
9
+ 'drag' ,
10
+ 'dragstart' ,
11
+ 'dragend' ,
12
+ 'dragright' ,
13
+ 'dragleft' ,
14
+ 'longpress' ,
15
+ ] ;
9
16
10
17
/*
11
- * Overrides default recognizer event names and thresholds.
12
- *
13
- * Our gesture names come from the Material Design gestures spec:
14
- * https://www.google.com/design/spec/patterns/gestures.html#gestures-touch-mechanics
15
- *
16
- * More information on default recognizers can be found in Hammer docs:
17
- * http://hammerjs.github.io/recognizer-pan/
18
- * http://hammerjs.github.io/recognizer-press/
19
- *
20
- * TODO: Confirm threshold numbers with Material Design UX Team
21
- * */
22
- overrides : { [ key : string ] : Object } = {
23
- 'pan' : { event : 'drag' , threshold : 6 } ,
24
- 'press' : { event : 'longpress' , time : 500 }
25
- } ;
18
+ * Builds Hammer instance manually to add custom recognizers that match the Material Design spec.
19
+ *
20
+ * Our gesture names come from the Material Design gestures spec:
21
+ * https://www.google.com/design/spec/patterns/gestures.html#gestures-touch-mechanics
22
+ *
23
+ * More information on default recognizers can be found in Hammer docs:
24
+ * http://hammerjs.github.io/recognizer-pan/
25
+ * http://hammerjs.github.io/recognizer-press/
26
+ *
27
+ * TODO: Confirm threshold numbers with Material Design UX Team
28
+ * */
29
+ buildHammer ( element : HTMLElement ) {
30
+ var mc = new Hammer ( element ) ;
31
+
32
+ // create custom gesture recognizers
33
+ var drag = new Hammer . Pan ( { event : 'drag' , threshold : 6 } ) ;
34
+ var longpress = new Hammer . Press ( { event : 'longpress' , time : 500 } ) ;
35
+
36
+ // ensure custom recognizers can coexist with the default gestures (i.e. pan, press, swipe)
37
+ var pan = new Hammer . Pan ( ) ;
38
+ var press = new Hammer . Press ( ) ;
39
+ var swipe = new Hammer . Swipe ( ) ;
40
+ drag . recognizeWith ( pan ) ;
41
+ drag . recognizeWith ( swipe ) ;
42
+ pan . recognizeWith ( swipe ) ;
43
+ longpress . recognizeWith ( press ) ;
44
+
45
+ // add customized gestures to Hammer manager
46
+ mc . add ( [ drag , pan , swipe , press , longpress ] ) ;
47
+ return mc ;
48
+ }
49
+
26
50
}
0 commit comments