mirror of
https://github.com/material-components/material-components-android.git
synced 2026-02-20 08:39:55 +08:00
Merge "Fix title not showing when AppBarLayout initially collapsed" into nyc-mr1-dev
GitOrigin-RevId=ea650460b67457efe95675d803b1a08c052efe10 PiperOrigin-RevId: 140564677
This commit is contained in:
parent
fb318a293f
commit
f212c53ccd
@ -1283,20 +1283,20 @@ public class AppBarLayout extends LinearLayout {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parcelable onSaveInstanceState(CoordinatorLayout parent, AppBarLayout appBarLayout) {
|
||||
final Parcelable superState = super.onSaveInstanceState(parent, appBarLayout);
|
||||
public Parcelable onSaveInstanceState(CoordinatorLayout parent, AppBarLayout abl) {
|
||||
final Parcelable superState = super.onSaveInstanceState(parent, abl);
|
||||
final int offset = getTopAndBottomOffset();
|
||||
|
||||
// Try and find the first visible child...
|
||||
for (int i = 0, count = appBarLayout.getChildCount(); i < count; i++) {
|
||||
View child = appBarLayout.getChildAt(i);
|
||||
for (int i = 0, count = abl.getChildCount(); i < count; i++) {
|
||||
View child = abl.getChildAt(i);
|
||||
final int visBottom = child.getBottom() + offset;
|
||||
|
||||
if (child.getTop() + offset <= 0 && visBottom >= 0) {
|
||||
final SavedState ss = new SavedState(superState);
|
||||
ss.firstVisibleChildIndex = i;
|
||||
ss.firstVisibleChildAtMinimumHeight =
|
||||
visBottom == ViewCompat.getMinimumHeight(child);
|
||||
visBottom == (ViewCompat.getMinimumHeight(child) + abl.getTopInset());
|
||||
ss.firstVisibleChildPercentageShown = visBottom / (float) child.getHeight();
|
||||
return ss;
|
||||
}
|
||||
|
||||
@ -413,20 +413,19 @@ public class CollapsingToolbarLayout extends FrameLayout {
|
||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
|
||||
// Update our child view offset helpers
|
||||
for (int i = 0, z = getChildCount(); i < z; i++) {
|
||||
final View child = getChildAt(i);
|
||||
|
||||
if (mLastInsets != null && !ViewCompat.getFitsSystemWindows(child)) {
|
||||
final int insetTop = mLastInsets.getSystemWindowInsetTop();
|
||||
if (child.getTop() < insetTop) {
|
||||
// If the child isn't set to fit system windows but is drawing within the inset
|
||||
// offset it down
|
||||
ViewCompat.offsetTopAndBottom(child, insetTop);
|
||||
if (mLastInsets != null) {
|
||||
// Shift down any views which are not set to fit system windows
|
||||
final int insetTop = mLastInsets.getSystemWindowInsetTop();
|
||||
for (int i = 0, z = getChildCount(); i < z; i++) {
|
||||
final View child = getChildAt(i);
|
||||
if (!ViewCompat.getFitsSystemWindows(child)) {
|
||||
if (child.getTop() < insetTop) {
|
||||
// If the child isn't set to fit system windows but is drawing within
|
||||
// the inset offset it down
|
||||
ViewCompat.offsetTopAndBottom(child, insetTop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getViewOffsetHelper(child).onViewLayout();
|
||||
}
|
||||
|
||||
// Update the collapsed bounds by getting it's transformed bounds
|
||||
@ -465,6 +464,12 @@ public class CollapsingToolbarLayout extends FrameLayout {
|
||||
}
|
||||
}
|
||||
|
||||
// Update our child view offset helpers. This needs to be done after the title has been
|
||||
// setup, so that any Toolbars are in their original position
|
||||
for (int i = 0, z = getChildCount(); i < z; i++) {
|
||||
getViewOffsetHelper(getChildAt(i)).onViewLayout();
|
||||
}
|
||||
|
||||
// Finally, set our minimum height to enable proper AppBarLayout collapsing
|
||||
if (mToolbar != null) {
|
||||
if (mCollapsingTitleEnabled && TextUtils.isEmpty(mCollapsingTextHelper.getText())) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user