Skip to content

Commit

Permalink
perf(module:time-picker): do not run change detection when scrolling (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
arturovt committed Dec 16, 2021
1 parent 9a37718 commit baf7f0a
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions components/time-picker/time-picker-panel.component.ts
Expand Up @@ -11,6 +11,7 @@ import {
ElementRef,
EventEmitter,
Input,
NgZone,
OnChanges,
OnDestroy,
OnInit,
Expand Down Expand Up @@ -445,12 +446,14 @@ export class NzTimePickerPanelComponent implements ControlValueAccessor, OnInit,
const difference = to - element.scrollTop;
const perTick = (difference / duration) * 10;

reqAnimFrame(() => {
element.scrollTop = element.scrollTop + perTick;
if (element.scrollTop === to) {
return;
}
this.scrollTo(element, to, duration - 10);
this.ngZone.runOutsideAngular(() => {
reqAnimFrame(() => {
element.scrollTop = element.scrollTop + perTick;
if (element.scrollTop === to) {
return;
}
this.scrollTo(element, to, duration - 10);
});
});
}

Expand Down Expand Up @@ -517,7 +520,12 @@ export class NzTimePickerPanelComponent implements ControlValueAccessor, OnInit,
return value.value.toUpperCase() === this.time.selected12Hours;
}

constructor(private cdr: ChangeDetectorRef, public dateHelper: DateHelperService, private elementRef: ElementRef) {
constructor(
private ngZone: NgZone,
private cdr: ChangeDetectorRef,
public dateHelper: DateHelperService,
private elementRef: ElementRef
) {
// TODO: move to host after View Engine deprecation
this.elementRef.nativeElement.classList.add('ant-picker-time-panel');
}
Expand Down

0 comments on commit baf7f0a

Please sign in to comment.