Skip to content

Commit

Permalink
yoga::Node::getStyle() to yoga::Node::style() (#42314)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #42314

X-link: facebook/yoga#1555

The next diff moves a bunch of methods to `yoga::Style`. This renames the function to be a tad bit shorter, for more readable callsites. It also makes it more consistent with style property getters.

Changelog: [Internal]

Reviewed By: rozele

Differential Revision: D52803393

fbshipit-source-id: 557df34a9f0fb0ee42ad23b1fda99c1e0eb1d4e3
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Jan 19, 2024
1 parent 9bd69d3 commit 0e4a3da
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ void YogaLayoutableShadowNode::updateYogaChildren() {
yogaLayoutableChildren_.at(yogaChildIndex)->yogaNode_;

isClean = isClean && !newYogaChildNode.isDirty() &&
(newYogaChildNode.getStyle() == oldYogaChildNode.getStyle());
(newYogaChildNode.style() == oldYogaChildNode.style());
}
}
}
Expand All @@ -378,7 +378,7 @@ void YogaLayoutableShadowNode::updateYogaProps() {
auto styleResult = applyAliasedProps(props.yogaStyle, props);

// Resetting `dirty` flag only if `yogaStyle` portion of `Props` was changed.
if (!yogaNode_.isDirty() && (styleResult != yogaNode_.getStyle())) {
if (!yogaNode_.isDirty() && (styleResult != yogaNode_.style())) {
yogaNode_.setDirty(true);
}

Expand Down Expand Up @@ -532,7 +532,7 @@ YogaLayoutableShadowNode& YogaLayoutableShadowNode::cloneChildInPlace(
void YogaLayoutableShadowNode::setSize(Size size) const {
ensureUnsealed();

auto style = yogaNode_.getStyle();
auto style = yogaNode_.style();
style.setDimension(yoga::Dimension::Width, yoga::value::points(size.width));
style.setDimension(yoga::Dimension::Height, yoga::value::points(size.height));
yogaNode_.setStyle(style);
Expand All @@ -542,7 +542,7 @@ void YogaLayoutableShadowNode::setSize(Size size) const {
void YogaLayoutableShadowNode::setPadding(RectangleEdges<Float> padding) const {
ensureUnsealed();

auto style = yogaNode_.getStyle();
auto style = yogaNode_.style();

auto leftPadding = yoga::value::points(padding.left);
auto topPadding = yoga::value::points(padding.top);
Expand All @@ -566,7 +566,7 @@ void YogaLayoutableShadowNode::setPositionType(
YGPositionType positionType) const {
ensureUnsealed();

auto style = yogaNode_.getStyle();
auto style = yogaNode_.style();
style.setPositionType(yoga::scopedEnum(positionType));
yogaNode_.setStyle(style);
yogaNode_.setDirty(true);
Expand Down Expand Up @@ -617,7 +617,7 @@ void YogaLayoutableShadowNode::layoutTree(
// `ownerHeight` to allow proper calculation of relative (e.g. specified in
// percents) style values.

auto& yogaStyle = yogaNode_.getStyle();
auto& yogaStyle = yogaNode_.style();

auto ownerWidth = yogaFloatFromFloat(maximumSize.width);
auto ownerHeight = yogaFloatFromFloat(maximumSize.height);
Expand Down Expand Up @@ -717,7 +717,7 @@ void YogaLayoutableShadowNode::layout(LayoutContext layoutContext) {
}
}

if (yogaNode_.getStyle().overflow() == yoga::Overflow::Visible) {
if (yogaNode_.style().overflow() == yoga::Overflow::Visible) {
// Note that the parent node's overflow layout is NOT affected by its
// transform matrix. That transform matrix is applied on the parent node as
// well as all of its child nodes, which won't cause changes on the
Expand Down Expand Up @@ -869,7 +869,7 @@ void YogaLayoutableShadowNode::swapStyleLeftAndRight() {

void YogaLayoutableShadowNode::swapLeftAndRightInYogaStyleProps(
const YogaLayoutableShadowNode& shadowNode) {
auto yogaStyle = shadowNode.yogaNode_.getStyle();
auto yogaStyle = shadowNode.yogaNode_.style();

// Swap Yoga node values, position, padding and margin.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ inline LayoutMetrics layoutMetricsFromYogaNode(yoga::Node& yogaNode) {
layoutMetrics.borderWidth.bottom +
floatFromYogaFloat(YGNodeLayoutGetPadding(&yogaNode, YGEdgeBottom))};

layoutMetrics.displayType =
yogaNode.getStyle().display() == yoga::Display::None ? DisplayType::None
: DisplayType::Flex;
layoutMetrics.displayType = yogaNode.style().display() == yoga::Display::None
? DisplayType::None
: DisplayType::Flex;

layoutMetrics.positionType =
positionTypeFromYogaPositionType(yogaNode.getStyle().positionType());
positionTypeFromYogaPositionType(yogaNode.style().positionType());

layoutMetrics.layoutDirection =
YGNodeLayoutGetDirection(&yogaNode) == YGDirectionRTL
Expand Down
67 changes: 33 additions & 34 deletions packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace {

template <auto GetterT, auto SetterT, typename ValueT>
void updateStyle(YGNodeRef node, ValueT value) {
auto& style = resolveRef(node)->getStyle();
auto& style = resolveRef(node)->style();
if ((style.*GetterT)() != value) {
(style.*SetterT)(value);
resolveRef(node)->markDirtyAndPropagate();
Expand All @@ -25,7 +25,7 @@ void updateStyle(YGNodeRef node, ValueT value) {

template <auto GetterT, auto SetterT, typename IdxT, typename ValueT>
void updateStyle(YGNodeRef node, IdxT idx, ValueT value) {
auto& style = resolveRef(node)->getStyle();
auto& style = resolveRef(node)->style();
if ((style.*GetterT)(idx) != value) {
(style.*SetterT)(idx, value);
resolveRef(node)->markDirtyAndPropagate();
Expand All @@ -40,8 +40,8 @@ void YGNodeCopyStyle(
auto dstNode = resolveRef(dstNodeRef);
auto srcNode = resolveRef(srcNodeRef);

if (!(dstNode->getStyle() == srcNode->getStyle())) {
dstNode->setStyle(srcNode->getStyle());
if (!(dstNode->style() == srcNode->style())) {
dstNode->setStyle(srcNode->style());
dstNode->markDirtyAndPropagate();
}
}
Expand All @@ -51,7 +51,7 @@ void YGNodeStyleSetDirection(const YGNodeRef node, const YGDirection value) {
}

YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) {
return unscopedEnum(resolveRef(node)->getStyle().direction());
return unscopedEnum(resolveRef(node)->style().direction());
}

void YGNodeStyleSetFlexDirection(
Expand All @@ -62,7 +62,7 @@ void YGNodeStyleSetFlexDirection(
}

YGFlexDirection YGNodeStyleGetFlexDirection(const YGNodeConstRef node) {
return unscopedEnum(resolveRef(node)->getStyle().flexDirection());
return unscopedEnum(resolveRef(node)->style().flexDirection());
}

void YGNodeStyleSetJustifyContent(
Expand All @@ -73,7 +73,7 @@ void YGNodeStyleSetJustifyContent(
}

YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) {
return unscopedEnum(resolveRef(node)->getStyle().justifyContent());
return unscopedEnum(resolveRef(node)->style().justifyContent());
}

void YGNodeStyleSetAlignContent(
Expand All @@ -84,7 +84,7 @@ void YGNodeStyleSetAlignContent(
}

YGAlign YGNodeStyleGetAlignContent(const YGNodeConstRef node) {
return unscopedEnum(resolveRef(node)->getStyle().alignContent());
return unscopedEnum(resolveRef(node)->style().alignContent());
}

void YGNodeStyleSetAlignItems(const YGNodeRef node, const YGAlign alignItems) {
Expand All @@ -93,7 +93,7 @@ void YGNodeStyleSetAlignItems(const YGNodeRef node, const YGAlign alignItems) {
}

YGAlign YGNodeStyleGetAlignItems(const YGNodeConstRef node) {
return unscopedEnum(resolveRef(node)->getStyle().alignItems());
return unscopedEnum(resolveRef(node)->style().alignItems());
}

void YGNodeStyleSetAlignSelf(const YGNodeRef node, const YGAlign alignSelf) {
Expand All @@ -102,7 +102,7 @@ void YGNodeStyleSetAlignSelf(const YGNodeRef node, const YGAlign alignSelf) {
}

YGAlign YGNodeStyleGetAlignSelf(const YGNodeConstRef node) {
return unscopedEnum(resolveRef(node)->getStyle().alignSelf());
return unscopedEnum(resolveRef(node)->style().alignSelf());
}

void YGNodeStyleSetPositionType(
Expand All @@ -113,7 +113,7 @@ void YGNodeStyleSetPositionType(
}

YGPositionType YGNodeStyleGetPositionType(const YGNodeConstRef node) {
return unscopedEnum(resolveRef(node)->getStyle().positionType());
return unscopedEnum(resolveRef(node)->style().positionType());
}

void YGNodeStyleSetFlexWrap(const YGNodeRef node, const YGWrap flexWrap) {
Expand All @@ -122,7 +122,7 @@ void YGNodeStyleSetFlexWrap(const YGNodeRef node, const YGWrap flexWrap) {
}

YGWrap YGNodeStyleGetFlexWrap(const YGNodeConstRef node) {
return unscopedEnum(resolveRef(node)->getStyle().flexWrap());
return unscopedEnum(resolveRef(node)->style().flexWrap());
}

void YGNodeStyleSetOverflow(const YGNodeRef node, const YGOverflow overflow) {
Expand All @@ -131,15 +131,15 @@ void YGNodeStyleSetOverflow(const YGNodeRef node, const YGOverflow overflow) {
}

YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) {
return unscopedEnum(resolveRef(node)->getStyle().overflow());
return unscopedEnum(resolveRef(node)->style().overflow());
}

void YGNodeStyleSetDisplay(const YGNodeRef node, const YGDisplay display) {
updateStyle<&Style::display, &Style::setDisplay>(node, scopedEnum(display));
}

YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) {
return unscopedEnum(resolveRef(node)->getStyle().display());
return unscopedEnum(resolveRef(node)->style().display());
}

void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
Expand All @@ -148,9 +148,8 @@ void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {

float YGNodeStyleGetFlex(const YGNodeConstRef nodeRef) {
const auto node = resolveRef(nodeRef);
return node->getStyle().flex().isUndefined()
? YGUndefined
: node->getStyle().flex().unwrap();
return node->style().flex().isUndefined() ? YGUndefined
: node->style().flex().unwrap();
}

void YGNodeStyleSetFlexGrow(const YGNodeRef node, const float flexGrow) {
Expand All @@ -160,9 +159,9 @@ void YGNodeStyleSetFlexGrow(const YGNodeRef node, const float flexGrow) {

float YGNodeStyleGetFlexGrow(const YGNodeConstRef nodeRef) {
const auto node = resolveRef(nodeRef);
return node->getStyle().flexGrow().isUndefined()
return node->style().flexGrow().isUndefined()
? Style::DefaultFlexGrow
: node->getStyle().flexGrow().unwrap();
: node->style().flexGrow().unwrap();
}

void YGNodeStyleSetFlexShrink(const YGNodeRef node, const float flexShrink) {
Expand All @@ -172,10 +171,10 @@ void YGNodeStyleSetFlexShrink(const YGNodeRef node, const float flexShrink) {

float YGNodeStyleGetFlexShrink(const YGNodeConstRef nodeRef) {
const auto node = resolveRef(nodeRef);
return node->getStyle().flexShrink().isUndefined()
return node->style().flexShrink().isUndefined()
? (node->getConfig()->useWebDefaults() ? Style::WebDefaultFlexShrink
: Style::DefaultFlexShrink)
: node->getStyle().flexShrink().unwrap();
: node->style().flexShrink().unwrap();
}

void YGNodeStyleSetFlexBasis(const YGNodeRef node, const float flexBasis) {
Expand All @@ -195,7 +194,7 @@ void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) {
}

YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
return (YGValue)resolveRef(node)->getStyle().flexBasis();
return (YGValue)resolveRef(node)->style().flexBasis();
}

void YGNodeStyleSetPosition(YGNodeRef node, YGEdge edge, float points) {
Expand All @@ -209,7 +208,7 @@ void YGNodeStyleSetPositionPercent(YGNodeRef node, YGEdge edge, float percent) {
}

YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) {
return (YGValue)resolveRef(node)->getStyle().position(scopedEnum(edge));
return (YGValue)resolveRef(node)->style().position(scopedEnum(edge));
}

void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float points) {
Expand All @@ -228,7 +227,7 @@ void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) {
}

YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) {
return (YGValue)resolveRef(node)->getStyle().margin(scopedEnum(edge));
return (YGValue)resolveRef(node)->style().margin(scopedEnum(edge));
}

void YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, float points) {
Expand All @@ -242,7 +241,7 @@ void YGNodeStyleSetPaddingPercent(YGNodeRef node, YGEdge edge, float percent) {
}

YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) {
return (YGValue)resolveRef(node)->getStyle().padding(scopedEnum(edge));
return (YGValue)resolveRef(node)->style().padding(scopedEnum(edge));
}

void YGNodeStyleSetBorder(
Expand All @@ -254,7 +253,7 @@ void YGNodeStyleSetBorder(
}

float YGNodeStyleGetBorder(const YGNodeConstRef node, const YGEdge edge) {
auto border = resolveRef(node)->getStyle().border(scopedEnum(edge));
auto border = resolveRef(node)->style().border(scopedEnum(edge));
if (border.isUndefined() || border.isAuto()) {
return YGUndefined;
}
Expand All @@ -271,7 +270,7 @@ void YGNodeStyleSetGap(
}

float YGNodeStyleGetGap(const YGNodeConstRef node, const YGGutter gutter) {
auto gapLength = resolveRef(node)->getStyle().gap(scopedEnum(gutter));
auto gapLength = resolveRef(node)->style().gap(scopedEnum(gutter));
if (gapLength.isUndefined() || gapLength.isAuto()) {
return YGUndefined;
}
Expand All @@ -285,7 +284,7 @@ void YGNodeStyleSetAspectRatio(const YGNodeRef node, const float aspectRatio) {
}

float YGNodeStyleGetAspectRatio(const YGNodeConstRef node) {
const FloatOptional op = resolveRef(node)->getStyle().aspectRatio();
const FloatOptional op = resolveRef(node)->style().aspectRatio();
return op.isUndefined() ? YGUndefined : op.unwrap();
}

Expand All @@ -305,7 +304,7 @@ void YGNodeStyleSetWidthAuto(YGNodeRef node) {
}

YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {
return (YGValue)resolveRef(node)->getStyle().dimension(Dimension::Width);
return (YGValue)resolveRef(node)->style().dimension(Dimension::Width);
}

void YGNodeStyleSetHeight(YGNodeRef node, float points) {
Expand All @@ -324,7 +323,7 @@ void YGNodeStyleSetHeightAuto(YGNodeRef node) {
}

YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
return (YGValue)resolveRef(node)->getStyle().dimension(Dimension::Height);
return (YGValue)resolveRef(node)->style().dimension(Dimension::Height);
}

void YGNodeStyleSetMinWidth(const YGNodeRef node, const float minWidth) {
Expand All @@ -338,7 +337,7 @@ void YGNodeStyleSetMinWidthPercent(const YGNodeRef node, const float minWidth) {
}

YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
return (YGValue)resolveRef(node)->getStyle().minDimension(Dimension::Width);
return (YGValue)resolveRef(node)->style().minDimension(Dimension::Width);
}

void YGNodeStyleSetMinHeight(const YGNodeRef node, const float minHeight) {
Expand All @@ -354,7 +353,7 @@ void YGNodeStyleSetMinHeightPercent(
}

YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
return (YGValue)resolveRef(node)->getStyle().minDimension(Dimension::Height);
return (YGValue)resolveRef(node)->style().minDimension(Dimension::Height);
}

void YGNodeStyleSetMaxWidth(const YGNodeRef node, const float maxWidth) {
Expand All @@ -368,7 +367,7 @@ void YGNodeStyleSetMaxWidthPercent(const YGNodeRef node, const float maxWidth) {
}

YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
return (YGValue)resolveRef(node)->getStyle().maxDimension(Dimension::Width);
return (YGValue)resolveRef(node)->style().maxDimension(Dimension::Width);
}

void YGNodeStyleSetMaxHeight(const YGNodeRef node, const float maxHeight) {
Expand All @@ -384,5 +383,5 @@ void YGNodeStyleSetMaxHeightPercent(
}

YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) {
return (YGValue)resolveRef(node)->getStyle().maxDimension(Dimension::Height);
return (YGValue)resolveRef(node)->style().maxDimension(Dimension::Height);
}
Loading

0 comments on commit 0e4a3da

Please sign in to comment.