The same index for two last items #20
Comments
This is a tricky one. Snapper has no control over the layout of the content, but the items here result in the last item not 'covering' the snap offset given. I'll have a think how we can tweak the |
As a quick workaround, instead of
We probably don't want to ship this in Snapper as it breaks some behaviors. |
Hi, I've tried proposed workaround and it's working in portrait mode, however in landscape, index is always greater than 0 and less than last item index. What I am trying to achieve is horizontal scrolling list with cards. Focused card (selected by scroll and snapping behavior) changed it's color and second part of the screen is filled with focused card description. Do you maybe have another ideas how to get proper index? Maybe I should adjust horizontal content paddings to make it much larger than current 16.dp in landscape? |
As I said earlier, I can't see a perfect solution here. In the example below (which is scrolled all the way to the end), what item is the 'current' item? It could be 18 or 19, but there's no way to determine that just from looking at the layout. We could look at the velocity (aka target index), but then it's looks pretty much random to the user which item would be selected. Maybe that is better than the current situation though. Increasing the content padding would work, but that also changes how the items are laid out at the start/end. You've basically re-implemented Accompanist Pager too. |
Thank you for time that you spent with investigating my issue and for answers. |
Hello @chrisbanes, Thanks for providing such a library it saves so much time. The same issue occurred to me while using LazyRow in Portrait mode (last two elements show the same index) and I solved it by increasing the contentPadding of the LazyRow, so it would be great if you can add this to the documentation along with how to obtain the current index in the first place as it is not in the documentation too. 🙏🏻 |
Hi, getting the current item is documented here: https://chrisbanes.github.io/snapper/usage/#finding-the-current-item |
Describe the bug
Hi,
Thanks for library. It is great!
I've got issues when trying to get current item.
LayoutInfo
's return the samecurrentItem.index
for two latest items.For example, when I got 4 items, after scroll one by one (horizontally)
layoutInfo.currentItem?.index
should returns 0, 1, 2, 3 index values, however it returns 0, 1, 2, 2 values.Here is simplified implementation to reproduce issue:
Environment:
The text was updated successfully, but these errors were encountered: