Skip to content

Don't expose Text style spans in Android accessibility node text (#60226) - #60226

Merged
meta-codesync[bot] merged 1 commit into
react:mainfrom
cipolleschi:export-D130207069
Nov 25, 2026
Merged

meta-codesync[bot] merged 1 commit into
react:mainfrom
cipolleschi:export-D130207069

Conversation

@cipolleschi

@cipolleschi cipolleschi commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

ReactForegroundColorSpan and ReactBackgroundColorSpan now extend CharacterStyle, and ReactAbsoluteSizeSpan extends MetricAffectingSpan, instead of subclassing Android's built-in colour and size spans. They keep the same drawing and measurement behaviour and the existing colour and size getters, but no longer implement ParcelableSpan. Android therefore does not send these rendering-only spans to accessibility services.

This fixes screen readers announcing colour and size styling for both <Text> and <TextInput>, without copying accessibility text or filtering its spans. Link, text-to-speech and locale spans remain intact. Underlines and strike-throughs without an explicit decoration colour still use the coloured run, whether its foreground span comes from React Native or Android.

Changelog:
[Android][Fixed] - Prevent screen readers from announcing colour and size styling in <Text> and <TextInput>

Reviewed By: Abbondanzo

Differential Revision: D130207069

@meta-codesync

meta-codesync Bot commented Nov 23, 2026

Copy link
Copy Markdown

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

@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 Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Visual regression

No visual differences at 2c0eb8ab609c.

ios: no capture

@meta-codesync meta-codesync Bot changed the title Don't expose Text style spans in Android accessibility node text Don't expose Text style spans in Android accessibility node text (#60226) Nov 23, 2026
cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Nov 23, 2026
…ct#60226)

Summary:

On Android, the accessibility node text of a `<Text>` was the rendered `Spanned`, including the visual spans React Native attaches for rendering (foreground/background color, absolute size, typeface, line height, ...). Some screen readers announce these spans along with the text, e.g. "start color black, background color black, 48 pixels". The node text is now a plain copy that keeps only spans with accessibility meaning (`ClickableSpan`, including `URLSpan` and React Native link spans, plus `TtsSpan` and `LocaleSpan`). This applies to both `PreparedLayoutTextView` and `ReactTextView`. Keeping `ClickableSpan` preserves link semantics when the whole text is a single link. For `ReactTextView` the copy is built from the view's own text, so link activation still resolves the original clickable spans. Rendering, layout, hit-testing and inline link virtual views are unchanged.

Changelog:
[Android][Fixed] - Screen readers no longer announce `<Text>` styling (color, size) as part of its accessible text

Differential Revision: D130207069
@cipolleschi
cipolleschi force-pushed the export-D130207069 branch 2 times, most recently from 6df45e4 to 459b348 Compare November 24, 2026 14:38
cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Nov 24, 2026
…ct#60226)

Summary:

`ReactForegroundColorSpan` and `ReactBackgroundColorSpan` now extend `CharacterStyle`, and `ReactAbsoluteSizeSpan` extends `MetricAffectingSpan`, instead of subclassing Android's built-in colour and size spans. They keep the same drawing and measurement behaviour and the existing colour and size getters, but no longer implement `ParcelableSpan`. Android therefore does not send these rendering-only spans to accessibility services.

This fixes screen readers announcing colour and size styling for both `<Text>` and `<TextInput>`, without copying accessibility text or filtering its spans. Link, text-to-speech and locale spans remain intact.

Changelog:
[Android][Fixed] - Prevent screen readers from announcing colour and size styling in `<Text>` and `<TextInput>`

Differential Revision: D130207069

@Abbondanzo Abbondanzo 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.

…ct#60226)

Summary:

`ReactForegroundColorSpan` and `ReactBackgroundColorSpan` now extend `CharacterStyle`, and `ReactAbsoluteSizeSpan` extends `MetricAffectingSpan`, instead of subclassing Android's built-in colour and size spans. They keep the same drawing and measurement behaviour and the existing colour and size getters, but no longer implement `ParcelableSpan`. Android therefore does not send these rendering-only spans to accessibility services.

This fixes screen readers announcing colour and size styling for both `<Text>` and `<TextInput>`, without copying accessibility text or filtering its spans. Link, text-to-speech and locale spans remain intact. Underlines and strike-throughs without an explicit decoration colour still use the coloured run, whether its foreground span comes from React Native or Android.

Changelog:
[Android][Fixed] - Prevent screen readers from announcing colour and size styling in `<Text>` and `<TextInput>`

Reviewed By: Abbondanzo

Differential Revision: D130207069
@meta-codesync
meta-codesync Bot merged commit 3e26819 into react:main Nov 25, 2026
60 checks passed
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @cipolleschi in 3e26819

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

@react-native-bot react-native-bot added the Merged This PR has been merged. label Nov 25, 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. Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants