Skip to content

Commit b935604

Browse files
Khang-NTveganafro
authored andcommitted
[AppBarLayout] Fix snap issue with transparent status bar
Resolves #2387 GIT_ORIGIN_REV_ID=47538c3b4cb10337c537d1ef532bd1d73b216ae3 PiperOrigin-RevId: 406835368
1 parent bed2ac1 commit b935604

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

lib/java/com/google/android/material/appbar/AppBarLayout.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,10 +1526,11 @@ public void onAnimationUpdate(@NonNull ValueAnimator animator) {
15261526
}
15271527

15281528
private int getChildIndexOnOffset(@NonNull T abl, final int offset) {
1529+
final int ablTopInset = abl.getTopInset() + abl.getPaddingTop();
15291530
for (int i = 0, count = abl.getChildCount(); i < count; i++) {
15301531
View child = abl.getChildAt(i);
1531-
int top = child.getTop();
1532-
int bottom = child.getBottom();
1532+
int top = child.getTop() - ablTopInset;
1533+
int bottom = child.getBottom() - ablTopInset;
15331534

15341535
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
15351536
if (checkFlag(lp.getScrollFlags(), LayoutParams.SCROLL_FLAG_SNAP_MARGINS)) {
@@ -1552,16 +1553,12 @@ private void snapToChildIfNeeded(CoordinatorLayout coordinatorLayout, @NonNull T
15521553
final View offsetChild = abl.getChildAt(offsetChildIndex);
15531554
final LayoutParams lp = (LayoutParams) offsetChild.getLayoutParams();
15541555
final int flags = lp.getScrollFlags();
1556+
final int ablTopInset = abl.getTopInset() + abl.getPaddingTop();
15551557

15561558
if ((flags & LayoutParams.FLAG_SNAP) == LayoutParams.FLAG_SNAP) {
15571559
// We're set the snap, so animate the offset to the nearest edge
1558-
int snapTop = -offsetChild.getTop();
1559-
int snapBottom = -offsetChild.getBottom();
1560-
1561-
if (offsetChildIndex == abl.getChildCount() - 1) {
1562-
// If this is the last child, we need to take the top inset and padding into account
1563-
snapBottom += abl.getTopInset() + abl.getPaddingTop();
1564-
}
1560+
int snapTop = -offsetChild.getTop() + ablTopInset;
1561+
int snapBottom = -offsetChild.getBottom() + ablTopInset;
15651562

15661563
if (checkFlag(flags, LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED)) {
15671564
// If the view is set only exit until it is collapsed, we'll abide by that

0 commit comments

Comments
 (0)