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

fix: Text cut off issues when adjusting text size and font weight in system settings #39581

Closed
wants to merge 1 commit into from

Conversation

jcdhlzq
Copy link
Contributor

@jcdhlzq jcdhlzq commented Sep 21, 2023

Fix Text cut off issues when adjusting text size and font weight in system settings.

Summary:

This pr fixed the problem that can be reproduced with the snack on Xiaomi devices with MIUI13 and MIUI14. The problem is shown as the image below: the number "999" is cut off and only "99" is rendered.
text-cutoff-when-scaling-miui14

The problem is produced with setting font scaling in system settings like the image below shows.

settings

This text cut off case can be avoided by setting allowFontScaling to false. But this pr can make it no matter what value allowFontScaling is set.

The root cause of this case, according to MIUI developers, is that Misans typeface, as a variable font which will adjust the weight of different font axes with different font size, gets different widths when Text is measured and drawn for a bug in the framework of MIUI rom. They will fix this bug in next version while this pr fixed it in old versions.

Changelog:

[ANDROID][FIXED]-Fix Text cut off issues when adjusting text size and font weight in system settings.

Test Plan:

The effect after fixed is shown in the image below.

fixed

@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 Sep 21, 2023
@analysis-bot
Copy link

analysis-bot commented Sep 21, 2023

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,337,034 -30
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 9,575,129 -230
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: 8c5340f
Branch: main

@github-actions
Copy link

github-actions bot commented Sep 21, 2023

Warnings
⚠️ One hour and a half have passed and the E2E jobs haven't finished yet.

Generated by 🚫 dangerJS against 1af2486

@facebook-github-bot
Copy link
Contributor

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

@ryancat
Copy link
Contributor

ryancat commented Sep 21, 2023

It would be helpful if we could have a test in RNTester for this. Does this only reproduce in Xiaomi devices?

@jcdhlzq
Copy link
Contributor Author

jcdhlzq commented Sep 22, 2023

It would be helpful if we could have a test in RNTester for this. Does this only reproduce in Xiaomi devices?

Yes, only Xiaomi devices with MIUI13 and MIUI14 devices are reported from users in product environment until now.

As for the test, there is a snack demo in this pr's summary, demo

@jcdhlzq
Copy link
Contributor Author

jcdhlzq commented Sep 22, 2023

It would be helpful if we could have a test in RNTester for this. Does this only reproduce in Xiaomi devices?

Some test cases are added in a seperate pr: #39594

Copy link
Contributor

@NickGerleman NickGerleman left a comment

Choose a reason for hiding this comment

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

Could you help point out which change here leads to the new behavior?

@jcdhlzq
Copy link
Contributor Author

jcdhlzq commented Sep 22, 2023

@ryancat One error happened on CircleCI, but I can not rerun it.

@jcdhlzq
Copy link
Contributor Author

jcdhlzq commented Sep 24, 2023

Could you help point out which change here leads to the new behavior?

The key change is to set text size by calling TextView#setTextSize(). That will actually set text size to mTextPaint of TextView, which will be used as an input when measure&draw.

@facebook-github-bot
Copy link
Contributor

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

@facebook-github-bot
Copy link
Contributor

@ryancat merged this pull request in babbc3e.

