Skip to content

Commit e644a72

Browse files
drchendsn5ft
authored andcommitted
Automated g4 rollback of changelist 435127325
PiperOrigin-RevId: 435152125
1 parent 493243e commit e644a72

File tree

3 files changed

+14
-129
lines changed

3 files changed

+14
-129
lines changed

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

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ void onLayout(@NonNull View bottomSheet) {}
277277
boolean hideable;
278278

279279
private boolean skipCollapsed;
280-
private boolean collapsible = true;
281280

282281
private boolean draggable = true;
283282

@@ -553,7 +552,6 @@ public boolean onLayoutChild(
553552
fitToContentsOffset = max(0, parentHeight - childHeight);
554553
calculateHalfExpandedOffset();
555554
calculateCollapsedOffset();
556-
onOffsetsUpdated();
557555

558556
if (state == STATE_EXPANDED) {
559557
ViewCompat.offsetTopAndBottom(child, getExpandedOffset());
@@ -727,12 +725,10 @@ public void onNestedPreScroll(
727725
consumed[1] = dy;
728726
ViewCompat.offsetTopAndBottom(child, -dy);
729727
setStateInternal(STATE_DRAGGING);
730-
} else if (!shouldSkipCollapsed()) {
728+
} else {
731729
consumed[1] = currentTop - collapsedOffset;
732730
ViewCompat.offsetTopAndBottom(child, -consumed[1]);
733731
setStateInternal(STATE_COLLAPSED);
734-
} else {
735-
// Do nothing, the bottom sheet should be fixed.
736732
}
737733
}
738734
}
@@ -875,7 +871,6 @@ public void setFitToContents(boolean fitToContents) {
875871
}
876872
// Fix incorrect expanded settings depending on whether or not we are fitting sheet to contents.
877873
setStateInternal((this.fitToContents && state == STATE_HALF_EXPANDED) ? STATE_EXPANDED : state);
878-
onOffsetsUpdated();
879874

