airbnb / epoxy

Epoxy is an Android library for building complex screens in a RecyclerView
https://goo.gl/eIK82p
Apache License 2.0
8.5k stars 733 forks source link

ModelView height was not updated in carousel #751

Closed quanlt closed 5 years ago

quanlt commented 5 years ago

Thank you for the great library 👍 I have a problem, and i hope that you can help me. I have two lists, it will be added to the carousel.

private val flag = false
private val list1 = listOf(Item(1), Item(2), Item(3), Item(4), Item(5), Item(6), Item(7), Item(8))  
private val list2 = listOf(Item(1), Item(3), Item(4), Item(5), Item(6), Item(7), Item(8))
private var finalList = list1
recyclerView.buildModelsWith { controller ->
            val models = mutableListOf<EpoxyModel<*>>()
            finalList.forEach {
                models.add(
                    ItemModelViewModel_()
                        .id(it.id)
                        .shouldShow(flag)
                )
            }
            CarouselModel_()
                .id(1)
                .models(models)
                .addTo(controller)
        }

layout :

<merge xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="144dp"
        android:layout_height="wrap_content"
        android:background="#D0A6F5"
        android:orientation="vertical">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scaleType="centerCrop"
            android:src="@drawable/ic_launcher_background" />

        <TextView
            android:id="@+id/tvTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/tvSubtitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
</merge>

The visiblity of ItemModelView will be decided based on shouldShow flag, and the initial list is list1

@AfterPropsSet
fun bindModel() {
    tvTitle.isVisible = shouldShow
    tvSubtitle.isVisible = shouldShow
}

if we update finalList to list2 (the 2nd item will be removed), the item height will not be updated. it works perfectly with the normal epoxy recyclerview, but it doesn't work with carousel. ezgif-4-d70f425fe90f source code: https://github.com/quanlt/EpoxyCarouselSample

Am I missing something? Thank you

quanlt commented 5 years ago

I solved this problem by changing the layoutResId

val layout = if (flag) R.layout.carsouel_full_size else R.layout.no_animation_carousel
            NoAnimationCarouselModel_()
                .id(1)
                .models(models)
                .layout(layout)
                .addTo(controller)
muhammadFawzy commented 5 years ago

is it solved?