Skip to content

Commit 11ab12e

Browse files
committed
address comemnts
1 parent c9b60ce commit 11ab12e

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/cdk-experimental/scrolling/auto-size-virtual-scroll.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,27 +94,24 @@ export class AutoSizeVirtualScrollStrategy implements VirtualScrollStrategy {
9494
this._viewport = null;
9595
}
9696

97-
/** Called when the viewport is scrolled. */
97+
/** Implemented as part of VirtualScrollStrategy. */
9898
onContentScrolled() {
9999
if (this._viewport) {
100100
this._renderContentForOffset(this._viewport.measureScrollOffset());
101101
}
102102
}
103103

104-
/** Called when the length of the data changes. */
104+
/** Implemented as part of VirtualScrollStrategy. */
105105
onDataLengthChanged() {
106106
if (this._viewport) {
107107
this._renderContentForOffset(this._viewport.measureScrollOffset());
108108
}
109109
}
110110

111-
/** Called when the range of items rendered in the DOM has changed. */
111+
/** Implemented as part of VirtualScrollStrategy. */
112112
onContentRendered() {
113113
if (this._viewport) {
114-
const renderedContentSize = this._viewport.measureRenderedContentSize();
115-
this._averager.addSample(
116-
this._viewport.getRenderedRange(), renderedContentSize);
117-
this._updateTotalContentSize(renderedContentSize);
114+
this._checkRenderedContentSize();
118115
}
119116
}
120117

@@ -129,6 +126,17 @@ export class AutoSizeVirtualScrollStrategy implements VirtualScrollStrategy {
129126
this._addBufferPx = addBufferPx;
130127
}
131128

129+
/**
130+
* Checks the size of the currently rendered content and uses it tp update the estimated item size
131+
* and estimated total content size.
132+
*/
133+
private _checkRenderedContentSize() {
134+
const viewport = this._viewport!;
135+
const renderedContentSize = viewport.measureRenderedContentSize();
136+
this._averager.addSample(viewport.getRenderedRange(), renderedContentSize);
137+
this._updateTotalContentSize(renderedContentSize);
138+
}
139+
132140
/**
133141
* Render the content that we estimate should be shown for the given scroll offset.
134142
* Note: must not be called if `this._viewport` is null
@@ -186,7 +194,7 @@ export class AutoSizeVirtualScrollStrategy implements VirtualScrollStrategy {
186194
}
187195

188196
/** Update the viewport's total content size. */
189-
private _updateTotalContentSize(renderedContentSize) {
197+
private _updateTotalContentSize(renderedContentSize: number) {
190198
const viewport = this._viewport!;
191199
const renderedRange = viewport.getRenderedRange();
192200
const totalSize = renderedContentSize +

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,8 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy {
180180

181181
/** Measure the combined size of all of the rendered items. */
182182
measureRenderedContentSize() {
183-
return this.orientation === 'horizontal' ?
184-
this._contentWrapper.nativeElement.offsetWidth :
185-
this._contentWrapper.nativeElement.offsetHeight;
183+
const contentEl = this._contentWrapper.nativeElement;
184+
return this.orientation === 'horizontal' ? contentEl.offsetWidth : contentEl.offsetHeight;
186185
}
187186

188187
ngOnInit() {

0 commit comments

Comments
 (0)