SwipeLayout icon indicating copy to clipboard operation
SwipeLayout copied to clipboard

Item not dragging properly left & right enabled

Open omkar-tenkale opened this issue 3 years ago • 2 comments

Strange behavior Item not dragging properly

I've enabled both left and right swipe But when item is swiped left,right swipe becomes too hard (After 4-5 attempts i can swipe right otherwise the draggable view just stays fixed at its position) and when swiped right left swipe becomes too hard

        <com.zerobranch.layout.SwipeLayout
            android:id="@+id/swipeLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:draggedItem="@id/coverHolder"
            app:rightItem="@id/next"
            android:layout_margin="16dp"
            app:leftItem="@id/previous"
            app:swipeDirection="left|right">


                <androidx.appcompat.widget.AppCompatImageButton
                    android:id="@+id/next"
                    android:layout_gravity="end"
                    android:paddingEnd="24dp"
                    android:paddingStart="24dp"
                    android:background="?android:attr/selectableItemBackgroundBorderless"
                    android:scaleType="center"
                    android:focusable="true"
                    app:srcCompat="@drawable/ic_next"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"/>

                <androidx.appcompat.widget.AppCompatImageButton
                    android:id="@+id/previous"
                    android:layout_gravity="start"
                    android:paddingEnd="24dp"
                    android:paddingStart="24dp"
                    android:background="?android:attr/selectableItemBackgroundBorderless"
                    android:scaleType="center"
                    android:focusable="true"
                    app:srcCompat="@drawable/ic_prev"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"/>

            <com.google.android.material.card.MaterialCardView
                android:id="@+id/coverHolder"
                app:cardElevation="0dp"
                android:clickable="true"
                android:focusable="true"
                android:layout_gravity="center"
                app:cardCornerRadius="5dp"
                app:cardBackgroundColor="#33000000"
                android:layout_width="match_parent"
                android:layout_height="match_parent">


                <androidx.appcompat.widget.AppCompatImageView
                    tools:background="#33000000"
                    android:id="@+id/cover"
                    android:scaleType="fitCenter"
                    android:adjustViewBounds="true"
                    app:srcCompat="@drawable/sample_cover"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"/>


            </com.google.android.material.card.MaterialCardView>
        </com.zerobranch.layout.SwipeLayout>

omkar-tenkale avatar Mar 26 '21 23:03 omkar-tenkale

Temperory fix

Set

    isLeftOpen = false;
    isRightOpen = false;

after calling layout.close();

But these variables are private so couldn't extend class and override close method

So just copy pasted whole code to another class

with modified onClose method as follows


    /**
     * Performs manual close
     *
     * @param animated - flag to animate closing
     */
    public void close(boolean animated) {
        if (animated) {
            close();
        } else {
            if (isTogether) {
                if (staticLeftView != null && currentDirection == RIGHT) {
                    staticLeftView.layout(CLOSE_POSITION, staticLeftView.getTop(),
                            staticLeftView.getWidth(), staticLeftView.getBottom());
                } else if (staticRightView != null && currentDirection == LEFT) {
                    staticRightView.layout(horizontalWidth - staticRightView.getWidth(), staticRightView.getTop(),
                            horizontalWidth, staticRightView.getBottom());
                } else if (currentDirection == HORIZONTAL && staticRightView != null && staticLeftView != null) {
                    staticLeftView.layout(CLOSE_POSITION, staticLeftView.getTop(),
                            staticLeftView.getWidth(), staticLeftView.getBottom());
                    staticRightView.layout(horizontalWidth - staticRightView.getWidth(), staticRightView.getTop(),
                            horizontalWidth, staticRightView.getBottom());
                }
            }

            draggedView.layout(CLOSE_POSITION,
                    draggedView.getTop(),
                    draggedView.getWidth(),
                    draggedView.getBottom());

            draggingViewLeft = CLOSE_POSITION;
            updateState();
        }
        isLeftOpen = false;
        isRightOpen = false;
    }

Issue could be reproduced with above layout and by setting listener

swipeLayout.setOnActionsListener(new SwipeLayout.SwipeActionsListener() {
            @Override
            public void onOpen(int direction, boolean isContinuous) {
                swipeLayout.close(true);
            }

            @Override
            public void onClose() {
            }
        });

omkar-tenkale avatar Mar 27 '21 06:03 omkar-tenkale

I have same issue

vishalpatel1327 avatar Apr 01 '22 05:04 vishalpatel1327