Ahmad-Hamwi / TabSync

An Android lightweight synchronizer between (Views) RecyclerView & TabLayout, (Compose) LazColumn and TabRow.
Apache License 2.0
154 stars 13 forks source link

Fix bug in findLastFullyVisibleItemIndex() #5

Closed erawhctim closed 1 year ago

erawhctim commented 1 year ago

Looks like there's a bug in findLastFullyVisibleItemIndex() (reverse == false, so it doesn't search for the last visible index).

Feel free to just close this PR if I've misunderstood the implementation 🙂

Ahmad-Hamwi commented 1 year ago

No, you're right, there is a bug, thank you for noticing!

You have changed the paramter for findFirstFullyVisibleItemIndex which should have stayed false, and we should pass true for findLastFullyVisibleItemIndex.

Can you fix the other function please? And I will happily accept the merge, and upload a new version for the library.

Also, here's some explanation regarding the implementation: The function will iterate over the items in the lazy list state that are visible (fully or partially). If an item has a start and an end inside of the bounds of the list then it's currently fully visible on screen, otherwise it's partially visible. The order of the items is the same as how they're rendered, so reversing their order and applying the same logic should get us the results for the last fully visible item position in the rendered list. That's why the reverse flag should only be passed to the function if we're searching for the lasy fully visible item position.

erawhctim commented 1 year ago

Good catch, thanks! Updated.

Ahmad-Hamwi commented 1 year ago

Thank you for your PR! I released version 1.0.1 of tabsync-compose to mavenCentral, it will be available soon.