Skip to content

Commit f326ec6

Browse files
committed
adds virtual scroll adapater
1 parent c618dde commit f326ec6

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

src/cdk/scrolling/public-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ export * from './viewport-ruler';
1414
export * from './virtual-for-of';
1515
export * from './virtual-scroll-strategy';
1616
export * from './virtual-scroll-viewport';
17+
export * from './virtual-scroll-adapter';

src/cdk/scrolling/virtual-for-of.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
import {Observable, Subject} from 'rxjs';
2828
import {pairwise, shareReplay, startWith, switchMap, takeUntil} from 'rxjs/operators';
2929
import {CdkVirtualScrollViewport} from './virtual-scroll-viewport';
30+
import {CdkVirtualScrollAdapter} from './virtual-scroll-adapter';
3031

3132

3233
/** The context for an item rendered by `CdkVirtualForOf` */
@@ -68,7 +69,8 @@ function getSize(orientation: 'horizontal' | 'vertical', node: Node): number {
6869
@Directive({
6970
selector: '[cdkVirtualFor][cdkVirtualForOf]',
7071
})
71-
export class CdkVirtualForOf<T> implements CollectionViewer, DoCheck, OnDestroy {
72+
export class CdkVirtualForOf<T> implements
73+
CdkVirtualScrollAdapter<T>, CollectionViewer, DoCheck, OnDestroy {
7274
/** Emits when the rendered view of the data changes. */
7375
viewChange = new Subject<ListRange>();
7476

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {Observable} from 'rxjs';
10+
import {ListRange} from '../collections';
11+
12+
export interface CdkVirtualScrollAdapter<T> {
13+
dataStream: Observable<T[] | ReadonlyArray<T>>;
14+
measureRangeSize(range: ListRange, orientation: 'horizontal' | 'vertical'): number;
15+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import {animationFrameScheduler, Observable, Subject, Observer} from 'rxjs';
2727
import {auditTime, startWith, takeUntil} from 'rxjs/operators';
2828
import {ScrollDispatcher} from './scroll-dispatcher';
2929
import {CdkScrollable, ExtendedScrollToOptions} from './scrollable';
30-
import {CdkVirtualForOf} from './virtual-for-of';
3130
import {VIRTUAL_SCROLL_STRATEGY, VirtualScrollStrategy} from './virtual-scroll-strategy';
31+
import {CdkVirtualScrollAdapter} from './virtual-scroll-adapter';
3232

3333

3434
/** Checks if the given ranges are equal. */
@@ -104,7 +104,7 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
104104
private _viewportSize = 0;
105105

106106
/** the currently attached CdkVirtualForOf. */
107-
private _forOf: CdkVirtualForOf<any> | null;
107+
private _forOf: CdkVirtualScrollAdapter<any> | null;
108108

109109
/** The last rendered content offset that was set. */
110110
private _renderedContentOffset = 0;
@@ -172,7 +172,7 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
172172
}
173173

174174
/** Attaches a `CdkVirtualForOf` to this viewport. */
175-
attach(forOf: CdkVirtualForOf<any>) {
175+
attach(forOf: CdkVirtualScrollAdapter<any>) {
176176
if (this._forOf) {
177177
throw Error('CdkVirtualScrollViewport is already attached.');
178178
}

0 commit comments

Comments
 (0)