From 6454b8709aa3deab58f15cc9591629fd882989c2 Mon Sep 17 00:00:00 2001 From: pekingme <8545955+pekingme@users.noreply.github.com> Date: Thu, 3 Feb 2022 20:37:48 -0800 Subject: [PATCH] [BottomSheet] Fixed IME bottom padding is ignored in edge-to-edge case. The regression on BottomSheet was introduced in 1.6.0-alpha01. Before this version, the bottom padding in edge-to-edge mode is calculated by getSystemWindowInsetBottom(). https://developer.android.com/reference/android/view/WindowInsets#getSystemWindowInsetBottom() This is deprecated in newer APIs. According to deprecation message, the replacement is to use getInsets(int) with Type#systemBars(). But this is not completely true, because it doesn't contain IME insets. https://developer.android.com/reference/android/view/WindowInsets.Type#systemBars() Resolves: https://github.com/material-components/material-components-android/issues/2543 PiperOrigin-RevId: 426304311 --- .../android/material/bottomsheet/BottomSheetBehavior.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java b/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java index edd93944d08..c25a88c126b 100644 --- a/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java +++ b/lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java @@ -1494,7 +1494,8 @@ public WindowInsetsCompat onApplyWindowInsets( int rightPadding = view.getPaddingRight(); if (paddingBottomSystemWindowInsets) { - insetBottom = systemBarInsets.bottom; + Insets imeInsets = insets.getInsets(WindowInsetsCompat.Type.ime()); + insetBottom = systemBarInsets.bottom + imeInsets.bottom; bottomPadding = initialPadding.bottom + insetBottom; }