Skip to content

Commit 775d286

Browse files
matpagdsn5ft
authored andcommitted
[BottomSheet] Added missing defensive checks to viewDragHelper calls
Resolves #1295 Resolves #1392 GIT_ORIGIN_REV_ID=cadca3f7e20c387562ab8088227f62f4cd6a40de PiperOrigin-RevId: 323870916 (cherry picked from commit 3821664)
1 parent 86ab1ae commit 775d286

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ public boolean onTouchEvent(
510510
velocityTracker.addMovement(event);
511511
// The ViewDragHelper tries to capture only the top-most View. We have to explicitly tell it
512512
// to capture the bottom sheet in case it is not captured and the touch slop is passed.
513-
if (action == MotionEvent.ACTION_MOVE && !ignoreEvents) {
513+
if (viewDragHelper != null && action == MotionEvent.ACTION_MOVE && !ignoreEvents) {
514514
if (Math.abs(initialY - event.getY()) > viewDragHelper.getTouchSlop()) {
515515
viewDragHelper.captureChildView(child, event.getPointerId(event.getActionIndex()));
516516
}
@@ -1296,9 +1296,10 @@ void settleToState(@NonNull View child, int state) {
12961296

12971297
void startSettlingAnimation(View child, int state, int top, boolean settleFromViewDragHelper) {
12981298
boolean startedSettling =
1299-
settleFromViewDragHelper
1300-
? viewDragHelper.settleCapturedViewAt(child.getLeft(), top)
1301-
: viewDragHelper.smoothSlideViewTo(child, child.getLeft(), top);
1299+
viewDragHelper != null
1300+
&& (settleFromViewDragHelper
1301+
? viewDragHelper.settleCapturedViewAt(child.getLeft(), top)
1302+
: viewDragHelper.smoothSlideViewTo(child, child.getLeft(), top));
13021303
if (startedSettling) {
13031304
setStateInternal(STATE_SETTLING);
13041305
// STATE_SETTLING won't animate the material shape, so do that here with the target state.

0 commit comments

Comments
 (0)