Repository navigation
Add getTextLayout() to Text refs (#60414) - #60414
Merged
Merged
Conversation
|
@markv has exported this pull request. If you are a Meta employee, you can view the originating Diff in D134142257. |
rubennorte
approved these changes
Nov 30, 2026
rubennorte
left a comment
Member
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
|
Warning JavaScript API change detected This PR commits an update to
This change was flagged as: |
Summary:
`onTextLayout` reaches JS after the first frame with the text is drawn, so output that depends on a text's lines shows unadjusted for a few frames.
This adds `getTextLayout()` to refs of a `<Text>` not nested in another `<Text>`. It synchronously returns `{lines}`, the same shape and lines as the `onTextLayout` event, so a layout effect can use them in the same commit.
- `ParagraphShadowNode` keeps the lines it measures for `onTextLayout` and exposes them through `TextLayoutLinesProvider`, a header-only interface.
- `dom::getTextLayoutLines` reads them through that interface; `NativeDOM.getTextLayout` resolves the revision and builds the `{lines}` object.
- `Text` adds the method before the ref receives the instance, only when a ref is passed; nested texts don't get it.
Changelog:
[General][Added] - Add `getTextLayout()` to `<Text>` refs
Reviewed By: rubennorte
Differential Revision: D134142257
markv
force-pushed
the
export-D134142257
branch
from
December 1, 2026 23:59
5e61d9a to
b62957a
Compare
Collaborator
|
This pull request was successfully merged by @markv in 2d0b824 When will my fix make it into a release? | How to file a pick request? |
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
onTextLayoutreaches JS after the first frame with the text is drawn, so output that depends on a text's lines shows unadjusted for a few frames.This adds
getTextLayout()to refs of a<Text>not nested in another<Text>. It synchronously returns{lines}, the same shape and lines as theonTextLayoutevent, so a layout effect can use them in the same commit.ParagraphShadowNodekeeps the lines it measures foronTextLayoutand exposes them throughTextLayoutLinesProvider, a header-only interface.dom::getTextLayoutLinesreads them through that interface;NativeDOM.getTextLayoutresolves the revision and builds the{lines}object.Textadds the method before the ref receives the instance, only when a ref is passed; nested texts don't get it.Changelog:
[General][Added] - Add
getTextLayout()to<Text>refsReviewed By: rubennorte
Differential Revision: D134142257