Skip to content

Commit

Permalink
refactor: scroll-blocking (#5972)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode authored Nov 20, 2023
1 parent 948be22 commit acbf5fd
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
EventEmitter,
Inject,
Input,
NgZone,
Output,
Self,
ViewChild,
Expand Down Expand Up @@ -131,6 +132,7 @@ export class TuiMobileCalendarComponent implements AfterViewInit {
@Inject(TUI_CHOOSE_DAY_OR_RANGE_TEXTS)
readonly chooseDayOrRangeTexts$: Observable<[string, string]>,
@Inject(TUI_ANIMATIONS_DURATION) private readonly duration: number,
@Inject(NgZone) private readonly ngZone: NgZone,
) {
valueChanges.pipe(takeUntil(this.destroy$)).subscribe(value => {
this.value = value;
Expand Down Expand Up @@ -222,9 +224,9 @@ export class TuiMobileCalendarComponent implements AfterViewInit {
this.activeYear = year;
this.scrollToActiveYear('smooth');

// Delay is required to run months scroll in the next frame to prevent flicker
setTimeout(() => {
this.scrollToActiveMonth();
this.ngZone.runOutsideAngular(() => {
// Delay is required to run months scroll in the next frame to prevent flicker
setTimeout(() => this.scrollToActiveMonth());
});
}

Expand Down Expand Up @@ -317,10 +319,12 @@ export class TuiMobileCalendarComponent implements AfterViewInit {
const touchstart$ = tuiTypedFromEvent(
yearsScrollRef.elementRef.nativeElement,
'touchstart',
{passive: true},
);
const touchend$ = tuiTypedFromEvent(
yearsScrollRef.elementRef.nativeElement,
'touchend',
{passive: true},
);
const click$ = tuiTypedFromEvent(
yearsScrollRef.elementRef.nativeElement,
Expand Down Expand Up @@ -387,6 +391,7 @@ export class TuiMobileCalendarComponent implements AfterViewInit {
const touchend$ = tuiTypedFromEvent(
monthsScrollRef.elementRef.nativeElement,
'touchend',
{passive: true},
);

// Smooth scroll to the closest month after scrolling is done
Expand Down

0 comments on commit acbf5fd

Please sign in to comment.