Skip to content

Commit 50ae66c

Browse files
committed
fix: don't intercept horizontal swipes in onInterceptTouchEvent
1 parent 926bfae commit 50ae66c

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ dependencyResolutionManagement {
6262

6363
```gradle
6464
dependencies {
65-
implementation 'com.github.Netsnake-TN:ExpressivepullToRefresh:v1.0.0'
65+
implementation 'com.github.Netsnake-TN:ExpressivepullToRefresh:v1.0.1'
6666
}
6767
```
6868

refresh/src/main/java/com/expressive/refresh/ExpressivePullToRefresh.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public class ExpressivePullToRefresh extends ViewGroup implements NestedScrollin
5858
private int mOriginalOffsetTop;
5959

6060
private float mInitialMotionY;
61+
private float mInitialMotionX;
6162
private boolean mIsBeingDragged;
6263
private int mActivePointerId = -1;
6364
private boolean mThresholdReached;
@@ -294,6 +295,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
294295
return false;
295296
}
296297
mInitialMotionY = initialMotionY;
298+
mInitialMotionX = ev.getX(ev.findPointerIndex(mActivePointerId));
297299
break;
298300

299301
case MotionEvent.ACTION_MOVE:
@@ -305,6 +307,17 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
305307
return false;
306308
}
307309
final float yDiff = y - mInitialMotionY;
310+
311+
final int xIndex = ev.findPointerIndex(mActivePointerId);
312+
if (xIndex >= 0) {
313+
final float xDiff = Math.abs(ev.getX(xIndex) - mInitialMotionX);
314+
if (xDiff > Math.abs(yDiff)) {
315+
mIsBeingDragged = false;
316+
mActivePointerId = -1;
317+
return false;
318+
}
319+
}
320+
308321
if (yDiff > mTouchSlop && !mIsBeingDragged) {
309322
mIsBeingDragged = true;
310323
}
@@ -340,6 +353,7 @@ public boolean onTouchEvent(MotionEvent ev) {
340353
case MotionEvent.ACTION_DOWN:
341354
mActivePointerId = ev.getPointerId(0);
342355
mIsBeingDragged = false;
356+
mInitialMotionX = ev.getX(ev.findPointerIndex(mActivePointerId));
343357
break;
344358

345359
case MotionEvent.ACTION_MOVE: {
@@ -350,6 +364,11 @@ public boolean onTouchEvent(MotionEvent ev) {
350364

351365
final float y = ev.getY(pointerIndex);
352366
final float yDiff = y - mInitialMotionY;
367+
368+
final float xDiff = Math.abs(ev.getX(pointerIndex) - mInitialMotionX);
369+
if (!mIsBeingDragged && xDiff > Math.abs(yDiff)) {
370+
return false;
371+
}
353372

354373
if (!mIsBeingDragged && yDiff > mTouchSlop) {
355374
mIsBeingDragged = true;
@@ -719,4 +738,4 @@ private void finishSpinner(float overscroll) {
719738
animateOffsetToStartPosition();
720739
}
721740
}
722-
}
741+
}

0 commit comments

Comments
 (0)