Skip to content

Commit 63aab21

Browse files
committed
fix(cdk/virtual-scroll): fix subpixel rounding errors on hdpi screens
Using `transform` appears to cause rounding errors that can accumulate and become significant after scrolling through a large number of items. Switching to `width` / `height` corrects this.
1 parent 8a05678 commit 63aab21

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@
99
Spacer used to force the scrolling container to the correct size for the *total* number of items
1010
so that the scrollbar captures the size of the entire data set.
1111
-->
12-
<div class="cdk-virtual-scroll-spacer" [style.transform]="_totalContentSizeTransform"></div>
12+
<div class="cdk-virtual-scroll-spacer"
13+
[style.width]="orientation == 'horizontal' ? _totalContentSize + 'px' : ''"
14+
[style.height]="orientation == 'vertical' ? _totalContentSize + 'px' : ''"></div>

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,10 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
8989
/** A stream that emits whenever the rendered range changes. */
9090
renderedRangeStream: Observable<ListRange> = this._renderedRangeSubject.asObservable();
9191

92-
/**
93-
* The transform used to scale the spacer to the same size as all content, including content that
94-
* is not currently rendered.
95-
*/
96-
_totalContentSizeTransform = '';
97-
9892
/**
9993
* The total size of all content (in pixels), including content that is not currently rendered.
10094
*/
101-
private _totalContentSize = 0;
95+
_totalContentSize = 0;
10296

10397
/**
10498
* The CSS transform applied to the rendered subset of items so that they appear within the bounds
@@ -238,8 +232,6 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
238232
setTotalContentSize(size: number) {
239233
if (this._totalContentSize !== size) {
240234
this._totalContentSize = size;
241-
const axis = this.orientation == 'horizontal' ? 'X' : 'Y';
242-
this._totalContentSizeTransform = `scale${axis}(${this._totalContentSize})`;
243235
this._markChangeDetectionNeeded();
244236
}
245237
}

tools/public_api_guard/cdk/scrolling.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export declare type CdkVirtualForOfContext<T> = {
9090

9191
export declare class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, OnDestroy {
9292
_contentWrapper: ElementRef<HTMLElement>;
93-
_totalContentSizeTransform: string;
93+
_totalContentSize: number;
9494
elementRef: ElementRef<HTMLElement>;
9595
orientation: 'horizontal' | 'vertical';
9696
renderedRangeStream: Observable<ListRange>;

0 commit comments

Comments
 (0)