17
17
package com .google .android .material .bottomsheet ;
18
18
19
19
import static androidx .annotation .RestrictTo .Scope .LIBRARY_GROUP ;
20
+ import static java .lang .Math .max ;
21
+ import static java .lang .Math .min ;
20
22
21
23
import android .animation .ValueAnimator ;
22
24
import android .animation .ValueAnimator .AnimatorUpdateListener ;
76
78
*/
77
79
public class BottomSheetBehavior <V extends View > extends CoordinatorLayout .Behavior <V > {
78
80
81
+
79
82
/** Callback for monitoring events about bottom sheets. */
80
83
public abstract static class BottomSheetCallback {
81
84
@@ -253,6 +256,7 @@ public abstract static class BottomSheetCallback {
253
256
254
257
private boolean nestedScrolled ;
255
258
259
+ private int childHeight ;
256
260
int parentWidth ;
257
261
int parentHeight ;
258
262
@@ -411,7 +415,8 @@ public boolean onLayoutChild(
411
415
// Offset the bottom sheet
412
416
parentWidth = parent .getWidth ();
413
417
parentHeight = parent .getHeight ();
414
- fitToContentsOffset = Math .max (0 , parentHeight - child .getHeight ());
418
+ childHeight = child .getHeight ();
419
+ fitToContentsOffset = max (0 , parentHeight - childHeight );
415
420
calculateHalfExpandedOffset ();
416
421
calculateCollapsedOffset ();
417
422
@@ -772,7 +777,7 @@ public final void setPeekHeight(int peekHeight, boolean animate) {
772
777
}
773
778
} else if (peekHeightAuto || this .peekHeight != peekHeight ) {
774
779
peekHeightAuto = false ;
775
- this .peekHeight = Math . max (0 , peekHeight );
780
+ this .peekHeight = max (0 , peekHeight );
776
781
layout = true ;
777
782
}
778
783
// If sheet is already laid out, recalculate the collapsed offset based on new setting.
@@ -1130,10 +1135,11 @@ private void updateDrawableForTargetState(@State int state) {
1130
1135
1131
1136
private int calculatePeekHeight () {
1132
1137
if (peekHeightAuto ) {
1133
- return Math .max (peekHeightMin , parentHeight - parentWidth * 9 / 16 );
1138
+ int desiredHeight = max (peekHeightMin , parentHeight - parentWidth * 9 / 16 );
1139
+ return min (desiredHeight , childHeight );
1134
1140
}
1135
1141
if (!gestureInsetBottomIgnored && gestureInsetBottom > 0 ) {
1136
- return Math . max (peekHeight , gestureInsetBottom + peekHeightGestureInsetBuffer );
1142
+ return max (peekHeight , gestureInsetBottom + peekHeightGestureInsetBuffer );
1137
1143
}
1138
1144
return peekHeight ;
1139
1145
}
@@ -1142,7 +1148,7 @@ private void calculateCollapsedOffset() {
1142
1148
int peek = calculatePeekHeight ();
1143
1149
1144
1150
if (fitToContents ) {
1145
- collapsedOffset = Math . max (parentHeight - peek , fitToContentsOffset );
1151
+ collapsedOffset = max (parentHeight - peek , fitToContentsOffset );
1146
1152
} else {
1147
1153
collapsedOffset = parentHeight - peek ;
1148
1154
}
0 commit comments