Skip to content

fix: cut out text on android - #99069

Merged
roryabraham merged 3 commits into
Expensify:mainfrom
software-mansion-labs:jakubstec/fix-android-cut-out-text
Aug 25, 2026
Merged

roryabraham merged 3 commits into
Expensify:mainfrom
software-mansion-labs:jakubstec/fix-android-cut-out-text

Conversation

@jakubstec

@jakubstec jakubstec commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Explanation of Change

On Android, text was losing its trailing word after a screen was re-mounted — Submit expenses to my employer rendered as Submit expenses to my, Your data is secure as Your data is — with no ellipsis and no change in row height. Reproducible on staging, never on production.

Root cause

TextLayoutManager sizes text layouts from ceil(Layout.getDesiredWidth(...)), which sums glyph advances only. On Android 15+ a line's visual glyph bounds can exceed that sum, so the layout ends up a fraction of a pixel narrower than the text actually needs. Line breaking is a step function, so that shortfall is enough to push a trailing word onto a second line inside a view whose height was computed for one line. That line is clipped, so the word simply disappears.

This is upstream #56402, still open.

Why it surfaced on 0.86 and not on 0.85.3

RN 0.86 turned Paint.LINEAR_TEXT_FLAG on for all Android text: upstream #56409 deleted the enableAndroidLinearText feature flag and made both of its call sites unconditional, and that flag defaulted to false in OSS. LINEAR_TEXT_FLAG disables font hinting, which shifts glyph advance widths by a fraction of a pixel and widens the advance-vs-visual-bounds gap — enough to push borderline strings over the wrapping threshold.

So the faulty measurement predates 0.86; 0.86 only made it reachable for many more strings.

Upstream has attempted this fix twice already. #54721 $ #53286 in December 2025 by calling setUseBoundsForWidth(true) on the final StaticLayout, gated behind fixTextClippingAndroid15useBoundsForWidth — which defaulted to false in OSS, so 0.85.3 never ran it either. RN 0.86.0 then removed the flag and both call sites after multiline and wrapping regressions, leaving only an unused setUseBoundsForWidthMethod reflection handle in TextLayoutManager. The bug was refiled as #56402.

Why it looked device-specific

Whether a given string lands on the wrong side of the wrapping boundary depends on the fractional residues of the layout, which come from screen width, density and font scale. On the reported Galaxy S25 FE the display density is overridden to 420 while the physical density is 450: at 450 dpi a 1080 px screen is exactly 384 dp, at 420 dpi it is 411.428571… dp, so every derived width carries a fraction. Devices left at their physical density mostly do not reproduce it, which is why most retests came back clean.

Worth calling out: #98507 (037+fix-stale-font-scale) was previously assumed to address #98499, but both issues still reproduced on 9.4.53-3 and 9.4.54-4, which already contained that patch. It addresses a different mechanism on the C++/Yoga side and is unrelated to this one.

The change

One new patch, react-native+0.86.0+040+fix-android15-text-clipping.patch, backporting upstream #57117. It adds a getDesiredWidth helper that, on API 35+, builds a probe StaticLayout with setUseBoundsForWidth(true) and returns max(advanceWidth, ceil(visualBoundsWidth)), so the desired width can never shrink below the previous value. Only the AT_MOST and UNDEFINED measure modes are affected: EXACTLY still uses the width Yoga supplies, and the final layout keeps the existing advance-based bounds mode. That narrowness is the whole point — it is what separates #57117 from the two attempts that were reverted.

The patch reuses the setUseBoundsForWidthMethod handle that 0.86 already ships unused. The upstream diff's TextLayoutManagerAbsoluteLayoutWithFractionalPixelTest.kt hunks are omitted, because the npm package does not ship ReactAndroid/src/test.

Trade-offs for review

  • Android & iOS - Workflows - Workflows icon is black #57117 is still open and has not been reviewed by Meta. It is documented in patches/react-native/details.md with a note to re-evaluate on the RN 0.87 upgrade and drop it once the fix lands upstream.
  • The probe costs one extra StaticLayout build per text measure on API 35+ in AT_MOST/UNDEFINED modes, which is a hot path.
  • Widening measured text can change wrapping app-wide on Android 15+. Since both earlier upstream attempts were reverted for wrapping regressions specifically, wrapping is what to focus regression testing on.

