Skip to content

Commit 3967a64

Browse files
committed
feat(virtual-scroll): fixed size virtual scroll (angular#9316)
* feat(virtual-scroll): fixed size virtual scroll * address some comments * change VirtualScrollStrategy interface a bit * address some more comments * fix lint & build
1 parent 1616f2f commit 3967a64

24 files changed

+945
-25
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
/src/demo-app/tooltip/** @andrewseguin
139139
/src/demo-app/tree/** @tinayuangao
140140
/src/demo-app/typography/** @crisbeto
141+
/src/demo-app/virtual-scroll/** @mmalerba
141142

142143
# E2E app
143144
/e2e/* @jelbourn

src/cdk/collections/collection-viewer.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
import {Observable} from 'rxjs';
1010

11+
12+
/** Represents a range of numbers with a specified start and end. */
13+
export type Range = {start: number, end: number};
14+
15+
1116
/**
1217
* Interface for any component that provides a view of some data collection and wants to provide
1318
* information regarding the view and any changes made.
@@ -17,5 +22,5 @@ export interface CollectionViewer {
1722
* A stream that emits whenever the `CollectionViewer` starts looking at a new portion of the
1823
* data. The `start` index is inclusive, while the `end` is exclusive.
1924
*/
20-
viewChange: Observable<{start: number, end: number}>;
25+
viewChange: Observable<Range>;
2126
}

src/cdk/collections/data-source.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import {Observable} from 'rxjs';
1010
import {CollectionViewer} from './collection-viewer';
1111

12+
1213
export abstract class DataSource<T> {
1314
/**
1415
* Connects a collection viewer (such as a data-table) to this data source. Note that

src/cdk/collections/public-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
export * from './collection-viewer';
1010
export * from './data-source';
1111
export * from './selection';
12+
export * from './static-array-data-source';
1213
export {
1314
UniqueSelectionDispatcher,
1415
UniqueSelectionDispatcherListener,
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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/Observable';
10+
import {of as observableOf} from 'rxjs/observable/of';
11+
import {DataSource} from './data-source';
12+
13+
14+
/** DataSource wrapper for a native array. */
15+
export class StaticArrayDataSource<T> implements DataSource<T> {
16+
constructor(private _data: T[]) {}
17+
18+
connect(): Observable<T[]> {
19+
return observableOf(this._data);
20+
}
21+
22+
disconnect() {}
23+
}

src/cdk/scrolling/BUILD.bazel

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package(default_visibility=["//visibility:public"])
22
load("@angular//:index.bzl", "ng_module")
33
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
4+
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_binary")
45

56

67
ng_module(
78
name = "scrolling",
89
srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]),
910
module_name = "@angular/cdk/scrolling",
11+
assets = [
12+
":virtual_scroll_viewport_css",
13+
],
1014
deps = [
15+
"//src/cdk/collections",
1116
"//src/cdk/platform",
1217
"@rxjs",
1318
],
@@ -42,3 +47,18 @@ ts_web_test(
4247
":scrolling_test_sources",
4348
],
4449
)
50+
51+
sass_binary(
52+
name = "virtual_scroll_viewport_scss",
53+
src = "virtual-scroll-viewport.scss",
54+
)
55+
56+
# TODO(jelbourn): remove this when sass_binary supports specifying an output filename and dir.
57+
# Copy the output of the sass_binary such that the filename and path match what we expect.
58+
genrule(
59+
name = "virtual_scroll_viewport_css",
60+
srcs = [":virtual_scroll_viewport_scss"],
61+
outs = ["virtual-scroll-viewport.css"],
62+
cmd = "cat $(locations :virtual_scroll_viewport_scss) > $@",
63+
)
64+

src/cdk/scrolling/public-api.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
export * from './virtual-for-of';
910
export * from './scroll-dispatcher';
1011
export * from './scrollable';
11-
export * from './viewport-ruler';
1212
export * from './scrolling-module';
13+
export * from './viewport-ruler';
14+
export * from './virtual-scroll-viewport';

src/cdk/scrolling/scrolling-module.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,23 @@
99
import {PlatformModule} from '@angular/cdk/platform';
1010
import {NgModule} from '@angular/core';
1111
import {CdkScrollable} from './scrollable';
12+
import {CdkVirtualForOf} from './virtual-for-of';
13+
import {CdkVirtualScrollFixedSize} from './virtual-scroll-fixed-size';
14+
import {CdkVirtualScrollViewport} from './virtual-scroll-viewport';
1215

1316
@NgModule({
1417
imports: [PlatformModule],
15-
exports: [CdkScrollable],
16-
declarations: [CdkScrollable],
18+
exports: [
19+
CdkVirtualForOf,
20+
CdkScrollable,
21+
CdkVirtualScrollFixedSize,
22+
CdkVirtualScrollViewport,
23+
],
24+
declarations: [
25+
CdkVirtualForOf,
26+
CdkScrollable,
27+
CdkVirtualScrollFixedSize,
28+
CdkVirtualScrollViewport,
29+
],
1730
})
1831
export class ScrollDispatchModule {}

src/cdk/scrolling/tsconfig-build.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"extends": "../tsconfig-build",
33
"files": [
4-
"public-api.ts"
4+
"public-api.ts",
5+
"../typings.d.ts"
56
],
67
"angularCompilerOptions": {
78
"annotateForClosureCompiler": true,

src/cdk/scrolling/typings.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare var module: {id: string};

0 commit comments

Comments
 (0)