material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.38k stars 3.07k forks source link

[BottomSheetBehavior] STATE_HALF_EXPANDED + CollapsingToolbarLayout scrollFlag scroll #489

Open kibotu opened 5 years ago

kibotu commented 5 years ago

Description:

When BottomSheetBehavior is in STATE_HALF_EXPANDED and AppBarLayout/CollapsingToolbarLayout has layout_scrollFlags="scroll", the bottom sheet won't scroll up / expand the bottom sheet view when RecyclerView has reached its end when the CollapsingToolbarLayout has expanded its content. (everything works fine if BottomSheetBehavior expanded or peek height)

Also RecyclerView has not correct size at the end. e.g. only 27 / 30 items would be possible to scroll up. looks like the RecyclerView has the wrong size or is not full scrolled up

Looks like the RecyclerView consumes all scrolling events, because touching the expanded CollapsingToolbarLayout view scrolls the BottomSheetBehavior view successfully up.

Expected behavior:

While the BottomSheetBehavior is in STATE_HALF_EXPANDED and the user scrolls up, the RecyclerView should scroll the last item into visible view port and after that the bottom sheet should expand. (which it does unless there is a scroll flag set)

Source code:

 <?xml version="1.0" encoding="utf-8"?>
 <androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/coordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!--  content  -->

    </androidx.constraintlayout.widget.ConstraintLayout>

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:id="@+id/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        app:behavior_fitToContents="false"
        app:behavior_hideable="false"
        app:behavior_peekHeight="78dp"
        app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
        tools:behavior_peekHeight="400dp">

        <com.google.android.material.appbar.AppBarLayout
            android:id="@+id/appBarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/color_background"
            app:expanded="true">

            <com.google.android.material.appbar.CollapsingToolbarLayout
                android:id="@+id/collapsingToolbarLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:minWidth="32dp"
                app:layout_scrollFlags="scroll|exitUntilCollapsed|enterAlways|snap">

                <com.google.android.material.card.MaterialCardView
                    android:id="@+id/tabCard"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="@dimen/keyline_4"
                    app:cardBackgroundColor="@android:color/transparent">

                    <com.google.android.material.tabs.TabLayout
                        android:id="@+id/show_tabs"
                        android:layout_width="match_parent"
                        android:layout_height="32dp"
                        android:background="@drawable/tab_layout_background"
                        app:layout_collapseMode="parallax"
                        app:tabBackground="@drawable/selector_tab_rounded_corner"
                        app:tabIndicatorHeight="0dp"
                        app:tabSelectedTextColor="?colorOnPrimary"
                        app:tabTextAppearance="?textAppearanceBody2"
                        app:tabTextColor="?colorOnSurface">

                        <com.google.android.material.tabs.TabItem
                            android:id="@+id/nextShowTab"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            tools:text="Tab 1" />

                        <com.google.android.material.tabs.TabItem
                            android:id="@+id/distanceTab"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            tools:text="Tab 2" />

                    </com.google.android.material.tabs.TabLayout>

                </com.google.android.material.card.MaterialCardView>

            </com.google.android.material.appbar.CollapsingToolbarLayout>

        </com.google.android.material.appbar.AppBarLayout>

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/filterResultList"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/color_background"
            android:clipToPadding="false"
            android:descendantFocusability="afterDescendants"
            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            tools:background="@color/md_red_200"
            tools:itemCount="10" />

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout> 

Android API version: 29

Material Library version: com.google.android.material:material:1.1.0-alpha08

Device: Samsung Galaxy S9

apuli commented 4 years ago

@kibotu were you able to solve this? I'm having this same problem now, and can't fix it :(

kibotu commented 4 years ago

not exactly, i kind of ended up manually adding bottom padding to the recyclerview :/ which does not work particularly well with different recyclerview items and / or in case they change height by e.g. collapsing / expanding

rekire commented 3 years ago

I ran into a similar situation my solution is to use marginButton to the recycler view