-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[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
[Fabric] Implement minimumFontScale in Text #14617
Conversation
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes @acoates-ms , you are right. I have raised an issue for that already. |
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:  After:  https://github.com/user-attachments/assets/fb9ae889-7d01-4317-a6e6-61e6b0708bc4 Reviewed By: NickGerleman Differential Revision: D73658489 Pulled By: cipolleschi fbshipit-source-id: 87ed27c0de2363e2ce0d908cc26670349586e7a6
Description
Type of Change
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:

After:

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