Skip to content

refactor: add virtual scroll repeater interface #16412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cdk/scrolling/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
4 changes: 3 additions & 1 deletion src/cdk/scrolling/virtual-for-of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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` */
Expand Down Expand Up @@ -74,7 +75,8 @@ function getSize(orientation: 'horizontal' | 'vertical', node: Node): number {
@Directive({
selector: '[cdkVirtualFor][cdkVirtualForOf]',
})
export class CdkVirtualForOf<T> implements CollectionViewer, DoCheck, OnDestroy {
export class CdkVirtualForOf<T> implements
CdkVirtualScrollRepeater<T>, CollectionViewer, DoCheck, OnDestroy {
/** Emits when the rendered view of the data changes. */
viewChange = new Subject<ListRange>();

Expand Down
18 changes: 18 additions & 0 deletions src/cdk/scrolling/virtual-scroll-repeater.ts
Original file line number Diff line number Diff line change
@@ -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<T> {
dataStream: Observable<T[] | ReadonlyArray<T>>;
measureRangeSize(range: ListRange, orientation: 'horizontal' | 'vertical'): number;
}
6 changes: 3 additions & 3 deletions src/cdk/scrolling/virtual-scroll-viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -116,7 +116,7 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
private _viewportSize = 0;

/** the currently attached CdkVirtualForOf. */
private _forOf: CdkVirtualForOf<any> | null;
private _forOf: CdkVirtualScrollRepeater<any> | null;

/** The last rendered content offset that was set. */
private _renderedContentOffset = 0;
Expand Down Expand Up @@ -184,7 +184,7 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
}

/** Attaches a `CdkVirtualForOf` to this viewport. */
attach(forOf: CdkVirtualForOf<any>) {
attach(forOf: CdkVirtualScrollRepeater<any>) {
if (this._forOf) {
throw Error('CdkVirtualScrollViewport is already attached.');
}
Expand Down