diff --git a/src/cdk/scrolling/public-api.ts b/src/cdk/scrolling/public-api.ts index 2c1cf815d1a0..f4a89ab4032c 100644 --- a/src/cdk/scrolling/public-api.ts +++ b/src/cdk/scrolling/public-api.ts @@ -14,3 +14,4 @@ export * from './viewport-ruler'; export * from './virtual-for-of'; export * from './virtual-scroll-strategy'; export * from './virtual-scroll-viewport'; +export * from './virtual-scroll-repeater'; diff --git a/src/cdk/scrolling/virtual-for-of.ts b/src/cdk/scrolling/virtual-for-of.ts index d438c2524670..b688981585d6 100644 --- a/src/cdk/scrolling/virtual-for-of.ts +++ b/src/cdk/scrolling/virtual-for-of.ts @@ -33,6 +33,7 @@ import { import {Observable, Subject, of as observableOf} from 'rxjs'; import {pairwise, shareReplay, startWith, switchMap, takeUntil} from 'rxjs/operators'; import {CdkVirtualScrollViewport} from './virtual-scroll-viewport'; +import {CdkVirtualScrollRepeater} from './virtual-scroll-repeater'; /** The context for an item rendered by `CdkVirtualForOf` */ @@ -74,7 +75,8 @@ function getSize(orientation: 'horizontal' | 'vertical', node: Node): number { @Directive({ selector: '[cdkVirtualFor][cdkVirtualForOf]', }) -export class CdkVirtualForOf implements CollectionViewer, DoCheck, OnDestroy { +export class CdkVirtualForOf implements + CdkVirtualScrollRepeater, CollectionViewer, DoCheck, OnDestroy { /** Emits when the rendered view of the data changes. */ viewChange = new Subject(); diff --git a/src/cdk/scrolling/virtual-scroll-repeater.ts b/src/cdk/scrolling/virtual-scroll-repeater.ts new file mode 100644 index 000000000000..1c82eaeb5a10 --- /dev/null +++ b/src/cdk/scrolling/virtual-scroll-repeater.ts @@ -0,0 +1,18 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {Observable} from 'rxjs'; +import {ListRange} from '../collections'; + +/** + * An item to be repeated by the VirtualScrollViewport + */ +export interface CdkVirtualScrollRepeater { + dataStream: Observable>; + measureRangeSize(range: ListRange, orientation: 'horizontal' | 'vertical'): number; +} diff --git a/src/cdk/scrolling/virtual-scroll-viewport.ts b/src/cdk/scrolling/virtual-scroll-viewport.ts index 2bd7c815e0b1..78cbca59f1b4 100644 --- a/src/cdk/scrolling/virtual-scroll-viewport.ts +++ b/src/cdk/scrolling/virtual-scroll-viewport.ts @@ -27,8 +27,8 @@ import {animationFrameScheduler, asapScheduler, Observable, Subject, Observer} f import {auditTime, startWith, takeUntil} from 'rxjs/operators'; import {ScrollDispatcher} from './scroll-dispatcher'; import {CdkScrollable, ExtendedScrollToOptions} from './scrollable'; -import {CdkVirtualForOf} from './virtual-for-of'; import {VIRTUAL_SCROLL_STRATEGY, VirtualScrollStrategy} from './virtual-scroll-strategy'; +import {CdkVirtualScrollRepeater} from './virtual-scroll-repeater'; /** Checks if the given ranges are equal. */ @@ -116,7 +116,7 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O private _viewportSize = 0; /** the currently attached CdkVirtualForOf. */ - private _forOf: CdkVirtualForOf | null; + private _forOf: CdkVirtualScrollRepeater | null; /** The last rendered content offset that was set. */ private _renderedContentOffset = 0; @@ -184,7 +184,7 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O } /** Attaches a `CdkVirtualForOf` to this viewport. */ - attach(forOf: CdkVirtualForOf) { + attach(forOf: CdkVirtualScrollRepeater) { if (this._forOf) { throw Error('CdkVirtualScrollViewport is already attached.'); }