CDK virtual scroll with fixed item heights or a custom VirtualScrollStrategy for a variable-height Ionic feed
0 reputation · 01 Jun 2020, 00:46 UTC
0 reputation · 01 Jun 2020, 00:46 UTC
We are migrating an Ionic/Angular app away from the deprecated ion-virtual-scroll to Angular CDK's cdk-virtual-scroll-viewport, following the Ionic documentation's recommended path. The list in question is a chat-style feed where items mix short text messages, images, and preview cards, so heights vary significantly and some content loads asynchronously.
The constraint is that CDK's default itemSize strategy assumes a fixed, known height per item. Our options appear to be either normalizing every feed item to a fixed height (reserving aspect-ratio boxes for media) or writing a custom VirtualScrollStrategy that measures items dynamically. The first option changes our UI design; the second adds code we must maintain and test ourselves. We also plan to keep ion-infinite-scroll for pagination, so whichever approach we pick must compose cleanly with it.
Assume a current Ionic v7/v8 with a recent Angular version; we will confirm the exact deprecation status against our installed major version.
For teams that have made this migration: is a custom VirtualScrollStrategy for variable heights reliable enough in production mobile WebViews, or is enforcing fixed heights the pragmatic choice? Are there documented pitfalls with scroll-position stability when asynchronous images change measured heights? Does either approach interact differently with ion-infinite-scroll when new pages append at the bottom?
A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.