66 * found in the LICENSE file at https://angular.io/license
77 */
88
9- import { Injectable , Optional } from '@angular/core' ;
9+ import { Injectable , InjectionToken , Inject , Optional } from '@angular/core' ;
1010import { HammerGestureConfig } from '@angular/platform-browser' ;
1111import { 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' ) ;
1325
1426/* Adjusts configuration of our gesture library, Hammer. */
1527@Injectable ( )
@@ -26,7 +38,9 @@ export class GestureConfig extends HammerGestureConfig {
2638 'slideleft'
2739 ] : [ ] ;
2840
29- constructor ( @Optional ( ) commonModule ?: MatCommonModule ) {
41+ constructor (
42+ @Optional ( ) @Inject ( MAT_HAMMER_OPTIONS ) private _hammerOptions ?: HammerOptions ,
43+ @Optional ( ) commonModule ?: MatCommonModule ) {
3044 super ( ) ;
3145 if ( commonModule ) {
3246 commonModule . _checkHammerIsAvailable ( ) ;
@@ -47,18 +61,18 @@ export class GestureConfig extends HammerGestureConfig {
4761 * @returns Newly-created HammerJS instance.
4862 */
4963 buildHammer ( element : HTMLElement ) : HammerInstance {
50- const mc = new this . _hammer ( element ) ;
64+ const mc = new this . _hammer ( element , this . _hammerOptions || undefined ) ;
5165
5266 // 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 ( ) ;
5670
5771 // Notice that a HammerJS recognizer can only depend on one other recognizer once.
5872 // Otherwise the previous `recognizeWith` will be dropped.
5973 // 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 } ) ;
6276
6377 // Overwrite the default `pan` event to use the swipe event.
6478 pan . recognizeWith ( swipe ) ;
0 commit comments