react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Fix `adjustsFontSizeToFit` for strings with a single character

Open j-piasecki opened this issue 1 year ago • 3 comments

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)
android_old android_new ios_old ios_new

j-piasecki avatar Oct 17 '24 08:10 j-piasecki

Let's make sure the CI is green before we import this 👍

cortinico avatar Oct 17 '24 16:10 cortinico

Fixes the bug

itsramiel avatar Oct 19 '24 07:10 itsramiel

@cortinico has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Oct 20 '24 12:10 facebook-github-bot

(Apologise for the late review @j-piasecki)

cortinico avatar Nov 06 '24 20:11 cortinico

@cortinico has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Nov 07 '24 15:11 facebook-github-bot

@NickGerleman has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Dec 06 '24 13:12 facebook-github-bot

@NickGerleman merged this pull request in facebook/react-native@47822e90480d61e197a3f223e088ee88a0f38ad7.

facebook-github-bot avatar Dec 09 '24 18:12 facebook-github-bot

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?

react-native-bot avatar Dec 09 '24 18:12 react-native-bot