Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -712,17 +712,6 @@ private void calculateOffsets(final float fraction) {
textPaint.setColor(getCurrentCollapsedTextColor());
}

if (collapsedLetterSpacing != expandedLetterSpacing) {
textPaint.setLetterSpacing(
lerp(
expandedLetterSpacing,
collapsedLetterSpacing,
fraction,
AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR));
} else {
textPaint.setLetterSpacing(collapsedLetterSpacing);
}

Comment on lines -715 to -725
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of removing this block, could it be moved into the else statement of if (fadeModeEnabled)?

if (fadeModeEnabled) {
   ...
} else {
   lerp letter spacing
}

// Calculates paint parameters for shadow layer.
currentShadowRadius = lerp(expandedShadowRadius, collapsedShadowRadius, fraction, null);
currentShadowDx = lerp(expandedShadowDx, collapsedShadowDx, fraction, null);
Expand Down Expand Up @@ -1099,7 +1088,6 @@ private void calculateUsingTextSize(final float fraction, boolean forceRecalcula
newTypeface = collapsedTypeface;
} else {
newTextSize = expandedTextSize;
newLetterSpacing = expandedLetterSpacing;
newTypeface = expandedTypeface;
if (isClose(fraction, /* targetValue= */ 0)) {
// If we're close to the expanded text size, snap to it and use a scale of 1
Expand All @@ -1111,6 +1099,11 @@ private void calculateUsingTextSize(final float fraction, boolean forceRecalcula
/ expandedTextSize;
}

newLetterSpacing = lerp(
expandedLetterSpacing, collapsedLetterSpacing,
1f, collapsedTextSize / expandedTextSize,
scale);

Comment on lines +1102 to +1106
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed if letter spacing lerping is replaced inside calculateOffsets

float textSizeRatio = collapsedTextSize / expandedTextSize;
// This is the size of the expanded bounds when it is scaled to match the
// collapsed text size
Expand Down Expand Up @@ -1320,11 +1313,11 @@ public void setStaticLayoutBuilderConfigurer(
}

/**
* Returns true if {@code value} is 'close' to it's closest decimal value. Close is currently
* Returns true if {@code value1} is 'close' to {@code value2}. Close is currently
* defined as it's difference being < 0.00001.
*/
private static boolean isClose(float value, float targetValue) {
return Math.abs(value - targetValue) < 0.00001f;
private static boolean isClose(float value1, float value2) {
return Math.abs(value1 - value2) < 0.00001f;
}

public ColorStateList getExpandedTextColor() {
Expand Down Expand Up @@ -1367,6 +1360,22 @@ private static float lerp(
return AnimationUtils.lerp(startValue, endValue, fraction);
}

private static float lerp(
float outputStart, float outputEnd,
float inputStart, float inputEnd,
float inputValue) {
if (isClose(inputEnd, inputStart)) {
if (isClose(outputEnd, outputStart)) {
return outputStart;
} else {
throw new RuntimeException("\"input\" range is empty, but \"output\" is not");
}
}

float value = (inputValue - inputStart) / (inputEnd - inputStart);
return outputStart + (outputEnd - outputStart) * value;
}

private static boolean rectEquals(@NonNull Rect r, int left, int top, int right, int bottom) {
return !(r.left != left || r.top != top || r.right != right || r.bottom != bottom);
}
Expand Down