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

Carousel don't nested scroll #638

Closed ShoMasegi closed 5 years ago

ShoMasegi commented 5 years ago

Hi! I'm using Carousel in Epoxy with AppBarLayout. But AppBarLayout do not scroll when drag from carousel row. I added app:layout_behavior="@string/appbar_scrolling_view_behavior" to EpoxyRecyclerView , but do not work well. please give me advices to fix this issue.

ezgif-5-d9fb8f32e5a2

activity.xml

<?xml version="1.0" encoding="utf-8"?>
<layout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:theme="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar_layout"
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:fitsSystemWindows="true"
                app:contentScrim="@color/colorPrimary"
                app:scrimAnimationDuration="100"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <android.support.v7.widget.AppCompatImageView
                    android:layout_width="match_parent"
                    android:layout_height="300dp"
                    android:src="@drawable/city"
                    android:scaleType="centerCrop"
                    android:fitsSystemWindows="true"/>

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    style="@style/Toolbar"
                    android:background="@android:color/transparent"
                    app:layout_collapseMode="pin"/>

            </android.support.design.widget.CollapsingToolbarLayout>

        </android.support.design.widget.AppBarLayout>

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    </android.support.design.widget.CoordinatorLayout>

</layout>

fragment.xml

<?xml version="1.0" encoding="utf-8"?>
<layout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <FrameLayout
        android:id="@+id/main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".ui.main.MainFragment"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <com.airbnb.epoxy.EpoxyRecyclerView
            android:id="@+id/epoxy_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    </FrameLayout>

</layout>

controller.kt

class MainController internal constructor(): TypedEpoxyController<City>() {

    override fun buildModels(data: City?) {
        data ?: return
        headerView {
            id("header view")
            cityName(data.name)
            description(data.description)
        }
        linkView {
            id("link view")
        }
        homeHeaderView {
            id("home header view")
        }
        carousel {
            id("carousel")
            numViewsToShowOnScreen(1.05f)
            padding(Carousel.Padding.dp(12, 0))
            withModelsFrom(data.popularHomes) {
                HomeItemBindingModel_()
                    .id(it.name)
                    .title(it.name)
                    .username(it.owner)
            }
        }
        .......
    }
}
haohaozaici commented 5 years ago

looks like you need to extend Carousel, and setNestedScrollingEnabled(false).

for example:

@ModelView(saveViewState = true, autoLayout = Size.MATCH_WIDTH_WRAP_HEIGHT)
class HorizontalCarousel(context: Context) : Carousel(context) {

    init {
        isNestedScrollingEnabled = false
    }

    override fun createLayoutManager(): RecyclerView.LayoutManager {
        return LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
    }

    ...

}
ShoMasegi commented 5 years ago

@haohaozaici It works well!! Thanks a lot!!