Skip to content

adds virtual scroll adapter #14287

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
wants to merge 3 commits into from
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-adapter';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs an extra newline at the end of the file.

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 @@ -27,6 +27,7 @@ import {
import {Observable, Subject} from 'rxjs';
import {pairwise, shareReplay, startWith, switchMap, takeUntil} from 'rxjs/operators';
import {CdkVirtualScrollViewport} from './virtual-scroll-viewport';
import {CdkVirtualScrollAdapter} from './virtual-scroll-adapter';


/** The context for an item rendered by `CdkVirtualForOf` */
Expand Down Expand Up @@ -68,7 +69,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
CdkVirtualScrollAdapter<T>, CollectionViewer, DoCheck, OnDestroy {
/** Emits when the rendered view of the data changes. */
viewChange = new Subject<ListRange>();

Expand Down
15 changes: 15 additions & 0 deletions src/cdk/scrolling/virtual-scroll-adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @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';

export interface CdkVirtualScrollAdapter<T> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs some docs explaining what it does and what it's useful for.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about CdkVirtualScrollRepeater?

dataStream: Observable<T[] | ReadonlyArray<T>>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmalerba shouldn't we call this a dataSource for consistency with some of the other components?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this is different than the dataSource, in the case of cdkVirtualForOf this stream is created by connecting to the data source, but it doesn't have to be.

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, Observable, Subject, Observer} from 'rxjs';
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 {CdkVirtualScrollAdapter} from './virtual-scroll-adapter';


/** Checks if the given ranges are equal. */
Expand Down Expand Up @@ -108,7 +108,7 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
private _viewportSize = 0;

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

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

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