Status Update
Comments
du...@google.com <du...@google.com> #2
To be clear, when you say jump pages, do you mean recyclerview is scrolling down, or is viewpager scrolling across multiple fragments?
A repro / sample project demonstrating the issue would definitely be helpful here.
du...@google.com <du...@google.com> #3
You also mentioned alph09 in the title, but alpha07 in the comment - could you specify which version of viewpager and paging you are using?
du...@google.com <du...@google.com> #4
Ah sorry I see that you have used both here, still could you specify which version of viewpager you are using as well?
vm...@letsgetchecked.com <vm...@letsgetchecked.com> #5
View Pager 2 : - implementation "androidx.viewpager2:viewpager2:1.0.0"
Paging 3 : - implementation "androidx.paging:paging-runtime-ktx:3.0.0-alpha09"
Example
Attached Video Explanation
When i click slowly on previous button it swipe single page, but if i click quickly multiple times on previous button it start scrolling more than we click and it's not stopping until we click on viewpager.
vm...@letsgetchecked.com <vm...@letsgetchecked.com> #6
du...@google.com <du...@google.com> #7
Haven't forgotten this - this is on my queue, just that my queue is quite long :)
vm...@letsgetchecked.com <vm...@letsgetchecked.com> #8
du...@google.com <du...@google.com> #9
This looks like a weird race scenario where the smooth scroll behavior in RV / ViewPager is attempting to do an animated scroll to an absolute position, but Paging is able to PREPEND items to the front of the list faster than the animation can scroll there.
I noticed that you're attempting to enablePlaceholders to mitigate this by telling Paging the total item count, but you never pass a value for placeholdersBefore / After in the initial result on REFRESH. This will prevent Paging understanding how many placeholder items there are in the list. This is probably something Paging should check for, but the proper solution to this ticket should probably be some kind of relative scrolling behavior on RecyclerView or ViewPager, however I expect boundary cases to be quite annoying to deal with there.
du...@google.com <du...@google.com> #10
I'm closing this out since it's not a Paging issue, but I'm happy to continue the thread here to help you get a working solution.
The first thing to try would be to return some positive value for placeholdersBefore
and placeholdersAfter
in PagingSource.load()
when LoadParams
is of type LoadParams.Refresh
. From here you'll need to know what the total number of items you want to show in your ViewPager is and add that boundary check to your next / previous buttons.
vm...@letsgetchecked.com <vm...@letsgetchecked.com> #11
Can you please explain how to access placeholdersBefore in pagingsource.load() method. Where i find the proper documentation of this method...
Thanks
vm...@letsgetchecked.com <vm...@letsgetchecked.com> #12
val adapter = viewpageradapter()
adapter.snapshot(). placeholdersBefore
But this is not assigned because of val.
So can you please guide me, what i am doing wrong
Thanks
du...@google.com <du...@google.com> #13
Placeholders are a count of the number of not-yet-loaded items in the dataset, which is returned by PagingSource.load()
in LoadResult.Page(...)
vm...@letsgetchecked.com <vm...@letsgetchecked.com> #14
du...@google.com <du...@google.com> #15
You just need to set
vm...@letsgetchecked.com <vm...@letsgetchecked.com> #16
LoadResult.Page(
data = data,
prevKey = if (data.isEmpty()) null else position - 1,
nextKey = if (data.isEmpty()) null else position + 1,
itemsBefore = position
)
I passed position in itemsbefore
I get the error
java.lang.IllegalArgumentException: itemsBefore cannot be negative
So what i am doing actually wrong?
and what value need to pass in itemsBefore and itemsAfter?
du...@google.com <du...@google.com> #17
You want to pass in the number of items in the full dataset that appear before the first item in data
to itemsBefore
and number of items that appear after the last item in data
to itemsAfter
So if you had these items in your db: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
A sample LoadResult.Page
with itemsBefore
and itemsAfter
set would be:
LoadResult.Page(
data = listOf(4, 5),
prevKey = 3,
nextKey = 6,
itemsBefore = 4,
itemsAfter = 4
)
It doesn't make sense to pass a negative number to itemsBefore
because it implies you've loaded data that shouldn't exist.
vm...@letsgetchecked.com <vm...@letsgetchecked.com> #18
whenever i set itemsbefore or itemsafter it show me null value
vm...@letsgetchecked.com <vm...@letsgetchecked.com> #19
Also i updated the logic inside here as well as library to stable version.
Description
Version used: androidx.paging:paging-runtime-ktx:3.0.0-alpha07
Hi, I used viewpager 2 with paging 3 with alpha 07. I added a functionality to swipe single page left or right in viewpager. So when i press button quickly, pages are swiping too many. But if i press button slowly it working fine to swipe single pages . Today I updated the alpha 09, then when i swipe slowly it will jump too many pages. so is it a bug from my side?
rightButton = {
viewpager.setCurrentItem(viewpager.currentItem.plus(1), true)
}
leftButton = {
viewpager.setCurrentItem(viewpager.currentItem.minus(1), true)
}
I used PagingDataAdapter with Recyclerview view holder in adapter.
Do you know what is the caused of this.
Thanks in advance