Skip to content

Commit 1fa246f

Browse files
Chris BanesAndroid (Google) Code Review
Chris Banes
authored and
Android (Google) Code Review
committedJul 1, 2016
Merge "Fix CTL scrim not working with activity transitions"
2 parents 9f75045 + a85f783 commit 1fa246f

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed
 

‎design/src/android/support/design/widget/CollapsingToolbarLayout.java

+23-6
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public class CollapsingToolbarLayout extends FrameLayout {
105105
private Toolbar mToolbar;
106106
private View mToolbarDirectChild;
107107
private View mDummyView;
108+
private int mToolbarDrawIndex;
108109

109110
private int mExpandedMarginStart;
110111
private int mExpandedMarginTop;
@@ -303,15 +304,16 @@ public void draw(Canvas canvas) {
303304
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
304305
// This is a little weird. Our scrim needs to be behind the Toolbar (if it is present),
305306
// but in front of any other children which are behind it. To do this we intercept the
306-
// drawChild() call, and draw our scrim first when drawing the toolbar
307-
ensureToolbar();
308-
if (child == mToolbar && mContentScrim != null && mScrimAlpha > 0) {
307+
// drawChild() call, and draw our scrim after the preceding view is drawn
308+
boolean invalidate = super.drawChild(canvas, child, drawingTime);
309+
310+
if (mContentScrim != null && mScrimAlpha > 0 && isToolbarChildDrawnNext(child)) {
309311
mContentScrim.mutate().setAlpha(mScrimAlpha);
310312
mContentScrim.draw(canvas);
313+
invalidate = true;
311314
}
312315

313-
// Carry on drawing the child...
314-
return super.drawChild(canvas, child, drawingTime);
316+
return invalidate;
315317
}
316318

317319
@Override
@@ -357,6 +359,10 @@ private void ensureToolbar() {
357359
mRefreshToolbar = false;
358360
}
359361

362+
private boolean isToolbarChildDrawnNext(View child) {
363+
return mToolbarDrawIndex >= 0 && mToolbarDrawIndex == indexOfChild(child) + 1;
364+
}
365+
360366
/**
361367
* Returns the direct child of this layout, which itself is the ancestor of the
362368
* given view.
@@ -452,6 +458,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
452458
getViewOffsetHelper(child).onViewLayout();
453459
}
454460

461+
ensureToolbar();
455462
// Finally, set our minimum height to enable proper AppBarLayout collapsing
456463
if (mToolbar != null) {
457464
if (mCollapsingTitleEnabled && TextUtils.isEmpty(mCollapsingTextHelper.getText())) {
@@ -460,10 +467,16 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
460467
}
461468
if (mToolbarDirectChild == null || mToolbarDirectChild == this) {
462469
setMinimumHeight(getHeightWithMargins(mToolbar));
470+
mToolbarDrawIndex = indexOfChild(mToolbar);
463471
} else {
464472
setMinimumHeight(getHeightWithMargins(mToolbarDirectChild));
473+
mToolbarDrawIndex = indexOfChild(mToolbarDirectChild);
465474
}
475+
} else {
476+
mToolbarDrawIndex = -1;
466477
}
478+
479+
updateScrimVisibility();
467480
}
468481

469482
private static int getHeightWithMargins(@NonNull final View view) {
@@ -1198,7 +1211,11 @@ final void updateScrimVisibility() {
11981211
final int getMaxOffsetForPinChild(View child) {
11991212
final ViewOffsetHelper offsetHelper = getViewOffsetHelper(child);
12001213
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
1201-
return getHeight() - (offsetHelper.getLayoutTop() + child.getHeight() + lp.bottomMargin);
1214+
return getHeight()
1215+
+ (mLastInsets != null ? mLastInsets.getSystemWindowInsetTop() : 0)
1216+
- offsetHelper.getLayoutTop()
1217+
- child.getHeight()
1218+
- lp.bottomMargin;
12021219
}
12031220

12041221
private class OffsetUpdateListener implements AppBarLayout.OnOffsetChangedListener {

0 commit comments

Comments
 (0)
Please sign in to comment.