Skip to content

[Fabric] Implement minimumFontScale in Text #14617

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

Merged
merged 6 commits into from
Apr 25, 2025

Conversation

anupriya13
Copy link
Contributor

@anupriya13 anupriya13 commented Apr 25, 2025

Description

Type of Change

  • New feature (non-breaking change which adds functionality)

Why

What is the motivation for this change? Add a few sentences describing the context and overall goals of the pull request's commits.

Resolves #13829

Related
facebook/react-native#50933
facebook/react-native#50934

What

What changes were made to the codebase to solve the bug, add the functionality, etc. that you specified above.
[Fabric] Implement minimumFontScale in Text

Refer https://github.com/facebook/react-native/blob/0ad9de86d14a63175029e036af297beaa3b6c743/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java#L88

Screenshots

Add any relevant screen captures here from before or after your changes.

Refer this for upstream changes facebook/react-native#50933

Before:
image

After:
image

Testing

minFontScale.mp4

Changelog

Should this change be included in the release notes: indicate yes or no
Yes

Add a brief summary of the change to use in the release notes for the next release.
[Fabric] Implement minimumFontScale in Text

Microsoft Reviewers: Open in CodeFlow

@anupriya13 anupriya13 marked this pull request as ready for review April 25, 2025 11:09
@anupriya13 anupriya13 requested a review from a team as a code owner April 25, 2025 11:09
@anupriya13 anupriya13 added API: Completion Area: Text New Architecture Broad category for issues that apply to the RN "new" architecture of Turbo Modules + Fabric Workstream: Component Parity Close the parity gap between RNW and RN for core RN components and their supporting APIs. labels Apr 25, 2025
@acoates-ms
Copy link
Contributor

While you are looking at this. I noticed that the adjustsFontSizeToFit seems to only account for width? -- In the Text RNTester page, there are buttons to modify the height of the text, which I assume is supposed to change the font size, but doesn't appear to?

@@ -231,8 +231,14 @@ void TextLayoutManager::GetTextLayout(

TextMeasurement::Attachments attachments;
if (paragraphAttributes.adjustsFontSizeToFit) {
auto minimumFontScale = 1.0f;
// Uncomment below part when minimumFontScale is available in ParagraphAttributes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an issue tracking this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see your PR in RN. Actually, I'm not sure how that would work.
I suspect adjustsFontSizeToFit can only work on single span text. Otherwise, how would we decide which span to scale?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, already raised PR and issue in react-native.

facebook/react-native#50933

facebook/react-native#50934

So in the doc https://reactnative.dev/docs/text#minimumfontscale-ios

  • it mentions only about font scale not size, minimumFontSize is a different property.

// TODO : changes for minimumFontScale prop can be added.

if (spTextLayout->GetFontSize() <= defaultMinFontSize) {
if (spTextLayout->GetFontSize() <= minimumFontScale) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add additional logic to ensure that the fontSize does not become negative when reducing it.

For example:

If fontSize is 0.9 , minimumFontScale is 0.5 and incase the text doesn't fit, the font size needs to be adjusted by subtracting 1.0, it would result in a negative value.

Ideally this case may not occur, Just letting you know though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the logic is above in commented code.. minimumFontScale would always be >= 0.01 and <= 1.0

https://reactnative.dev/docs/text#minimumfontscale-ios

Let me look more deeper if this can be optimised further

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vineethkuttan
Copy link
Contributor

While you are looking at this. I noticed that the adjustsFontSizeToFit seems to only account for width? -- In the Text RNTester page, there are buttons to modify the height of the text, which I assume is supposed to change the font size, but doesn't appear to?

Yes @acoates-ms , you are right. I have raised an issue for that already.

#14559

@anupriya13 anupriya13 merged commit a4e227e into microsoft:main Apr 25, 2025
59 checks passed
facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Apr 30, 2025
Summary:
Support minimumFontScale in paragraphAttributes

Resolves #50934

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[GENERAL] [ADDED] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
Support minimumFontScale in paragraphAttributes

Pull Request resolved: #50933

Test Plan:
Tested via this code here: microsoft/react-native-windows#14617

Before:
![image](https://github.com/user-attachments/assets/76b94aa8-228b-4a7e-9ec0-c366c7bf38ac)

After:
![image](https://github.com/user-attachments/assets/f9fbf8c2-9776-429f-8605-5663f9c7b7c9)

https://github.com/user-attachments/assets/fb9ae889-7d01-4317-a6e6-61e6b0708bc4

Reviewed By: NickGerleman

Differential Revision: D73658489

Pulled By: cipolleschi

fbshipit-source-id: 87ed27c0de2363e2ce0d908cc26670349586e7a6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API: Completion Area: Text New Architecture Broad category for issues that apply to the RN "new" architecture of Turbo Modules + Fabric Workstream: Component Parity Close the parity gap between RNW and RN for core RN components and their supporting APIs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement minimumFontScale property for Text in Fabric
3 participants