Skip to content
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

Refactor adjustSpannableFontToFit to fix adjustsFontSizeToFit Text prop on Android #48915

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hrastnik
Copy link

Summary:

The adjustSpannableFontToFit method had a miscalculation that caused incorrect font sizes to be applied to Text elements on Android when adjustsFontSizeToFit was set to true. Specifically, the applied font size incorrectly depended on the initial fontSize of the Text component rather than properly adjusting to fit the container.

In the screenshot below, the left side illustrates the issue. Three Text components display the same text:
"This line must be the same size as the other ones with the same text."
Each of these components has a fontSize value that would render the text larger than its container. With the adjustsFontSizeToFit prop enabled, the font size should adjust so the text fits within a single line.

However, due to the incorrect calculation, the font size depended on the initially applied fontSize, leading to inconsistent behavior.

The issue has been fixed, as shown on the right side of the screenshot. Now, the font size adjusts correctly to ensure the text fits the container, regardless of the initial fontSize.

In addition to resolving the issue, a binary search algorithm has been implemented to improve performance when determining the appropriate font size.

text-issue

Changelog:

[ANDROID] [FIXED] - Fixed adjustsFontSizeToFit on Android sometimes applying wrong fontSize

Test Plan:

The screenshot above demonstrates the changes.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants