ericktijerou / koleton

The easiest library to show skeleton screens in an Android app.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug Report] - RecyclerView wrap_content problem

TurKurT656 opened this issue · comments

When I set the recyclerView's height to wrap_content Skeleton does not show up. But On match_parent and fixed height values everything works fine

I've upgraded the lib -v to 0.7.3 but the problem still exist. any idea? Also when I try a fixed height skeleton shows up, but after calling .hideSkeleton() item's does not appear.

I used recycler_view_items of your layout and works well. Can you please provide more information about your recyclerview/adapter configuration?

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recycler_view_items"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

So after a long review, I found that there is two issue related:

  1. If I set height to a fixed size or match_parent and then call .loadSkeleton() the recyclerView shows skeleton. But if before hiding skeleton I update list data with adapter.submitList(data) and then hide skeleton I can't see new List but it hides skeleton and the result is an empty listView. So because I have a ViewModel that has two LiveDatas -> one for loading and one for data list and I'm observing those values, I cannot know which one observes first (I can set a delay to temporary fix the bug but that is a dirty solution).

  2. If I set the height to wrap_content, the .loadSkeleton() function cannot show the skeleton but after adapter.submitList(data) the recyclerView updates with new set of data. I've checked your sample code and didn't realize what causing this issue. So I made a very small application that mimics this issue:
    KoletonTest
    You can clone it and toggle between RecyclerView height to see the issue.

@TurKurT656 Thanks for the sample project. I cloned it and fixed the second issue. Please try out 0.7.4 version.

Regarding the first issue, I couldn't reproduce it, could you edit your sample project to demonstrate the first issue, because it's difficult to figure out where problem is?

Thnaks. the second issue fixed.

I found the problem. I'm using DataBinding library to set data to the RecyclerView:

@BindingAdapter("binding:setData")
fun <T> RecyclerView.setRecyclerViewData(data: List<T>?) {
    data?.let {
         if (adapter is MyAdapter<*>)
            (adapter as MyAdapter<T>).submitList(it)
    }
}

so I think when data is on loading state the library changes RecyclerView to KoletonView and because of that the BindingAdapter function never invokes. I've updated the sample project to demonstrate the issue.

I've created a new issue (#14) related with DataBinding problem.

This issue (#9) has been solved. I'll close it. 👍

Thanks again!