reddit / IndicatorFastScroll

Android library providing a simple UI control for scrolling through RecyclerViews
MIT License
706 stars 57 forks source link

Multiple span support #36

Closed Dosssik closed 4 years ago

Dosssik commented 4 years ago

Hey guys,

Thanks for the amazing library! I'd like to use it for lists with several spans (GridLayoutManager, span count 2 or 3 etc.). Just implemented it accordingly the example from README but looks like indexing works wrong if there is more than 1 span - e.g. I select letter "W" but when scroll finished items with W at first letter are on the bottom of the screen or even below the visible part of the list.

Here is how it looks like 👇🏽

fastscroll

I'm trying to figure out how can I fix this issue. Is it possible to define a delegate to handle scroll manually or something like this?

Thank you

enricocid commented 4 years ago

You can override how the scrolling is handled and find a method in GridLayoutManager to snap the RecyclerView to a given position.

https://github.com/reddit/IndicatorFastScroll#custom-scroll-handling

Here is what I did for a LinearLayoutManager to solve this issue: linearLayoutManager.scrollToPositionWithOffset(itemPosition, 0)

Also, I think this is an issue with RecyclerView not the lib itself. In my app I've found this issue with a linear/horizontal RecyclerView too when using smoothScrollToPosition method et similia. It happens especially when the given position is not visible.

To fix I'm now using this extension (the code inside the onStop method is not needed).

Dosssik commented 4 years ago

Thanks a lot @enricocid That's exactly what I needed, problem solved 🙂