Skip to content

Commit 1445e6d

Browse files
hunterstichymarian
authored andcommitted
[CollapsingToolbarLayout] Updated fade mode to allow expanded title to translate 1:1 with scrolling content.
PiperOrigin-RevId: 372565826 (cherry picked from commit c754183)
1 parent 982f74d commit 1445e6d

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

lib/java/com/google/android/material/internal/CollapsingTextHelper.java

+8-14
Original file line numberDiff line numberDiff line change
@@ -528,19 +528,23 @@ private void calculateCurrentOffsets() {
528528

529529
private void calculateOffsets(final float fraction) {
530530
interpolateBounds(fraction);
531+
float textBlendFraction;
531532
if (fadeModeEnabled) {
532533
if (fraction < fadeModeThresholdFraction) {
534+
textBlendFraction = 0F;
533535
currentDrawX = expandedDrawX;
534-
currentDrawY = lerp(expandedDrawY, collapsedDrawY, fraction, positionInterpolator);
536+
currentDrawY = expandedDrawY;
535537

536538
setInterpolatedTextSize(expandedTextSize);
537539
} else {
540+
textBlendFraction = 1F;
538541
currentDrawX = collapsedDrawX;
539542
currentDrawY = collapsedDrawY - currentOffsetY;
540543

541544
setInterpolatedTextSize(collapsedTextSize);
542545
}
543546
} else {
547+
textBlendFraction = fraction;
544548
currentDrawX = lerp(expandedDrawX, collapsedDrawX, fraction, positionInterpolator);
545549
currentDrawY = lerp(expandedDrawY, collapsedDrawY, fraction, positionInterpolator);
546550

@@ -556,7 +560,8 @@ private void calculateOffsets(final float fraction) {
556560
// If the collapsed and expanded text colors are different, blend them based on the
557561
// fraction
558562
textPaint.setColor(
559-
blendColors(getCurrentExpandedTextColor(), getCurrentCollapsedTextColor(), fraction));
563+
blendColors(
564+
getCurrentExpandedTextColor(), getCurrentCollapsedTextColor(), textBlendFraction));
560565
} else {
561566
textPaint.setColor(getCurrentCollapsedTextColor());
562567
}
@@ -726,18 +731,7 @@ private void calculateBaseOffsets() {
726731

727732
private void interpolateBounds(float fraction) {
728733
if (fadeModeEnabled) {
729-
if (fraction < fadeModeThresholdFraction) {
730-
currentBounds.left = expandedBounds.left;
731-
currentBounds.top = lerp(expandedDrawY, collapsedDrawY, fraction, positionInterpolator);
732-
currentBounds.right = expandedBounds.right;
733-
currentBounds.bottom =
734-
lerp(expandedBounds.bottom, collapsedBounds.bottom, fraction, positionInterpolator);
735-
} else {
736-
currentBounds.left = collapsedBounds.left;
737-
currentBounds.top = collapsedBounds.top;
738-
currentBounds.right = collapsedBounds.right;
739-
currentBounds.bottom = collapsedBounds.bottom;
740-
}
734+
currentBounds.set(fraction < fadeModeThresholdFraction ? expandedBounds : collapsedBounds);
741735
} else {
742736
currentBounds.left =
743737
lerp(expandedBounds.left, collapsedBounds.left, fraction, positionInterpolator);

0 commit comments

Comments
 (0)