jmartinesp / SpannedGridLayoutManager

Android RecyclerView.LayoutManager that resizes and reorders views based on SpanSize
MIT License
600 stars 105 forks source link

Fix #36 #37

Closed sikeeoh closed 5 years ago

sikeeoh commented 5 years ago

issue #36

2018-11-29 2 36 02

2018-11-29 2 35 59

When adding data to the adapter for the first time after receiving an asynchronous request, the scroll value is set to a different value which was supposed to be zero.

GauthierChan commented 5 years ago

~ Chiming in ~

I think this issue https://github.com/Arasthel/SpannedGridLayoutManager/issues/5 references the same bug 😃 I proposed a solution there that I still use today, I think it's worth the reflexion to find out which solution is the cleanest. What do you guys think @Arasthel @sikeeoh ?

jmartinesp commented 5 years ago

~ Chiming in ~

I think this issue #5 references the same bug 😃 I proposed a solution there that I still use today, I think it's worth the reflexion to find out which solution is the cleanest. What do you guys think @Arasthel @sikeeoh ?

Actually, I just took a look at why your solution and @sikeeoh's both work and it helped me find the real cause. It was an edge case of allItemsInScreen calculation when there are 0 elements, which in turn caused a buggy overscroll calculation which made the RecyclerView scroll and messed up the whole layouting of views until the scroll was corrected... by scrolling the RV manually.

Changing allItemsInScreen to:

val allItemsInScreen = itemCount == 0 || (firstVisiblePosition == 0 && isLastItemInScreen)

Fixes this. I'm still testing if there are any side-effects with view restoration, rotation and scroll. If everything goes right I expect to release a fixed version tomorrow. Thank you both for your help!

sikeeoh commented 5 years ago

I applied feedback @Arasthel