feat(cdk/scrolling): Viewport needs asynchronous functions to set data
- Dominant language
- TypeScript
- Stars
- 25k
- Forks
- 6.8k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 91
Description
#### Feature Description
The virtual scrolling viewport is [asynchronously initialized](https://github.com/angular/components/blob/master/src/cdk/scrolling/virtual-scroll-viewport.ts#L195). Normally developers can expect that when `ngAfterViewInit()` is called in a component's parent, the component will be ready for interaction, but the viewport is not yet ready at that point. The application needs to wait a tick so that the viewport can finish initializing before using functions like `scrollToIndex`. Developers should not need to know this before using the viewport.
I request that all functions requiring a fully initialized viewport be replaced with asynchronous versions that defer the execution of those functions until the viewport is finished with initialization. A viable alternative would be to provide an Observable that declares that the viewport is ready to receive commands.
#### Use Case
I want to be able to use the viewport in `ngAfterViewInit` as can normally be done with child components. See [this Stackblitz](https://stackblitz.com/edit/autoscroll?file=src%2Fapp%2Fapp.component.ts).
Contributor guide
Research direction
Start with src/cdk/scrolling/virtual-scroll-viewport.ts around the asynchronous initialization at line 195, then review the scrollToIndex use case and linked StackBlitz. Identify which viewport commands depend on readiness and determine whether deferred methods or a readiness Observable best supports use from ngAfterViewInit; done means commands work without an extra caller-supplied tick.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100