Created
September 14, 2020 14:45
-
-
Save agustinhaller/1bab0e8c1484ac5a1d9e698d017357ed to your computer and use it in GitHub Desktop.
Idea de como mejorar el código que carga las librerías de tracking para el Store
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Injectable, Inject, Optional, Type} from '@angular/core'; | |
import {HammerGestureConfig} from '@angular/platform-browser'; | |
import {MAT_HAMMER_OPTIONS} from '@angular/material/core'; | |
/** | |
* Noop hammer instance that is used when an instance is requested, but | |
* Hammer has not been loaded on the page yet. | |
*/ | |
const noopHammerInstance = { | |
on: () => {}, | |
off: () => {}, | |
}; | |
/** | |
* Gesture config that provides custom Hammer gestures on top of the default Hammer | |
* gestures. These gestures will be available as events in component templates. | |
*/ | |
@Injectable() | |
export class GestureConfig extends HammerGestureConfig { | |
/** List of event names to add to the Hammer gesture plugin list */ | |
events = [ | |
'longpress', | |
'slide', | |
'slidestart', | |
'slideend', | |
'slideright', | |
'slideleft' | |
]; | |
constructor(@Optional() @Inject(MAT_HAMMER_OPTIONS) private hammerOptions?: any) { | |
super(); | |
} | |
/** | |
* Builds Hammer instance manually to add custom recognizers that match the | |
* Material Design specification. Gesture names originate from the Material Design | |
* gestures: https://material.io/design/#gestures-touch-mechanics | |
* | |
* More information on default recognizers can be found in the Hammer docs: | |
* http://hammerjs.github.io/recognizer-pan/ | |
* http://hammerjs.github.io/recognizer-press/ | |
* @param element Element to which to assign the new HammerJS gestures. | |
* @returns Newly-created HammerJS instance. | |
*/ | |
buildHammer(element: HTMLElement): any { | |
const hammer: any = typeof window !== 'undefined' ? (window as any).Hammer : null; | |
if (!hammer) { | |
return noopHammerInstance; | |
} | |
const mc = new hammer(element, this.hammerOptions || undefined); | |
// Default Hammer Recognizers. | |
const pan = new hammer.Pan(); | |
const swipe = new hammer.Swipe(); | |
const press = new hammer.Press(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment