-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Inverted descent/ascent Android prioritisation to match iOS lineHeight behaviour #16448
Closed
bartolkaruza
wants to merge
6
commits into
facebook:master
from
bartolkaruza:feature/fix-inconsistent-lineheight-android
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
80f15bf
Inverted descent/ascent prioritization to match iOS
6a2dbb1
fix ascent in case lineHeight is bigger than fontMetrics
6ac5133
revert fix to match style of initial implementation
5dc3294
add license header
b063523
Revert the committed change in behaviour from previous commit
c7e373e
fixed issue for large lineHeight and small lineHeight cases
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 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
89 changes: 89 additions & 0 deletions
89
ReactAndroid/src/test/java/com/facebook/react/views/text/CustomLineHeightSpanTest.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.facebook.react.views.text; | ||
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. This is missing the license header, mind adding this so we can land this change? |
||
|
||
import android.graphics.Paint; | ||
|
||
import static org.fest.assertions.api.Assertions.assertThat; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.powermock.core.classloader.annotations.PowerMockIgnore; | ||
import org.robolectric.RobolectricTestRunner; | ||
|
||
@RunWith(RobolectricTestRunner.class) | ||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "android.*"}) | ||
public class CustomLineHeightSpanTest { | ||
|
||
@Test | ||
public void shouldIncreaseAllMetricsProportionally() { | ||
CustomLineHeightSpan customLineHeightSpan = new CustomLineHeightSpan(22); | ||
Paint.FontMetricsInt fm = new Paint.FontMetricsInt(); | ||
fm.top = -10; | ||
fm.ascent = -5; | ||
fm.descent = 5; | ||
fm.bottom = 10; | ||
customLineHeightSpan.chooseHeight("Hi", 0, 2, 0, 0, fm); | ||
assertThat(fm.top).isEqualTo(-11); | ||
assertThat(fm.ascent).isEqualTo(-6); | ||
assertThat(fm.descent).isEqualTo(6); | ||
assertThat(fm.bottom).isEqualTo(11); | ||
} | ||
|
||
@Test | ||
public void shouldReduceTopFirst() { | ||
CustomLineHeightSpan customLineHeightSpan = new CustomLineHeightSpan(19); | ||
Paint.FontMetricsInt fm = new Paint.FontMetricsInt(); | ||
fm.top = -10; | ||
fm.ascent = -5; | ||
fm.descent = 5; | ||
fm.bottom = 10; | ||
customLineHeightSpan.chooseHeight("Hi", 0, 2, 0, 0, fm); | ||
assertThat(fm.top).isEqualTo(-9); | ||
assertThat(fm.ascent).isEqualTo(-5); | ||
assertThat(fm.descent).isEqualTo(5); | ||
assertThat(fm.bottom).isEqualTo(10); | ||
} | ||
|
||
@Test | ||
public void shouldReduceBottomSecond() { | ||
CustomLineHeightSpan customLineHeightSpan = new CustomLineHeightSpan(14); | ||
Paint.FontMetricsInt fm = new Paint.FontMetricsInt(); | ||
fm.top = -10; | ||
fm.ascent = -5; | ||
fm.descent = 5; | ||
fm.bottom = 10; | ||
customLineHeightSpan.chooseHeight("Hi", 0, 2, 0, 0, fm); | ||
assertThat(fm.top).isEqualTo(-5); | ||
assertThat(fm.ascent).isEqualTo(-5); | ||
assertThat(fm.descent).isEqualTo(5); | ||
assertThat(fm.bottom).isEqualTo(9); | ||
} | ||
|
||
@Test | ||
public void shouldReduceAscentThird() { | ||
CustomLineHeightSpan customLineHeightSpan = new CustomLineHeightSpan(9); | ||
Paint.FontMetricsInt fm = new Paint.FontMetricsInt(); | ||
fm.top = -10; | ||
fm.ascent = -5; | ||
fm.descent = 5; | ||
fm.bottom = 10; | ||
customLineHeightSpan.chooseHeight("Hi", 0, 2, 0, 0, fm); | ||
assertThat(fm.top).isEqualTo(-4); | ||
assertThat(fm.ascent).isEqualTo(-4); | ||
assertThat(fm.descent).isEqualTo(5); | ||
assertThat(fm.bottom).isEqualTo(5); | ||
} | ||
|
||
@Test | ||
public void shouldReduceDescentLast() { | ||
CustomLineHeightSpan customLineHeightSpan = new CustomLineHeightSpan(4); | ||
Paint.FontMetricsInt fm = new Paint.FontMetricsInt(); | ||
fm.top = -10; | ||
fm.ascent = -5; | ||
fm.descent = 5; | ||
fm.bottom = 10; | ||
customLineHeightSpan.chooseHeight("Hi", 0, 2, 0, 0, fm); | ||
assertThat(fm.top).isEqualTo(0); | ||
assertThat(fm.ascent).isEqualTo(0); | ||
assertThat(fm.descent).isEqualTo(4); | ||
assertThat(fm.bottom).isEqualTo(4); | ||
} | ||
} |
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.
Why are you using integers? This will cause rounding errors since aditional is an int and 2 is an int so anything that is not divisible by two will be rounded down. (See: #10712 (comment) )
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.
Hi, for us it has solved the problems in the design completely, but I see that there is still something wrong for your design case. Maybe you can open up a new issue for this and see if you can get the attention of other developers, linking to these issues, to get your specific case fixed. Even better to open a new issue, with a PR that fixes it.