Skip to content

fix: paint Android text decorations when a text update keeps the view's frame - #58847

Merged
meta-codesync[bot] merged 1 commit into
react:mainfrom
tshmieldev:fix/android-text-decoration-null-layout
Nov 20, 2026
Merged

meta-codesync[bot] merged 1 commit into
react:mainfrom
tshmieldev:fix/android-text-decoration-null-layout

Conversation

@tshmieldev

@tshmieldev tshmieldev commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

This is #58579 by @MatiPl01, a fix for a bug I found. Mati is no longer at Software Mansion, so I'm picking this up from my fork. Thanks Mati!

Summary:

Since #56768 underline and strikethrough are painted by ReactTextView.onDraw through CanvasEffectSpans, and only when getLayout() is non-null. TextView.setText drops the Layout and rebuilds it in onMeasure, but Fabric measures a view only when its frame changed. A text update that keeps the frame (textDecorationLine or textDecorationColor changing on a text that keeps its size) therefore reaches onDraw without a Layout, the decorations are skipped and super.onDraw() paints plain text; they show up only once something else re-measures the view.

onDraw now rebuilds the Layout at the current size before painting the effects; TextView.onDraw would build one for the text anyway.

Changelog:

[ANDROID] [FIXED] - Draw text decorations after a text update that did not change the view's frame

Test Plan:

Android emulator API 34, RN 0.88.0-rc.1. With logging in onDraw, every frame-preserving update arrived as setText -> onDraw with getLayout() == null and no decoration painted, both for setState toggling textDecorationLine and for a Reanimated animation updating it every frame; the same update followed by a frame change painted it.

textDecorationLine cycling none / underline / line-through / underline line-through every 0.75 s, before and after:

before-after-android-textDecorationLine.mp4

Copilot AI balanced review requested due to automatic review settings October 5, 2026 10:21
@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 Oct 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@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 Oct 5, 2026
ReactTextView.onDraw paints CanvasEffectSpans (underline, strikethrough) only when
getLayout() is non-null. TextView drops its Layout in setText and rebuilds it in
onMeasure, and Fabric measures a view only when its frame changed, so a text state
update that keeps the frame (a decoration or color change on a text of the same
size) reaches onDraw with no Layout and the decorations are skipped until something
else re-measures the view. Rebuild the Layout at the current size before painting;
TextView.onDraw would build one for the plain text anyway.
@mdziubak

Copy link
Copy Markdown

We're hitting this in production on 0.88.0: swapping a Text's content without changing its size drops the underline on nested Text until something re-measures the view. We've been shipping this PR as a local patch and it fixes it for us.

Since it's a 0.88 regression from #56768, a review would be much appreciated so it can be picked into 0.88.x, like the related crash fixes #58366 and #59050 (picked for 0.88.1 in reactwg/react-native-releases#1456).

@meta-codesync

meta-codesync Bot commented Nov 2, 2026

Copy link
Copy Markdown

@Abbondanzo has imported this pull request. If you are a Meta employee, you can view this in D129144546.

@ogard

ogard commented Nov 12, 2026

Copy link
Copy Markdown

Another data point, from a production app rather than an animation: this reproduces on 0.87.1 with a plain colour change, no Reanimated involved.

Trigger: a <Text> with textDecorationLine: 'underline' whose color changes on press. The underline paints on first mount, disappears on the colour change, and never comes back until the view is recreated.

Environment: react-native 0.87.1, New Architecture, Android 16 (API 36), 1080×2400 @420dpi emulator.

Measured by sampling the underline row across the label width (317px-wide label):

state contiguous pixels on the underline row
first render 317 px, #595959
pressed (colour → #000000) 6 px — gone, glyphs recolour correctly
released (colour → #595959) 6 px — still gone

Every glyph row is byte-identical between the first frame and the released frame; only the two decoration rows change.

It is not specific to press. A Fast Refresh that changes only the component's style leaves the underline missing in the resting state as well, which matches this PR's "text update keeps the view's frame" framing.

Two things that may be useful:

  1. reactwg/react-native-releases#1456 describes the self-drawn decoration path (ReactUnderlineSpan / drawSpannedDecoration) as new in 0.88 via feat(android): honor textDecorationStyle on Text decorations #56768. Those classes are present in 0.87.1, and the repaint bug reproduces there, so the affected range looks wider than 0.88+. The crash in [Packager] Source maps do not seem to work in Chrome #1456 does appear to be 0.88-only — I could not reproduce it on 0.87.1: a label truncated by numberOfLines={1} with an underline drew a 931px decoration run with no exception.

  2. Setting textDecorationColor explicitly does not work around it — tested from a cold start, same result. The only workaround I found is forcing the Text to remount by changing its key when the colour changes, which repaints the decoration correctly in every state, disabled included.

Is there a plan to pick this into 0.88.x or 0.89? #58579 was closed in favour of this PR in October, and this is currently the only thing tracking the issue, so anyone on a released version has no fix available.

@mdziubak

Copy link
Copy Markdown

Thanks, you're right about the range, and my "0.88 regression" above was wrong. #56768 landed on 4 June and shipped in 0.87.0; TextDecorationStyle.kt, ReactUnderlineSpan.kt and CanvasEffectSpan.kt are byte-identical in 0.87.1 and 0.88.0, and ReactTextView.onDraw has the same getLayout() != null gate. So both bugs are 0.87+.

On the crash, I'd expect it on 0.87.1 too, just not with that repro. getPrimaryHorizontal throws only for an offset past getLineEnd(lastLine), and an ellipsized last line runs to the end of its paragraph. A one-line label underlined as a whole stays inside that, so nothing throws, but the run is measured over the hidden text: the 931 px on a 317 px label is the overrun #58366 clamps. It needs an underlined nested span in a later paragraph than the last visible line; ours were multi-paragraph descriptions with numberOfLines={3}.

textDecorationColor can't help: the decoration is skipped because onDraw has no Layout, not because of the colour. A new key works because the new view gets measured, and this PR covers the colour change the same way, since it's another setText that keeps the frame.

@javache javache left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

@Abbondanzo
Abbondanzo enabled auto-merge (squash) November 20, 2026 16:23
@meta-codesync
meta-codesync Bot merged commit 7b6e790 into react:main Nov 20, 2026
55 checks passed
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @tshmieldev in 7b6e790

When will my fix make it into a release? | How to file a pick request?

@mdziubak

Copy link
Copy Markdown

Thanks for landing this. To answer the question above: I've filed pick requests for 0.88 (reactwg/react-native-releases#1542) and 0.89 (reactwg/react-native-releases#1543). The commit applies cleanly to 0.87-stable too, so a 0.87 pick should be straightforward if someone on 0.87 requests 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. 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.

6 participants