-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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: apply font size to ReactTextView to fix ellipsis cut #37248
Conversation
Base commit: a310217 |
Could you add the repro for this issue to RNTester as well and show before/after in your video? |
...ges/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java
Outdated
Show resolved
Hide resolved
@javache Updated the PR description with the before/after of the repro example, also added the repro to rn-tester |
c13e8a8
to
9c7d14d
Compare
public void setFontSize(float fontSize) { | ||
mFontSize = | ||
mAdjustsFontSizeToFit | ||
? (float) Math.ceil(PixelUtil.toPixelFromSP(fontSize)) |
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 we using SP here?
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.
I ended up basing this code in the snippet from TextAttributes.java.
Should it be removed?
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.
It looks like the code there is using it in conjunction with allowFontScaling
to find font size. Not anything with adjustFontSizeToFit
.
Can we reuse getEffectiveFontSize()
? E.g. have the view manager or ShadowNode call setTextSize()
?
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.
Oh, you're right!
Can we reuse getEffectiveFontSize()?
Not directly because ReactTextView
does not use TextAttributes
. We could extract that logic and use a static method, but it would require passing mMaxFontSizeMultiplier
and mAllowFontScaling
(or just use defaults), which I'm not sure it would be the best, I'm not really sure what's the implications of this.
We could just remove the adjust logic and just use toPixelFromDIP
, would it be best?
I think it should be technically safe to set base test size on the container. We do that now with TextInput now as well for different reasons. Though ideally we'd fix this so that everything lays out consistently. I tried to grep through some of the code for this at https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/widget/TextView.java out of curiosity. I wonder, do we need to be calling |
You mean, should we force the ellipsize call on RN size? I don't think it would make any difference. When I opened the bug on Android tracker - https://issuetracker.google.com/issues/278044456 - I used a similar setup of using a Spannable and calling the setEllipsize on the TextView. It seems like the total size of the spannable is not being taken into consideration when the ellipsis are being applied. I didn't go any deeper than that by debugging the Android codebase, so I'm not sure where the problem is. |
Ah, I missed that the cutoff happened in an out of the box I think the approach of setting metrics on the If you look at |
Perhaps it makes sense to make it similar to what was made in ReactEditText and apply attributes like Update: checked and indeed it causes the same problem with the ellipsis when some letterSpacing values are applied. If letterSpacing is applied to the TextView, the problem is solved. So, it seems like the solution in this PR is incomplete. The question is what properties should be applied to the TextView: all the same ones that are now being applied to the
Yeah, I noticed that, I'm also investigating a bug related to line height in |
I applied the fix for letter spacing, basically a similar solution to what's currently in |
@NickGerleman has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@NickGerleman merged this pull request in 6d24ee1. |
Summary:
This PR aims to fix #36350. In certain cases, when the text is cut due to
numberOfLines
, the ellipsis appear cut. This is actually an Android bug, which was reported on their side here.This PR contains a workaround for it by applying the text size to the TextView directly instead of just the Spannable inside it. This solves all problems and it seems like it does not cause any regressions.
Changelog:
[ANDROID] [FIXED] - Fix ellipsis being cut on certain font sizes
Test Plan:
One piece of code where the problem could be replicated would be the one below, running on an Pixel 3A emulator.
RN-tester of the problem:
RN-Tester comparison:
main.mp4
fix.mp4