-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[Internal] Make letter spacing dependent on text size in CollapsingTextHelper #4640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pubiqq
wants to merge
1
commit into
material-components:master
Choose a base branch
from
pubiqq:internal/adjust-letter-spacing-with-text-size-in-cth
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
| } | ||
|
|
||
| // Calculates paint parameters for shadow layer. | ||
| currentShadowRadius = lerp(expandedShadowRadius, collapsedShadowRadius, fraction, null); | ||
| currentShadowDx = lerp(expandedShadowDx, collapsedShadowDx, fraction, null); | ||
|
|
@@ -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 | ||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No longer needed if letter spacing lerping is replaced inside |
||
| float textSizeRatio = collapsedTextSize / expandedTextSize; | ||
| // This is the size of the expanded bounds when it is scaled to match the | ||
| // collapsed text size | ||
|
|
@@ -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() { | ||
|
|
@@ -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); | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
elsestatement ofif (fadeModeEnabled)?