Skip to content

Commit

Permalink
[Side Sheet] Fix vertically scrolling sheet swipe issue by deleting m…
Browse files Browse the repository at this point in the history
…ost of the nested scrolling code

We shouldn't need nested scrolling in side sheet because the scroll and swipe directions are different, and horizontal nested scrolling doesn't seem supported

PiperOrigin-RevId: 493756832
(cherry picked from commit 401527f)
  • Loading branch information
dsn5ft committed Dec 9, 2022
1 parent 0c4e4a7 commit 3bc1f6e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 284 deletions.
Expand Up @@ -16,15 +16,12 @@

package com.google.android.material.sidesheet;

import static com.google.android.material.sidesheet.Sheet.STATE_DRAGGING;
import static com.google.android.material.sidesheet.Sheet.STATE_EXPANDED;
import static com.google.android.material.sidesheet.Sheet.STATE_HIDDEN;
import static java.lang.Math.max;

import android.view.View;
import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.view.ViewCompat;
import androidx.customview.widget.ViewDragHelper;
import com.google.android.material.sidesheet.Sheet.SheetEdge;
import com.google.android.material.sidesheet.Sheet.StableSheetState;
Expand Down Expand Up @@ -105,79 +102,6 @@ private boolean isSwipeSignificant(float xVelocity, float yVelocity) {
&& yVelocity > sheetBehavior.getSignificantVelocityThreshold();
}

@Override
<V extends View> void setTargetStateOnNestedPreScroll(
@NonNull CoordinatorLayout coordinatorLayout,
@NonNull V child,
@NonNull View target,
int dx,
int dy,
@NonNull int[] consumed,
int type) {
int currentLeft = child.getLeft();
int newLeft = currentLeft - dx;
if (dx < 0) { // Moving towards the left.
if (newLeft > getExpandedOffset()) {
consumed[1] = currentLeft - getExpandedOffset();
ViewCompat.offsetLeftAndRight(child, -consumed[1]);
sheetBehavior.setStateInternal(STATE_EXPANDED);
} else {
if (!sheetBehavior.isDraggable()) {
// Prevent dragging
return;
}

consumed[1] = dx;
ViewCompat.offsetLeftAndRight(child, -dx);
sheetBehavior.setStateInternal(STATE_DRAGGING);
}
} else if (dx > 0) { // Moving towards the right.
if (!target.canScrollHorizontally(-1)) {
if (newLeft <= getHiddenOffset()) {
if (!sheetBehavior.isDraggable()) {
// Prevent dragging
return;
}

consumed[1] = dx;
ViewCompat.offsetLeftAndRight(child, dx);
sheetBehavior.setStateInternal(STATE_DRAGGING);
} else {
consumed[1] = currentLeft - getHiddenOffset();
ViewCompat.offsetLeftAndRight(child, consumed[1]);
sheetBehavior.setStateInternal(STATE_HIDDEN);
}
}
}
}

@Override
@StableSheetState
<V extends View> int calculateTargetStateOnStopNestedScroll(@NonNull V child) {
@StableSheetState int targetState;
if (sheetBehavior.getLastNestedScrollDx() > 0) {
targetState = STATE_EXPANDED;
} else if (sheetBehavior.shouldHide(child, sheetBehavior.getXVelocity())) {
targetState = STATE_HIDDEN;
} else if (sheetBehavior.getLastNestedScrollDx() == 0) {
int currentLeft = child.getLeft();

if (Math.abs(currentLeft - getExpandedOffset()) < Math.abs(currentLeft - getHiddenOffset())) {
targetState = STATE_EXPANDED;
} else {
targetState = STATE_HIDDEN;
}
} else {
targetState = STATE_HIDDEN;
}
return targetState;
}

@Override
<V extends View> boolean hasReachedExpandedOffset(@NonNull V child) {
return child.getLeft() == getExpandedOffset();
}

@Override
boolean shouldHide(@NonNull View child, float velocity) {
final float newRight = child.getRight() + velocity * sheetBehavior.getHideFriction();
Expand Down
25 changes: 0 additions & 25 deletions lib/java/com/google/android/material/sidesheet/SheetDelegate.java
Expand Up @@ -18,7 +18,6 @@

import android.view.View;
import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import com.google.android.material.sidesheet.Sheet.SheetEdge;
import com.google.android.material.sidesheet.Sheet.StableSheetState;
import com.google.android.material.sidesheet.SideSheetBehavior.StateSettlingTracker;
Expand Down Expand Up @@ -57,30 +56,6 @@ abstract class SheetDelegate {
abstract int calculateTargetStateOnViewReleased(
@NonNull View releasedChild, float xVelocity, float yVelocity);

/**
* Sets the target sheet state from the {@link
* SideSheetBehavior#onNestedPreScroll(CoordinatorLayout, View, View, int, int, int[], int)}
* callback, based on scroll and position information provided by the method parameters.
*/
abstract <V extends View> void setTargetStateOnNestedPreScroll(
@NonNull CoordinatorLayout coordinatorLayout,
@NonNull V child,
@NonNull View target,
int dx,
int dy,
@NonNull int[] consumed,
int type);

@StableSheetState
abstract <V extends View> int calculateTargetStateOnStopNestedScroll(@NonNull V child);

/**
* Whether the sheet has reached the expanded offset at the end of a nested scroll, used to
* determine when to set the {@link SideSheetBehavior.SheetState} to {@link
* SideSheetBehavior.SheetState#STATE_EXPANDED}.
*/
abstract <V extends View> boolean hasReachedExpandedOffset(@NonNull V child);

/**
* Whether the sheet should hide, based on the position of child, velocity of the drag event, and
* {@link SideSheetBehavior#getHideThreshold()}.
Expand Down

0 comments on commit 3bc1f6e

Please sign in to comment.