androidx / constraintlayout

ConstraintLayout is an Android layout component which allows you to position and size widgets in a flexible way
Apache License 2.0
1.08k stars 174 forks source link

Different behaviour when I scroll RecyclerView inside MotionLayout #132

Open alirezaeiii opened 3 years ago

alirezaeiii commented 3 years ago

I am using a RecyclerView inside a ViewPager which is inside a MotionLayout ( fragment_detail ):

<?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"
    xmlns:tools="http://schemas.android.com/tools">

    <data>

        <variable
            name="tmdbItem"
            type="com.sample.android.tmdb.domain.TmdbItem" />

        <variable
            name="vm"
            type="com.sample.android.tmdb.ui.detail.DetailViewModel" />
    </data>

    <androidx.constraintlayout.motion.widget.MotionLayout
        android:id="@+id/details_motion"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layoutDescription="@xml/scene_show_details">

        <ImageView
            android:id="@+id/details_backdrop"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:scaleType="centerCrop"
            app:imageUrl="@{@string/base_backdrop_path(tmdbItem.backdropPath)}"
            tools:ignore="ContentDescription" />

        <View
            android:id="@+id/details_backdrop_scrim"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toBottomOf="@id/details_backdrop"
            app:layout_constraintEnd_toEndOf="@id/details_backdrop"
            app:layout_constraintStart_toStartOf="@id/details_backdrop"
            app:layout_constraintTop_toTopOf="@id/details_backdrop" />

        <androidx.appcompat.widget.AppCompatImageView
            android:id="@+id/details_poster"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:background="@drawable/placeholder"
            android:scaleType="centerCrop"
            android:transformPivotX="0px"
            android:transformPivotY="0px"
            android:transitionName="@string/view_name_header_image"
            app:imageUrl="@{@string/base_poster_path(tmdbItem.posterPath)}" />

        <View
            android:id="@+id/details_gap_filler"
            android:layout_width="match_parent"
            android:layout_height="2px"
            android:background="@color/window_background"
            app:layout_constraintBottom_toTopOf="@id/details_rv"
            tools:ignore="PxUsage" />

        <com.sample.android.tmdb.widget.TopLeftCutoutBackgroundView
            android:id="@+id/details_appbar_background"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:backgroundColor="@color/window_background"
            app:topLeftCutSize="@dimen/details_corner_cutout" />

        <androidx.appcompat.widget.AppCompatTextView
            android:id="@+id/details_title"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:ellipsize="end"
            android:text="@{tmdbItem.name}"
            android:textAppearance="@style/TextAppearance.AppCompat.Title"
            android:transitionName="@string/view_name_header_title" />

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/details_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="?attr/actionBarSize"
            app:theme="@style/Toolbar" />

        <androidx.core.widget.NestedScrollView
            android:id="@+id/details_rv"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:background="@color/window_background"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/details_appbar_background">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <TextView
                    style="@style/TmdbMargin.Small"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/padding_normal"
                    android:text="@{@string/release_date(tmdbItem.releaseDate)}"
                    app:toVisibility="@{!tmdbItem.releaseDate.empty &amp; tmdbItem.releaseDate!=null}" />

                <TextView
                    style="@style/TmdbMargin.Small"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@{@string/rating(tmdbItem.voteAverage)}"
                    app:toVisibility="@{tmdbItem.voteAverage!=0.0}" />

                <TextView
                    android:id="@+id/summary_label"
                    style="@style/TmdbMargin.Title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/summary" />

                <TextView
                    android:id="@+id/summary"
                    style="@style/TmdbMargin.Body"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@{tmdbItem.overview}" />

                <include
                    layout="@layout/trailers"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/padding_normal"
                    android:layout_marginTop="@dimen/padding_large"
                    app:vm="@{vm}"
                    tools:ignore="RtlHardcoded" />

                <com.google.android.material.tabs.TabLayout
                    android:id="@+id/tab_layout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:tabSelectedTextColor="@color/colorAccent"
                    app:tabTextColor="@android:color/white" />

                <androidx.viewpager2.widget.ViewPager2
                    android:id="@+id/pager"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </androidx.core.widget.NestedScrollView>

        <View
            android:id="@+id/details_status_bar_anchor"
            android:layout_width="match_parent"
            android:layout_height="24dp"
            android:background="@color/status_bar_scrim_translucent_dark" />

    </androidx.constraintlayout.motion.widget.MotionLayout>

</layout>

And here is RecyclerView which I use in ViewPager2 ( fragment_credit ) :

<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/credit_list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="12dp"
    app:layoutManager="GridLayoutManager"
    app:spanCount="@integer/no_of_columns" />

Sometimes when I scroll in MotionLayout, it scroll in whole page.

But sometimes it scrolls just in RecyclerView under ViewPager and not whole page.

You can find the code at : https://github.com/Ali-Rezaei/TMDb-Paging

jafu888 commented 3 years ago

When you file a bug please provide a description of what was the desired and/or expected behavior. In the case of animations a video would be helpful for to understand exactly what you are seeing.

alirezaeiii commented 3 years ago

My expected behaviour : when I scroll in Layout, it get scrolled in the whole page. Not just under recyclerView in the ViewPager. In the recorded video, first you see unexpected behaviour for a TVShow and then you see expected behaviour for a Movie in my app. When there is one row in the recyclerView, it most probably jumps to end of screen on its own and then unexpected behaviour happens. You can find the recorded video at : https://drive.google.com/file/d/1GJgieu-i6tkFUwldfkazs0ynAk5ssif8/view?usp=sharing