daimajia / AndroidSwipeLayout

The Most Powerful Swipe Layout!
MIT License
12.38k stars 2.67k forks source link

There is a bug when use lay_down mode. #233

Open xzchaoo opened 9 years ago

xzchaoo commented 9 years ago

my layout:

<com.daimajia.swipe.SwipeLayout
    app:clickToClose="true"
    app:drag_edge="right"
    app:show_mode="lay_down"
    >
    <TextView
        android:id="@+id/del"
        android:text="删除"
        />
    <TextView
        android:id="@+id/tv"
        android:text="TEXT"
        />

</com.daimajia.swipe.SwipeLayout>

First, drag TEXT to open the layout. Then click on "删除" and drag it left or right. You will see TEXT is moved out of the legal area(I think), leaving a white space between surface view and bottom view.

And I have a solution: SwipeLayout.mDragHelperCallback.onViewPositionChanged:

} else if (getBottomViews().contains(changedView)) {
    if (mShowMode == ShowMode.PullOut) {
        ...
    } else {
        ...
        if (mCurrentDragEdge == DragEdge.Left) {
            if (newLeft < getPaddingLeft()) newLeft = getPaddingLeft();
            if (newLeft > mDragDistance) newLeft = mDragDistance;//my modification
        } else if (mCurrentDragEdge == DragEdge.Right) {
            if (newLeft > getPaddingLeft()) newLeft = getPaddingLeft();
            if (newLeft < -mDragDistance)newLeft = -mDragDistance;//my modification
        } else ...
        ...
    }
}

the original code:

if (mCurrentDragEdge == DragEdge.Left && newLeft < getPaddingLeft())
    newLeft = getPaddingLeft();
else if (mCurrentDragEdge == DragEdge.Right && newLeft > getPaddingLeft())
    newLeft = getPaddingLeft();
else ...
xzchaoo commented 9 years ago

And pull_out mode has same problem. And I fix this problem by modifying SwipeLayout.mDragHelperCallback.clampViewPositionHorizontal:

            } else if (getCurrentBottomView() == child) {

                switch (mCurrentDragEdge) {
                    case Top:
                    case Bottom:
                        return getPaddingLeft();
                    case Left:
                        if (mShowMode == ShowMode.PullOut) {
                            if (left > getPaddingLeft()) return getPaddingLeft();
                            //my addition
                            if (left < getPaddingLeft() - mDragDistance)
                                left = getPaddingLeft() - mDragDistance;
                        }
                        break;
                    case Right:
                        if (mShowMode == ShowMode.PullOut) {
                            if (left < getMeasuredWidth() - mDragDistance) {
                                return getMeasuredWidth() - mDragDistance;
                            }
                            //my addition
                            if (left > getMeasuredWidth()) {
                                left = getMeasuredWidth();
                            }
                        }
                        break;
                }

It seems that the codes in github are different from codes downloaded by gradle. I clone one from github, leading to another problem: "删除"'s bounds are not correct when using pull_out. After I change the codes to those downloaded by gradle. This problem disappears.