An earlier revision of this PR instead reverted LINEAR_TEXT_FLAG (040+restore-non-linear-text). That also fixed the reported cases and was verified on the reported device, but it only removed the amplifier — the advance-based measurement stayed wrong, so borderline strings could still wrap — and it was a deliberate deviation from upstream that we would have carried indefinitely. This backport fixes the measurement itself and can be dropped when upstream lands the fix.

Fixed Issues

$ #98499
$ #98690

Tests

Preconditions:

  • Android 16
  • those settings (type it in your console while your Android device is connected via usb)
adb shell wm size 1080x2340
  adb shell wm density 420
  adb shell settings put system font_scale 0.8

I

  1. Launch Expensify app.
  2. Log in with a new Gmail account.
  3. Tap Skip on work email step.
  4. Tap Submit expenses to my employer.
  5. Tap app back button.
  6. Verify, that "Submit expenses to my employer" is shown after navigating back.

II

  1. Launch Expensify app.
  2. Go to workspace settings > Expensify Card.
  3. Tap Issue new card.
  4. Tap app back button.
  5. Tap Issue new card.
  6. Verify, that "Your data is secure" is fully visible.
  • Verify that no errors appear in the JS console

Offline tests

N/A

QA Steps

Same as Tests.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ This PR is possibly changing native code and/or updating libraries, it may cause problems with HybridApp. Please check if any patch updates are required in the HybridApp repo and run an AdHoc build to verify that HybridApp will not break. Ask Contributor Plus for help if you are not sure how to handle this. ⚠️

@jakubstec

Copy link
Copy Markdown
Member Author

@MelvinBot could you please trigger the adhoc build workflow?

@MelvinBot

Copy link
Copy Markdown
Contributor

I can't trigger the adhoc build for you, and I want to be upfront about why rather than quietly work around it.

The testBuild.yml workflow is gated by validateBuildRequest.yml, which requires the person dispatching it to:

  1. Be an Expensify employee with write access, and
  2. Check REVIEWED_CODE — i.e. affirm "I reviewed this pull request and verified that it does not contain any malicious code."

That check is a deliberate security gate that runs before any of this PR's code is checked out or build secrets are exposed. For me to start the build I'd have to assert that malicious-code review on a human's behalf — which I can't honestly do — and it would also substitute my write access for the trusted employee the gate is meant to require.

How to get the build: an Expensify employee with write access (e.g. an assigned reviewer or internal engineer) should review this PR and run it themselves from the Build and deploy apps for testing workflow → Run workflow, setting:

  • APP_PULL_REQUEST_URL: https://github.com/Expensify/App/pull/99069
  • REVIEWED_CODE: ✅ checked

That takes just a moment once someone has looked over the diff.


view run

@github-actions

Copy link
Copy Markdown
Contributor

🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here.

@github-actions

This comment has been minimized.

@m-natarajan

Copy link
Copy Markdown

Not repro, Samsung Galaxy S25 FE / Android 16, Ad-hoc build

Screen_Recording_20260821_195828_Expensify.Adhoc.mp4
Screen_Recording_20260821_195850_Expensify.Adhoc.mp4

@jakubstec
jakubstec marked this pull request as ready for review August 21, 2026 12:28
@jakubstec
jakubstec requested a review from a team as a code owner August 21, 2026 12:28
@melvin-bot
melvin-bot Bot requested a review from suneox August 21, 2026 12:28
@melvin-bot

melvin-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown

@suneox Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@roryabraham

Copy link
Copy Markdown
Contributor

@jakubstec should we try patching in these two upstream PRs instead?

That way we can report upstream if they fix our issue or not.

@jakubstec

jakubstec commented Aug 24, 2026 •

Copy link
Copy Markdown
Member Author

@roryabraham

react/react-native#56864 - I think it shouldn't land here, as there are some problems regarding the code (react/react-native#56864 (comment)).

