Commit 16bf4b8a authored by Matt Jones's avatar Matt Jones Committed by Commit Bot

Stop the bottom sheet from intercepting touch events on its shadow

This patch has the bottom sheet ignore touch events on its shadow. If
the down event was inside the usable part of the view, the gesture is
continued.

Bug: b/157034370, 1086670
Change-Id: I44d074adaa19d2513720e167b20b5e97c2a1e60b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2216377
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773298}
parent 481de14f
...@@ -221,6 +221,10 @@ class BottomSheet extends FrameLayout ...@@ -221,6 +221,10 @@ class BottomSheet extends FrameLayout
@Override @Override
public boolean onInterceptTouchEvent(MotionEvent e) { public boolean onInterceptTouchEvent(MotionEvent e) {
if (!isTouchEventInUsableArea(e) && e.getActionMasked() == MotionEvent.ACTION_DOWN) {
return false;
}
// If touch is disabled, act like a black hole and consume touch events without doing // If touch is disabled, act like a black hole and consume touch events without doing
// anything with them. // anything with them.
if (!mIsTouchEnabled) return true; if (!mIsTouchEnabled) return true;
...@@ -232,6 +236,10 @@ class BottomSheet extends FrameLayout ...@@ -232,6 +236,10 @@ class BottomSheet extends FrameLayout
@Override @Override
public boolean onTouchEvent(MotionEvent e) { public boolean onTouchEvent(MotionEvent e) {
if (!isTouchEventInUsableArea(e) && e.getActionMasked() == MotionEvent.ACTION_DOWN) {
return false;
}
// If touch is disabled, act like a black hole and consume touch events without doing // If touch is disabled, act like a black hole and consume touch events without doing
// anything with them. // anything with them.
if (!mIsTouchEnabled) return true; if (!mIsTouchEnabled) return true;
...@@ -393,6 +401,16 @@ class BottomSheet extends FrameLayout ...@@ -393,6 +401,16 @@ class BottomSheet extends FrameLayout
return (swipeToDismissEnabled() ? getHiddenRatio() : getPeekRatio()) * mContainerHeight; return (swipeToDismissEnabled() ? getHiddenRatio() : getPeekRatio()) * mContainerHeight;
} }
/**
* Test whether a motion event is in the area of the sheet considered to be usable (i.e. not
* on the shadow shown above the sheet or some other decorative part of the view).
* @param e The motion event relative to the bottom sheet view.
* @return Whether the event is considered to be in the usable area of the sheet.
*/
public boolean isTouchEventInUsableArea(MotionEvent event) {
return event.getY() > getToolbarShadowHeight();
}
@Override @Override
public boolean isTouchEventInToolbar(MotionEvent event) { public boolean isTouchEventInToolbar(MotionEvent event) {
mToolbarHolder.getLocationInWindow(mCachedLocation); mToolbarHolder.getLocationInWindow(mCachedLocation);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment