Skip to content

fix(android): clamp text decoration offsets to truncated layout - #58366

Open
lazerg wants to merge 1 commit into
react:mainfrom
lazerg:fix/issue-58356-clamp-decoration-offsets
Open

fix(android): clamp text decoration offsets to truncated layout#58366
lazerg wants to merge 1 commit into
react:mainfrom
lazerg:fix/issue-58356-clamp-decoration-offsets

Conversation

@lazerg

@lazerg lazerg commented Sep 6, 2026

Copy link
Copy Markdown

Summary:

On Android, a Text with numberOfLines can crash when a nested Text has textDecorationLine: 'underline' or 'line-through' and the decorated span starts or ends past what the truncated layout actually rendered. drawSpannedDecoration() reads start/end from the full, untruncated Spanned text and passes them straight to Layout.getPrimaryHorizontal(), which throws IndexOutOfBoundsException once numberOfLines cuts the layout shorter than the span.

This clamps both offsets to the last position the truncated (and possibly tail-ellipsized) layout can actually resolve before using them, so a partially hidden span draws its decoration up to the visible boundary and a fully hidden span draws nothing, instead of crashing.

Changelog:

[ANDROID] [FIXED] - Fix crash drawing text decoration (underline/strikethrough) when a nested Text's span extends past a numberOfLines-truncated layout

Test Plan:

Added two regression tests in TextDecorationStyleTest: both build a single-line, tail-ellipsized StaticLayout and confirm they throw IndexOutOfBoundsException against the pre-fix code. With the fix, one asserts the decoration line is drawn clamped to the visible boundary for a span that starts visible and runs past it, and the other asserts a span that starts entirely past the visible boundary draws a zero-length (invisible) line instead of crashing.

Fixes #58356

@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 Sep 6, 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 Sep 6, 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.

[Android][0.87.1] numberOfLines crashes when a decorated nested Text range is outside the truncated layout

1 participant