Support for (de)serializing node state (#1570)

Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1570

X-link: https://github.com/facebook/react-native/pull/42751

tsia. Need node state

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D53206323

fbshipit-source-id: eb48c3873536eb52c8ffcce8005725da274e5373
This commit is contained in:
Joe Vilches
2024-02-09 16:44:32 -08:00
committed by Facebook GitHub Bot
parent f90ad378ff
commit 753b319977
7 changed files with 120 additions and 79 deletions

View File

@@ -21,7 +21,7 @@ constexpr uint32_t kNumRepititions = 1000;
using SteadyClockDurations = using SteadyClockDurations =
std::array<steady_clock::duration, kNumRepititions>; std::array<steady_clock::duration, kNumRepititions>;
std::shared_ptr<YGConfig> buildConfigFromJson(json& j) { std::shared_ptr<const YGConfig> buildConfigFromJson(const json& j) {
json jsonConfig = j["config"]; json jsonConfig = j["config"];
std::shared_ptr<YGConfig> config(YGConfigNew(), YGConfigFree); std::shared_ptr<YGConfig> config(YGConfigNew(), YGConfigFree);
for (json::iterator it = jsonConfig.begin(); it != jsonConfig.end(); it++) { for (json::iterator it = jsonConfig.begin(); it != jsonConfig.end(); it++) {
@@ -51,150 +51,165 @@ std::string edgeStringFromPropertyName(
return key.substr(propertyName.length() + 1); return key.substr(propertyName.length() + 1);
} }
void setStylesFromJson(json& j, std::shared_ptr<YGNode> node) { void setStylesFromJson(const json& j, YGNodeRef node) {
json style = j["style"]; json style = j["style"];
for (const auto& [key, value] : style.items()) { for (const auto& [key, value] : style.items()) {
if (key == "flex-direction") { if (key == "flex-direction") {
YGNodeStyleSetFlexDirection(node.get(), flexDirectionFromString(value)); YGNodeStyleSetFlexDirection(node, flexDirectionFromString(value));
} else if (key == "justify-content") { } else if (key == "justify-content") {
YGNodeStyleSetJustifyContent(node.get(), justifyContentFromString(value)); YGNodeStyleSetJustifyContent(node, justifyContentFromString(value));
} else if (key == "align-items") { } else if (key == "align-items") {
YGNodeStyleSetAlignItems(node.get(), alignFromString(value)); YGNodeStyleSetAlignItems(node, alignFromString(value));
} else if (key == "align-content") { } else if (key == "align-content") {
YGNodeStyleSetAlignContent(node.get(), alignFromString(value)); YGNodeStyleSetAlignContent(node, alignFromString(value));
} else if (key == "align-self") { } else if (key == "align-self") {
YGNodeStyleSetAlignSelf(node.get(), alignFromString(value)); YGNodeStyleSetAlignSelf(node, alignFromString(value));
} else if (key == "flex-wrap") { } else if (key == "flex-wrap") {
YGNodeStyleSetFlexWrap(node.get(), wrapFromString(value)); YGNodeStyleSetFlexWrap(node, wrapFromString(value));
} else if (key == "overflow") { } else if (key == "overflow") {
YGNodeStyleSetOverflow(node.get(), overflowFromString(value)); YGNodeStyleSetOverflow(node, overflowFromString(value));
} else if (key == "display") { } else if (key == "display") {
YGNodeStyleSetDisplay(node.get(), displayFromString(value)); YGNodeStyleSetDisplay(node, displayFromString(value));
} else if (key == "position-type") { } else if (key == "position-type") {
YGNodeStyleSetPositionType(node.get(), positionTypeFromString(value)); YGNodeStyleSetPositionType(node, positionTypeFromString(value));
} else if (key == "flex-grow") { } else if (key == "flex-grow") {
YGNodeStyleSetFlexGrow(node.get(), value); YGNodeStyleSetFlexGrow(node, value);
} else if (key == "flex-shrink") { } else if (key == "flex-shrink") {
YGNodeStyleSetFlexShrink(node.get(), value); YGNodeStyleSetFlexShrink(node, value);
} else if (key == "flex") { } else if (key == "flex") {
YGNodeStyleSetFlex(node.get(), value); YGNodeStyleSetFlex(node, value);
} else if (key == "flex-basis") { } else if (key == "flex-basis") {
YGUnit unit = unitFromJson(value); YGUnit unit = unitFromJson(value);
if (unit == YGUnitAuto) { if (unit == YGUnitAuto) {
YGNodeStyleSetFlexBasisAuto(node.get()); YGNodeStyleSetFlexBasisAuto(node);
} else if (unit == YGUnitPoint) { } else if (unit == YGUnitPoint) {
YGNodeStyleSetFlexBasis(node.get(), value["value"]); YGNodeStyleSetFlexBasis(node, value["value"]);
} else if (unit == YGUnitPercent) { } else if (unit == YGUnitPercent) {
YGNodeStyleSetFlexBasisPercent(node.get(), value["value"]); YGNodeStyleSetFlexBasisPercent(node, value["value"]);
} }
} else if (key.starts_with("position")) { } else if (key.starts_with("position")) {
YGEdge edge = edgeFromString(edgeStringFromPropertyName(key, "position")); YGEdge edge = edgeFromString(edgeStringFromPropertyName(key, "position"));
YGUnit unit = unitFromJson(value); YGUnit unit = unitFromJson(value);
if (unit == YGUnitPoint) { if (unit == YGUnitPoint) {
YGNodeStyleSetPosition(node.get(), edge, value["value"]); YGNodeStyleSetPosition(node, edge, value["value"]);
} else if (unit == YGUnitPercent) { } else if (unit == YGUnitPercent) {
YGNodeStyleSetPositionPercent(node.get(), edge, value["value"]); YGNodeStyleSetPositionPercent(node, edge, value["value"]);
} }
} else if (key.starts_with("padding")) { } else if (key.starts_with("padding")) {
YGEdge edge = edgeFromString(edgeStringFromPropertyName(key, "padding")); YGEdge edge = edgeFromString(edgeStringFromPropertyName(key, "padding"));
YGUnit unit = unitFromJson(value); YGUnit unit = unitFromJson(value);
if (unit == YGUnitPoint) { if (unit == YGUnitPoint) {
YGNodeStyleSetPadding(node.get(), edge, value["value"]); YGNodeStyleSetPadding(node, edge, value["value"]);
} else if (unit == YGUnitPercent) { } else if (unit == YGUnitPercent) {
YGNodeStyleSetPaddingPercent(node.get(), edge, value["value"]); YGNodeStyleSetPaddingPercent(node, edge, value["value"]);
} }
} else if (key.starts_with("border")) { } else if (key.starts_with("border")) {
YGEdge edge = edgeFromString(edgeStringFromPropertyName(key, "border")); YGEdge edge = edgeFromString(edgeStringFromPropertyName(key, "border"));
YGUnit unit = unitFromJson(value); YGUnit unit = unitFromJson(value);
if (unit == YGUnitPoint) { if (unit == YGUnitPoint) {
YGNodeStyleSetBorder(node.get(), edge, value["value"]); YGNodeStyleSetBorder(node, edge, value["value"]);
} }
} else if (key.starts_with("margin")) { } else if (key.starts_with("margin")) {
YGEdge edge = edgeFromString(edgeStringFromPropertyName(key, "margin")); YGEdge edge = edgeFromString(edgeStringFromPropertyName(key, "margin"));
YGUnit unit = unitFromJson(value); YGUnit unit = unitFromJson(value);
if (unit == YGUnitPoint) { if (unit == YGUnitPoint) {
YGNodeStyleSetMargin(node.get(), edge, value["value"]); YGNodeStyleSetMargin(node, edge, value["value"]);
} else if (unit == YGUnitPercent) { } else if (unit == YGUnitPercent) {
YGNodeStyleSetMarginPercent(node.get(), edge, value["value"]); YGNodeStyleSetMarginPercent(node, edge, value["value"]);
} else if (unit == YGUnitAuto) { } else if (unit == YGUnitAuto) {
YGNodeStyleSetMarginAuto(node.get(), edge); YGNodeStyleSetMarginAuto(node, edge);
} }
} else if (key == "gap") { } else if (key == "gap") {
YGUnit unit = unitFromJson(value); YGUnit unit = unitFromJson(value);
if (unit == YGUnitPoint) { if (unit == YGUnitPoint) {
YGNodeStyleSetGap(node.get(), YGGutterAll, value["value"]); YGNodeStyleSetGap(node, YGGutterAll, value["value"]);
} }
} else if (key == "column-gap") { } else if (key == "column-gap") {
YGUnit unit = unitFromJson(value); YGUnit unit = unitFromJson(value);
if (unit == YGUnitPoint) { if (unit == YGUnitPoint) {
YGNodeStyleSetGap(node.get(), YGGutterColumn, value["value"]); YGNodeStyleSetGap(node, YGGutterColumn, value["value"]);
} }
} else if (key == "row-gap") { } else if (key == "row-gap") {
YGUnit unit = unitFromJson(value); YGUnit unit = unitFromJson(value);
if (unit == YGUnitPoint) { if (unit == YGUnitPoint) {
YGNodeStyleSetGap(node.get(), YGGutterRow, value["value"]); YGNodeStyleSetGap(node, YGGutterRow, value["value"]);
} }
} else if (key == "height") { } else if (key == "height") {
YGUnit unit = unitFromJson(value); YGUnit unit = unitFromJson(value);
if (unit == YGUnitAuto) { if (unit == YGUnitAuto) {
YGNodeStyleSetHeightAuto(node.get()); YGNodeStyleSetHeightAuto(node);
} else if (unit == YGUnitPoint) { } else if (unit == YGUnitPoint) {
YGNodeStyleSetHeight(node.get(), value["value"]); YGNodeStyleSetHeight(node, value["value"]);
} else if (unit == YGUnitPercent) { } else if (unit == YGUnitPercent) {
YGNodeStyleSetHeightPercent(node.get(), value["value"]); YGNodeStyleSetHeightPercent(node, value["value"]);
} }
} else if (key == "width") { } else if (key == "width") {
YGUnit unit = unitFromJson(value); YGUnit unit = unitFromJson(value);
if (unit == YGUnitAuto) { if (unit == YGUnitAuto) {
YGNodeStyleSetWidthAuto(node.get()); YGNodeStyleSetWidthAuto(node);
} else if (unit == YGUnitPoint) { } else if (unit == YGUnitPoint) {
YGNodeStyleSetWidth(node.get(), value["value"]); YGNodeStyleSetWidth(node, value["value"]);
} else if (unit == YGUnitPercent) { } else if (unit == YGUnitPercent) {
YGNodeStyleSetWidthPercent(node.get(), value["value"]); YGNodeStyleSetWidthPercent(node, value["value"]);
} }
} else if (key == "min-height") { } else if (key == "min-height") {
YGUnit unit = unitFromJson(value); YGUnit unit = unitFromJson(value);
if (unit == YGUnitPoint) { if (unit == YGUnitPoint) {
YGNodeStyleSetMinHeight(node.get(), value["value"]); YGNodeStyleSetMinHeight(node, value["value"]);
} else if (unit == YGUnitPercent) { } else if (unit == YGUnitPercent) {
YGNodeStyleSetMinHeightPercent(node.get(), value["value"]); YGNodeStyleSetMinHeightPercent(node, value["value"]);
} }
} else if (key == "min-width") { } else if (key == "min-width") {
YGUnit unit = unitFromJson(value); YGUnit unit = unitFromJson(value);
if (unit == YGUnitPoint) { if (unit == YGUnitPoint) {
YGNodeStyleSetMinWidth(node.get(), value["value"]); YGNodeStyleSetMinWidth(node, value["value"]);
} else if (unit == YGUnitPercent) { } else if (unit == YGUnitPercent) {
YGNodeStyleSetMinWidthPercent(node.get(), value["value"]); YGNodeStyleSetMinWidthPercent(node, value["value"]);
} }
} else if (key == "max-height") { } else if (key == "max-height") {
YGUnit unit = unitFromJson(value); YGUnit unit = unitFromJson(value);
if (unit == YGUnitPoint) { if (unit == YGUnitPoint) {
YGNodeStyleSetMaxHeight(node.get(), value["value"]); YGNodeStyleSetMaxHeight(node, value["value"]);
} else if (unit == YGUnitPercent) { } else if (unit == YGUnitPercent) {
YGNodeStyleSetMaxHeightPercent(node.get(), value["value"]); YGNodeStyleSetMaxHeightPercent(node, value["value"]);
} }
} else if (key == "max-width") { } else if (key == "max-width") {
YGUnit unit = unitFromJson(value); YGUnit unit = unitFromJson(value);
if (unit == YGUnitPoint) { if (unit == YGUnitPoint) {
YGNodeStyleSetMaxWidth(node.get(), value["value"]); YGNodeStyleSetMaxWidth(node, value["value"]);
} else if (unit == YGUnitPercent) { } else if (unit == YGUnitPercent) {
YGNodeStyleSetMaxWidthPercent(node.get(), value["value"]); YGNodeStyleSetMaxWidthPercent(node, value["value"]);
} }
} }
} }
} }
YogaNodeAndConfig std::shared_ptr<YGNode> buildNodeFromJson(
buildTreeFromJson(json& j, YogaNodeAndConfig* parent, size_t index) { const json& j,
std::shared_ptr<YGConfig> config = buildConfigFromJson(j); std::shared_ptr<const YGConfig> config) {
std::shared_ptr<YGNode> node(YGNodeNewWithConfig(config.get()), YGNodeFree); std::shared_ptr<YGNode> node(YGNodeNewWithConfig(config.get()), YGNodeFree);
json nodeState = j["node"];
for (json::iterator it = nodeState.begin(); it != nodeState.end(); it++) {
if (it.key() == "always-forms-containing-block") {
YGNodeSetAlwaysFormsContainingBlock(node.get(), it.value());
}
}
return node;
}
YogaNodeAndConfig
buildTreeFromJson(const json& j, YogaNodeAndConfig* parent, size_t index) {
std::shared_ptr<const YGConfig> config = buildConfigFromJson(j);
std::shared_ptr<YGNode> node = buildNodeFromJson(j, config);
YogaNodeAndConfig wrapper{node, config, std::vector<YogaNodeAndConfig>{}}; YogaNodeAndConfig wrapper{node, config, std::vector<YogaNodeAndConfig>{}};
if (parent != nullptr) { if (parent != nullptr) {
YGNodeInsertChild(parent->node_.get(), node.get(), index); YGNodeInsertChild(parent->node_.get(), node.get(), index);
parent->children_.push_back(wrapper); parent->children_.push_back(wrapper);
} }
setStylesFromJson(j, node); setStylesFromJson(j, node.get());
json children = j["children"]; json children = j["children"];
size_t childIndex = 0; size_t childIndex = 0;

View File

@@ -18,7 +18,7 @@ namespace facebook::yoga {
struct YogaNodeAndConfig { struct YogaNodeAndConfig {
std::shared_ptr<YGNode> node_; std::shared_ptr<YGNode> node_;
std::shared_ptr<YGConfig> config_; std::shared_ptr<const YGConfig> config_;
std::vector<YogaNodeAndConfig> children_; std::vector<YogaNodeAndConfig> children_;
}; };

View File

@@ -17,7 +17,8 @@ void captureTree(YGNodeRef node, const std::filesystem::path& path) {
nodeToString( nodeToString(
str, str,
node, node,
PrintOptions::Style | PrintOptions::Children | PrintOptions::Config); PrintOptions::Style | PrintOptions::Children | PrintOptions::Config |
PrintOptions::Node);
std::ofstream file(path); std::ofstream file(path);
file << str; file << str;
} }

View File

@@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
#include <memory>
#include <capture/NodeToString.h> #include <capture/NodeToString.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
@@ -126,131 +128,130 @@ static void nodeToStringImpl(json& j, YGNodeRef node, PrintOptions options) {
j["layout"]["top"] = YGNodeStyleGetPosition(node, YGEdgeTop).value; j["layout"]["top"] = YGNodeStyleGetPosition(node, YGEdgeTop).value;
j["layout"]["left"] = YGNodeStyleGetPosition(node, YGEdgeLeft).value; j["layout"]["left"] = YGNodeStyleGetPosition(node, YGEdgeLeft).value;
} }
std::unique_ptr<YGNode, decltype(&YGNodeFree)> defaultNode(
YGNodeNew(), YGNodeFree);
if ((options & PrintOptions::Style) == PrintOptions::Style) { if ((options & PrintOptions::Style) == PrintOptions::Style) {
const YGNodeRef defaultNode = YGNodeNew();
appendEnumValueIfNotDefault( appendEnumValueIfNotDefault(
j["style"], j["style"],
"flex-direction", "flex-direction",
YGFlexDirectionToString(YGNodeStyleGetFlexDirection(node)), YGFlexDirectionToString(YGNodeStyleGetFlexDirection(node)),
YGFlexDirectionToString(YGNodeStyleGetFlexDirection(defaultNode))); YGFlexDirectionToString(
YGNodeStyleGetFlexDirection(defaultNode.get())));
appendEnumValueIfNotDefault( appendEnumValueIfNotDefault(
j["style"], j["style"],
"justify-content", "justify-content",
YGJustifyToString(YGNodeStyleGetJustifyContent(node)), YGJustifyToString(YGNodeStyleGetJustifyContent(node)),
YGJustifyToString(YGNodeStyleGetJustifyContent(defaultNode))); YGJustifyToString(YGNodeStyleGetJustifyContent(defaultNode.get())));
appendEnumValueIfNotDefault( appendEnumValueIfNotDefault(
j["style"], j["style"],
"align-items", "align-items",
YGAlignToString(YGNodeStyleGetAlignItems(node)), YGAlignToString(YGNodeStyleGetAlignItems(node)),
YGAlignToString(YGNodeStyleGetAlignItems(defaultNode))); YGAlignToString(YGNodeStyleGetAlignItems(defaultNode.get())));
appendEnumValueIfNotDefault( appendEnumValueIfNotDefault(
j["style"], j["style"],
"align-content", "align-content",
YGAlignToString(YGNodeStyleGetAlignContent(node)), YGAlignToString(YGNodeStyleGetAlignContent(node)),
YGAlignToString(YGNodeStyleGetAlignContent(defaultNode))); YGAlignToString(YGNodeStyleGetAlignContent(defaultNode.get())));
appendEnumValueIfNotDefault( appendEnumValueIfNotDefault(
j["style"], j["style"],
"align-self", "align-self",
YGAlignToString(YGNodeStyleGetAlignSelf(node)), YGAlignToString(YGNodeStyleGetAlignSelf(node)),
YGAlignToString(YGNodeStyleGetAlignSelf(defaultNode))); YGAlignToString(YGNodeStyleGetAlignSelf(defaultNode.get())));
appendEnumValueIfNotDefault( appendEnumValueIfNotDefault(
j["style"], j["style"],
"flex-wrap", "flex-wrap",
YGWrapToString(YGNodeStyleGetFlexWrap(node)), YGWrapToString(YGNodeStyleGetFlexWrap(node)),
YGWrapToString(YGNodeStyleGetFlexWrap(defaultNode))); YGWrapToString(YGNodeStyleGetFlexWrap(defaultNode.get())));
appendEnumValueIfNotDefault( appendEnumValueIfNotDefault(
j["style"], j["style"],
"overflow", "overflow",
YGOverflowToString(YGNodeStyleGetOverflow(node)), YGOverflowToString(YGNodeStyleGetOverflow(node)),
YGOverflowToString(YGNodeStyleGetOverflow(defaultNode))); YGOverflowToString(YGNodeStyleGetOverflow(defaultNode.get())));
appendEnumValueIfNotDefault( appendEnumValueIfNotDefault(
j["style"], j["style"],
"display", "display",
YGDisplayToString(YGNodeStyleGetDisplay(node)), YGDisplayToString(YGNodeStyleGetDisplay(node)),
YGDisplayToString(YGNodeStyleGetDisplay(defaultNode))); YGDisplayToString(YGNodeStyleGetDisplay(defaultNode.get())));
appendEnumValueIfNotDefault( appendEnumValueIfNotDefault(
j["style"], j["style"],
"position-type", "position-type",
YGPositionTypeToString(YGNodeStyleGetPositionType(node)), YGPositionTypeToString(YGNodeStyleGetPositionType(node)),
YGPositionTypeToString(YGNodeStyleGetPositionType(defaultNode))); YGPositionTypeToString(YGNodeStyleGetPositionType(defaultNode.get())));
appendFloatIfNotDefault( appendFloatIfNotDefault(
j["style"], j["style"],
"flex-grow", "flex-grow",
YGNodeStyleGetFlexGrow(node), YGNodeStyleGetFlexGrow(node),
YGNodeStyleGetFlexGrow(defaultNode)); YGNodeStyleGetFlexGrow(defaultNode.get()));
appendFloatIfNotDefault( appendFloatIfNotDefault(
j["style"], j["style"],
"flex-shrink", "flex-shrink",
YGNodeStyleGetFlexShrink(node), YGNodeStyleGetFlexShrink(node),
YGNodeStyleGetFlexShrink(defaultNode)); YGNodeStyleGetFlexShrink(defaultNode.get()));
appendFloatIfNotDefault( appendFloatIfNotDefault(
j["style"], j["style"],
"flex", "flex",
YGNodeStyleGetFlex(node), YGNodeStyleGetFlex(node),
YGNodeStyleGetFlex(defaultNode)); YGNodeStyleGetFlex(defaultNode.get()));
appendYGValueIfNotDefault( appendYGValueIfNotDefault(
j["style"], j["style"],
"flex-basis", "flex-basis",
YGNodeStyleGetFlexBasis(node), YGNodeStyleGetFlexBasis(node),
YGNodeStyleGetFlexBasis(defaultNode)); YGNodeStyleGetFlexBasis(defaultNode.get()));
appendEdges<&YGNodeStyleGetMargin>(j, "margin", node, defaultNode); appendEdges<&YGNodeStyleGetMargin>(j, "margin", node, defaultNode.get());
appendEdges<&YGNodeStyleGetPadding>(j, "padding", node, defaultNode); appendEdges<&YGNodeStyleGetPadding>(j, "padding", node, defaultNode.get());
appendEdges<&borderFloatToYGValue>(j, "border", node, defaultNode); appendEdges<&borderFloatToYGValue>(j, "border", node, defaultNode.get());
appendEdges<&YGNodeStyleGetPosition>(j, "position", node, defaultNode); appendEdges<&YGNodeStyleGetPosition>(
j, "position", node, defaultNode.get());
appendFloatIfNotDefault( appendFloatIfNotDefault(
j["style"], j["style"],
"gap", "gap",
YGNodeStyleGetGap(node, YGGutterAll), YGNodeStyleGetGap(node, YGGutterAll),
YGNodeStyleGetGap(defaultNode, YGGutterAll)); YGNodeStyleGetGap(defaultNode.get(), YGGutterAll));
appendFloatIfNotDefault( appendFloatIfNotDefault(
j["style"], j["style"],
"column-gap", "column-gap",
YGNodeStyleGetGap(node, YGGutterColumn), YGNodeStyleGetGap(node, YGGutterColumn),
YGNodeStyleGetGap(defaultNode, YGGutterColumn)); YGNodeStyleGetGap(defaultNode.get(), YGGutterColumn));
appendFloatIfNotDefault( appendFloatIfNotDefault(
j["style"], j["style"],
"row-gap", "row-gap",
YGNodeStyleGetGap(node, YGGutterRow), YGNodeStyleGetGap(node, YGGutterRow),
YGNodeStyleGetGap(defaultNode, YGGutterRow)); YGNodeStyleGetGap(defaultNode.get(), YGGutterRow));
appendYGValueIfNotDefault( appendYGValueIfNotDefault(
j["style"], j["style"],
"width", "width",
YGNodeStyleGetWidth(node), YGNodeStyleGetWidth(node),
YGNodeStyleGetWidth(defaultNode)); YGNodeStyleGetWidth(defaultNode.get()));
appendYGValueIfNotDefault( appendYGValueIfNotDefault(
j["style"], j["style"],
"height", "height",
YGNodeStyleGetHeight(node), YGNodeStyleGetHeight(node),
YGNodeStyleGetHeight(defaultNode)); YGNodeStyleGetHeight(defaultNode.get()));
appendYGValueIfNotDefault( appendYGValueIfNotDefault(
j["style"], j["style"],
"max-width", "max-width",
YGNodeStyleGetMaxWidth(node), YGNodeStyleGetMaxWidth(node),
YGNodeStyleGetMaxWidth(defaultNode)); YGNodeStyleGetMaxWidth(defaultNode.get()));
appendYGValueIfNotDefault( appendYGValueIfNotDefault(
j["style"], j["style"],
"max-height", "max-height",
YGNodeStyleGetMaxHeight(node), YGNodeStyleGetMaxHeight(node),
YGNodeStyleGetMaxHeight(defaultNode)); YGNodeStyleGetMaxHeight(defaultNode.get()));
appendYGValueIfNotDefault( appendYGValueIfNotDefault(
j["style"], j["style"],
"min-width", "min-width",
YGNodeStyleGetMinWidth(node), YGNodeStyleGetMinWidth(node),
YGNodeStyleGetMinWidth(defaultNode)); YGNodeStyleGetMinWidth(defaultNode.get()));
appendYGValueIfNotDefault( appendYGValueIfNotDefault(
j["style"], j["style"],
"min-height", "min-height",
YGNodeStyleGetMinHeight(node), YGNodeStyleGetMinHeight(node),
YGNodeStyleGetMinHeight(defaultNode)); YGNodeStyleGetMinHeight(defaultNode.get()));
if (YGNodeHasMeasureFunc(node)) {
j["style"]["has-custom-measure"] = true;
}
} }
if ((options & PrintOptions::Config) == PrintOptions::Config) { if ((options & PrintOptions::Config) == PrintOptions::Config) {
@@ -286,6 +287,17 @@ static void nodeToStringImpl(json& j, YGNodeRef node, PrintOptions options) {
} }
} }
if ((options & PrintOptions::Node) == PrintOptions::Node) {
appendBoolIfNotDefault(
j["node"],
"always-forms-containing-block",
YGNodeGetAlwaysFormsContainingBlock(node),
YGNodeGetAlwaysFormsContainingBlock(defaultNode.get()));
if (YGNodeHasMeasureFunc(node)) {
j["node"]["has-custom-measure"] = true;
}
}
const size_t childCount = YGNodeGetChildCount(node); const size_t childCount = YGNodeGetChildCount(node);
if ((options & PrintOptions::Children) == PrintOptions::Children && if ((options & PrintOptions::Children) == PrintOptions::Children &&
childCount > 0) { childCount > 0) {

View File

@@ -18,6 +18,7 @@ enum class PrintOptions : uint8_t {
Children = 1 << 1, Children = 1 << 1,
Style = 1 << 2, Style = 1 << 2,
Config = 1 << 3, Config = 1 << 3,
Node = 1 << 4,
}; };
YG_DEFINE_ENUM_FLAG_OPERATORS(PrintOptions); YG_DEFINE_ENUM_FLAG_OPERATORS(PrintOptions);

View File

@@ -329,6 +329,10 @@ void YGNodeSetAlwaysFormsContainingBlock(
resolveRef(node)->setAlwaysFormsContainingBlock(alwaysFormsContainingBlock); resolveRef(node)->setAlwaysFormsContainingBlock(alwaysFormsContainingBlock);
} }
bool YGNodeGetAlwaysFormsContainingBlock(YGNodeConstRef node) {
return resolveRef(node)->alwaysFormsContainingBlock();
}
// TODO: This leaks internal details to the public API. Remove after removing // TODO: This leaks internal details to the public API. Remove after removing
// ComponentKit usage of it. // ComponentKit usage of it.
bool YGNodeCanUseCachedMeasurement( bool YGNodeCanUseCachedMeasurement(

View File

@@ -273,6 +273,14 @@ YG_EXPORT void YGNodeSetAlwaysFormsContainingBlock(
YGNodeRef node, YGNodeRef node,
bool alwaysFormsContainingBlock); bool alwaysFormsContainingBlock);
/**
* Whether the node will always form a containing block for any descendant. This
* can happen in situation where the client implements something like a
* transform that can affect containing blocks but is not handled by Yoga
* directly.
*/
YG_EXPORT bool YGNodeGetAlwaysFormsContainingBlock(YGNodeConstRef node);
/** /**
* @deprecated * @deprecated
*/ */