Skip to content

Commit

Permalink
[BottomSheet] Update edge-to-edge paddings when bottom sheet is laid out
Browse files Browse the repository at this point in the history
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
  • Loading branch information
drchen authored and raajkumars committed Feb 18, 2022
1 parent b49284e commit 19af0ac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Expand Up @@ -107,6 +107,8 @@ public abstract static class BottomSheetCallback {
* expanded states and from -1 to 0 it is between hidden and collapsed states.
*/
public abstract void onSlide(@NonNull View bottomSheet, float slideOffset);

void onLayout(@NonNull View bottomSheet) {}
}

/** The bottom sheet is dragging. */
Expand Down Expand Up @@ -553,6 +555,10 @@ public boolean onLayoutChild(
}

nestedScrollingChildRef = new WeakReference<>(findScrollingChild(child));

for (int i = 0; i < callbacks.size(); i++) {
callbacks.get(i).onLayout(child);
}
return true;
}

Expand Down
Expand Up @@ -452,6 +452,11 @@ public void onSlide(@NonNull View bottomSheet, float slideOffset) {
setPaddingForPosition(bottomSheet);
}

@Override
void onLayout(@NonNull View bottomSheet) {
setPaddingForPosition(bottomSheet);
}

private void setPaddingForPosition(View bottomSheet) {
if (bottomSheet.getTop() < insetsCompat.getSystemWindowInsetTop()) {
// If the bottomsheet is light, we should set light status bar so the icons are visible
Expand Down

0 comments on commit 19af0ac

Please sign in to comment.