-
Notifications
You must be signed in to change notification settings - Fork 6.8k
virtual-scroll: emit the currently scrolled to index #12381
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
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
868bbf9
virtual scroll: implement scrollTo functions
amcdnl a31a4c8
fix(scroll): fix scrolling not working all the time
amcdnl 017a131
chore: pr nit
amcdnl 2527306
chore: throw exception for offset getter
amcdnl 05c29b9
chore: better checks for scroll smooth
amcdnl dce1cad
Merge branch 'master' into scroll-to
amcdnl 38487f7
tweak API slightly and add demo
mmalerba 91bcd58
update BUILD file
mmalerba 5a63174
Merge remote-tracking branch 'upstream/master' into vs-scroll-to
mmalerba 0947381
fix duplicate template ref name
mmalerba 2f47b3d
add output for scrolledIndexChange
mmalerba 92ac9a9
Merge remote-tracking branch 'upstream/master' into vs-scroll-out
mmalerba 4c733ea
Merge remote-tracking branch 'upstream/master' into vs-scroll-out
mmalerba b6dd29d
add test
mmalerba fc725b3
address comments
mmalerba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,11 +18,12 @@ import { | |
NgZone, | ||
OnDestroy, | ||
OnInit, | ||
Output, | ||
ViewChild, | ||
ViewEncapsulation, | ||
} from '@angular/core'; | ||
import {animationFrameScheduler, fromEvent, Observable, Subject} from 'rxjs'; | ||
import {sampleTime, takeUntil} from 'rxjs/operators'; | ||
import {sample, sampleTime, takeUntil} from 'rxjs/operators'; | ||
import {CdkVirtualForOf} from './virtual-for-of'; | ||
import {VIRTUAL_SCROLL_STRATEGY, VirtualScrollStrategy} from './virtual-scroll-strategy'; | ||
|
||
|
@@ -54,9 +55,22 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy { | |
/** Emits when the rendered range changes. */ | ||
private _renderedRangeSubject = new Subject<ListRange>(); | ||
|
||
/** Emits when a change detection cycle completes. */ | ||
private _changeDetectionComplete = new Subject<void>(); | ||
|
||
/** The direction the viewport scrolls. */ | ||
@Input() orientation: 'horizontal' | 'vertical' = 'vertical'; | ||
|
||
// Note: we don't use the typical EventEmitter here because we need to subscribe to the scroll | ||
// strategy lazily (i.e. only if the user is actually listening to the events). We do this because | ||
// depending on how the strategy calculates the scrolled index, it may come at a cost to | ||
// performance. | ||
/** Emits when the index of the first element visible in the viewport changes. */ | ||
@Output() scrolledIndexChange = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs type info. |
||
Observable.create(observer => this._scrollStrategy.scrolledIndexChange | ||
.pipe(sample(this._changeDetectionComplete)) | ||
.subscribe(observer)); | ||
|
||
/** The element that wraps the rendered content. */ | ||
@ViewChild('contentWrapper') _contentWrapper: ElementRef<HTMLElement>; | ||
|
||
|
@@ -139,6 +153,7 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy { | |
// Complete all subjects | ||
this._renderedRangeSubject.complete(); | ||
this._detachedSubject.complete(); | ||
this._changeDetectionComplete.complete(); | ||
this._destroyed.complete(); | ||
} | ||
|
||
|
@@ -363,5 +378,7 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy { | |
for (const fn of runAfterChangeDetection) { | ||
fn(); | ||
} | ||
|
||
this._ngZone.run(() => this._changeDetectionComplete.next()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just do
throw Error('...')
without thenew
operator.