Skip to content

Commit

Permalink
add more detailed explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
u7759982 committed Oct 23, 2024
1 parent a8c1708 commit 626367b
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,24 @@ public boolean onInterceptTouchEvent(@NonNull final CoordinatorLayout parent,
}
}
}
// Implement the distance threshold logic
// Implement the distance threshold logic, when the gesture move distance
// is shorter than the threshold, just do not intercept the touch event.
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_DOWN://initialize the tracked total distance
startY = event.getY();
totalDrag = 0f;
break;
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_MOVE://accumulate the total distance
final float currentY = event.getY();
totalDrag += Math.abs(currentY - startY);
startY = currentY;
if (totalDrag < dragThreshold) {
return false; // Do not intercept touch events yet
return false; // Do not intercept touch events yet if shorter than threshold
} else {
return super.onInterceptTouchEvent(parent, child, event);
}
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_CANCEL://reset the drag distance and start point
totalDrag = 0f;
startY = 0f;
break;
Expand Down

0 comments on commit 626367b

Please sign in to comment.