Skip to content

Commit ba1879a

Browse files
committed
fix(cdk/scrolling): move setting transform to ngAfterViewChecked
1 parent f8c0b8d commit ba1879a

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/cdk/scrolling/virtual-scroll-viewport.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {ListRange} from '@angular/cdk/collections';
1111
import {Platform} from '@angular/cdk/platform';
1212
import {
1313
afterNextRender,
14+
AfterViewChecked,
1415
booleanAttribute,
1516
ChangeDetectionStrategy,
1617
ChangeDetectorRef,
@@ -81,7 +82,10 @@ const SCROLL_SCHEDULER =
8182
},
8283
],
8384
})
84-
export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements OnInit, OnDestroy {
85+
export class CdkVirtualScrollViewport
86+
extends CdkVirtualScrollable
87+
implements AfterViewChecked, OnInit, OnDestroy
88+
{
8589
private _platform = inject(Platform);
8690

8791
/** Emits when the viewport is detached from a CdkVirtualForOf. */
@@ -504,6 +508,14 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
504508
}
505509
}
506510

511+
ngAfterViewChecked() {
512+
// Apply the content transform. The transform can't be set via an Angular binding because
513+
// bypassSecurityTrustStyle is banned in Google. However the value is safe, it's composed of
514+
// string literals, a variable that can only be 'X' or 'Y', and user input that is run through
515+
// the `Number` function first to coerce it to a numeric value.
516+
this._contentWrapper.nativeElement.style.transform = this._renderedContentTransform;
517+
}
518+
507519
/** Run change detection. */
508520
private _doChangeDetection() {
509521
if (this._isDestroyed) {
@@ -515,11 +527,6 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
515527
afterNextRender(
516528
() => {
517529
this._isChangeDetectionPending = false;
518-
// Apply the content transform. The transform can't be set via an Angular binding because
519-
// bypassSecurityTrustStyle is banned in Google. However the value is safe, it's composed of
520-
// string literals, a variable that can only be 'X' or 'Y', and user input that is run through
521-
// the `Number` function first to coerce it to a numeric value.
522-
this._contentWrapper.nativeElement.style.transform = this._renderedContentTransform;
523530
const runAfterChangeDetection = this._runAfterChangeDetection;
524531
this._runAfterChangeDetection = [];
525532
for (const fn of runAfterChangeDetection) {

tools/public_api_guard/cdk/scrolling.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
```ts
66

7+
import { AfterViewChecked } from '@angular/core';
78
import { ChangeDetectorRef } from '@angular/core';
89
import { CollectionViewer } from '@angular/cdk/collections';
910
import { DataSource } from '@angular/cdk/collections';
@@ -183,7 +184,7 @@ export interface CdkVirtualScrollRepeater<T> {
183184
}
184185

185186
// @public
186-
export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements OnInit, OnDestroy {
187+
export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements AfterViewChecked, OnInit, OnDestroy {
187188
constructor(elementRef: ElementRef<HTMLElement>, _changeDetectorRef: ChangeDetectorRef, ngZone: NgZone, _scrollStrategy: VirtualScrollStrategy, dir: Directionality, scrollDispatcher: ScrollDispatcher, viewportRuler: ViewportRuler, scrollable: CdkVirtualScrollable);
188189
appendOnly: boolean;
189190
attach(forOf: CdkVirtualScrollRepeater<any>): void;
@@ -205,6 +206,8 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
205206
// (undocumented)
206207
static ngAcceptInputType_appendOnly: unknown;
207208
// (undocumented)
209+
ngAfterViewChecked(): void;
210+
// (undocumented)
208211
ngOnDestroy(): void;
209212
// (undocumented)
210213
ngOnInit(): void;

0 commit comments

Comments
 (0)