-
Notifications
You must be signed in to change notification settings - Fork 24k
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
Fix single line text not fully rendered #41770
base: main
Are you sure you want to change the base?
Conversation
Base commit: 44f9371 |
thanks a lot @dmytrorykun. When you do plan to merge this PR? |
Thanks @dmytrorykun, could we land this PR? Thanks |
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.
Forwarding an internal comment:
- The premise that we need to use the simpler
BoringLayout
to get the max width text could take without breaking seems strange.StaticLayout
has options to not line break (maybe we should be setting that for single line instead?)- This will leave the bug when there is a unicode, RTL, or other complicated character.
- This code is duplicated into Fabric (
TextLayoutManager.java
and now some more variants), and this code does not change anything there. If has same issue, we introduce new Fabric regression to Paper. If it isn't there, it has a different solution probably.
// StaticLayout#getLineWidth does not work with single-line text. | ||
boolean overrideTextBreakStrategySingleLine = | ||
boring == null | ||
? false | ||
: mNumberOfLines == 1 && !mAdjustsFontSizeToFit && boring.width > width; |
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.
What about
// StaticLayout#getLineWidth does not work with single-line text. | |
boolean overrideTextBreakStrategySingleLine = | |
boring == null | |
? false | |
: mNumberOfLines == 1 && !mAdjustsFontSizeToFit && boring.width > width; | |
// StaticLayout#getLineWidth does not work with single-line text. | |
boolean overrideTextBreakStrategySingleLine = | |
boring != null && mNumberOfLines == 1 && !mAdjustsFontSizeToFit && boring.width > width; |
and we avoid the ternary?
This reverts commit 0da2607.
calculatedLineCount == 1 does not mean that text is single line, only that it has 1 line, but if adds more images, they need to wrap on second line.
Thanks for the code review.
I updated the solution to use StaticLayout instead of BoringLayout.
The new solution supports not boring text, emoji, RTL, etc (test cases).
I added the Fabric implementation and included tests of the functionalities on Fabric and Paper. |
@dmytrorykun has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@fabOnReact there is a new comment in the corresponding issue #39722 |
@realsoelynn this might be related to the measurement issues you are working on. |
Summary:
Please re-state the problem that we are trying to solve in this issue.
ReactTextShadowNode#measure calculates the wrong width for single line Text that has an ellipsis (fixes #39722).
What is the root cause of that problem?
React Native sets the wrong width in the ReactTextShadowNode onMeasure function for single line Text, demonstrated with:
The android minimum reproducible example:
onMeasure
). It is not the expected/intended behavior on Android.What changes do you think we should make in order to solve the problem?
Set the correct width for single-line Text in the measure callback.
Changelog:
[ANDROID] [FIXED] - Fix single line text not fully rendered
Test Plan: