-
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
adjustsFontSizeToFit not working #20906
Comments
This is still happening in 0.56 and 0.57, adjustsFontSizeToFit works fine on iOS but does nothing on Android |
Yep, still happening on 0.57. Is there any workaround? |
Extremely hacky and extremely no-no. Full combat solution until I find something better I created a text component that for Ios basically returns Text and in android returns a Text with this onLayout thing on top of it. Please I can't encourage anyone enough to not use this in their projects, and find a real solution but if you are in a hurry this patched my problem
This is not a fix of course 1.7 is a random number that seems to fit my project properly in all resolutions I have tested so far, onLayout fires after render so there is a bit of a visual glitch etc... etc... I will try to find a decent fix if it doesn't get fixed eventually but for now, I'm going with this shameful hack. |
I can confirm that this is still happening. @pabloga265 I think the above might work better if you can use Dimensions to determine screen width and calculate the correct fontSize before the first render. |
@pabloga265 I took your code and took out the constants. TLDR: you're code breaks for some font-families, mine should fix that. See below. Basically, I took figured if we have to render the text twice, we might as well get some useful information, so I'm rendering the first pass at fontSize 5 (if we start out too small it gets less accurate because the letters are so small). I did some testing and found the following:
We can use also use this equation to calculate an appropriate fontSize to get the desired width of the text element. I was also running into some problems with multiple adjustments so I created a switch that would only allow it to be adjusted one time. I also made sure to use the smaller of the two fontSize values, as your code adjusts no matter what, while the adjustsFontSizeToFit property only shrinks text that is clipping.
|
If you want to use a value of "numberOfLines" >= 1 you have to modify a little this component, because how it's written it will always calculate a fontSize that will fit in just 1 line. I needed a numberOfLines = 2. changing
in
and
in
did the trick for me. |
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions. |
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information. |
Environment
Description
Since 0.54.x,
adjustsFontSizeToFit
option inText
has not been working. It worked as expected on 0.53.xReproducible Demo
The text was updated successfully, but these errors were encountered: