6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
- import { Injectable , Optional } from '@angular/core' ;
9
+ import { Injectable , InjectionToken , Inject , Optional } from '@angular/core' ;
10
10
import { HammerGestureConfig } from '@angular/platform-browser' ;
11
11
import { MatCommonModule } from '../common-behaviors/common-module' ;
12
- import { HammerInstance , HammerStatic , Recognizer , RecognizerStatic } from './gesture-annotations' ;
12
+ import {
13
+ HammerStatic ,
14
+ HammerInstance ,
15
+ Recognizer ,
16
+ RecognizerStatic ,
17
+ HammerOptions ,
18
+ } from './gesture-annotations' ;
19
+
20
+ /**
21
+ * Injection token that can be used to provide options to the Hammerjs instance.
22
+ * More info at http://hammerjs.github.io/api/.
23
+ */
24
+ export const MAT_HAMMER_OPTIONS = new InjectionToken < HammerOptions > ( 'MAT_HAMMER_OPTIONS' ) ;
13
25
14
26
/* Adjusts configuration of our gesture library, Hammer. */
15
27
@Injectable ( )
@@ -26,7 +38,9 @@ export class GestureConfig extends HammerGestureConfig {
26
38
'slideleft'
27
39
] : [ ] ;
28
40
29
- constructor ( @Optional ( ) commonModule ?: MatCommonModule ) {
41
+ constructor (
42
+ @Optional ( ) @Inject ( MAT_HAMMER_OPTIONS ) private _hammerOptions ?: HammerOptions ,
43
+ @Optional ( ) commonModule ?: MatCommonModule ) {
30
44
super ( ) ;
31
45
if ( commonModule ) {
32
46
commonModule . _checkHammerIsAvailable ( ) ;
@@ -47,18 +61,18 @@ export class GestureConfig extends HammerGestureConfig {
47
61
* @returns Newly-created HammerJS instance.
48
62
*/
49
63
buildHammer ( element : HTMLElement ) : HammerInstance {
50
- const mc = new this . _hammer ( element ) ;
64
+ const mc = new this . _hammer ( element , this . _hammerOptions || undefined ) ;
51
65
52
66
// Default Hammer Recognizers.
53
- let pan = new this . _hammer . Pan ( ) ;
54
- let swipe = new this . _hammer . Swipe ( ) ;
55
- let press = new this . _hammer . Press ( ) ;
67
+ const pan = new this . _hammer . Pan ( ) ;
68
+ const swipe = new this . _hammer . Swipe ( ) ;
69
+ const press = new this . _hammer . Press ( ) ;
56
70
57
71
// Notice that a HammerJS recognizer can only depend on one other recognizer once.
58
72
// Otherwise the previous `recognizeWith` will be dropped.
59
73
// TODO: Confirm threshold numbers with Material Design UX Team
60
- let slide = this . _createRecognizer ( pan , { event : 'slide' , threshold : 0 } , swipe ) ;
61
- let longpress = this . _createRecognizer ( press , { event : 'longpress' , time : 500 } ) ;
74
+ const slide = this . _createRecognizer ( pan , { event : 'slide' , threshold : 0 } , swipe ) ;
75
+ const longpress = this . _createRecognizer ( press , { event : 'longpress' , time : 500 } ) ;
62
76
63
77
// Overwrite the default `pan` event to use the swipe event.
64
78
pan . recognizeWith ( swipe ) ;
0 commit comments