Skip to content

Add YGNodeSetMeasureFuncFollowsMeasureModes - #2095

Open
pentiumao wants to merge 1 commit into
react:mainfrom
pentiumao:export-D132244372
Open

pentiumao wants to merge 1 commit into
react:mainfrom
pentiumao:export-D132244372

Conversation

@pentiumao

Copy link
Copy Markdown
Contributor

Summary:
YGNodeSetMeasureFuncFollowsMeasureModes(node, false) tells Yoga that the node's measure function
doesn't size as the measure modes describe (max-content for Undefined, fit-content for AtMost,
stretch-fit for Exactly), for example because it fills the space it is given or picks a layout by
it. Yoga then infers nothing about the node from a measurement under other constraints.

  • The default is true, today's behaviour.
  • With it false, the layout cache and the measurement cache reuse the node's measurement only
    under the same constraints. A node in a column is then measured twice in one layout: with no
    height bound, then at exactly the height it measured.
  • For automatic minimum sizing (on when YGErrataMinSizeUndefinedInsteadOfAuto is cleared), its
    measure function isn't called with AtMost 0. Its min-content size is the one set with
    YGNodeSetMinContentWidth/Height, if any; otherwise its padding and border plus what its
    YGMinContentMeasureFunc returns, or plus 0 without one.
  • No effect on the layout of a node without a measure function. Changing the value marks the node
    dirty; clones and moves keep it; YGNodeReset restores true. The deprecated
    YGNodeCanUseCachedMeasurement keeps its signature and behaviour.
  • Java and Kotlin: YogaNode.setMeasureFunctionFollowsMeasureModes and
    YogaNode.measureFunctionFollowsMeasureModes, open with defaults so existing subclasses keep
    working. JavaScript: setMeasureFuncFollowsMeasureModes and getMeasureFuncFollowsMeasureModes.
    Documented in "Integrating with external layout systems". Tree captures record it, and the
    benchmark reads it back.
  • React Native's C++ API snapshots gain the new facebook::yoga::Node methods and the new
    canUseCachedMeasurement parameter.
  • Cost with the default: a bit read and a never-taken branch per cache check of a node with a
    measure function. On Yoga's C benchmark (YGBenchmark.c, opt build) that is +0.04%
    instructions against the parent commit (perf stat, two runs each).

Nothing uses this yet: Litho's custom layouts will set it on their Yoga nodes.

Changelog:
[General][Added] - Add YGNodeSetMeasureFuncFollowsMeasureModes to opt out of measure-mode sizing assumptions

Reviewed By: adityasharat

Differential Revision: D132244372

Summary:
`YGNodeSetMeasureFuncFollowsMeasureModes(node, false)` tells Yoga that the node's measure function
doesn't size as the measure modes describe (max-content for `Undefined`, fit-content for `AtMost`,
stretch-fit for `Exactly`), for example because it fills the space it is given or picks a layout by
it. Yoga then infers nothing about the node from a measurement under other constraints.

- The default is `true`, today's behaviour.
- With it `false`, the layout cache and the measurement cache reuse the node's measurement only
  under the same constraints. A node in a column is then measured twice in one layout: with no
  height bound, then at exactly the height it measured.
- For automatic minimum sizing (on when `YGErrataMinSizeUndefinedInsteadOfAuto` is cleared), its
  measure function isn't called with `AtMost 0`. Its min-content size is the one set with
  `YGNodeSetMinContentWidth`/`Height`, if any; otherwise its padding and border plus what its
  `YGMinContentMeasureFunc` returns, or plus 0 without one.
- No effect on the layout of a node without a measure function. Changing the value marks the node
  dirty; clones and moves keep it; `YGNodeReset` restores `true`. The deprecated
  `YGNodeCanUseCachedMeasurement` keeps its signature and behaviour.
- Java and Kotlin: `YogaNode.setMeasureFunctionFollowsMeasureModes` and
  `YogaNode.measureFunctionFollowsMeasureModes`, open with defaults so existing subclasses keep
  working. JavaScript: `setMeasureFuncFollowsMeasureModes` and `getMeasureFuncFollowsMeasureModes`.
  Documented in "Integrating with external layout systems". Tree captures record it, and the
  benchmark reads it back.
- React Native's C++ API snapshots gain the new `facebook::yoga::Node` methods and the new
  `canUseCachedMeasurement` parameter.
- Cost with the default: a bit read and a never-taken branch per cache check of a node with a
  measure function. On Yoga's C benchmark (`YGBenchmark.c`, opt build) that is +0.04%
  instructions against the parent commit (`perf stat`, two runs each).

Nothing uses this yet: Litho's custom layouts will set it on their Yoga nodes.

Changelog:
[General][Added] - Add `YGNodeSetMeasureFuncFollowsMeasureModes` to opt out of measure-mode sizing assumptions

Reviewed By: adityasharat

Differential Revision: D132244372
@meta-cla meta-cla Bot added the CLA Signed label Nov 18, 2026
@meta-codesync

meta-codesync Bot commented Nov 18, 2026

Copy link
Copy Markdown

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant