Skip to content

Commit

Permalink
[AppBarLayout] Fix snap issue with transparent status bar
Browse files Browse the repository at this point in the history
Resolves #2387

GIT_ORIGIN_REV_ID=47538c3b4cb10337c537d1ef532bd1d73b216ae3
PiperOrigin-RevId: 406835368
  • Loading branch information
Khang-NT authored and veganafro committed Nov 1, 2021
1 parent bed2ac1 commit b935604
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions lib/java/com/google/android/material/appbar/AppBarLayout.java
Expand Up @@ -1526,10 +1526,11 @@ public void onAnimationUpdate(@NonNull ValueAnimator animator) {
}

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

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

if ((flags & LayoutParams.FLAG_SNAP) == LayoutParams.FLAG_SNAP) {
// We're set the snap, so animate the offset to the nearest edge
int snapTop = -offsetChild.getTop();
int snapBottom = -offsetChild.getBottom();

if (offsetChildIndex == abl.getChildCount() - 1) {
// If this is the last child, we need to take the top inset and padding into account
snapBottom += abl.getTopInset() + abl.getPaddingTop();
}
int snapTop = -offsetChild.getTop() + ablTopInset;
int snapBottom = -offsetChild.getBottom() + ablTopInset;

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

0 comments on commit b935604

Please sign in to comment.