1
1
/**
2
2
* Custom HammerJS configuration forked from Angular Material. With Angular v9,
3
3
* Angular Material dropped HammerJS as a dependency. This configuration was added
4
- * automatically to this application because `ng update` detected that this application
5
- * directly used HammerJS.
4
+ * automatically to this application because ng- update detected that this application
5
+ * directly used custom HammerJS gestures defined by Angular Material .
6
6
*
7
- * If this application does not depend on the custom gestures originally defined by
8
- * Angular Material, this file can be deleted.
7
+ * Read more in the dedicated guide: https://git.io/ng-material-v9-hammer-migration
9
8
*/
10
9
11
10
import {Injectable, Inject, Optional, Type} from '@angular/core';
12
11
import {HammerGestureConfig} from '@angular/platform-browser';
13
12
import {MAT_HAMMER_OPTIONS} from '@angular/material/core';
14
13
15
- const SUPPORTED_CUSTOM_GESTURES = [
16
- 'longpress',
17
- 'slide',
18
- 'slidestart',
19
- 'slideend',
20
- 'slideright',
21
- 'slideleft'
22
- ];
23
-
24
14
/**
25
- * Fake HammerInstance that is used when a Hammer instance is requested when
26
- * HammerJS has not been loaded on the page.
15
+ * Noop hammer instance that is used when an instance is requested, but
16
+ * Hammer has not been loaded on the page yet .
27
17
*/
28
18
const noopHammerInstance = {
29
19
on: () => {},
30
20
off: () => {},
31
21
};
32
22
33
23
/**
34
- * Adjusts configuration of our gesture library, Hammer.
35
- * @deprecated No longer being used. To be removed.
36
- * @breaking-change 10.0.0
24
+ * Gesture config that provides custom Hammer gestures on top of the default Hammer
25
+ * gestures. These gestures will be available as events in component templates.
37
26
*/
38
27
@Injectable()
39
28
export class GestureConfig extends HammerGestureConfig {
40
- /** List of new event names to add to the gesture support list */
41
- events = SUPPORTED_CUSTOM_GESTURES;
42
-
43
- constructor(
44
- @Optional() @Inject(MAT_HAMMER_OPTIONS) private _hammerOptions?: any) {
29
+ /** List of event names to add to the Hammer gesture plugin list */
30
+ events = [
31
+ 'longpress',
32
+ 'slide',
33
+ 'slidestart',
34
+ 'slideend',
35
+ 'slideright',
36
+ 'slideleft'
37
+ ];
38
+
39
+ constructor(@Optional() @Inject(MAT_HAMMER_OPTIONS) private hammerOptions?: any) {
45
40
super();
46
41
}
47
42
48
43
/**
49
44
* Builds Hammer instance manually to add custom recognizers that match the
50
- * Material Design spec.
51
- *
52
- * Our gesture names come from the Material Design gestures spec:
53
- * https://material.io/design/#gestures-touch-mechanics
54
- *
55
- * More information on default recognizers can be found in Hammer docs:
56
- * http://hammerjs.github.io/recognizer-pan/
57
- * http://hammerjs.github.io/recognizer-press/
45
+ * Material Design specification. Gesture names originate from the Material Design
46
+ * gestures: https://material.io/design/#gestures-touch-mechanics
58
47
*
48
+ * More information on default recognizers can be found in the Hammer docs:
49
+ * http://hammerjs.github.io/recognizer-pan/
50
+ * http://hammerjs.github.io/recognizer-press/
59
51
* @param element Element to which to assign the new HammerJS gestures.
60
52
* @returns Newly-created HammerJS instance.
61
53
*/
@@ -66,7 +58,7 @@ export class GestureConfig extends HammerGestureConfig {
66
58
return noopHammerInstance;
67
59
}
68
60
69
- const mc = new hammer(element, this._hammerOptions || undefined);
61
+ const mc = new hammer(element, this.hammerOptions || undefined);
70
62
71
63
// Default Hammer Recognizers.
72
64
const pan = new hammer.Pan();
@@ -95,11 +87,10 @@ export class GestureConfig extends HammerGestureConfig {
95
87
}
96
88
97
89
/** Creates a new recognizer, without affecting the default recognizers of HammerJS */
98
- private _createRecognizer(base: Object , options: any, ...inheritances: Object []) {
90
+ private _createRecognizer(base: object , options: any, ...inheritances: object []) {
99
91
const recognizer = new (base.constructor as Type<any>)(options);
100
92
inheritances.push(base);
101
93
inheritances.forEach(item => recognizer.recognizeWith(item));
102
94
return recognizer;
103
95
}
104
-
105
96
}
0 commit comments