Skip to content

Measure text lines for onTextLayout (#60336) - #60336

Merged
meta-codesync[bot] merged 1 commit into
react:mainfrom
markv:export-D134743317
Nov 30, 2026
Merged

meta-codesync[bot] merged 1 commit into
react:mainfrom
markv:export-D134743317

Conversation

@markv

@markv markv commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Fantom didn't deliver onTextLayout: the platform-agnostic C++ TextLayoutManager had no measureLines, so ParagraphShadowNode only logged a warning.

This adds a virtual measureLines to that TextLayoutManager, whose base implementation returns no lines. Fantom's FantomTextLayoutManager overrides it with the layout it paints screenshots with, so onTextLayout reports the lines Fantom draws.

  • Text cut by numberOfLines ends with a tail ellipsis in the reported lines and the screenshot, except after an inline view or emoji on the last line.
  • Selectable text is now painted, and baseline alignment uses the measured lines.
  • Other users of the C++ TextLayoutManager measure no lines: they no longer log the warning and still send no onTextLayout event.

Changelog: [Internal]

Reviewed By: rubennorte

Differential Revision: D134743317

@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 27, 2026
@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Nov 27, 2026
@markv
markv force-pushed the export-D134743317 branch from 60addfa to 6cc04ed Compare November 27, 2026 16:36

@rubennorte rubennorte left a comment

Copy link
Copy Markdown
Member

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.

@meta-codesync

meta-codesync Bot commented Nov 27, 2026

Copy link
Copy Markdown

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

Summary:
Pull Request resolved: react#60336

Fantom didn't deliver `onTextLayout`: the platform-agnostic C++ `TextLayoutManager` had no `measureLines`, so `ParagraphShadowNode` only logged a warning.

This adds a virtual `measureLines` to that `TextLayoutManager`, whose base implementation returns no lines. Fantom's `FantomTextLayoutManager` overrides it with the layout it paints screenshots with, so `onTextLayout` reports the lines Fantom draws.
- Text cut by `numberOfLines` ends with a tail ellipsis in the reported lines and the screenshot, except after an inline view or emoji on the last line.
- Selectable text is now painted, and baseline alignment uses the measured lines.
- Other users of the C++ `TextLayoutManager` measure no lines: they no longer log the warning and still send no `onTextLayout` event.

Changelog: [Internal]

Reviewed By: rubennorte

Differential Revision: D134743317
@meta-codesync meta-codesync Bot changed the title Measure text lines for onTextLayout Measure text lines for onTextLayout (#60336) Nov 30, 2026
@markv
markv force-pushed the export-D134743317 branch from 6cc04ed to d6ab096 Compare November 30, 2026 20:12
@github-actions github-actions Bot removed the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Nov 30, 2026
@meta-codesync
meta-codesync Bot merged commit e361372 into react:main Nov 30, 2026
93 of 97 checks passed
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @markv in e361372

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 30, 2026
ide added a commit to expo/react-native that referenced this pull request Dec 4, 2026
Why
===

Upstream's `onTextLayout` tests in `Text-itest.js` (from react#60336 and react#60414) check the lines that Fantom's Skia text layout reports: their `x` under `textAlign: 'center'`, their count under `numberOfLines`, and the ellipsis that ends a cut line. Frontier turns `enableStringChildren` on by default, and with it on Fantom measures text on a fixed grid of 10pt characters, which reports lines that ignore the alignment and the line limit. Five of these tests fail.

One test also expects "The quick fox" to fit on one line in a 100pt box. Frontier's default font size in Fantom is 16pt rather than React Native's 14pt, and at 16pt the text wraps onto two lines.

How
===

Run the suite with `@fantom_flags enableStringChildren:false`, as `FantomScreenshot-itest.js`, `FantomScreenSnapshots-itest.js` and `FantomTextMeasurement-itest.js` already do for the same reason. For the text that fits, compare the lines joined together with the whole text, which holds at either default font size and still fails if the text is cut.

Test Plan
=========

`yarn fantom packages/react-native/Libraries/Text/__tests__/Text-itest.js` passes. Before the change it failed five tests with the flag on, and with only the flag added it failed the one test of the fitting text.
ide added a commit to expo/react-native that referenced this pull request Dec 5, 2026
Why
===

Upstream's `onTextLayout` tests in `Text-itest.js` (from react#60336 and react#60414) check the lines that Fantom's Skia text layout reports: their `x` under `textAlign: 'center'`, their count under `numberOfLines`, and the ellipsis that ends a cut line. Frontier turns `enableStringChildren` on by default, and with it on Fantom measures text on a fixed grid of 10pt characters, which reports lines that ignore the alignment and the line limit. Five of these tests fail.

One test also expects "The quick fox" to fit on one line in a 100pt box. Frontier's default font size in Fantom is 16pt rather than React Native's 14pt, and at 16pt the text wraps onto two lines.

How
===

Run the suite with `@fantom_flags enableStringChildren:false`, as `FantomScreenshot-itest.js`, `FantomScreenSnapshots-itest.js` and `FantomTextMeasurement-itest.js` already do for the same reason. For the text that fits, compare the lines joined together with the whole text, which holds at either default font size and still fails if the text is cut.

Test Plan
=========

`yarn fantom packages/react-native/Libraries/Text/__tests__/Text-itest.js` passes. Before the change it failed five tests with the flag on, and with only the flag added it failed the one test of the fitting text.
ide added a commit to expo/react-native that referenced this pull request Dec 5, 2026
Why
===

Upstream's `onTextLayout` tests in `Text-itest.js` (from react#60336 and react#60414) check the lines that Fantom's Skia text layout reports: their `x` under `textAlign: 'center'`, their count under `numberOfLines`, and the ellipsis that ends a cut line. Frontier turns `enableStringChildren` on by default, and with it on Fantom measures text on a fixed grid of 10pt characters, which reports lines that ignore the alignment and the line limit. Five of these tests fail.

One test also expects "The quick fox" to fit on one line in a 100pt box. Frontier's default font size in Fantom is 16pt rather than React Native's 14pt, and at 16pt the text wraps onto two lines.

How
===

Run the suite with `@fantom_flags enableStringChildren:false`, as `FantomScreenshot-itest.js`, `FantomScreenSnapshots-itest.js` and `FantomTextMeasurement-itest.js` already do for the same reason. For the text that fits, compare the lines joined together with the whole text, which holds at either default font size and still fails if the text is cut.

Test Plan
=========

`yarn fantom packages/react-native/Libraries/Text/__tests__/Text-itest.js` passes. Before the change it failed five tests with the flag on, and with only the flag added it failed the one test of the fitting text.
ide added a commit to expo/react-native that referenced this pull request Dec 5, 2026
Why
===

Upstream's `onTextLayout` tests in `Text-itest.js` (from react#60336 and react#60414) check the lines that Fantom's Skia text layout reports: their `x` under `textAlign: 'center'`, their count under `numberOfLines`, and the ellipsis that ends a cut line. Frontier turns `enableStringChildren` on by default, and with it on Fantom measures text on a fixed grid of 10pt characters, which reports lines that ignore the alignment and the line limit. Five of these tests fail.

One test also expects "The quick fox" to fit on one line in a 100pt box. Frontier's default font size in Fantom is 16pt rather than React Native's 14pt, and at 16pt the text wraps onto two lines.

How
===

Run the suite with `@fantom_flags enableStringChildren:false`, as `FantomScreenshot-itest.js`, `FantomScreenSnapshots-itest.js` and `FantomTextMeasurement-itest.js` already do for the same reason. For the text that fits, compare the lines joined together with the whole text, which holds at either default font size and still fails if the text is cut.

Test Plan
=========

`yarn fantom packages/react-native/Libraries/Text/__tests__/Text-itest.js` passes. Before the change it failed five tests with the flag on, and with only the flag added it failed the one test of the fitting text.
ide added a commit to expo/react-native that referenced this pull request Dec 5, 2026
Why
===

Upstream's `onTextLayout` tests in `Text-itest.js` (from react#60336 and react#60414) check the lines that Fantom's Skia text layout reports: their `x` under `textAlign: 'center'`, their count under `numberOfLines`, and the ellipsis that ends a cut line. Frontier turns `enableStringChildren` on by default, and with it on Fantom measures text on a fixed grid of 10pt characters, which reports lines that ignore the alignment and the line limit. Five of these tests fail.

One test also expects "The quick fox" to fit on one line in a 100pt box. Frontier's default font size in Fantom is 16pt rather than React Native's 14pt, and at 16pt the text wraps onto two lines.

How
===

Run the suite with `@fantom_flags enableStringChildren:false`, as `FantomScreenshot-itest.js`, `FantomScreenSnapshots-itest.js` and `FantomTextMeasurement-itest.js` already do for the same reason. For the text that fits, compare the lines joined together with the whole text, which holds at either default font size and still fails if the text is cut.

Test Plan
=========

`yarn fantom packages/react-native/Libraries/Text/__tests__/Text-itest.js` passes. Before the change it failed five tests with the flag on, and with only the flag added it failed the one test of the fitting text.
ide added a commit to expo/react-native that referenced this pull request Dec 5, 2026
Why
===

Upstream's `onTextLayout` tests in `Text-itest.js` (from react#60336 and react#60414) check the lines that Fantom's Skia text layout reports: their `x` under `textAlign: 'center'`, their count under `numberOfLines`, and the ellipsis that ends a cut line. Frontier turns `enableStringChildren` on by default, and with it on Fantom measures text on a fixed grid of 10pt characters, which reports lines that ignore the alignment and the line limit. Five of these tests fail.

One test also expects "The quick fox" to fit on one line in a 100pt box. Frontier's default font size in Fantom is 16pt rather than React Native's 14pt, and at 16pt the text wraps onto two lines.

How
===

Run the suite with `@fantom_flags enableStringChildren:false`, as `FantomScreenshot-itest.js`, `FantomScreenSnapshots-itest.js` and `FantomTextMeasurement-itest.js` already do for the same reason. For the text that fits, compare the lines joined together with the whole text, which holds at either default font size and still fails if the text is cut.

Test Plan
=========

`yarn fantom packages/react-native/Libraries/Text/__tests__/Text-itest.js` passes. Before the change it failed five tests with the flag on, and with only the flag added it failed the one test of the fitting text.
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