Skip to content

Commit af7f254

Browse files
Material Design Teamleticiarossi
authored andcommitted
[Bottom Sheet] Prevent ACTION_DOWN events on the BottomSheetHandleDragView from setting touchingScrollChild to true.
Previously, a BottomSheetHandleDragView overlapping the nestedScrollingChildRef would not always be able to resize/drag the bottom sheet. PiperOrigin-RevId: 752730372
1 parent e97782e commit af7f254

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ void onLayout(@NonNull View bottomSheet) {}
329329

330330
@Nullable WeakReference<V> viewRef;
331331
@Nullable WeakReference<View> accessibilityDelegateViewRef;
332+
@Nullable WeakReference<View> dragHandleViewRef;
332333

333334
@Nullable WeakReference<View> nestedScrollingChildRef;
334335

@@ -649,10 +650,11 @@ public boolean onInterceptTouchEvent(
649650
// Only intercept nested scrolling events here if the view not being moved by the
650651
// ViewDragHelper.
651652
if (state != STATE_SETTLING) {
652-
View scroll = nestedScrollingChildRef != null ? nestedScrollingChildRef.get() : null;
653-
if (scroll != null && parent.isPointInChildBounds(scroll, initialX, initialY)) {
653+
if (isTouchingScrollingChild(parent, initialX, initialY)) {
654654
activePointerId = event.getPointerId(event.getActionIndex());
655-
touchingScrollingChild = true;
655+
if (!isTouchingDragHandle(parent, initialX, initialY)) {
656+
touchingScrollingChild = true;
657+
}
656658
}
657659
}
658660
ignoreEvents =
@@ -1532,6 +1534,20 @@ private float calculateCornerInterpolation(
15321534
return 0;
15331535
}
15341536

1537+
private boolean isTouchingScrollingChild(
1538+
@NonNull CoordinatorLayout parent, int xCoordinate, int yCoordinate) {
1539+
View scrollingChild = nestedScrollingChildRef != null ? nestedScrollingChildRef.get() : null;
1540+
return scrollingChild != null
1541+
&& parent.isPointInChildBounds(scrollingChild, xCoordinate, yCoordinate);
1542+
}
1543+
1544+
private boolean isTouchingDragHandle(
1545+
@NonNull CoordinatorLayout parent, int xCoordinate, int yCoordinate) {
1546+
View dragHandleView = dragHandleViewRef != null ? dragHandleViewRef.get() : null;
1547+
return dragHandleView != null
1548+
&& parent.isPointInChildBounds(dragHandleView, xCoordinate, yCoordinate);
1549+
}
1550+
15351551
private boolean isAtTopOfScreen() {
15361552
if (viewRef == null || viewRef.get() == null) {
15371553
return false;
@@ -2020,10 +2036,7 @@ public void onViewReleased(@NonNull View releasedChild, float xvel, float yvel)
20202036

20212037
@Override
20222038
public int clampViewPositionVertical(@NonNull View child, int top, int dy) {
2023-
return MathUtils.clamp(
2024-
top,
2025-
getExpandedOffset(),
2026-
getViewVerticalDragRange(child));
2039+
return MathUtils.clamp(top, getExpandedOffset(), getViewVerticalDragRange(child));
20272040
}
20282041

20292042
@Override
@@ -2346,6 +2359,10 @@ private void updateImportantForAccessibility(boolean expanded) {
23462359
}
23472360
}
23482361

2362+
void setDragHandleView(@Nullable BottomSheetDragHandleView dragHandleView) {
2363+
dragHandleViewRef = dragHandleView != null ? new WeakReference<>(dragHandleView) : null;
2364+
}
2365+
23492366
void setAccessibilityDelegateView(@Nullable View accessibilityDelegateView) {
23502367
if (accessibilityDelegateView == null && accessibilityDelegateViewRef != null) {
23512368
clearAccessibilityAction(

lib/java/com/google/android/material/bottomsheet/BottomSheetDragHandleView.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,12 @@ private void setBottomSheetBehavior(@Nullable BottomSheetBehavior<?> behavior) {
207207
if (bottomSheetBehavior != null) {
208208
bottomSheetBehavior.removeBottomSheetCallback(bottomSheetCallback);
209209
bottomSheetBehavior.setAccessibilityDelegateView(null);
210+
bottomSheetBehavior.setDragHandleView(null);
210211
}
211212
bottomSheetBehavior = behavior;
212213
if (bottomSheetBehavior != null) {
213214
bottomSheetBehavior.setAccessibilityDelegateView(this);
215+
bottomSheetBehavior.setDragHandleView(this);
214216
onBottomSheetStateChanged(bottomSheetBehavior.getState());
215217
bottomSheetBehavior.addBottomSheetCallback(bottomSheetCallback);
216218
}

0 commit comments

Comments
 (0)