Home > Back-end >  RecyclerView blocks swipe in MotionLayout
RecyclerView blocks swipe in MotionLayout

Time:03-10

I have problem with swipe in my views in front (add folder kind of dialog) of recycler view. When I perform the swipe gesture it's just scrolling in RecyclerView behind it.

However when I tried to set visibility of RecyclerView to GONE, it was working well so I suspect there is something wrong with focus or Recycler it self, although I clear focus when the scenes change.

This is video without RecyclerView

And this is video with the RecyclerView

Methods where I show settings and folder dialog:

private void showSettings(){
        if (!settingBox.hasFocus()){
            settingBox.requestFocus();
        }

        foldersGridRecyclerView.clearFocus();


        root.transitionToState(R.id.settingsShowed);
    }

    private void showAddFolderBox(){
        if (!addFolderBox.hasFocus()){
            addFolderBox.requestFocus();
        }

        foldersGridRecyclerView.clearFocus();

        root.transitionToState(R.id.addFolderBoxShowed);
    }

Here is my grapth file:

<?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">

    <ConstraintSet android:id="@ id/addFolderBoxHidden">
        <Constraint
            android:id="@ id/addFolderBox"
            android:layout_width="match_parent"
            android:layout_height="330dp"
            android:layout_marginBottom="1dp"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:background="@drawable/add_folder_background"
            android:paddingHorizontal="17dp"
            app:layout_constraintBottom_toTopOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHeight_default="percent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"/>

        <Constraint
            android:id="@ id/settingsBox"
            android:layout_width="match_parent"
            android:layout_height="600dp"
            android:layout_marginTop="1dp"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:background="@drawable/settings_bar_background"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="parent"
            android:translationZ="6dp"/>

    </ConstraintSet>

    <ConstraintSet android:id="@ id/addFolderBoxShowed">
        <Constraint
            android:id="@ id/addFolderBox"
            android:layout_width="match_parent"
            android:layout_height="330dp"
            android:layout_marginBottom="-330dp"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:background="@drawable/add_folder_background"
            android:paddingHorizontal="17dp"
            app:layout_constraintBottom_toTopOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHeight_default="percent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"/>

        <Constraint
            android:id="@ id/settingsBox"
            android:layout_width="match_parent"
            android:layout_height="600dp"
            android:layout_marginTop="1dp"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:background="@drawable/settings_bar_background"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="parent"
            android:translationZ="6dp"/>
    </ConstraintSet>

    <ConstraintSet android:id="@ id/settingsHidden">
        <Constraint
            android:id="@ id/addFolderBox"
            android:layout_width="match_parent"
            android:layout_height="330dp"
            android:layout_marginBottom="1dp"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:background="@drawable/add_folder_background"
            android:paddingHorizontal="17dp"
            app:layout_constraintBottom_toTopOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHeight_default="percent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"/>

        <Constraint
            android:id="@ id/settingsBox"
            android:layout_width="match_parent"
            android:layout_height="600dp"
            android:layout_marginTop="1dp"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:background="@drawable/settings_bar_background"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="parent"
            android:translationZ="6dp"/>
    </ConstraintSet>

    <ConstraintSet android:id="@ id/settingsShowed">
        <Constraint
            android:id="@ id/addFolderBox"
            android:layout_width="match_parent"
            android:layout_height="330dp"
            android:layout_marginBottom="1dp"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:background="@drawable/add_folder_background"
            android:paddingHorizontal="17dp"
            app:layout_constraintBottom_toTopOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHeight_default="percent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"/>
        <Constraint
            android:id="@ id/settingsBox"
            android:layout_width="match_parent"
            android:layout_height="600dp"
            android:layout_marginTop="-600dp"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:background="@drawable/settings_bar_background"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="parent"
            android:translationZ="6dp"/>
    </ConstraintSet>

    <Transition
        app:constraintSetEnd="@ id/addFolderBoxHidden"
        app:constraintSetStart="@ id/addFolderBoxShowed" >
        <OnSwipe
            app:touchAnchorId="@id/addFolderBox"
            app:touchRegionId="@id/addFolderBox"
            app:dragDirection="dragUp"
            app:touchAnchorSide="bottom" />

    </Transition>

    <Transition
        app:constraintSetEnd="@ id/settingsHidden"
        app:constraintSetStart="@ id/settingsShowed" >
        <OnSwipe
            app:touchAnchorId="@id/settingsBox"
            app:touchRegionId="@id/settingsBox"
            app:dragDirection="dragDown"
            app:touchAnchorSide="top" />

    </Transition>

    <Transition
        app:constraintSetStart="@ id/addFolderBoxShowed"
        app:constraintSetEnd="@ id/addFolderBoxHidden">

    </Transition>

    <Transition
        app:constraintSetStart="@ id/settingsHidden"
        app:constraintSetEnd="@ id/settingsShowed">

    </Transition>

</MotionScene>

And finally the activity layout:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout 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/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?attr/backgroundColor"
    tools:context=".activities.MainActivity"
    app:layoutDescription="@xml/activity_main_scene">

<androidx.recyclerview.widget.RecyclerView
        android:id="@ id/group_grid_layout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:numColumns="2"
        android:visibility="visible"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@ id/constraintLayout">

    </androidx.recyclerview.widget.RecyclerView>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@ id/addFolderBox"
        android:layout_width="match_parent"
        android:layout_height="330dp"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:layout_marginBottom="1dp"
        android:background="@drawable/add_folder_background"
        android:paddingHorizontal="17dp"
        app:layout_constraintBottom_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHeight_default="percent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"><.../>

<androidx.constraintlayout.widget.ConstraintLayout
        android:id="@ id/settingsBox"
        android:layout_width="match_parent"
        android:layout_height="600dp"
        android:layout_marginTop="1dp"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:background="@drawable/settings_bar_background"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="parent"
        android:translationZ="6dp"></...>

CodePudding user response:

In the onswipe's try adding :

app:nestedScrollFlags="disableScroll"

This will tell the MotionLayout to ignore the RecyclerView (nestedScrollView) inside the motionLayout.

That is probably the behavior you want. You would probably need to have a little of the UI at the top and bottom peaking out. Other wise you will always grab RecyclerView. Others have put invisible views at the top and bottom to grab on to.

CodePudding user response:

It was just the wrong approach to this problem.

So better way to make something like this is to make those panels BottomSheetDialog's and disable the overlay.

  • Related