Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item not dragging properly left & right enabled #5

Open
omkar-tenkale opened this issue Mar 26, 2021 · 2 comments
Open

Item not dragging properly left & right enabled #5

omkar-tenkale opened this issue Mar 26, 2021 · 2 comments

Comments

@omkar-tenkale
Copy link

omkar-tenkale commented Mar 26, 2021

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 omkar-tenkale changed the title setOnActionsListener is not called Item not dragging properly left & right enabled Mar 27, 2021
@omkar-tenkale
Copy link
Author

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() {
            }
        });

@vishalpatel1327
Copy link

I have same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants