fix: app‑extension‑safe guard and fallback in RCTFontSizeMultiplier()#54952
fix: app‑extension‑safe guard and fallback in RCTFontSizeMultiplier()#54952SmartArray wants to merge 1 commit into
Conversation
… so it returns a positive default (1.0) when UIApplication (or preferred content size category) is unavailable + clamp
|
Hi @SmartArray! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
This PR is stale because it has been open for 180 days with no activity. It will be closed in 7 days unless you comment on it or remove the "Stale" label. |
Summary:
This change fixes a text rendering issue on iOS when using the new architecture (Fabric), most notably in app extensions on iOS.
While migrating an app extension to the new architecture, all the labels in our app became invisible. A bare
<Text>component initially appeared to work, which made the issue hard to track down.Text rendered correctly with default styles, but once
fontSizeorfontFamilywas applied, text would ignore sizing or become invisible. Because text was still visible by default, the problem did not immediately appear to be related to font scaling or measurement, so it took me WEEKS to understand.Please check out the issue I created almost a month ago: #54642
After deeper investigation into Fabric text measurement and after using 100 different breakpoint attempts, the root cause turned out to be an invalid font size multiplier coming from
RCTFontSizeMultiplier()when running inside an app extension.In app extensions,
RCTSharedApplication()can (or will!) returnnil. When that happened,RCTFontSizeMultiplier()could return an invalid value, which later caused Fabric text measurement to produce zero-height paragraphs. As a result,<Text>components could ignorefontSizeor become invisible whenfontFamilywas set.The fix makes
RCTFontSizeMultiplier()app-extension-safe by returning a positive default (1.0) whenUIApplicationor the preferred content size category is unavailable, and by clamping invalid values.Related issue:
#54642
Changelog:
[IOS] [FIXED] - Make
RCTFontSizeMultiplier()app-extension-safe by adding a default fallback and clamping invalid values to a positive number, such that fonts are never scaled down to zeroTest Plan:
<Text>rendering correctly by default but ignoringfontSizeor becoming invisible whenfontFamilywas appliedRCTFontSizeMultiplier()fontSizeTo test this fix the repro that I provided in the issue above can easily be used.
First run the code without the commit (observe the bad outcome) then run it with the commit (observe the good outcome)