Skip to content

Commit

Permalink
fix(core): Slide bug with touch scroll, related to #465
Browse files Browse the repository at this point in the history
  • Loading branch information
MurhafSousli committed Oct 4, 2022
1 parent 32aca2c commit a26d63f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
29 changes: 14 additions & 15 deletions projects/ng-gallery/src/lib/components/gallery-slider.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class GallerySliderComponent implements OnInit, OnChanges, OnDestroy {

private activateGestures() {
if (typeof Hammer !== 'undefined') {
let direction: 'VERTICAL' | 'HORIZONTAL';
let direction: number;
let touchAction: 'pan-x' | 'pan-y' | 'compute' = 'compute';

if (this.config.slidingDirection === SlidingDirection.Horizontal) {
Expand All @@ -170,24 +170,23 @@ export class GallerySliderComponent implements OnInit, OnChanges, OnDestroy {
this._hammer.get('pan').set({ direction });

this._zone.runOutsideAngular(() => {
this._hammer.on('panmove', (e) => {
this._hammer.on('pan', (e) => {
switch (this.config.slidingDirection) {
case SlidingDirection.Horizontal:
this.updateSlider({ value: e.deltaX, instant: true });
if (e.isFinal) {
this.updateSlider({ value: 0, instant: false });
this.horizontalPan(e);
} else {
this.updateSlider({ value: e.deltaX, instant: true });
}
break;
case SlidingDirection.Vertical:
this.updateSlider({ value: e.deltaY, instant: true });
}
});

this._hammer.on('panend', (e) => {
this.updateSlider({ value: 0, instant: false });
switch (this.config.slidingDirection) {
case SlidingDirection.Horizontal:
this.horizontalPan(e);
break;
case SlidingDirection.Vertical:
this.verticalPan(e);
if (e.isFinal) {
this.updateSlider({ value: 0, instant: false });
this.verticalPan(e);
} else {
this.updateSlider({ value: e.deltaY, instant: true });
}
}
});
});
Expand Down
13 changes: 11 additions & 2 deletions projects/ng-gallery/src/lib/components/gallery-thumbs.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,22 @@ export class GalleryThumbsComponent implements OnInit, OnChanges, OnDestroy {
if (!this.config.disableThumb && typeof Hammer !== 'undefined') {

let direction: number;
let touchAction: 'pan-x' | 'pan-y' | 'compute' = 'compute';

switch (this.config.thumbPosition) {
case ThumbnailsPosition.Right:
case ThumbnailsPosition.Left:
direction = Hammer.DIRECTION_VERTICAL;
if (this.config.reserveGesturesAction) {
touchAction = 'pan-y';
}
break;
case ThumbnailsPosition.Top:
case ThumbnailsPosition.Bottom:
direction = Hammer.DIRECTION_HORIZONTAL;
if (this.config.reserveGesturesAction) {
touchAction = 'pan-x';
}
break;
}

Expand Down Expand Up @@ -186,18 +193,20 @@ export class GalleryThumbsComponent implements OnInit, OnChanges, OnDestroy {
switch (this.config.thumbPosition) {
case ThumbnailsPosition.Right:
case ThumbnailsPosition.Left:
this.updateSlider({ value: e.deltaY, instant: true });
if (e.isFinal) {
this.updateSlider({ value: 0, instant: false });
this.verticalPan(e);
} else {
this.updateSlider({ value: e.deltaY, instant: true });
}
break;
case ThumbnailsPosition.Top:
case ThumbnailsPosition.Bottom:
this.updateSlider({ value: e.deltaX, instant: true });
if (e.isFinal) {
this.updateSlider({ value: 0, instant: false });
this.horizontalPan(e);
} else {
this.updateSlider({ value: e.deltaX, instant: true });
}
}
}
Expand Down

0 comments on commit a26d63f

Please sign in to comment.