react/react-native#57117 - I've backported it and it fixes the bug on my local Android build, so I think it's worth replacing the current implementation (which reverts a 0.86 change to restore 0.85 text rendering) with a patch that's aligned with upstream and can be dropped in the next RN update. PR is updated with it.

Screen.Recording.2026-08-24.at.17.15.50.mov

I think we can retrigger adhoc's and test it, or go forward with it.

@roryabraham

Copy link
Copy Markdown
Contributor

@parasharrajat awaiting C+ review here

@roryabraham

Copy link
Copy Markdown
Contributor

Actually, nevermind. We'll just use an AdHoc build and have applause retest the linked issues

@github-actions

Copy link
Copy Markdown
Contributor

🚧 roryabraham has triggered a test Expensify/App build. You can view the workflow run here.

@github-actions

This comment has been minimized.

@roryabraham

Copy link
Copy Markdown
Contributor

@jakubstec

Copy link
Copy Markdown
Member Author

@roryabraham retests were done

#98499 (comment) - not repro
#98690 (comment) - not repro

I think we can merge it 😄

@roryabraham

Copy link
Copy Markdown
Contributor

agree

@roryabraham

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari

@roryabraham
roryabraham merged commit 8c5a3d5 into Expensify:main Aug 25, 2026
25 of 27 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚧 roryabraham has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify OSBotify mentioned this pull request Aug 25, 2026
63 tasks done
@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/roryabraham in version: 9.4.61-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/AndrewGable in version: 9.4.61-4 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

ivomiyashiro added a commit to ivomiyashiro/onerm that referenced this pull request Oct 5, 2026
…15+ (#85)

Refs #19

Fixes the text clipping raised in the F2 review (#83): on some launches
the «Abrir la hoja» button of the showcase rendered as «Abrir la».

## Cause (measured on the emulator)

A temporary `onTextLayout`/`onLayout` probe on the button labels showed
the gap:

| Label | Line width the text needs | Box the text got |
|---|---|---|
| Abrir la hoja | 90.7455 dp | **90.6667 dp** |
| Ver todos | 72.5372 dp | 72.7619 dp |
| Abrir el diálogo | 114.4985 dp | 114.6667 dp |

On Android 15+, React Native 0.86 measures text by the sum of glyph
advances (`TextLayoutManager`, `Layout.getDesiredWidth`) but the final
layout follows the visual glyph bounds, which can be a fraction of a
pixel wider.
- When the measured box lands just under that width, the last word wraps
to a second line that the box hides.
- It depends on the exact width and position, which is why it came and
went.
- Upstream: react/react-native#57117, still open. Expensify/App#99069
backports it as a native patch, but Expo uses the prebuilt React Native
Android, so a JS fix it is.

## Fix

- **`src/presentation/components/text.tsx`:** the app's `Text`. On
Android 15+ it adds half a physical pixel of end padding, added to any
padding the caller set.
  - Yoga rounds a text node's left edge down and its right edge up.
- With that padding the text area always ends up at least one pixel
wider than measured, which covers the sub-pixel difference.
  - Android 14 and iOS are untouched.
- **Every component and screen uses it.** A `no-restricted-imports` rule
(with its test) forbids importing React Native's `Text` in
`src/presentation` and `app/`.
- The comment points to the upstream PR so the workaround is removed
when React Native includes the fix.

## How it was tested

- [x] Unit tests:
- `text.test.tsx`: the slack on Android 35/36, merged with the caller's
padding, and none on Android 34 or iOS;
  - `app-text.test.ts`: the lint rule.
  
  Total: 896 passing.
- [x] Manual test on the `OneRM_API35` emulator (Android 15):
1. Before: on every cold start, «Abrir la hoja» rendered as «Abrir la».
2. After two cold starts: the label is complete, and the other screens
(tabs, cards, sync states) are unchanged.

## Checklist (Definition of Done)

- [x] CI passes (typecheck, lint with the layer rules, tests)
- [x] UI texts come from `presentation/strings`
- [x] No specification change
- [x] `CHANGELOG.md`: not user-visible yet (no real screen)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants