Skip to content

Commit 19af0ac

Browse files
drchenraajkumars
authored andcommitted
[BottomSheet] Update edge-to-edge paddings when bottom sheet is laid out
Since adding bottom sheet behavior callbacks won't trigger any callbacks to be called, the bottom sheet paddings won't be updated right away. This causes the issue that top paddings are not correctly applied when the bottom sheet is initially expanded. Besides that, due to some unknown reason, bottom sheet's getTop() method will only return a non-zero value that is the offset to the container top when calling from bottom sheet behavior callbacks. It seems related to how ViewCompat.offsetTopAndBottom() is working. Not 100% sure. Therefore this CL add a internal callback to BottomSheetCallback class so when bottom sheet is being laid out (and getting offset), we can update paddings right away. Resolves #2165 PiperOrigin-RevId: 429071367
1 parent b49284e commit 19af0ac

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public abstract static class BottomSheetCallback {
107107
* expanded states and from -1 to 0 it is between hidden and collapsed states.
108108
*/
109109
public abstract void onSlide(@NonNull View bottomSheet, float slideOffset);
110+
111+
void onLayout(@NonNull View bottomSheet) {}
110112
}
111113

112114
/** The bottom sheet is dragging. */
@@ -553,6 +555,10 @@ public boolean onLayoutChild(
553555
}
554556

555557
nestedScrollingChildRef = new WeakReference<>(findScrollingChild(child));
558+
559+
for (int i = 0; i < callbacks.size(); i++) {
560+
callbacks.get(i).onLayout(child);
561+
}
556562
return true;
557563
}
558564

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,11 @@ public void onSlide(@NonNull View bottomSheet, float slideOffset) {
452452
setPaddingForPosition(bottomSheet);
453453
}
454454

455+
@Override
456+
void onLayout(@NonNull View bottomSheet) {
457+
setPaddingForPosition(bottomSheet);
458+
}
459+
455460
private void setPaddingForPosition(View bottomSheet) {
456461
if (bottomSheet.getTop() < insetsCompat.getSystemWindowInsetTop()) {
457462
// If the bottomsheet is light, we should set light status bar so the icons are visible

0 commit comments

Comments
 (0)