material-components-android icon indicating copy to clipboard operation
material-components-android copied to clipboard

[CoordinatorLayout] "header" scroll and "content" scroll don't mix well

Open heybradharris opened this issue 3 years ago • 4 comments
trafficstars

https://user-images.githubusercontent.com/31834244/182727490-6796c66d-84bd-4a4c-a667-430722a78a5e.MOV

expected behavior: No flicker when interrupting a scroll

heybradharris avatar Aug 03 '22 23:08 heybradharris

https://user-images.githubusercontent.com/31834244/182727600-1ab2f1f4-78f1-476c-a79c-cc7b69799b41.MOV

heybradharris avatar Aug 03 '22 23:08 heybradharris

Must download video to view I guess.

heybradharris avatar Aug 03 '22 23:08 heybradharris

Can you elaborate what you mean by flickering? I can't really tell from the video...

drchen avatar Aug 08 '22 14:08 drchen

https://drive.google.com/file/d/1XkmWpTfQpDWRGttcE-dfpFlNA7ueyN2G/view?usp=sharing

Here is a slow-mo video. You can see I scroll on the header then the scrollable content below. THIS IS NOT SMOOTH.

heybradharris avatar Aug 11 '22 22:08 heybradharris

Can you provide your layout file of the screen in the video?

drchen avatar Sep 29 '22 21:09 drchen

<com.act4software.android.cecore.ui.view.notification.CEConstraintLayout 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/courseDetailsFragment_root" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".ui.course.details.CourseDetailsFragment">

<com.google.android.material.appbar.MaterialToolbar
    android:id="@+id/courseDetailsFragment_toolbar"
    android:layout_width="0dp"
    android:layout_height="?actionBarSize"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:menu="@menu/course_details_fragment_app_bar"
    app:navigationIcon="@drawable/ic_back" />

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:id="@+id/courseDetailsFragment_coordinatorLayout"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/courseDetailsFragment_toolbar">

    <com.act4software.android.cecore.ui.view.ScrollFixingAppBarLayout
        android:id="@+id/courseDetailsFragment_cEAppBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:gravity="center_horizontal">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:contentScrim="@android:color/transparent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

            <include layout="@layout/course_details_collapsing_toolbar" />
        </com.google.android.material.appbar.CollapsingToolbarLayout>

        <TextView
            android:id="@+id/courseDetailsFragment_textTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginHorizontal="40dp"
            android:layout_marginTop="16dp"
            android:layout_marginBottom="32dp"
            android:ellipsize="end"
            android:gravity="center_horizontal"
            android:letterSpacing="-0.02"
            android:lineHeight="28.8dp"
            android:maxWidth="420dp"
            android:maxLines="3"
            android:text="Breaking the Silence: Reporting is Key"
            android:textFontWeight="600"
            android:textSize="24dp"
            app:layout_scrollFlags="scroll" />

        <com.act4software.android.cecore.ui.view.CEPrimaryButton
            android:id="@+id/courseDetailsFragment_buttonBuy"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="32dp" />

        <com.google.android.material.tabs.TabLayout
            android:theme="@style/ThemeOverlay.CECore.PrimaryColor"
            android:id="@+id/courseDetailsFragment_tabLayout"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_marginHorizontal="@dimen/margin_dynamic"
            android:background="@drawable/course_details_tab_layout_background"
            app:tabGravity="fill"
            app:tabIndicator="@drawable/course_details_tab_layout_indicator"
            app:tabIndicatorAnimationMode="linear"
            app:tabIndicatorColor="@color/grey_background"
            app:tabIndicatorFullWidth="true"
            app:tabIndicatorHeight="100dp"
            app:tabMaxWidth="0dp"
            app:tabMode="fixed"
            app:tabRippleColor="@android:color/white"
            app:tabSelectedTextColor="?colorSecondary"
            app:tabTextAppearance="@style/TextAppearance.CECore.CourseDetails.Tab" />
    </com.act4software.android.cecore.ui.view.ScrollFixingAppBarLayout>

    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/courseDetailsFragment_viewPager2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="8dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

</com.act4software.android.cecore.ui.view.notification.CEConstraintLayout>

heybradharris avatar Sep 29 '22 21:09 heybradharris

Here is the inside the CollapsingToolbarLayout

<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent" android:layout_height="wrap_content" android:paddingVertical="16dp" app:layout_collapseMode="parallax">

<androidx.cardview.widget.CardView
    android:layout_width="260dp"
    android:layout_height="260dp"
    android:backgroundTint="@color/grey_background"
    app:cardCornerRadius="32dp"
    app:cardElevation="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

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

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="128.89dp"
            android:layout_height="155.56dp"
            android:layout_marginTop="24dp"
            android:src="@drawable/course_details_course_icon"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:orientation="horizontal"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/imageView">

            <androidx.cardview.widget.CardView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                app:cardCornerRadius="40dp"
                app:cardElevation="0dp">

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginHorizontal="12dp"
                    android:orientation="horizontal"
                    android:translationX="-3dp">

                    <ImageView
                        android:layout_width="24dp"
                        android:layout_height="24dp"
                        android:src="@drawable/ic_diamond" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="24dp"
                        android:layout_gravity="center_vertical"
                        android:gravity="center"
                        android:text="10"
                        android:textFontWeight="500"
                        android:textSize="14dp" />
                </LinearLayout>
            </androidx.cardview.widget.CardView>

            <androidx.cardview.widget.CardView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:layout_marginLeft="8dp"
                app:cardCornerRadius="40dp"
                app:cardElevation="0dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="24dp"
                    android:layout_gravity="center_vertical"
                    android:layout_marginHorizontal="12dp"
                    android:gravity="center"
                    android:text="25 min"
                    android:textFontWeight="500"
                    android:textSize="14dp" />
            </androidx.cardview.widget.CardView>
        </LinearLayout>

    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>

</androidx.constraintlayout.widget.ConstraintLayout>

heybradharris avatar Sep 29 '22 21:09 heybradharris

It looks like you are using a custom ScrollFixingAppBarLayout?

Will you be able to provide a minimal repo sample? Or it's pretty hard for us to guess the possible reason.

drchen avatar Sep 29 '22 21:09 drchen

class ScrollFixingAppBarLayout @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null ) : AppBarLayout(context, attrs) { override fun getBehavior(): CoordinatorLayout.Behavior<AppBarLayout> { return Behavior().also { it.setDragCallback(object : Behavior.DragCallback() { override fun canDrag(appBarLayout: AppBarLayout) = true }) } } }

heybradharris avatar Sep 29 '22 21:09 heybradharris

This is just a fix for another bug LOL. Sometimes the header would not recognize a scroll. I got this off stackoverflow. I will try to find you the link.

heybradharris avatar Sep 29 '22 21:09 heybradharris

https://lightrun.com/answers/material-components-material-components-android-collapsingtoolbarlayout-collapsingtoolbarlayout-scroll-issue-with-viewpager

heybradharris avatar Sep 29 '22 21:09 heybradharris

This should just work haha

heybradharris avatar Sep 29 '22 21:09 heybradharris

This still happens without the ScrollFixingAppBarLayout

heybradharris avatar Sep 29 '22 21:09 heybradharris

Ah cool. Thanks for the info. Let me check if we can find someone to take a look. Sorry that our team has been pretty overloadded these days so this may take a while.

drchen avatar Sep 29 '22 22:09 drchen