Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Virtual Scroll For angular 4 Variable/Dynamic height images

I am implementing a feed screen like twitter that contains images and text. I am using angular 4. Currently I am using Virtual Scroll to improve performance when user scrolled deep like 100 items. My problem is in my list all items have variable size and this library does not completely support dynamic height. Like need some minimum fixed height. That cause flickering in mobile devices and some browsers. I want to implement React Js Virtual scroll with Angular if its possible. Can any one suggest me any solution so my feed list become smooth.

like image 562
Rakesh Avatar asked Mar 26 '18 12:03

Rakesh


2 Answers

As ngx-ui-scroll is supporting all required functionality like variable height content. I suggest to all use this if you really want to overcome this problem.

like image 86
Rakesh Avatar answered Nov 15 '22 05:11

Rakesh


If you don't want to use third-party libraries and go with Google Material, do this (for Angular 7.2):

import { ScrollingModule } from '@angular/cdk/scrolling';
import { ScrollingModule as ExperimentalScrollingModule } from '@angular/cdk-experimental/scrolling';

and put both in the module's imports. Set on <cdk-virtual-scroll-viewport> a height by CSS (might be calc(100vh - 50px) for example, if you want to exclude a header of 50 px and fill the screen) and itemSize="10" (or any other small number, it just works).

And on the iterated item set [style.height]="'auto'".

Keep in mind some features will not work with this, like scrolling to an item or infinite scroll (because the number of visible items is calculated by itemSize and you don't know it precisely, unless you start measuring every item and calculate the mean which is way too hacky for me personally)

Source: https://github.com/angular/material2/issues/10113

like image 3
Phil Avatar answered Nov 15 '22 03:11

Phil