Skip to content

Commit

Permalink
[BottomSheet] Added missing defensive checks to viewDragHelper calls
Browse files Browse the repository at this point in the history
Resolves #1295
Resolves #1392

GIT_ORIGIN_REV_ID=cadca3f7e20c387562ab8088227f62f4cd6a40de
PiperOrigin-RevId: 323870916

(cherry picked from commit 3821664)
  • Loading branch information
matpag authored and dsn5ft committed Aug 28, 2020
1 parent 86ab1ae commit 775d286
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ public boolean onTouchEvent(
velocityTracker.addMovement(event);
// The ViewDragHelper tries to capture only the top-most View. We have to explicitly tell it
// to capture the bottom sheet in case it is not captured and the touch slop is passed.
if (action == MotionEvent.ACTION_MOVE && !ignoreEvents) {
if (viewDragHelper != null && action == MotionEvent.ACTION_MOVE && !ignoreEvents) {
if (Math.abs(initialY - event.getY()) > viewDragHelper.getTouchSlop()) {
viewDragHelper.captureChildView(child, event.getPointerId(event.getActionIndex()));
}
Expand Down Expand Up @@ -1296,9 +1296,10 @@ void settleToState(@NonNull View child, int state) {

void startSettlingAnimation(View child, int state, int top, boolean settleFromViewDragHelper) {
boolean startedSettling =
settleFromViewDragHelper
? viewDragHelper.settleCapturedViewAt(child.getLeft(), top)
: viewDragHelper.smoothSlideViewTo(child, child.getLeft(), top);
viewDragHelper != null
&& (settleFromViewDragHelper
? viewDragHelper.settleCapturedViewAt(child.getLeft(), top)
: viewDragHelper.smoothSlideViewTo(child, child.getLeft(), top));
if (startedSettling) {
setStateInternal(STATE_SETTLING);
// STATE_SETTLING won't animate the material shape, so do that here with the target state.
Expand Down

0 comments on commit 775d286

Please sign in to comment.