Skip to content

virtual-scroll: merge into master under cdk-experimental #11354

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

Merged
merged 32 commits into from
May 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3967a64
feat(virtual-scroll): fixed size virtual scroll (#9316)
mmalerba Feb 15, 2018
1c19ca4
chore: move virtual-scroll to cdk-experimental (#9974)
mmalerba Feb 20, 2018
7495ee7
virtual-scroll: simplify scroll listener logic (#10102)
mmalerba Feb 27, 2018
e0591b3
virtual-scroll: only move views that need to be moved (#10099)
mmalerba Feb 27, 2018
55da6b2
virtual-scroll: switch `throttleTime` to `sampleTime` (#10179)
mmalerba Feb 28, 2018
1471964
virtual-scroll: allow user to pass `Observable<T[]>` (#10158)
mmalerba Feb 28, 2018
ece59ba
virtual-scroll: rename `Range` to `ListRange` to avoid confusion with…
mmalerba Mar 5, 2018
b105916
virtual-scroll: add autosize scroll strategy (#10219)
mmalerba Mar 6, 2018
f04b470
virtual-scroll: add `onContentRendered` hook to `VirtualScrollStrateg…
mmalerba Mar 7, 2018
4b8a2c5
virtual-scroll: add incremental scroll logic in `AutosizeVirtualScrol…
mmalerba Apr 5, 2018
3acadda
fix bazel
mmalerba Apr 5, 2018
2538942
fix devapp
mmalerba Apr 5, 2018
8565c60
fix lint
mmalerba Apr 5, 2018
0bba2dc
Merge remote-tracking branch 'upstream/master' into virtual-scroll
mmalerba Apr 12, 2018
97d623b
cleanup
mmalerba Apr 12, 2018
ed6ab9a
virtual-scroll: rewrite offset in terms of "to-top" and fix a bug whe…
mmalerba Apr 27, 2018
1f9051e
Merge remote-tracking branch 'upstream/master' into virtual-scroll
mmalerba Apr 27, 2018
285fe6c
virtual-scroll: address amcdnl's feedback (#10988)
mmalerba Apr 27, 2018
0e4a580
virtual-scroll: fix updating when data changes and add trackBy demos …
mmalerba May 1, 2018
604f743
virtual-scroll: add logic to correct the scroll position as user move…
mmalerba May 7, 2018
11783b7
fix(scrolling): adds right to fix pushed content (#11192)
amcdnl May 7, 2018
5ad55da
virtual-scroll: add tests for fixed size items (#11255)
mmalerba May 10, 2018
c196eec
virtual-scroll: add tests for `cdkVirtualFor` logic (#11275)
mmalerba May 11, 2018
4bef998
add some basic tests (#11295)
mmalerba May 12, 2018
0cb7d70
Merge remote-tracking branch 'upstream/master' into virtual-scroll
mmalerba May 14, 2018
2253b6d
fix lint
mmalerba May 14, 2018
9497bad
virtual-scroll: add e2e tests for autosize scroll strategy (#11345)
mmalerba May 15, 2018
341bb15
address comments
mmalerba May 16, 2018
78e27b6
Merge remote-tracking branch 'upstream/master' into virtual-scroll
mmalerba May 16, 2018
63e058e
fix lint and tests
mmalerba May 16, 2018
c4177ff
fix bad rebase
mmalerba May 16, 2018
fe54f73
fix(scrolling): scrollbar jump when data change on scroll (#11193)
amcdnl May 16, 2018
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
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
# CDK experimental package
/src/cdk-experimental/** @jelbourn
/src/cdk-experimental/dialog/** @jelbourn @josephperrott @crisbeto
/src/cdk-experimental/scrolling/** @mmalerba

# Docs examples & guides
/guides/** @amcdnl @jelbourn
Expand Down Expand Up @@ -141,6 +142,7 @@
/src/demo-app/tooltip/** @andrewseguin
/src/demo-app/tree/** @tinayuangao
/src/demo-app/typography/** @crisbeto
/src/demo-app/virtual-scroll/** @mmalerba

# E2E app
/e2e/* @jelbourn
Expand All @@ -165,6 +167,7 @@
/e2e/components/stepper-e2e.spec.ts @mmalerba
/e2e/components/tabs-e2e.spec.ts @andrewseguin
/e2e/components/toolbar-e2e.spec.ts @devversion
/e2e/components/virtual-scroll-e2e.spec.ts @mmalerba
/e2e/util/** @jelbourn
/src/e2e-app/* @jelbourn
/src/e2e-app/block-scroll-strategy/** @andrewseguin @crisbeto
Expand All @@ -183,6 +186,7 @@
/src/e2e-app/sidenav/** @mmalerba
/src/e2e-app/slide-toggle/** @devversion
/src/e2e-app/tabs/** @andrewseguin
/src/e2e-app/virtual-scroll/** @mmalerba

# Universal app
/src/universal-app/** @jelbourn
Expand Down
117 changes: 117 additions & 0 deletions e2e/components/virtual-scroll-e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import {browser, by, element, ElementFinder} from 'protractor';
import {ILocation, ISize} from 'selenium-webdriver';

declare var window: any;


describe('autosize cdk-virtual-scroll', () => {
let viewport: ElementFinder;

describe('with uniform items', () => {
beforeEach(() => {
browser.get('/virtual-scroll');
viewport = element(by.css('.demo-virtual-scroll-uniform-size cdk-virtual-scroll-viewport'));
});

it('should scroll down slowly', async () => {
await browser.executeAsyncScript(smoothScrollViewportTo, viewport, 2000);
const offScreen = element(by.css('.demo-virtual-scroll-uniform-size [data-index="39"]'));
const onScreen = element(by.css('.demo-virtual-scroll-uniform-size [data-index="40"]'));
expect(await isVisibleInViewport(offScreen, viewport)).toBe(false);
expect(await isVisibleInViewport(onScreen, viewport)).toBe(true);
});

it('should jump scroll position down and slowly scroll back up', async () => {
// The estimate of the total content size is exactly correct, so we wind up scrolled to the
// same place as if we slowly scrolled down.
await browser.executeAsyncScript(scrollViewportTo, viewport, 2000);
const offScreen = element(by.css('.demo-virtual-scroll-uniform-size [data-index="39"]'));
const onScreen = element(by.css('.demo-virtual-scroll-uniform-size [data-index="40"]'));
expect(await isVisibleInViewport(offScreen, viewport)).toBe(false);
expect(await isVisibleInViewport(onScreen, viewport)).toBe(true);

// As we slowly scroll back up we should wind up back at the start of the content.
await browser.executeAsyncScript(smoothScrollViewportTo, viewport, 0);
const first = element(by.css('.demo-virtual-scroll-uniform-size [data-index="0"]'));
expect(await isVisibleInViewport(first, viewport)).toBe(true);
});
});

describe('with variable size', () => {
beforeEach(() => {
browser.get('/virtual-scroll');
viewport = element(by.css('.demo-virtual-scroll-variable-size cdk-virtual-scroll-viewport'));
});

it('should scroll down slowly', async () => {
await browser.executeAsyncScript(smoothScrollViewportTo, viewport, 2000);
const offScreen = element(by.css('.demo-virtual-scroll-variable-size [data-index="19"]'));
const onScreen = element(by.css('.demo-virtual-scroll-variable-size [data-index="20"]'));
expect(await isVisibleInViewport(offScreen, viewport)).toBe(false);
expect(await isVisibleInViewport(onScreen, viewport)).toBe(true);
});

it('should jump scroll position down and slowly scroll back up', async () => {
// The estimate of the total content size is slightly different than the actual, so we don't
// wind up in the same spot as if we scrolled slowly down.
await browser.executeAsyncScript(scrollViewportTo, viewport, 2000);
const offScreen = element(by.css('.demo-virtual-scroll-variable-size [data-index="18"]'));
const onScreen = element(by.css('.demo-virtual-scroll-variable-size [data-index="19"]'));
expect(await isVisibleInViewport(offScreen, viewport)).toBe(false);
expect(await isVisibleInViewport(onScreen, viewport)).toBe(true);

// As we slowly scroll back up we should wind up back at the start of the content. As we
// scroll the error from when we jumped the scroll position should be slowly corrected.
await browser.executeAsyncScript(smoothScrollViewportTo, viewport, 0);
const first = element(by.css('.demo-virtual-scroll-variable-size [data-index="0"]'));
expect(await isVisibleInViewport(first, viewport)).toBe(true);
});
});
});


/** Checks if the given element is visible in the given viewport. */
async function isVisibleInViewport(el: ElementFinder, viewport: ElementFinder): Promise<boolean> {
if (!await el.isPresent() || !await el.isDisplayed() || !await viewport.isPresent() ||
!await viewport.isDisplayed()) {
return false;
}
const viewportRect = getRect(await viewport.getLocation(), await viewport.getSize());
const elRect = getRect(await el.getLocation(), await el.getSize());
return elRect.left < viewportRect.right && elRect.right > viewportRect.left &&
elRect.top < viewportRect.bottom && elRect.bottom > viewportRect.top;
}


/** Gets the rect for an element given its location ans size. */
function getRect(location: ILocation, size: ISize):
{top: number, left: number, bottom: number, right: number} {
return {
top: location.y,
left: location.x,
bottom: location.y + size.height,
right: location.x + size.width
};
}


/** Immediately scrolls the viewport to the given offset. */
function scrollViewportTo(viewportEl: any, offset: number, done: () => void) {
viewportEl.scrollTop = offset;
window.requestAnimationFrame(() => done());
}


/** Smoothly scrolls the viewport to the given offset, 25px at a time. */
function smoothScrollViewportTo(viewportEl: any, offset: number, done: () => void) {
let promise = Promise.resolve();
let curOffset = viewportEl.scrollTop;
do {
const co = curOffset += Math.min(25, Math.max(-25, offset - curOffset));
promise = promise.then(() => new Promise<void>(resolve => {
viewportEl.scrollTop = co;
window.requestAnimationFrame(() => resolve());
}));
} while (curOffset != offset);
promise.then(() => done());
}
15 changes: 15 additions & 0 deletions packages.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ CDK_PACKAGES = [

CDK_TARGETS = ["//src/cdk"] + ["//src/cdk/%s" % p for p in CDK_PACKAGES]

CDK_EXPERIMENTAL_PACKAGES = [
# "dialog", # Disabled because BUILD.bazel doesn't exist yet
"scrolling",
]

CDK_EXPERIMENTAL_TARGETS = ["//src/cdk-experimental"] + [
"//src/cdk-experimental/%s" % p for p in CDK_EXPERIMENTAL_PACKAGES
]

MATERIAL_PACKAGES = [
"autocomplete",
"badge",
Expand Down Expand Up @@ -84,6 +93,12 @@ ROLLUP_GLOBALS.update({
"@angular/cdk/%s" % p: "ng.cdk.%s" % p for p in CDK_PACKAGES
})

# Rollup globals for cdk subpackages in the form of, e.g.,
# {"@angular/cdk-experimental/scrolling": "ng.cdkExperimental.scrolling"}
ROLLUP_GLOBALS.update({
"@angular/cdk-experimental/%s" % p: "ng.cdkExperimental.%s" % p for p in CDK_EXPERIMENTAL_PACKAGES
})

# Rollup globals for material subpackages, e.g., {"@angular/material/list": "ng.material.list"}
ROLLUP_GLOBALS.update({
"@angular/material/%s" % p: "ng.material.%s" % p for p in MATERIAL_PACKAGES
Expand Down
11 changes: 6 additions & 5 deletions src/cdk-experimental/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_module", "ng_package")
load("//:packages.bzl", "CDK_TARGETS", "ROLLUP_GLOBALS", "VERSION_PLACEHOLDER_REPLACEMENTS")
load("//:packages.bzl", "CDK_EXPERIMENTAL_PACKAGES", "CDK_EXPERIMENTAL_TARGETS", "CDK_TARGETS", "ROLLUP_GLOBALS", "VERSION_PLACEHOLDER_REPLACEMENTS")

# Export the CDK tsconfig so that subpackages can reference it directly.
exports_files(["tsconfig-build.json"])

ng_module(
name = "cdk-experimental",
srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]),
srcs = glob(["*.ts"], exclude=["**/*.spec.ts"]),
module_name = "@angular/cdk-experimental",
deps = CDK_TARGETS,
assets = glob(["**/*.css", "**/*.html"]),
deps = ["//src/cdk-experimental/%s" % p for p in CDK_EXPERIMENTAL_PACKAGES],
tsconfig = "//src/lib:tsconfig-build.json",
)

Expand All @@ -18,6 +19,6 @@ ng_package(
entry_point = "src/cdk-experimental/public_api.js",
globals = ROLLUP_GLOBALS,
replacements = VERSION_PLACEHOLDER_REPLACEMENTS,
deps = [":cdk-experimental"],
deps = CDK_EXPERIMENTAL_TARGETS,
tags = ["publish"],
)
2 changes: 1 addition & 1 deletion src/cdk-experimental/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"homepage": "https://github.com/angular/material2#readme",
"peerDependencies": {
"@angular/material": "0.0.0-PLACEHOLDER",
"@angular/cdk": "0.0.0-PLACEHOLDER",
"@angular/core": "0.0.0-NG"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions src/cdk-experimental/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
*/

export * from './version';
export * from '@angular/cdk-experimental/scrolling';
62 changes: 62 additions & 0 deletions src/cdk-experimental/scrolling/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_binary")


ng_module(
name = "scrolling",
srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]),
module_name = "@angular/cdk-experimental/scrolling",
assets = [":virtual_scroll_viewport_css"] + glob(["**/*.html"]),
deps = [
"//src/cdk/coercion",
"//src/cdk/collections",
"@rxjs",
],
tsconfig = "//src/cdk-experimental:tsconfig-build.json",
)

sass_binary(
name = "virtual_scroll_viewport_scss",
src = "virtual-scroll-viewport.scss",
)

# TODO(jelbourn): remove this when sass_binary supports specifying an output filename and dir.
# Copy the output of the sass_binary such that the filename and path match what we expect.
genrule(
name = "virtual_scroll_viewport_css",
srcs = [":virtual_scroll_viewport_scss.css"],
outs = ["virtual-scroll-viewport.css"],
cmd = "cp $< $@",
)

ts_library(
name = "scrolling_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
":scrolling",
"//src/cdk/collections",
"//src/cdk/testing",
"@rxjs",
],
tsconfig = "//src/cdk-experimental:tsconfig-build.json",
)

ts_web_test(
name = "unit_tests",
bootstrap = [
"//:web_test_bootstrap_scripts",
],
tags = ["manual"],

# Do not sort
deps = [
"//:tslib_bundle",
"//:angular_bundles",
"//:angular_test_bundles",
"//test:angular_test_init",
":scrolling_test_sources",
],
)
Loading