Skip to content

Commit d1e8308

Browse files
committed
feat: 右滑滑动问题
1 parent 64cbfa4 commit d1e8308

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

swipeback/src/main/java/per/goweii/swipeback/SwipeBackLayout.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import android.content.Context;
55
import android.graphics.Canvas;
66
import android.graphics.Color;
7-
import android.graphics.Paint;
87
import android.graphics.Rect;
98
import android.graphics.drawable.Drawable;
109
import android.graphics.drawable.GradientDrawable;
@@ -46,6 +45,7 @@ public class SwipeBackLayout extends FrameLayout {
4645
private float mSwipeBackVelocity = 2000f;
4746

4847
private boolean mCheckedIntercept = false;
48+
private boolean mShouldIntercept = false;
4949
private boolean mSwiping = false;
5050
@SwipeBackDirection
5151
private int mDirection = 0;
@@ -215,6 +215,7 @@ public boolean dispatchTouchEvent(@NonNull MotionEvent ev) {
215215
final int actionMasked = ev.getActionMasked();
216216
if (actionMasked == MotionEvent.ACTION_DOWN) {
217217
mCheckedIntercept = false;
218+
mShouldIntercept = false;
218219
mDirection = 0;
219220
beforeSwipe();
220221
}
@@ -234,6 +235,7 @@ public boolean dispatchTouchEvent(@NonNull MotionEvent ev) {
234235
int directionByTouchedEdge = getDirectionByTouchedEdge();
235236
if (mSwipeBackForceEdge && directionByTouchedEdge != 0) {
236237
mCheckedIntercept = true;
238+
mShouldIntercept = true;
237239
mDirection = directionByTouchedEdge;
238240
} else {
239241
float dx = x - mDownX;
@@ -245,12 +247,14 @@ public boolean dispatchTouchEvent(@NonNull MotionEvent ev) {
245247
if (hasDirection(SwipeBackDirection.RIGHT)) {
246248
if (mScrollDirectionResult != null && !mScrollDirectionResult.hasDirection(ScrollCompat.SCROLL_DIRECTION_LEFT)) {
247249
mDirection = SwipeBackDirection.RIGHT;
250+
mShouldIntercept = true;
248251
}
249252
}
250253
} else {
251254
if (hasDirection(SwipeBackDirection.LEFT)) {
252255
if (mScrollDirectionResult != null && !mScrollDirectionResult.hasDirection(ScrollCompat.SCROLL_DIRECTION_RIGHT)) {
253256
mDirection = SwipeBackDirection.LEFT;
257+
mShouldIntercept = true;
254258
}
255259
}
256260
}
@@ -259,12 +263,14 @@ public boolean dispatchTouchEvent(@NonNull MotionEvent ev) {
259263
if (hasDirection(SwipeBackDirection.BOTTOM)) {
260264
if (mScrollDirectionResult != null && !mScrollDirectionResult.hasDirection(ScrollCompat.SCROLL_DIRECTION_UP)) {
261265
mDirection = SwipeBackDirection.BOTTOM;
266+
mShouldIntercept = true;
262267
}
263268
}
264269
} else {
265270
if (hasDirection(SwipeBackDirection.TOP)) {
266271
if (mScrollDirectionResult != null && !mScrollDirectionResult.hasDirection(ScrollCompat.SCROLL_DIRECTION_DOWN)) {
267272
mDirection = SwipeBackDirection.TOP;
273+
mShouldIntercept = true;
268274
}
269275
}
270276
}
@@ -273,24 +279,22 @@ public boolean dispatchTouchEvent(@NonNull MotionEvent ev) {
273279
}
274280
}
275281
break;
276-
}
277-
final boolean result = super.dispatchTouchEvent(ev);
278-
switch (actionMasked) {
279282
case MotionEvent.ACTION_UP:
280283
case MotionEvent.ACTION_CANCEL:
281284
mCheckedIntercept = false;
285+
mShouldIntercept = false;
282286
mScrollDirectionResult = null;
283287
break;
284288
}
285-
return result;
289+
return super.dispatchTouchEvent(ev);
286290
}
287291

288292
@Override
289293
public boolean onInterceptTouchEvent(MotionEvent ev) {
290294
if (!isSwipeBackEnable()) return false;
291295
if (ev.getActionMasked() == MotionEvent.ACTION_MOVE) {
292296
if (mCheckedIntercept) {
293-
if (mDirection != 0) {
297+
if (mShouldIntercept) {
294298
return mDragHelper.shouldInterceptTouchEvent(ev);
295299
}
296300
}
@@ -305,7 +309,7 @@ public boolean onTouchEvent(MotionEvent ev) {
305309
if (!isSwipeBackEnable()) return false;
306310
if (ev.getActionMasked() == MotionEvent.ACTION_MOVE) {
307311
if (mCheckedIntercept) {
308-
if (mDirection != 0) {
312+
if (mShouldIntercept) {
309313
mDragHelper.processTouchEvent(ev);
310314
return true;
311315
}

0 commit comments

Comments
 (0)