mirror of
https://github.com/material-components/material-components-android.git
synced 2026-02-20 08:39:55 +08:00
Merge "Fix window insets for AppBarLayouts in ViewPager" into mnc-ub-dev am: 75fd07ac98
am: edc47e19cd * commit 'edc47e19cddd681bffd02103661b7c03db87c2ce': Fix window insets for AppBarLayouts in ViewPager GitOrigin-RevId=31b690241124e22631b9e9f485bc4dbf88254db1 PiperOrigin-RevId: 140559774
This commit is contained in:
parent
9b597185ab
commit
dbb75c008e
@ -165,8 +165,7 @@ public class AppBarLayout extends LinearLayout {
|
||||
@Override
|
||||
public WindowInsetsCompat onApplyWindowInsets(View v,
|
||||
WindowInsetsCompat insets) {
|
||||
setWindowInsets(insets);
|
||||
return insets.consumeSystemWindowInsets();
|
||||
return setWindowInsets(insets);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -424,7 +423,7 @@ public class AppBarLayout extends LinearLayout {
|
||||
}
|
||||
|
||||
final int getMinimumHeightForVisibleOverlappingContent() {
|
||||
final int topInset = mLastInsets != null ? mLastInsets.getSystemWindowInsetTop() : 0;
|
||||
final int topInset = getTopInset();
|
||||
final int minHeight = ViewCompat.getMinimumHeight(this);
|
||||
if (minHeight != 0) {
|
||||
// If this layout has a min height, use it (doubled)
|
||||
@ -474,19 +473,11 @@ public class AppBarLayout extends LinearLayout {
|
||||
return mLastInsets != null ? mLastInsets.getSystemWindowInsetTop() : 0;
|
||||
}
|
||||
|
||||
private void setWindowInsets(WindowInsetsCompat insets) {
|
||||
private WindowInsetsCompat setWindowInsets(WindowInsetsCompat insets) {
|
||||
// Invalidate the total scroll range...
|
||||
mTotalScrollRange = INVALID_SCROLL_RANGE;
|
||||
mLastInsets = insets;
|
||||
|
||||
// Now dispatch them to our children
|
||||
for (int i = 0, z = getChildCount(); i < z; i++) {
|
||||
final View child = getChildAt(i);
|
||||
insets = ViewCompat.dispatchApplyWindowInsets(child, insets);
|
||||
if (insets.isConsumed()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return insets;
|
||||
}
|
||||
|
||||
public static class LayoutParams extends LinearLayout.LayoutParams {
|
||||
|
||||
@ -23,7 +23,6 @@ import android.graphics.Rect;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.IntDef;
|
||||
@ -66,7 +65,8 @@ import java.lang.annotation.RetentionPolicy;
|
||||
* <h4>Status bar scrim</h4>
|
||||
* A scrim which is show or hidden behind the status bar when the scroll position has hit a certain
|
||||
* threshold. You can change this via {@link #setStatusBarScrim(Drawable)}. This only works
|
||||
* on {@link Build.VERSION_CODES#LOLLIPOP LOLLIPOP} devices when we set to fit system windows.
|
||||
* on {@link android.os.Build.VERSION_CODES#LOLLIPOP LOLLIPOP} devices when we set to fit system
|
||||
* windows.
|
||||
*
|
||||
* <h4>Parallax scrolling children</h4>
|
||||
* Child views can opt to be scrolled within this layout in a parallax fashion.
|
||||
@ -207,9 +207,7 @@ public class CollapsingToolbarLayout extends FrameLayout {
|
||||
@Override
|
||||
public WindowInsetsCompat onApplyWindowInsets(View v,
|
||||
WindowInsetsCompat insets) {
|
||||
mLastInsets = insets;
|
||||
requestLayout();
|
||||
return insets.consumeSystemWindowInsets();
|
||||
return setWindowInsets(insets);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -226,6 +224,9 @@ public class CollapsingToolbarLayout extends FrameLayout {
|
||||
}
|
||||
((AppBarLayout) parent).addOnOffsetChangedListener(mOnOffsetChangedListener);
|
||||
}
|
||||
|
||||
// We're attached, so lets request an inset dispatch
|
||||
ViewCompat.requestApplyInsets(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -239,6 +240,14 @@ public class CollapsingToolbarLayout extends FrameLayout {
|
||||
super.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
private WindowInsetsCompat setWindowInsets(WindowInsetsCompat insets) {
|
||||
if (mLastInsets != insets) {
|
||||
mLastInsets = insets;
|
||||
requestLayout();
|
||||
}
|
||||
return insets.consumeSystemWindowInsets();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
super.draw(canvas);
|
||||
@ -417,7 +426,7 @@ public class CollapsingToolbarLayout extends FrameLayout {
|
||||
if (child.getTop() < insetTop) {
|
||||
// If the child isn't set to fit system windows but is drawing within the inset
|
||||
// offset it down
|
||||
child.offsetTopAndBottom(insetTop);
|
||||
ViewCompat.offsetTopAndBottom(child, insetTop);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -328,14 +328,17 @@ public class CoordinatorLayout extends ViewGroup implements NestedScrollingParen
|
||||
setStatusBarBackground(new ColorDrawable(color));
|
||||
}
|
||||
|
||||
private void setWindowInsets(WindowInsetsCompat insets) {
|
||||
private WindowInsetsCompat setWindowInsets(WindowInsetsCompat insets) {
|
||||
if (mLastInsets != insets) {
|
||||
mLastInsets = insets;
|
||||
mDrawStatusBarBackground = insets != null && insets.getSystemWindowInsetTop() > 0;
|
||||
setWillNotDraw(!mDrawStatusBarBackground && getBackground() == null);
|
||||
dispatchChildApplyWindowInsets(insets);
|
||||
|
||||
// Now dispatch to the Behaviors
|
||||
insets = dispatchApplyWindowInsetsToBehaviors(insets);
|
||||
requestLayout();
|
||||
}
|
||||
return insets;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -745,9 +748,9 @@ public class CoordinatorLayout extends ViewGroup implements NestedScrollingParen
|
||||
setMeasuredDimension(width, height);
|
||||
}
|
||||
|
||||
private void dispatchChildApplyWindowInsets(WindowInsetsCompat insets) {
|
||||
private WindowInsetsCompat dispatchApplyWindowInsetsToBehaviors(WindowInsetsCompat insets) {
|
||||
if (insets.isConsumed()) {
|
||||
return;
|
||||
return insets;
|
||||
}
|
||||
|
||||
for (int i = 0, z = getChildCount(); i < z; i++) {
|
||||
@ -764,14 +767,10 @@ public class CoordinatorLayout extends ViewGroup implements NestedScrollingParen
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Now let the view try and consume them
|
||||
insets = ViewCompat.dispatchApplyWindowInsets(child, insets);
|
||||
if (insets.isConsumed()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return insets;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2579,15 +2578,15 @@ public class CoordinatorLayout extends ViewGroup implements NestedScrollingParen
|
||||
}
|
||||
}
|
||||
|
||||
final class ApplyInsetsListener implements android.support.v4.view.OnApplyWindowInsetsListener {
|
||||
private class ApplyInsetsListener
|
||||
implements android.support.v4.view.OnApplyWindowInsetsListener {
|
||||
@Override
|
||||
public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
|
||||
setWindowInsets(insets);
|
||||
return insets.consumeSystemWindowInsets();
|
||||
return setWindowInsets(insets);
|
||||
}
|
||||
}
|
||||
|
||||
final class HierarchyChangeListener implements OnHierarchyChangeListener {
|
||||
private class HierarchyChangeListener implements OnHierarchyChangeListener {
|
||||
@Override
|
||||
public void onChildViewAdded(View parent, View child) {
|
||||
if (mOnHierarchyChangeListener != null) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user