Skip to content

Commit

Permalink
fix: Time performance (#3166)
Browse files Browse the repository at this point in the history
  • Loading branch information
JKMarkowski committed Sep 1, 2020
1 parent b3f5ac2 commit 0953b63
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions libs/core/src/lib/utils/directives/carousel/carousel.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ElementRef,
EventEmitter,
Input,
OnDestroy,
Output,
QueryList
} from '@angular/core';
Expand Down Expand Up @@ -40,7 +41,7 @@ export const DEFAULT_TRANSITION_DURATION = '150ms';
class: 'fd-carousel'
}
})
export class CarouselDirective implements AfterContentInit {
export class CarouselDirective implements AfterContentInit, OnDestroy {

/** Configuration for carousel */
@Input()
Expand Down Expand Up @@ -74,6 +75,9 @@ export class CarouselDirective implements AfterContentInit {
/** @hidden */
private _currentTransitionPx = 0;

/** @hidden */
private _hammer: Hammer = null;

/** @hidden */
constructor(
private _elementRef: ElementRef,
Expand All @@ -87,6 +91,13 @@ export class CarouselDirective implements AfterContentInit {
}
}

/** @hidden */
ngOnDestroy(): void {
if (this._hammer) {
this._hammer.destroy();
}
}

/** Change active element */
goToItem(item: CarouselItemDirective, smooth?: boolean): void {
let index: number = this.getIndexOfItem(item);
Expand Down Expand Up @@ -210,18 +221,18 @@ export class CarouselDirective implements AfterContentInit {

/** @hidden */
private _hammerSetup(): void {
const hammer = new Hammer(this._elementRef.nativeElement, new HammerConfig());
this._hammer = new Hammer(this._elementRef.nativeElement, new HammerConfig());

hammer.get('pan').set({ direction: Hammer.DIRECTION_ALL });
this._hammer.get('pan').set({ direction: Hammer.DIRECTION_ALL });

if (this.config.vertical) {
hammer.on('panmove', (event) => this._handlePan(event.deltaY));
hammer.on('panstart', () => this._handlePanStart());
hammer.on('panend', (event) => this._handlePanEnd(event.deltaY));
this._hammer.on('panmove', (event) => this._handlePan(event.deltaY));
this._hammer.on('panstart', () => this._handlePanStart());
this._hammer.on('panend', (event) => this._handlePanEnd(event.deltaY));
} else {
hammer.on('panmove', (event) => this._handlePan(event.deltaX));
hammer.on('panstart', () => this._handlePanStart());
hammer.on('panend', (event) => this._handlePanEnd(event.deltaX));
this._hammer.on('panmove', (event) => this._handlePan(event.deltaX));
this._hammer.on('panstart', () => this._handlePanStart());
this._hammer.on('panend', (event) => this._handlePanEnd(event.deltaX));
}
}

Expand Down

0 comments on commit 0953b63

Please sign in to comment.