PagedList RecyclerView jumping after pagedList invalidation
Asked Answered
W

1

6

Setup :

We are using PagedListEpoxyController, RxPagedListBuilder, ItemKeyedDataSource with a runtime Mockgenerator which just creates a user with respect to the index of data that is generated, for eg. user1, user100, user500 etc.

Paging configuration is :

val pageSize = 50
val initialLoadSizeHint = 80
val prefetchDistance = 16

Expected behaviour

Whenever we scroll down to the 400th item and come back to the 300th item and invalidate the list by clicking Follow/Unfollow the UI jumps. When the button is clicked the PagedList is invalidated like this:

enter image description here

followers.dataSource.invalidate()

loadInitial() inside ItemKeyedDataSource should be called with the value of params.key so we can get the same page that was previously displayed to be re-displayed. For example if user300 was visible in the screen, that item requestedInitialKey should be in the range of [user221,user280].

Where is the issue?

Paging Library tracks of the last item that was fetched in the pagedList before invalidation but does not provide a way to know which was the last item/range that was visible in the screen just before invalidation.

After invalidating the pagedList, The first callback which gets called after pagedList invalidation is loadInitial(params : LoadInitialParams, callback : LoadInitialCallback) with the params only holds the information about pageSize and placeholder along with requestedInitialKey as last item that was fetched before invalidation which is very misleading. Why, after invalidation a pagedList does request the last item to be fetched in the list as the requestedInitialKey / item in the firstPage rather than the last item that was displayed before invalidation?. Sorry if I have totally misunderstood this thing but couldn't really make sense of it.

Question :

I wish pagedList to start fetching the first page in new PagedList after invalidation from the previous scroll Location rather than the last item in the previous pagedList.

  • But if PagedList is not supposed to work this way then How can I know any of the item/index that was previously visible in the screen before invalidation?

  • If I can't do that currently either, what is the recommended way to achieve this requirement?

This issue can be found here :

To reproduce : Scroll down far enough (like 60th item) and press "Refresh" you will see the jump in the list. Link to github issue

Wert answered 13/6, 2019 at 5:32 Comment(1)
Any updates? Have the same problem on my project.Outermost
W
0

The way we solved this issue is, UI only listens from Room Database as a single source of truth. This issue is not present in that setup. But when we use ItemKeyedDatasource, this issue is persistent even until now.

Wert answered 4/8, 2019 at 5:15 Comment(1)
What about PageKeyedDataSource where the endpoint accepts filter parameters? How do you cache it in this instance?Fascine

© 2022 - 2024 — McMap. All rights reserved.