Skip to content
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

Full page mode #4

Open
nicolas-t opened this issue Dec 14, 2021 · 2 comments
Open

Full page mode #4

nicolas-t opened this issue Dec 14, 2021 · 2 comments

Comments

@nicolas-t
Copy link

nicolas-t commented Dec 14, 2021

Hello,

I'm working on a Vue implementation of your library. (I will open source it later)
It's going pretty well in a container, but i'm trying to achieve the same behaviour in the full page, where the body is the viewport and the scroll event listener is attached to window.

I'm calling virtualScrollDriver like this :

      const bounds = document.querySelector("body").getBoundingClientRect();
      const scrollTop = -bounds.top;
      const viewportHeight = window.innerHeight;
      const newState = virtualScrollDriver(
        {
          totalItems: this.items.length,
          minRowHeight: 100,
          viewportHeight: viewportHeight,
          scrollTop: scrollTop,
        },
        this.scrollerState,
        this.getRenderedItemHeight
      );

It works well, until you have DOM elements in the body, before the list.

For example here, I have a <pre> tag before the list, and it disturbs the virtual scroll behaviour.
image
If you remove the <pre> tag (or change it's position to fixed) it fixes the bug.

You can play with the code here (it can take a while to load) :
https://codesandbox.io/s/flamboyant-easley-ix9pe?file=/src/App.vue

How would you implement the full page mode when the list is not the only item the body ?

Also, not related to the full page mode, before any scroll happen, the lastItems are displayed:
image

Thanks for your help.

@vitalif
Copy link
Owner

vitalif commented Dec 17, 2021

Hi

Also, not related to the full page mode, before any scroll happen, the lastItems are displayed:

That's because on the first pass your getRenderedItemHeight returns 0 and driver is not called again when the page is rendered. See componentDidUpdate in VirtualScrollDriver.js - it also calls driver(). The rest of this method relates to scrollToItem() so you don't strictly need it.

How would you implement the full page mode when the list is not the only item the body ?

I think it's similar to the "fixed header" in the sample http://yourcmc.ru/dynamic-virtual-scroll/. You should just subtract fixed header/footer sizes from the total viewport size.

@nicolas-t
Copy link
Author

Hello,

Thanks for your answer 👍

That's because on the first pass your getRenderedItemHeight returns 0 and driver is not called again when the page is rendered. See componentDidUpdate in VirtualScrollDriver.js - it also calls driver(). The rest of this method relates to scrollToItem() so you don't strictly need it.

Perfect :)

I think it's similar to the "fixed header" in the sample http://yourcmc.ru/dynamic-virtual-scroll/. You should just subtract fixed header/footer sizes from the total viewport size.

It's not exactly similar, because the topbar is not fixed, so once it's out of the viewport, we want the list items to fill the whole viewport.
With the substract method there is a blank space were the header used to be before we scrolled it out of the viewport:
image

Best regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants