Skip to content
This repository was archived by the owner on Jun 9, 2023. It is now read-only.

Commit

Permalink
Fix pull to collapse in split screen
Browse files Browse the repository at this point in the history
`MotionEvent.getRawX/Y` methods always return screen coordinates meaning that they are calculated from the top left corner of the device screen. This works incorrectly for when the application is located in the bottom/right split space of the device. The reason for that is the difference in code which checks whether the touched point lies inside of a view (`me.saked.dank.utils.touchLiesOn`). It deals with coordinates that are calculated from top left corner of the **application** area and not the **screen** area.

The fix is to use `MotionEvent.getX/Y` which return local coordinates that later can be correctly located in view rectangles.
  • Loading branch information
Tunous committed Dec 27, 2018
1 parent 7d54df6 commit 3f1500e
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public void setCollapseDistanceThreshold(int threshold) {
public boolean onTouch(View v, MotionEvent event) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
downX = event.getRawX();
downY = event.getRawY();
downX = event.getX();
downY = event.getY();
lastMoveY = downY;

eligibleForCollapse = false;
Expand All @@ -87,9 +87,9 @@ public boolean onTouch(View v, MotionEvent event) {
return false;
}

float deltaY = event.getRawY() - lastMoveY;
float totalSwipeDistanceX = event.getRawX() - downX;
float totalSwipeDistanceY = event.getRawY() - downY;
float deltaY = event.getY() - lastMoveY;
float totalSwipeDistanceX = event.getX() - downX;
float totalSwipeDistanceY = event.getY() - downY;
float totalSwipeDistanceXAbs = Math.abs(totalSwipeDistanceX);
float totalSwipeDistanceYAbs = Math.abs(totalSwipeDistanceY);

Expand Down Expand Up @@ -156,15 +156,15 @@ public boolean onTouch(View v, MotionEvent event) {
expandablePage.setTranslationY(translationY);
dispatchPulledCallback(resistedDeltaY, translationY, upwardSwipe, deltaUpwardSwipe);

lastMoveY = event.getRawY();
lastMoveY = event.getY();
return true;
}

case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
// Collapse or restore the page when the finger is lifted, depending on
// the pull distance
float totalSwipeDistanceY = event.getRawY() - downY;
float totalSwipeDistanceY = event.getY() - downY;
if (Math.abs(totalSwipeDistanceY) >= touchSlop) {
dispatchReleaseCallback();
}
Expand Down

1 comment on commit 3f1500e

@saket
Copy link

@saket saket commented on 3f1500e Dec 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very useful. I did not know this. I'll add this fix to InboxRecyclerView.

Please sign in to comment.