1

I'm trying to use PagingSource, LazyPagingItems and LazyColumn to display a dataset that extends into the past and the future.

I want the initial load of my list to be centered on "today", and allow the user to scroll up to go back in time, down to go forward in time. My paging source does this with a custom key, but the principle is the same as starting on the not-first page.

So for example, if my first page is 5, the first LoadResult.Page I return would look like this:

LoadResult.Page(
    data = list,
    prevKey = 4,
    nextKey = 6
)

If I do this, though, when the first page is loaded the LazyColumn immediately triggers the previous page load. I assume this is because after updating it is initially scrolled to the top, triggering the prev page load. This then continues to happen as more data is loaded and the list jumps to the new top over and over. This happens forever, loading every page in the past until there are no more.

How can I prevent the Column from jumping to the top when a previous page is loaded? Is Paging3 not suited to having a bi-directional set of data?

blork
  • 2,150
  • 6
  • 26
  • 45

1 Answers1

0

The solution was simply to provide keys for the items.

Without giving the items keys, they are identified solely by position, so the scroll state tries to keep the 0th item at the top. So we jump up forever.

I assumed that the items were identified through some other means by Compose, but no, just position.

blork
  • 2,150
  • 6
  • 26
  • 45