Skip to content

Fix RTL start-side text clipping on Android 15+ - #58073

Open
ayush-singh-0601 wants to merge 1 commit into
react:mainfrom
ayush-singh-0601:fix/android-rtl-text-start-overhang
Open

Fix RTL start-side text clipping on Android 15+#58073
ayush-singh-0601 wants to merge 1 commit into
react:mainfrom
ayush-singh-0601:fix/android-rtl-text-start-overhang

Conversation

@ayush-singh-0601

Copy link
Copy Markdown

Summary:

On Android 15+, Arabic glyphs whose ink sticks out past the advance box (alef-madda, alef-wasla, lam-alef) get clipped at the start of an RTL line. Mid-line instances render fine, and iOS is unaffected. That's #58064.

Android already has APIs for this exact case:

  • StaticLayout.Builder.setUseBoundsForWidth(true)
  • StaticLayout.Builder.setShiftDrawingOffsetForStartOverhang(true)

TextLayoutManager.buildLayout() is the only place we construct StaticLayouts, and it wasn't calling either one. There was even a leftover reflection handle for setUseBoundsForWidth with zero call sites.

This wires those setters up:

  • Fabric / prepared text: set them on StaticLayout.Builder before build().
  • Paper: set the matching TextView methods from ReactTextView.initView(), because Paper still lets TextView make its own layout.

I used reflection plus AndroidVersion.VERSION_CODE_VANILLA_ICE_CREAM instead of calling the methods directly. Some internal targets still compile against SDK 34, which is why that unused handle existed in the first place.

I did not bring back the two-pass visual-bounds measurement from #54721 / #8347cc4. That path grew AT_MOST/UNDEFINED layouts and was later removed after wrapping regressions. Full-width (EXACTLY) RTL paragraphs never went through it anyway — which is the repro in this issue.

setUseBoundsForWidth(true) can still change wrapping a little for glyphs whose visual bounds are wider than their advances. That's the same tradeoff Android's own TextView made on API 35. If you'd rather have a kill switch, I'm happy to put this behind a feature flag.

Changelog:

[ANDROID] [FIXED] - Fix RTL Arabic start-side glyph clipping on Android 15+

Test Plan:

Added Robolectric coverage in TextLayoutManagerStartOverhangTest:

  • API 33: RTL Arabic text still builds a layout
  • API 35: StaticLayout.Builder exposes the start-overhang setters
  • API 35: an EXACTLY-width layout has useBoundsForWidth and shiftDrawingOffsetForStartOverhang enabled
  • API 35: TextView gets the same setters (Paper path)

I wasn't able to run ./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest locally — this checkout doesn't have Yarn autolink set up, and the machine only has android-36.1 installed (RN currently compiles against 37). I also haven't visually re-checked the clip on an Android 15/16 device against this branch.

The issue has a complete repro: https://github.com/muhasabahhub/android-react-native-arabic

If someone can run that repro on this branch, that's the real visual confirmation. CI should still run the new unit tests.

Wire StaticLayout.Builder.setUseBoundsForWidth and
setShiftDrawingOffsetForStartOverhang through reflection so Arabic
glyphs that overhang their advance box are drawn at RTL line starts
instead of clipped. Apply the same TextView setters for Paper.

Fixes react#58064
@meta-cla

meta-cla Bot commented Aug 22, 2026

Copy link
Copy Markdown

Hi @ayush-singh-0601!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@ayush-singh-0601

Copy link
Copy Markdown
Author

please suggest me any changes which i have to make if there is any you would suggest

@meta-cla

meta-cla Bot commented Aug 22, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@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 Aug 22, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Aug 22, 2026
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. 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.

1 participant