ShevO27 pushed a commit to ShevO27/react-native that referenced this pull request Sep 26, 2023
…system settings (facebook#39581)

Summary:
Fix Text cut off issues when adjusting text size and font weight in system settings.

This pr fixed the problem that can be reproduced with the [snack](https://snack.expo.dev/fl5DSrLBJ) on Xiaomi devices with MIUI13 and MIUI14. The problem is shown as the image below: the number "999" is cut off and only "99" is rendered.
<img src="https://github.com/facebook/react-native/assets/23273745/64269ced-4060-4ab5-8233-8199e4f2acbd" width="20%" height="20%" alt="text-cutoff-when-scaling-miui14" />

The problem is produced with setting font scaling in system settings like the image below shows.

<img src="https://github.com/facebook/react-native/assets/23273745/c31d1bf2-d038-4536-b1a4-509050f2aa7c" width="20%" height="20%" alt="settings" />

This text cut off case can be avoided by setting [`allowFontScaling`](https://reactnative.cn/docs/text#allowfontscaling) to false. But this pr can make it no matter what value `allowFontScaling` is set.

The root cause of this case, according to MIUI developers, is that Misans typeface, as a variable font which will adjust the weight of different font axes with different font size, gets different widths when Text is measured and drawn for a bug in the framework of MIUI rom. They will fix this bug in next version while this pr fixed it in old versions.

## Changelog:

[ANDROID][FIXED]-Fix Text cut off issues when adjusting text size and font weight in system settings.

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

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

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

Pull Request resolved: facebook#39581

Test Plan:
The effect after fixed is shown in the image below.

<img src="https://github.com/facebook/react-native/assets/23273745/1f93f47f-5cdf-4ee1-934a-6cb3b04309ea" width="20%" height="20%" alt="fixed" />

Reviewed By: NickGerleman

Differential Revision: D49509633

Pulled By: ryancat

fbshipit-source-id: fd93f14bdbced8026a45dc9e0299465962433de5
@facebook-github-bot
Copy link
Contributor

This pull request has been reverted by 36057da.

@jcdhlzq
Copy link
Contributor Author

jcdhlzq commented Sep 27, 2023

@ryancat One error happened on CircleCI, but I can not rerun it.

@ryancat This pr is reverted, what's the reason and what can I do to proceed?

@NickGerleman
Copy link
Contributor

It ended up causing a few hundred test failures due to NPEs. I will see if I can dig up the stack trace soon.

@NickGerleman
Copy link
Contributor

09-26 12:49:01.153  4183  4183 E AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.facebook.react.views.text.TextAttributes.setLetterSpacing(float)' on a null object reference
09-26 12:49:01.153  4183  4183 E AndroidRuntime: 	at com.facebook.react.views.text.ReactTextView.setLetterSpacing(ReactTextView.java:668)
09-26 12:49:01.153  4183  4183 E AndroidRuntime: 	at android.widget.TextView.<init>(TextView.java:1411)
09-26 12:49:01.153  4183  4183 E AndroidRuntime: 	at android.widget.TextView.<init>(TextView.java:704)
09-26 12:49:01.153  4183  4183 E AndroidRuntime: 	at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:113)
09-26 12:49:01.153  4183  4183 E AndroidRuntime: 	at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:108)
09-26 12:49:01.153  4183  4183 E AndroidRuntime: 	at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:104)
09-26 12:49:01.153  4183  4183 E AndroidRuntime: 	at com.facebook.react.views.text.ReactTextView.<init>(ReactTextView.java:75)
09-26 12:49:01.153  4183  4183 E AndroidRuntime: 	at com.facebook.react.views.text.ReactTextViewManager.createViewInstance(ReactTextViewManager.java:82)
09-26 12:49:01.153  4183  4183 E AndroidRuntime: 	at com.facebook.react.views.text.ReactTextViewManager.createViewInstance(ReactTextViewManager.java:36)
09-26 12:49:01.153  4183  4183 E AndroidRuntime: 	at com.facebook.react.uimanager.ViewManager.createViewInstance(ViewManager.java:176)

@jcdhlzq
Copy link
Contributor Author

jcdhlzq commented Sep 29, 2023

09-26 12:49:01.153  4183  4183 E AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.facebook.react.views.text.TextAttributes.setLetterSpacing(float)' on a null object reference
09-26 12:49:01.153  4183  4183 E AndroidRuntime: 	at com.facebook.react.views.text.ReactTextView.setLetterSpacing(ReactTextView.java:668)
09-26 12:49:01.153  4183  4183 E AndroidRuntime: 	at android.widget.TextView.<init>(TextView.java:1411)
09-26 12:49:01.153  4183  4183 E AndroidRuntime: 	at android.widget.TextView.<init>(TextView.java:704)
09-26 12:49:01.153  4183  4183 E AndroidRuntime: 	at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:113)
09-26 12:49:01.153  4183  4183 E AndroidRuntime: 	at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:108)
09-26 12:49:01.153  4183  4183 E AndroidRuntime: 	at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:104)
09-26 12:49:01.153  4183  4183 E AndroidRuntime: 	at com.facebook.react.views.text.ReactTextView.<init>(ReactTextView.java:75)
09-26 12:49:01.153  4183  4183 E AndroidRuntime: 	at com.facebook.react.views.text.ReactTextViewManager.createViewInstance(ReactTextViewManager.java:82)
09-26 12:49:01.153  4183  4183 E AndroidRuntime: 	at com.facebook.react.views.text.ReactTextViewManager.createViewInstance(ReactTextViewManager.java:36)
09-26 12:49:01.153  4183  4183 E AndroidRuntime: 	at com.facebook.react.uimanager.ViewManager.createViewInstance(ViewManager.java:176)

ok, I fixed this npe in latest jcdhlzq:fix/text-cutoff-when-scaling.

@jcdhlzq
Copy link
Contributor Author

jcdhlzq commented Sep 29, 2023

It seems that this pr cannot be reopened, so I make a new one #39711 @NickGerleman @ryancat

@jcdhlzq
Copy link
Contributor Author

jcdhlzq commented Oct 9, 2023

It ended up causing a few hundred test failures due to NPEs. I will see if I can dig up the stack trace soon.

Hi, @ryancat

The NPE is caused by overriding setLetterSpacing which is called in super constructor. I've renamed it with setLetterSpacingAttr in new PR #39711 .

And all checks have passed in #39711. Shall we proceed with it?

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. Merged This PR has been merged. Reverted 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.

5 participants