Skip to content

Commit 517b09d

Browse files
committed
feat(virtual-scroll): fixed size virtual scroll (#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 6405da9 commit 517b09d

24 files changed

+968
-48
lines changed

.github/CODEOWNERS

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Angular Material components
22
/src/lib/* @jelbourn
33
/src/lib/autocomplete/** @kara @crisbeto
4+
/src/lib/badge/** @amcdnl
45
/src/lib/bottom-sheet/** @jelbourn @crisbeto
56
/src/lib/button-toggle/** @tinayuangao
67
/src/lib/button/** @tinayuangao
@@ -32,7 +33,6 @@
3233
/src/lib/tabs/** @andrewseguin
3334
/src/lib/toolbar/** @devversion
3435
/src/lib/tooltip/** @andrewseguin
35-
/src/lib/badge/** @amcdnl
3636
/src/lib/tree/** @tinayuangao
3737

3838
# Angular Material core
@@ -42,10 +42,10 @@
4242
/src/lib/core/datetime/** @mmalerba
4343
/src/lib/core/error/** @crisbeto @mmalerba
4444
/src/lib/core/gestures/** @jelbourn
45+
/src/lib/core/label/** @kara @mmalerba
4546
/src/lib/core/line/** @jelbourn
4647
/src/lib/core/option/** @kara @crisbeto
4748
/src/lib/core/placeholder/** @kara @mmalerba
48-
/src/lib/core/label/** @kara @mmalerba
4949
/src/lib/core/ripple/** @devversion
5050
/src/lib/core/selection/** @tinayuangao @jelbourn
5151
/src/lib/core/selection/pseudo*/** @crisbeto @jelbourn
@@ -93,8 +93,9 @@
9393
/src/demo-app/* @jelbourn
9494
/src/demo-app/a11y/** @tinayuangao
9595
/src/demo-app/autocomplete/** @kara @crisbeto
96-
/src/demo-app/bottom-sheet/** @jelbourn @crisbeto
96+
/src/demo-app/badge/** @amcdnl
9797
/src/demo-app/baseline/** @mmalerba
98+
/src/demo-app/bottom-sheet/** @jelbourn @crisbeto
9899
/src/demo-app/button-toggle/** @tinayuangao
99100
/src/demo-app/button/** @tinayuangao
100101
/src/demo-app/card/** @jelbourn
@@ -135,7 +136,7 @@
135136
/src/demo-app/tooltip/** @andrewseguin
136137
/src/demo-app/tree/** @tinayuangao
137138
/src/demo-app/typography/** @crisbeto
138-
/src/demo-app/badge/** @amcdnl
139+
/src/demo-app/virtual-scroll/** @mmalerba
139140

140141
# E2E app
141142
/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/Observable';
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/Observable';
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: 21 additions & 3 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
],
@@ -28,9 +33,7 @@ ts_library(
2833

2934
ts_web_test(
3035
name = "unit_tests",
31-
bootstrap = [
32-
"//:web_test_bootstrap_scripts",
33-
],
36+
bootstrap = ["//:web_test_bootstrap_scripts"],
3437

3538
# Do not sort
3639
deps = [
@@ -41,3 +44,18 @@ ts_web_test(
4144
":scrolling_test_sources",
4245
],
4346
)
47+
48+
sass_binary(
49+
name = "virtual_scroll_viewport_scss",
50+
src = "virtual-scroll-viewport.scss",
51+
)
52+
53+
# TODO(jelbourn): remove this when sass_binary supports specifying an output filename and dir.
54+
# Copy the output of the sass_binary such that the filename and path match what we expect.
55+
genrule(
56+
name = "virtual_scroll_viewport_css",
57+
srcs = [":virtual_scroll_viewport_scss"],
58+
outs = ["virtual-scroll-viewport.css"],
59+
cmd = "cat $(locations :virtual_scroll_viewport_scss) > $@",
60+
)
61+

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)