Skip to content

Add YogaLayoutableShadowNode::getLayoutMargins() - #60572

Open
YevheniiKotyrlo wants to merge 1 commit into
react:mainfrom
YevheniiKotyrlo:feature/yoga-layoutable-shadow-node-layout-margins
Open

YevheniiKotyrlo wants to merge 1 commit into
react:mainfrom
YevheniiKotyrlo:feature/yoga-layoutable-shadow-node-layout-margins

Conversation

@YevheniiKotyrlo

@YevheniiKotyrlo YevheniiKotyrlo commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

LayoutMetrics carries a laid-out node's frame, borders and paddings but not its margins, and yogaNode_ is protected, so C++ that reads a node from the mounted tree, such as a UIManagerMountHook, has no read of the margins the node was laid out with.

This adds EdgeInsets YogaLayoutableShadowNode::getLayoutMargins() const, which reads them from the node's Yoga layout by physical edge, as layoutMetricsFromYogaNode reads the borders and paddings. It returns a value, so no reference to the Yoga node leaves the class.

Adding margins to LayoutMetrics instead would add Update mutations for changes in a node's resolved margins alone, since ShadowView::operator== compares layoutMetrics.

An auto margin reads 0, which is what Yoga stores for it (react/yoga#2224).

Related: #60571 adds enableBaseline(), and both add their tests at the end of ViewTest.cpp, so the second to merge keeps both; #60578 corrects enableMeasurement()'s comment; #60581 passes the source revision to shouldNewRevisionDirtyMeasurement() in completeClone(); #60583 dirties a node connected by enableMeasurement() when its props or the font scale change. #60578, #60581 and #60583 merge with this without conflict. #59048 and #59139 add tests to ViewTest.cpp too, apart from this one's.

Changelog:

[GENERAL] [ADDED] - Add YogaLayoutableShadowNode::getLayoutMargins(), the margins a node was laid out with

Test Plan:

YogaLayoutableShadowNodeTest.layoutMarginsAreResolvedPhysicalEdges, in ViewTest.cpp, lays out a 100 × 100 view with marginStart: 10 and marginTop: 10% in a 300 × 200 right-to-left root, and expects {left: 0, top: 30, right: 10, bottom: 0}: the start margin on the right, and the percentage against the root's width, not its height.

On 624329a, each job's commands run locally:

  • test_react_common_cxx: 100% tests passed, 0 tests failed out of 1655, the new test among them.
  • validate_cxx_api_snapshots (Doxygen 1.16.1): passes with each of the 12 snapshots listing public facebook::react::EdgeInsets getLayoutMargins() const;.
  • format: yarn format-javascript, format-cpp, format-kotlin, format-java and format-python, then git diff --exit-code leaving out packages/react-native/package.json and yarn.lock, as format.yml does: exit 0.

Not run here: format-swift, lint, test_js and build_js_types (no Swift or JavaScript changes), and the Android, iOS and Fantom builds.

@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 Dec 4, 2026
LayoutMetrics carries a node's borders and paddings but not its margins,
and the Yoga node that holds them is protected. getLayoutMargins() reads
the margins of the node's last layout by physical edge.

Signed-off-by: YevheniiKotyrlo <44449990+YevheniiKotyrlo@users.noreply.github.com>
@YevheniiKotyrlo
YevheniiKotyrlo force-pushed the feature/yoga-layoutable-shadow-node-layout-margins branch from 016c405 to 624329a Compare December 4, 2026 19:32
@YevheniiKotyrlo
YevheniiKotyrlo marked this pull request as ready for review December 4, 2026 21:44
@intergalacticspacehighway

Copy link
Copy Markdown
Collaborator

Thanks for this. Could you share the use case behind getLayoutMargins()?

@YevheniiKotyrlo

Copy link
Copy Markdown
Contributor Author

It's for getComputedStyle() on host components, in a library outside react-native. For margin-* of an element with a box it returns the used value (CSSOM), so a start/end or percentage margin has to come from the node's layout, not its props.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants