Skip to content

[web] [feat] [window-scroll] adding simple path for initial scroll at window end (in addition to initialScrollAtEnd) #427

@PaulSenon

Description

@PaulSenon

SCOPE:

  • web
  • window-scroll virtualization
  • initial scroll position

WHAT:

Unlike when we are using a scroll-container, when we are using window-scroll, there are two meaning of "end".

  • The current one: the last item position (initialScrollAtEnd)
  • The missing one: the window end (when using window-scroll only)

WHY:

Because when controlling window scroll with LegendList, currently, if we need an "initial scroll at window end" we either have to

  • have the window scroll only contain our virtualized list (nothing bellow it, so last item position === window end) but thats not a realistic constraint
  • hook in the virtualize lifecycle to manually trigger a "scroll to window end" on the right timing, but this is currently quite complicated to do. This is hard to reliably sync a window.scrollTo({top: document.documentElement.scrollHeight, behavior: "instant"}); after height is stable, but before first paint.
    • 🔴 initialScrollAtEnd + useLayoutEffect: is before first paint but document.documentElement.scrollHeight isn't stable yet (often miss)
    • 🔴 initialScrollAtEnd + onLayout (gated once): this kind of work but needs double raf to be consistant (otherwise document.documentElement.scrollHeight not stable yet) so also need to hide the list when not yet stable and scrolled to window end. And also there is some inconsistancy in onLayout trigger (as mentioned in this unrelated issue: [web] - LegendList onLayout never triggered ? (3.0.0-beta.43) #423 )
    • 🟢 initialScrollAtEnd + onLayout (once) + onLoad (fallback) + opacity 0 until ready: the onLoad catches up the few misses of onLayout (despite being really too late, so not a viable full replacement of onLayout if you want to show the content asap), and the opacity 0 hide the unstable state where it's visually at last index position, then scroll to window end position.).

Note

I think we can reasonably assume that this is overly complicated for just an "initial scroll at window end" we should either have a built-in feature, or a simple way to hook on the initial layout with stable height.

HOW:

I don't know if the "scroll to window end" should be

  • a built-in feature (like a initialScrollAtWindowEnd) (I would suggest that if makes sense in current implementation) or
  • a user responsibility to implement over the LegendList lifecycle, but have a simple reliable path/hook for that. Not requiring a full hacky setup.

=> So it's an open question for now. Don't hesitate if anyone think I'm fighting the virtualizer too much or if it exists a better workaround that makes my feature request not needed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions