Skip to content

Commit

Permalink
[CollapsingToolbarLayout] Fixed scrolling sibling view bottom cut off…
Browse files Browse the repository at this point in the history
… issue

There was an issue when navigating back to a fragment with a CollapsingToolbarLayout, where the items at bottom of the CollapsingToolbarLayout's scrolling sibling view were cut off and couldn't be reached by scrolling. It had to do with the minimum height of the CollapsingToolbarLayout not being set at the point when HeaderScrollingViewBehavior calculates the height of the scrolling view in its onMeasureChild() method. The onMeasureChild() method factors in AppBarLayout#getTotalScrollRange which is dependent on the minimum height of the CollapsingToolbarLayout, so moving the CollapsingToolbarLayout's setMinimumHeight() from its onLayout() to its onMeasure() fixes the issue by making the minimum height available earlier.

Resolves #1558
Resolves #846
Resolves #1070
Resolves #1198

PiperOrigin-RevId: 337309314
  • Loading branch information
dsn5ft authored and hunterstich committed Oct 15, 2020
1 parent 8c6a164 commit a21a300
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,15 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
MeasureSpec.makeMeasureSpec(getMeasuredHeight() + topInset, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

// Set our minimum height to enable proper AppBarLayout collapsing
if (toolbar != null) {
if (toolbarDirectChild == null || toolbarDirectChild == this) {
setMinimumHeight(getHeightWithMargins(toolbar));
} else {
setMinimumHeight(getHeightWithMargins(toolbarDirectChild));
}
}
}

@Override
Expand Down Expand Up @@ -496,17 +505,11 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
}
}

// Set our minimum height to enable proper AppBarLayout collapsing
if (toolbar != null) {
if (collapsingTitleEnabled && TextUtils.isEmpty(collapsingTextHelper.getText())) {
// If we do not currently have a title, try and grab it from the Toolbar
setTitle(toolbar.getTitle());
}
if (toolbarDirectChild == null || toolbarDirectChild == this) {
setMinimumHeight(getHeightWithMargins(toolbar));
} else {
setMinimumHeight(getHeightWithMargins(toolbarDirectChild));
}
}

updateScrimVisibility();
Expand All @@ -521,9 +524,9 @@ private static int getHeightWithMargins(@NonNull final View view) {
final ViewGroup.LayoutParams lp = view.getLayoutParams();
if (lp instanceof MarginLayoutParams) {
final MarginLayoutParams mlp = (MarginLayoutParams) lp;
return view.getHeight() + mlp.topMargin + mlp.bottomMargin;
return view.getMeasuredHeight() + mlp.topMargin + mlp.bottomMargin;
}
return view.getHeight();
return view.getMeasuredHeight();
}

@NonNull
Expand Down

0 comments on commit a21a300

Please sign in to comment.