Fix `adjustsFontSizeToFit` for strings with a single character
Summary:
Fixes https://github.com/facebook/react-native/issues/47045
On Android adjustsFontSizeToFit relies on two metrics:
- Text with line breaks results in more lines than
maximumNumberOfLines - The overall height of the text is larger than the available height
None of these two was fulfilled when a single-character string had a higher width than the available one (a single character will not be broken into multiple lines). This PR adds exactly that as a third option to trigger the scaling algorithm - a single-character string that has a higher width than the available one.
On iOS adjustsFontSizeToFit relies on truncatedGlyphRangeInLineFragmentForGlyphAtIndex which seems to be returning NSNotFound when a single-character sting gets truncated. Similarly to Android, this PR adds an additional check to make sure that single-character strings actually fit inside the container.
Changelog:
[GENERAL] [FIXED] - Fixed adjustsFontSizeToFit not working for text with a single character
Test Plan:
Tested on the code from the issue:
| Android (old arch) | Android (new arch) | iOS (old arch) | iOS (new arch) |
|---|---|---|---|
Let's make sure the CI is green before we import this 👍
Fixes the bug
@cortinico has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
(Apologise for the late review @j-piasecki)
@cortinico has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
@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 facebook/react-native@47822e90480d61e197a3f223e088ee88a0f38ad7.
This pull request was successfully merged by @j-piasecki in 47822e90480d61e197a3f223e088ee88a0f38ad7
When will my fix make it into a release? | How to file a pick request?