Skip to content

Commit

Permalink
fix(core): Setting gestures to false breaks the gallery, closes #464, #…
Browse files Browse the repository at this point in the history
  • Loading branch information
MurhafSousli committed Oct 3, 2022
1 parent 82ea76d commit 0fce03a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
30 changes: 19 additions & 11 deletions projects/ng-gallery/src/lib/components/gallery-slider.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ export class GallerySliderComponent implements OnInit, OnChanges, OnDestroy {
}

ngOnInit() {
this._zone.runOutsideAngular(() => {
// Set styles manually avoid triggering change detection on dragging
this._sliderStateSub$ = this.sliderState$.pipe(
tap((state: SliderState) => {
this.slider.style.transform = state.style.transform;
this.slider.style.height = state.style.height;
this.slider.style.width = state.style.width;
this.slider.classList.toggle('g-no-transition', state.instant);
this.container.style.transform = this.zoom.transform;
})
).subscribe();
});

if (this.config.gestures && typeof Hammer !== 'undefined') {

const direction = this.config.slidingDirection === SlidingDirection.Horizontal
Expand Down Expand Up @@ -139,17 +152,6 @@ export class GallerySliderComponent implements OnInit, OnChanges, OnDestroy {
}
}
});

// Set styles manually avoid triggering change detection on dragging
this._sliderStateSub$ = this.sliderState$.pipe(
tap((state: SliderState) => {
this.slider.style.transform = state.style.transform;
this.slider.style.height = state.style.height;
this.slider.style.width = state.style.width;
this.slider.classList.toggle('g-no-transition', state.instant);
this.container.style.transform = this.zoom.transform;
})
).subscribe();
});
}

Expand All @@ -162,6 +164,12 @@ export class GallerySliderComponent implements OnInit, OnChanges, OnDestroy {
}
}

ngAfterViewInit() {
// setTimeout(() => {
// this.updateSlider({ value: 0, instant: true });
// }, 200)
}

ngOnDestroy() {
this._hammer?.destroy();
this._resizeSub$?.unsubscribe();
Expand Down
22 changes: 12 additions & 10 deletions projects/ng-gallery/src/lib/components/gallery-thumbs.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ export class GalleryThumbsComponent implements OnInit, OnChanges, OnDestroy {
}

ngOnInit() {
this._zone.runOutsideAngular(() => {
// Set styles manually avoid triggering change detection on dragging
this._sliderStateSub$ = this.sliderState$.pipe(
tap((state: SliderState) => {
this.slider.style.transform = state.style.transform;
this.slider.style.height = state.style.height;
this.slider.style.width = state.style.width;
this.slider.classList.toggle('g-no-transition', state.instant);
})
).subscribe();
});

if (this.config.gestures && !this.config.disableThumb && typeof Hammer !== 'undefined') {

let direction: number;
Expand Down Expand Up @@ -139,16 +151,6 @@ export class GalleryThumbsComponent implements OnInit, OnChanges, OnDestroy {
case ThumbnailsMode.Free:
this._hammer.on('pan', (e) => this.freeMode(e));
}

// Set styles manually avoid triggering change detection on dragging
this._sliderStateSub$ = this.sliderState$.pipe(
tap((state: SliderState) => {
this.slider.style.transform = state.style.transform;
this.slider.style.height = state.style.height;
this.slider.style.width = state.style.width;
this.slider.classList.toggle('g-no-transition', state.instant);
})
).subscribe();
});
}
}
Expand Down

0 comments on commit 0fce03a

Please sign in to comment.