|
16 | 16 |
|
17 | 17 | package com.google.android.material.bottomsheet; |
18 | 18 |
|
19 | | -import com.google.android.material.R; |
20 | | - |
21 | 19 | import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP; |
22 | 20 |
|
23 | 21 | import android.animation.ValueAnimator; |
|
30 | 28 | import android.os.Build.VERSION_CODES; |
31 | 29 | import android.os.Parcel; |
32 | 30 | import android.os.Parcelable; |
| 31 | +import android.util.AttributeSet; |
| 32 | +import android.util.Log; |
| 33 | +import android.util.TypedValue; |
| 34 | +import android.view.MotionEvent; |
| 35 | +import android.view.VelocityTracker; |
| 36 | +import android.view.View; |
| 37 | +import android.view.ViewConfiguration; |
| 38 | +import android.view.ViewGroup; |
| 39 | +import android.view.ViewParent; |
33 | 40 | import androidx.annotation.FloatRange; |
34 | 41 | import androidx.annotation.IntDef; |
35 | 42 | import androidx.annotation.NonNull; |
36 | 43 | import androidx.annotation.Nullable; |
37 | 44 | import androidx.annotation.RestrictTo; |
38 | 45 | import androidx.annotation.VisibleForTesting; |
| 46 | +import androidx.coordinatorlayout.widget.CoordinatorLayout; |
| 47 | +import androidx.coordinatorlayout.widget.CoordinatorLayout.LayoutParams; |
39 | 48 | import androidx.core.math.MathUtils; |
40 | | -import androidx.customview.view.AbsSavedState; |
41 | 49 | import androidx.core.view.ViewCompat; |
| 50 | +import androidx.core.view.WindowInsetsCompat; |
42 | 51 | import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; |
43 | 52 | import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.AccessibilityActionCompat; |
44 | 53 | import androidx.core.view.accessibility.AccessibilityViewCommand; |
| 54 | +import androidx.customview.view.AbsSavedState; |
45 | 55 | import androidx.customview.widget.ViewDragHelper; |
46 | | -import android.util.AttributeSet; |
47 | | -import android.util.Log; |
48 | | -import android.util.TypedValue; |
49 | | -import android.view.MotionEvent; |
50 | | -import android.view.VelocityTracker; |
51 | | -import android.view.View; |
52 | | -import android.view.ViewConfiguration; |
53 | | -import android.view.ViewGroup; |
54 | | -import android.view.ViewParent; |
55 | | -import android.view.WindowInsets; |
56 | | -import androidx.coordinatorlayout.widget.CoordinatorLayout; |
57 | | -import androidx.coordinatorlayout.widget.CoordinatorLayout.LayoutParams; |
| 56 | +import com.google.android.material.R; |
| 57 | +import com.google.android.material.internal.ViewUtils; |
| 58 | +import com.google.android.material.internal.ViewUtils.RelativePadding; |
58 | 59 | import com.google.android.material.resources.MaterialResources; |
59 | 60 | import com.google.android.material.shape.MaterialShapeDrawable; |
60 | 61 | import com.google.android.material.shape.ShapeAppearanceModel; |
@@ -370,7 +371,7 @@ public boolean onLayoutChild( |
370 | 371 | // First layout with this behavior. |
371 | 372 | peekHeightMin = |
372 | 373 | parent.getResources().getDimensionPixelSize(R.dimen.design_bottom_sheet_peek_height_min); |
373 | | - setSystemGestureInsets(parent); |
| 374 | + setSystemGestureInsets(child); |
374 | 375 | viewRef = new WeakReference<>(child); |
375 | 376 | // Only set MaterialShapeDrawable as background if shapeTheming is enabled, otherwise will |
376 | 377 | // default to android:background declared in styles or layout. |
@@ -1237,13 +1238,22 @@ public void onAnimationUpdate(@NonNull ValueAnimator animation) { |
1237 | 1238 | }); |
1238 | 1239 | } |
1239 | 1240 |
|
1240 | | - private void setSystemGestureInsets(@NonNull CoordinatorLayout parent) { |
1241 | | - if (VERSION.SDK_INT >= VERSION_CODES.Q && !isGestureInsetBottomIgnored()) { |
1242 | | - WindowInsets windowInsets = parent.getRootWindowInsets(); |
1243 | | - if (windowInsets != null) { |
1244 | | - int systemMandatoryInsetsBottom = windowInsets.getSystemGestureInsets().bottom; |
1245 | | - peekHeight += systemMandatoryInsetsBottom; |
1246 | | - } |
| 1241 | + /** |
| 1242 | + * Ensure the peek height is at least as large as the bottom gesture inset size so that the sheet |
| 1243 | + * can always be dragged, but only when the inset is required by the system. |
| 1244 | + */ |
| 1245 | + private void setSystemGestureInsets(@NonNull View child) { |
| 1246 | + if (VERSION.SDK_INT >= VERSION_CODES.Q && !isGestureInsetBottomIgnored() && !peekHeightAuto) { |
| 1247 | + ViewUtils.doOnApplyWindowInsets( |
| 1248 | + child, |
| 1249 | + new ViewUtils.OnApplyWindowInsetsListener() { |
| 1250 | + @Override |
| 1251 | + public WindowInsetsCompat onApplyWindowInsets( |
| 1252 | + View view, WindowInsetsCompat insets, RelativePadding initialPadding) { |
| 1253 | + setPeekHeight(peekHeight + insets.getMandatorySystemGestureInsets().bottom); |
| 1254 | + return insets; |
| 1255 | + } |
| 1256 | + }); |
1247 | 1257 | } |
1248 | 1258 | } |
1249 | 1259 |
|
|
0 commit comments