Skip to content

Add getTextLayout() to Text refs (#60414) - #60414

Merged
meta-codesync[bot] merged 1 commit into
react:mainfrom
markv:export-D134142257
Dec 2, 2026
Merged

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

Conversation

@markv

@markv markv commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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

@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 30, 2026
@meta-codesync

meta-codesync Bot commented Nov 30, 2026

Copy link
Copy Markdown

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

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

@github-actions

Copy link
Copy Markdown

Warning

JavaScript API change detected

This PR commits an update to ReactNativeApi.d.ts, indicating a change to React Native's public JavaScript API.

  • Please include a clear changelog message.
  • This change will be subject to additional review.

This change was flagged as: POTENTIALLY_BREAKING

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
@meta-codesync meta-codesync Bot changed the title Add getTextLayout() to Text refs Add getTextLayout() to Text refs (#60414) Dec 1, 2026
@markv
markv force-pushed the export-D134142257 branch from 5e61d9a to b62957a Compare December 1, 2026 23:59
@meta-codesync
meta-codesync Bot merged commit 2d0b824 into react:main Dec 2, 2026
102 of 105 checks passed
@react-native-bot

Copy link
Copy Markdown
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?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Dec 2, 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