880875
updateAccessibilityActions();
881876
}
@@ -971,7 +966,6 @@ public final void setPeekHeight(int peekHeight, boolean animate) {
971966
private void updatePeekHeight(boolean animate) {
972967
if (viewRef != null) {
973968
calculateCollapsedOffset();
974-
onOffsetsUpdated();
975969
if (state == STATE_COLLAPSED) {
976970
V view = viewRef.get();
977971
if (view != null) {
@@ -1210,10 +1204,6 @@ public void setState(@StableState int state) {
12101204
Log.w(TAG, "Cannot set state: " + state);
12111205
return;
12121206
}
1213-
if (ensureExpandedStateIfNotCollapsible(state)) {
1214-
// setState() will be called again.
1215-
return;
1216-
}
12171207
final int finalState;
12181208
if (state == STATE_HALF_EXPANDED
12191209
&& fitToContents
@@ -1288,7 +1278,7 @@ void setStateInternal(@State int state) {
12881278
return;
12891279
}
12901280
this.state = state;
1291-
if ((collapsible && state == STATE_COLLAPSED)
1281+
if (state == STATE_COLLAPSED
12921282
|| state == STATE_EXPANDED
12931283
|| state == STATE_HALF_EXPANDED
12941284
|| (hideable && state == STATE_HIDDEN)) {
@@ -1362,19 +1352,6 @@ private void calculateCollapsedOffset() {
13621352
}
13631353
}
13641354

1365-
private void onOffsetsUpdated() {
1366-
collapsible = collapsedOffset != getExpandedOffset();
1367-
ensureExpandedStateIfNotCollapsible(state);
1368-
}
1369-
1370-
private boolean ensureExpandedStateIfNotCollapsible(@State int state) {
1371-
if (!collapsible && state == STATE_COLLAPSED) {
1372-
setState(STATE_EXPANDED);
1373-
return true;
1374-
}
1375-
return false;
1376-
}
1377-
13781355
private void calculateHalfExpandedOffset() {
13791356
this.halfExpandedOffset = (int) (parentHeight * (1 - halfExpandedRatio));
13801357
}
@@ -1408,7 +1385,7 @@ private void restoreOptionalState(@NonNull SavedState ss) {
14081385
}
14091386

14101387
boolean shouldHide(@NonNull View child, float yvel) {
1411-
if (shouldSkipCollapsed()) {
1388+
if (skipCollapsed) {
14121389
return true;
14131390
}
14141391
if (child.getTop() < collapsedOffset) {
@@ -1420,10 +1397,6 @@ boolean shouldHide(@NonNull View child, float yvel) {
14201397
return Math.abs(newTop - collapsedOffset) / (float) peek > HIDE_THRESHOLD;
14211398
}
14221399

1423-
private boolean shouldSkipCollapsed() {
1424-
return !collapsible || skipCollapsed;
1425-
}
1426-
14271400
@Nullable
14281401
@VisibleForTesting
14291402
View findScrollingChild(View view) {

tests/javatests/com/google/android/material/bottomsheet/BottomSheetBehaviorTest.java

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,10 @@ public void testSkipCollapsedFullyExpanded() throws Throwable {
433433
testSkipCollapsed();
434434
}
435435

436-
private void testSkipCollapsed_smallSwipe(int expectedState, float swipeViewHeightPercentage) {
436+
private void testSkipCollapsed_smallSwipe(int expectedState, float swipeViewHeightPercentage)
437+
throws Throwable {
438+
getBehavior().setSkipCollapsed(true);
439+
checkSetState(BottomSheetBehavior.STATE_EXPANDED, ViewMatchers.isDisplayed());
437440
Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
438441
.perform(
439442
DesignViewActions.withCustomConstraints(
@@ -473,23 +476,16 @@ private void testSkipCollapsed_smallSwipe(int expectedState, float swipeViewHeig
473476
}
474477
}
475478

476-
private void setSkipCollapsed() throws Throwable {
477-
getBehavior().setSkipCollapsed(true);
478-
checkSetState(BottomSheetBehavior.STATE_EXPANDED, ViewMatchers.isDisplayed());
479-
}
480-
481479
@Test
482480
@MediumTest
483481
public void testSkipCollapsed_smallSwipe_remainsExpanded() throws Throwable {
484-
setSkipCollapsed();
485482
testSkipCollapsed_smallSwipe(
486483
BottomSheetBehavior.STATE_EXPANDED, /* swipeViewHeightPercentage = */ 0.5f);
487484
}
488485

489486
@Test
490487
@MediumTest
491488
public void testSkipCollapsedFullyExpanded_smallSwipe_remainsExpanded() throws Throwable {
492-
setSkipCollapsed();
493489
getBehavior().setFitToContents(false);
494490
testSkipCollapsed_smallSwipe(
495491
BottomSheetBehavior.STATE_HALF_EXPANDED, /* swipeViewHeightPercentage = */ 0.5f);
@@ -498,41 +494,18 @@ public void testSkipCollapsedFullyExpanded_smallSwipe_remainsExpanded() throws T
498494
@Test
499495
@MediumTest
500496
public void testSkipCollapsed_smallSwipePastThreshold_getsHidden() throws Throwable {
501-
setSkipCollapsed();
502497
testSkipCollapsed_smallSwipe(
503498
BottomSheetBehavior.STATE_HIDDEN, /* swipeViewHeightPercentage = */ 0.75f);
504499
}
505500

506501
@Test
507502
@MediumTest
508503
public void testSkipCollapsedFullyExpanded_smallSwipePastThreshold_getsHidden() throws Throwable {
509-
setSkipCollapsed();
510504
getBehavior().setFitToContents(false);
511505
testSkipCollapsed_smallSwipe(
512506
BottomSheetBehavior.STATE_HIDDEN, /* swipeViewHeightPercentage = */ 0.75f);
513507
}
514508

515-
private void makeBottomSheetNotCollapsible() {
516-
// Set a peek height that equals to expanded height so it always stays EXPANDED.
517-
getBehavior().setPeekHeight(5000);
518-
}
519-
520-
@Test
521-
@MediumTest
522-
public void testNotCollapsible_smallSwipe_remainsExpanded() {
523-
makeBottomSheetNotCollapsible();
524-
testSkipCollapsed_smallSwipe(
525-
BottomSheetBehavior.STATE_EXPANDED, /* swipeViewHeightPercentage = */ 0.5f);
526-
}
527-
528-
@Test
529-
@MediumTest
530-
public void testNotCollapsible_smallSwipePastThreshold_getsHidden() {
531-
makeBottomSheetNotCollapsible();
532-
testSkipCollapsed_smallSwipe(
533-
BottomSheetBehavior.STATE_HIDDEN, /* swipeViewHeightPercentage = */ 0.75f);
534-
}
535-
536509
@Test
537510
@MediumTest
538511
public void testSwipeUpToExpand() {
@@ -962,22 +935,16 @@ public void testDynamicContent() throws Throwable {
962935
@Test
963936
@MediumTest
964937
public void testExpandedPeekHeight() throws Throwable {
965-
registerIdlingResourceCallback();
966938
activityTestRule.runOnUiThread(
967939
() -> {
968940
// Make the peek height as tall as the bottom sheet.
969-
getBehavior().setPeekHeight(getBottomSheet().getHeight());
941+
BottomSheetBehavior<?> behavior = getBehavior();
942+
behavior.setPeekHeight(getBottomSheet().getHeight());
943+
assertThat(behavior.getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
970944
});
971-
Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
972-
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
973-
assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED));
974-
unregisterIdlingResourceCallback();
975-
// Both of these will not animate the sheet, and the state should be fixed as EXPANDED.
945+
// Both of these will not animate the sheet , but the state should be changed.
976946
checkSetState(BottomSheetBehavior.STATE_EXPANDED, ViewMatchers.isDisplayed());
977-
checkSetState(
978-
BottomSheetBehavior.STATE_COLLAPSED,
979-
BottomSheetBehavior.STATE_EXPANDED,
980-
ViewMatchers.isDisplayed());
947+
checkSetState(BottomSheetBehavior.STATE_COLLAPSED, ViewMatchers.isDisplayed());
981948
}
982949

983950
@Test
@@ -995,17 +962,12 @@ public void testFindScrollingChildEnabled() {
995962
}
996963

997964
private void checkSetState(final int state, Matcher<View> matcher) throws Throwable {
998-
checkSetState(state, state, matcher);
999-
}
1000-
1001-
private void checkSetState(
1002-
final int stateToSet, final int stateToExpect, Matcher<View> matcher) throws Throwable {
1003965
registerIdlingResourceCallback();
1004966
try {
1005-
activityTestRule.runOnUiThread(() -> getBehavior().setState(stateToSet));
967+
activityTestRule.runOnUiThread(() -> getBehavior().setState(state));
1006968
Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
1007969
.check(ViewAssertions.matches(matcher));
1008-
assertThat(getBehavior().getState(), is(stateToExpect));
970+
assertThat(getBehavior().getState(), is(state));
1009971
assertAccessibilityActions(getBehavior(), getBottomSheet());
1010972
} finally {
1011973
unregisterIdlingResourceCallback();

tests/javatests/com/google/android/material/bottomsheet/BottomSheetDialogTest.java

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,6 @@ public void testHideThenShow() throws Throwable {
188188
final DialogInterface.OnCancelListener onCancelListener =
189189
mock(DialogInterface.OnCancelListener.class);
190190
showDialog();
191-
onView(ViewMatchers.withId(R.id.design_bottom_sheet))
192-
.perform(setShortPeekHeight())
193-
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
194191
dialog.setOnCancelListener(onCancelListener);
195192
onView(ViewMatchers.withId(R.id.design_bottom_sheet))
196193
.perform(setState(BottomSheetBehavior.STATE_HIDDEN));
@@ -208,33 +205,6 @@ public void testHideThenShow() throws Throwable {
208205
.onStateChanged(any(View.class), eq(BottomSheetBehavior.STATE_COLLAPSED));
209206
}
210207

211-
@Test
212-
@MediumTest
213-
public void testHideThenShowNotCollapsible() throws Throwable {
214-
// Hide the bottom sheet and wait for the dialog to be canceled.
215-
final DialogInterface.OnCancelListener onCancelListener =
216-
mock(DialogInterface.OnCancelListener.class);
217-
showDialog();
218-
onView(ViewMatchers.withId(R.id.design_bottom_sheet))
219-
.perform(setTallPeekHeight())
220-
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
221-
dialog.setOnCancelListener(onCancelListener);
222-
onView(ViewMatchers.withId(R.id.design_bottom_sheet))
223-
.perform(setState(BottomSheetBehavior.STATE_HIDDEN));
224-
verify(onCancelListener, timeout(3000)).onCancel(any(DialogInterface.class));
225-
// Reshow the same dialog instance and wait for the bottom sheet to be collapsed.
226-
final BottomSheetBehavior.BottomSheetCallback callback =
227-
mock(BottomSheetBehavior.BottomSheetCallback.class);
228-
BottomSheetBehavior.from(dialog.findViewById(R.id.design_bottom_sheet))
229-
.addBottomSheetCallback(callback);
230-
// Show the same dialog again.
231-
activityTestRule.runOnUiThread(() -> dialog.show());
232-
verify(callback, timeout(3000))
233-
.onStateChanged(any(View.class), eq(BottomSheetBehavior.STATE_SETTLING));
234-
verify(callback, timeout(3000))
235-
.onStateChanged(any(View.class), eq(BottomSheetBehavior.STATE_EXPANDED));
236-
}
237-
238208
private void showDialog() throws Throwable {
239209
activityTestRule.runOnUiThread(
240210
() -> {
@@ -269,26 +239,6 @@ public void perform(UiController uiController, View view) {
269239
};
270240
}
271241

272-
private static ViewAction setShortPeekHeight() {
273-
return new ViewAction() {
274-
@Override
275-
public Matcher<View> getConstraints() {
276-
return ViewMatchers.isDisplayed();
277-
}
278-
279-
@Override
280-
public String getDescription() {
281-
return "set tall peek height";
282-
}
283-
284-
@Override
285-
public void perform(UiController uiController, View view) {
286-
BottomSheetBehavior<?> behavior = BottomSheetBehavior.from(view);
287-
behavior.setPeekHeight(view.getHeight() / 2);
288-
}
289-
};
290-
}
291-
292242
private static ViewAction setState(@BottomSheetBehavior.State final int state) {
293243
return new ViewAction() {
294244
@Override

0 commit comments

Comments
 (0)