Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Motion layout prevents update on recyclerview

I have started using motion layout for some top bar scrolling, and looks like there is an issue that prevents recycler view from showing updated data. Currently I am using 2.0.0-alpha3 of ConstraintLayout. In the view I have toolbar and 2 tabs that act as filter, lets say filterX and filterY those pass some rx stuff that basically just filters list of items based on the type this is not important because data is filtered properly, thread is correct, data is passed to adapter every time, but when I do scroll my motion layout to top or bottom, from time to time the changes are not reflected in recycler view, they reload after I scroll it a little bit or even touch, its not happening in case of standard ConstraitLayout. Have anyone experienced this and know any solution?

Edit: Layout with motion layout:

<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layoutDescription="@xml/scene_month">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:navigationIcon="@drawable/ic_back"/>

    <TextView
        android:id="@+id/title"
        style="@style/ActivityTitle"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/toolbar" />

    <com.example.FilterView
        android:id='@+id/filter_view'
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/title"/>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:clipToPadding="false"
        android:paddingBottom="16dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/filter_view" />

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

And motion scene

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

    <Transition
        app:constraintSetEnd="@id/end"
        app:constraintSetStart="@id/start">
        <OnSwipe
            app:dragDirection="dragUp"
            app:touchAnchorId="@id/recycler"
            app:touchAnchorSide="top" />
    </Transition>

    <ConstraintSet android:id="@+id/start">
        <Constraint android:id="@id/title"
            android:text="@string/title"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:gravity="center_vertical"
            android:textSize="28sp"
            android:textColor="@color/dark_gray"
            android:fontFamily="@font/rubik_medium"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/toolbar">
            <CustomAttribute
                app:attributeName="textSize"
                app:customFloatValue="28"/>
        </Constraint>
    </ConstraintSet>

    <ConstraintSet android:id="@+id/end">
        <Constraint android:id="@id/title"
            android:text="@string/title"
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"
            android:gravity="center_vertical"
            android:minHeight="?actionBarSize"
            android:textSize="28sp"
            android:textColor="@color/dark_gray"
            android:fontFamily="@font/rubik_regular"
            android:layout_marginStart="72dp"
            android:layout_marginEnd="16dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">
            <CustomAttribute
                app:attributeName="textSize"
                app:customFloatValue="20"/>
        </Constraint>
    </ConstraintSet>

</MotionScene>
like image 912
user2141889 Avatar asked Mar 12 '19 08:03

user2141889


2 Answers

By following the possible solution as discussed here: https://issuetracker.google.com/issues/130386093

adding the tag motion:layoutDuringTransition="honorRequest" to the Transition fixed the issue

Example:

<Transition
    android:id="@+id/myTransition"
    motion:constraintSetEnd="@+id/end"
    motion:constraintSetStart="@+id/start"
    motion:layoutDuringTransition="honorRequest"
    motion:motionInterpolator="linear">
    <OnSwipe
        motion:dragDirection="dragUp"
        motion:onTouchUp="stop"
        motion:touchAnchorId="@+id/swipeRefreshLayout"
        motion:touchAnchorSide="top" />

besides that, can also try to update to newer version, in my case, I'm currently using

implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta08'
implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha05'

Note: layoutDuringTransition tag only available with beta04 version of constraint layout and above

like image 168
Wai Choong Wong Avatar answered Sep 28 '22 04:09

Wai Choong Wong


RecyclerView.scrollBy(0, 0) as temporary workaround.

Link to these Google Issue Tracker

  • https://issuetracker.google.com/issues/130386093
  • https://issuetracker.google.com/issues/130862165
like image 23
Samnang CHEA Avatar answered Sep 28 '22 02:09

Samnang CHEA