Skip to content

Conversation

@cortinico
Copy link
Contributor

Summary:
This enables the fixTextClippingAndroid15useBoundsForWidth for experimetnal
builds of React Native.

Differential Revision: D88487332

chrfalch and others added 2 commits December 5, 2025 06:53
…ebook#54721)

Summary:
Android 15 (API 35) changed TextView's default behavior to use visual glyph bounds for width calculation (useBoundsForWidth=true).  This causes text clipping for italic fonts and other typefaces where glyphs extend beyond their advance width:

https://developer.android.com/about/versions/15/behavior-changes-15

This PR uses a two-pass layout approach on Android 15+:

1. Create an unconstrained layout with setUseBoundsForWidth(true) to measure the actual visual bounds width
2. Create the final layout using the visual bounds width as layoutWidth

This ensures the container is sized correctly to accommodate the full visual extent of the text, preventing clipping while maintaining backwards compatibility with earlier Android versions.

Performance impact:
- On Android 14 and below: No change
- On Android 15+: Creates two StaticLayout instances instead of one for text with unconstrained or AT_MOST width.  This overhead is mitigated by React Native's text measurement caching in the C++ layer, which avoids redundant measurements.

Text with EXACTLY width mode is unaffected as it only requires a single layout pass.

Closes facebook#53286

Thanks a lot to intergalacticspacehighway for finding the root cause and creating a proof of concept fix.

## Changelog:

[ANDROID] [FIXED] - Fix text clipping on Android 15+ due to useBoundsForWidth change

Pull Request resolved: facebook#54721

Test Plan:
Run the tests from facebook#53286 to verify.

**Images from original issue:**

<img width="800" alt="image" src="https://github.com/user-attachments/assets/db6fa569-f6d6-4526-90ff-a3d71bfbb7c6" />

**With fix (with some additional text spans for testing):**

_Android 16_
<img width="220" alt="image" src="https://github.com/user-attachments/assets/43b7e648-a38f-4100-9186-a4efa14e3e04" />

_Android Pre 15_
<img width="220" alt="image" src="https://github.com/user-attachments/assets/75fb34cd-2455-439b-a12d-a2c15577008c" />

Reviewed By: javache

Differential Revision: D88001642

Pulled By: cortinico
Summary:
This enables the `fixTextClippingAndroid15useBoundsForWidth` for experimetnal
builds of React Native.

Differential Revision: D88487332
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 5, 2025
@meta-codesync
Copy link

meta-codesync bot commented Dec 5, 2025

@cortinico has exported this pull request. If you are a Meta employee, you can view the originating Diff in D88487332.

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. fb-exported meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants