ngx-virtual-scroller icon indicating copy to clipboard operation
ngx-virtual-scroller copied to clipboard

Support automatic sizing of the virtual-scroller element

Open lincolnthree opened this issue 4 years ago • 17 comments

First, thanks for this awesome scrolling library. It's still the best out there and provides solutions for almost every scenario. Hopefully this adds another useful solution. We are currently using a forked build with this patch in production.

For consistent positioning and sizing of parent elements, and elements below scroll-container:

This pull request allows the height or width of the virtual-scroller element to be set automatically to (roughly) the exact required pixels to display all items, accounting for wrapping in both horizontal and vertical directions. This does NOT change the number of virtual items that are rendered on screen.

It simply allows the ngx-virtual-scroller to be used in parent containers with fixed elements and sibling elements before and after the virtual scroller in the dom. Without this patch, fixed elements will eventually scroll off the screen as the scroll-container exceeds the height of the virtual scroller element (even when set to 100% height or width.)

This patch also removes the need to manually set height or width of the virtual-scroller element when this setting is enabled for the common case.

I'm sure it is not a perfect solution, but it seems like a decent compromise for those people dealing with situations like this.

CAVEAT: This feature requires the child heights to be of equal size.

NOTE: I disabled this feature by default to maintain backwards compatibility, but I do believe it is reasonable to default this to 'enabled' in reality. I think it is more intuitive than manually setting the height or width of the scroll container, in general, and provides a fairly safe function. It can always be disabled and height/width set manually if users wish to override the default.

lincolnthree avatar May 29 '20 16:05 lincolnthree

@whyboris Do you have thoughts about this pull request? I'd love to hear them. This is currently running in production and working very well on a high-use site.

lincolnthree avatar Aug 03 '20 15:08 lincolnthree

I'm honored to be a contributor to this repository, but I would want someone like @speige to review and merge.

As far as I can tell by looking at the code it doesn't interfere with anything unless calculateDimensionsAutomatically is set, and if it's set, it will do what you describe 👍

whyboris avatar Aug 03 '20 15:08 whyboris

Awesome! Thanks. I was curious as I saw your reaction but wasn't sure what it meant :) Agreed. Would love a review.

lincolnthree avatar Aug 03 '20 15:08 lincolnthree

Any news about this feature? :)

SvenBudak avatar Nov 25 '20 15:11 SvenBudak

I wish I knew. We cloned the repo into our local codebase because it doesn't seem like this library is actively maintained, currently. We're actively looking for other solutions, but so far, this is still the least buggy.

lincolnthree avatar Nov 25 '20 16:11 lincolnthree

@lincolnthree is your solution currently working correctly ? we have massive problems with it in our messenger: https://mark6-demo.web.app/messenger

you will finde bugs like this: http://prntscr.com/vpz61q You need to scroll up to see it. mostly you will see it on mobile viewport.

SvenBudak avatar Nov 25 '20 16:11 SvenBudak

@SvenBudak Yes it's working in production, currently for both single-column and multi-column layouts.

lincolnthree avatar Nov 25 '20 16:11 lincolnthree

I think our problem is the unknown dynamic height of the items. If this is also working. Can you send me please your local version? I would be happy if I can try it in our messenger.

SvenBudak avatar Nov 25 '20 16:11 SvenBudak

@SvenBudak I'd just clone & checkout the repository from my branch and copy it into your app. That would be the same thing as me sending you the local version.

lincolnthree avatar Nov 25 '20 16:11 lincolnthree

It solves the exact problem you're having. It's the reason we made the change... so I think it will be worth your time.

lincolnthree avatar Nov 25 '20 16:11 lincolnthree

Awesome! Where can I find the full file? I am sorry if you linked it already.. I looked already before my first post. But I am a bit confused which one is complete and final.

SvenBudak avatar Nov 25 '20 16:11 SvenBudak

@SvenBudak This branch: https://github.com/lincolnthree/ngx-virtual-scroller/tree/automatic-element-sizing

lincolnthree avatar Nov 25 '20 17:11 lincolnthree

@lincolnthree Thank you! I have sent the branch to my colleague. he will try it out.

maybe we should create a fork and actively develop it further? it's a pity, there seem to be a lot of people who are interested in further development.

SvenBudak avatar Nov 25 '20 21:11 SvenBudak

@speige -- any thoughts on this?

ps - if you were to merge it, do we still need @rintoj to create a new release, or it's something you're able to do as well?

whyboris avatar Nov 25 '20 21:11 whyboris

In worst case people can copy the .ts file manually to the project. better then nothing. There is no working alternative currently.

SvenBudak avatar Nov 25 '20 22:11 SvenBudak

Sorry to do this, but... Bump.

lincolnthree avatar Jan 05 '21 16:01 lincolnthree

Sorry to do this, but... Bump. V2

nosTa1337 avatar Mar 02 '22 13:03 nosTa1337