Skip to content

Commit

Permalink
YGEdge -> yoga::Edge (facebook#41391)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#41391

X-link: facebook/yoga#1461

Converts usages of `YGEdge` within internal APIs to `yoga::Edge` scoped enum.

With the exception of YGUnit which is in its own state of transition, this is the last public yoga enum to need to be moved to scoped enum form for usages internal to the Yoga public API.

Changelog: [internal]

Reviewed By: rshest

Differential Revision: D51152779

fbshipit-source-id: 17378a8710afa2b22c63ae5098be51a3391a6019
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Nov 14, 2023
1 parent 3f99100 commit 516021a
Show file tree
Hide file tree
Showing 22 changed files with 583 additions and 533 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ - (void)setUp
props.accessible = true;
auto &yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.setPosition(YGEdgeLeft, yoga::value::points(0));
yogaStyle.setPosition(YGEdgeTop, yoga::value::points(0));
yogaStyle.setPosition(yoga::Edge::Left, yoga::value::points(0));
yogaStyle.setPosition(yoga::Edge::Top, yoga::value::points(0));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(200));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(200));
return sharedProps;
Expand Down Expand Up @@ -214,8 +214,8 @@ - (void)setUp
props.accessible = true;
auto &yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.setPosition(YGEdgeLeft, yoga::value::points(0));
yogaStyle.setPosition(YGEdgeTop, yoga::value::points(30));
yogaStyle.setPosition(yoga::Edge::Left, yoga::value::points(0));
yogaStyle.setPosition(yoga::Edge::Top, yoga::value::points(30));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(200));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(50));
return sharedProps;
Expand Down Expand Up @@ -258,8 +258,8 @@ - (void)setUp
props.accessible = true;
auto &yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.setPosition(YGEdgeLeft, yoga::value::points(0));
yogaStyle.setPosition(YGEdgeTop, yoga::value::points(90));
yogaStyle.setPosition(yoga::Edge::Left, yoga::value::points(0));
yogaStyle.setPosition(yoga::Edge::Top, yoga::value::points(90));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(200));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(50));
return sharedProps;
Expand Down Expand Up @@ -432,8 +432,8 @@ - (void)testEntireParagraphLink
props.accessibilityTraits = AccessibilityTraits::Link;
auto &yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.setPosition(YGEdgeLeft, yoga::value::points(0));
yogaStyle.setPosition(YGEdgeTop, yoga::value::points(90));
yogaStyle.setPosition(yoga::Edge::Left, yoga::value::points(0));
yogaStyle.setPosition(yoga::Edge::Top, yoga::value::points(90));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(200));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(20));
return sharedProps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ class AndroidTextInputComponentDescriptor final
// paddingStart, and vice-versa with paddingRight/paddingEnd.
// For now this assumes no RTL.
ThemePadding result{
.start = textInputProps.yogaStyle.padding(YGEdgeStart),
.end = textInputProps.yogaStyle.padding(YGEdgeEnd),
.top = textInputProps.yogaStyle.padding(YGEdgeTop),
.bottom = textInputProps.yogaStyle.padding(YGEdgeBottom)};
.start = textInputProps.yogaStyle.padding(yoga::Edge::Start),
.end = textInputProps.yogaStyle.padding(yoga::Edge::End),
.top = textInputProps.yogaStyle.padding(yoga::Edge::Top),
.bottom = textInputProps.yogaStyle.padding(yoga::Edge::Bottom)};

bool changedPadding = false;
if (!textInputProps.hasPadding && !textInputProps.hasPaddingStart &&
Expand Down Expand Up @@ -161,10 +161,10 @@ class AndroidTextInputComponentDescriptor final
// Set new props on node
yoga::Style& style =
const_cast<AndroidTextInputProps&>(textInputProps).yogaStyle;
style.setPadding(YGEdgeStart, result.start);
style.setPadding(YGEdgeEnd, result.end);
style.setPadding(YGEdgeTop, result.top);
style.setPadding(YGEdgeBottom, result.bottom);
style.setPadding(yoga::Edge::Start, result.start);
style.setPadding(yoga::Edge::End, result.end);
style.setPadding(yoga::Edge::Top, result.top);
style.setPadding(yoga::Edge::Bottom, result.bottom);

// Communicate new props to Yoga part of the node
textInputShadowNode.updateYogaProps();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,20 +358,24 @@ BorderMetrics BaseViewProps::resolveBorderMetrics(
bool{layoutMetrics.layoutDirection == LayoutDirection::RightToLeft};

auto borderWidths = CascadedBorderWidths{
/* .left = */ optionalFloatFromYogaValue(yogaStyle.border(YGEdgeLeft)),
/* .top = */ optionalFloatFromYogaValue(yogaStyle.border(YGEdgeTop)),
/* .left = */ optionalFloatFromYogaValue(
yogaStyle.border(yoga::Edge::Left)),
/* .top = */
optionalFloatFromYogaValue(yogaStyle.border(yoga::Edge::Top)),
/* .right = */
optionalFloatFromYogaValue(yogaStyle.border(YGEdgeRight)),
optionalFloatFromYogaValue(yogaStyle.border(yoga::Edge::Right)),
/* .bottom = */
optionalFloatFromYogaValue(yogaStyle.border(YGEdgeBottom)),
optionalFloatFromYogaValue(yogaStyle.border(yoga::Edge::Bottom)),
/* .start = */
optionalFloatFromYogaValue(yogaStyle.border(YGEdgeStart)),
/* .end = */ optionalFloatFromYogaValue(yogaStyle.border(YGEdgeEnd)),
optionalFloatFromYogaValue(yogaStyle.border(yoga::Edge::Start)),
/* .end = */
optionalFloatFromYogaValue(yogaStyle.border(yoga::Edge::End)),
/* .horizontal = */
optionalFloatFromYogaValue(yogaStyle.border(YGEdgeHorizontal)),
optionalFloatFromYogaValue(yogaStyle.border(yoga::Edge::Horizontal)),
/* .vertical = */
optionalFloatFromYogaValue(yogaStyle.border(YGEdgeVertical)),
/* .all = */ optionalFloatFromYogaValue(yogaStyle.border(YGEdgeAll)),
optionalFloatFromYogaValue(yogaStyle.border(yoga::Edge::Vertical)),
/* .all = */
optionalFloatFromYogaValue(yogaStyle.border(yoga::Edge::All)),
};

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ void ViewShadowNode::initialize() noexcept {
HostPlatformViewTraitsInitializer::formsStackingContext(viewProps);

bool hasBorder = [&]() {
for (int edge = YGEdgeLeft; edge != YGEdgeAll; ++edge) {
if (viewProps.yogaStyle.border(static_cast<YGEdge>(edge)).isDefined()) {
for (int edge = 0; edge < yoga::ordinalCount<yoga::Edge>(); ++edge) {
if (viewProps.yogaStyle.border(static_cast<yoga::Edge>(edge))
.isDefined()) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,54 +392,54 @@ void YogaLayoutableShadowNode::updateYogaProps() {

// Aliases with precedence
if (props.insetInlineEnd.isDefined()) {
result.setPosition(YGEdgeEnd, props.insetInlineEnd);
result.setPosition(yoga::Edge::End, props.insetInlineEnd);
}
if (props.insetInlineStart.isDefined()) {
result.setPosition(YGEdgeStart, props.insetInlineStart);
result.setPosition(yoga::Edge::Start, props.insetInlineStart);
}
if (props.marginInline.isDefined()) {
result.setMargin(YGEdgeHorizontal, props.marginInline);
result.setMargin(yoga::Edge::Horizontal, props.marginInline);
}
if (props.marginInlineStart.isDefined()) {
result.setMargin(YGEdgeStart, props.marginInlineStart);
result.setMargin(yoga::Edge::Start, props.marginInlineStart);
}
if (props.marginInlineEnd.isDefined()) {
result.setMargin(YGEdgeEnd, props.marginInlineEnd);
result.setMargin(yoga::Edge::End, props.marginInlineEnd);
}
if (props.marginBlock.isDefined()) {
result.setMargin(YGEdgeVertical, props.marginBlock);
result.setMargin(yoga::Edge::Vertical, props.marginBlock);
}
if (props.paddingInline.isDefined()) {
result.setPadding(YGEdgeHorizontal, props.paddingInline);
result.setPadding(yoga::Edge::Horizontal, props.paddingInline);
}
if (props.paddingInlineStart.isDefined()) {
result.setPadding(YGEdgeStart, props.paddingInlineStart);
result.setPadding(yoga::Edge::Start, props.paddingInlineStart);
}
if (props.paddingInlineEnd.isDefined()) {
result.setPadding(YGEdgeEnd, props.paddingInlineEnd);
result.setPadding(yoga::Edge::End, props.paddingInlineEnd);
}
if (props.paddingBlock.isDefined()) {
result.setPadding(YGEdgeVertical, props.paddingBlock);
result.setPadding(yoga::Edge::Vertical, props.paddingBlock);
}

// Aliases without precedence
if (result.position(YGEdgeBottom).isUndefined()) {
result.setPosition(YGEdgeBottom, props.insetBlockEnd);
if (result.position(yoga::Edge::Bottom).isUndefined()) {
result.setPosition(yoga::Edge::Bottom, props.insetBlockEnd);
}
if (result.position(YGEdgeTop).isUndefined()) {
result.setPosition(YGEdgeTop, props.insetBlockStart);
if (result.position(yoga::Edge::Top).isUndefined()) {
result.setPosition(yoga::Edge::Top, props.insetBlockStart);
}
if (result.margin(YGEdgeTop).isUndefined()) {
result.setMargin(YGEdgeTop, props.marginBlockStart);
if (result.margin(yoga::Edge::Top).isUndefined()) {
result.setMargin(yoga::Edge::Top, props.marginBlockStart);
}
if (result.margin(YGEdgeBottom).isUndefined()) {
result.setMargin(YGEdgeBottom, props.marginBlockEnd);
if (result.margin(yoga::Edge::Bottom).isUndefined()) {
result.setMargin(yoga::Edge::Bottom, props.marginBlockEnd);
}
if (result.padding(YGEdgeTop).isUndefined()) {
result.setPadding(YGEdgeTop, props.paddingBlockStart);
if (result.padding(yoga::Edge::Top).isUndefined()) {
result.setPadding(yoga::Edge::Top, props.paddingBlockStart);
}
if (result.padding(YGEdgeBottom).isUndefined()) {
result.setPadding(YGEdgeBottom, props.paddingBlockEnd);
if (result.padding(yoga::Edge::Bottom).isUndefined()) {
result.setPadding(yoga::Edge::Bottom, props.paddingBlockEnd);
}

return result;
Expand Down Expand Up @@ -545,14 +545,14 @@ void YogaLayoutableShadowNode::setPadding(RectangleEdges<Float> padding) const {
auto rightPadding = yoga::value::points(padding.right);
auto bottomPadding = yoga::value::points(padding.bottom);

if (leftPadding != style.padding(YGEdgeLeft) ||
topPadding != style.padding(YGEdgeTop) ||
rightPadding != style.padding(YGEdgeRight) ||
bottomPadding != style.padding(YGEdgeBottom)) {
style.setPadding(YGEdgeTop, yoga::value::points(padding.top));
style.setPadding(YGEdgeLeft, yoga::value::points(padding.left));
style.setPadding(YGEdgeRight, yoga::value::points(padding.right));
style.setPadding(YGEdgeBottom, yoga::value::points(padding.bottom));
if (leftPadding != style.padding(yoga::Edge::Left) ||
topPadding != style.padding(yoga::Edge::Top) ||
rightPadding != style.padding(yoga::Edge::Right) ||
bottomPadding != style.padding(yoga::Edge::Bottom)) {
style.setPadding(yoga::Edge::Top, yoga::value::points(padding.top));
style.setPadding(yoga::Edge::Left, yoga::value::points(padding.left));
style.setPadding(yoga::Edge::Right, yoga::value::points(padding.right));
style.setPadding(yoga::Edge::Bottom, yoga::value::points(padding.bottom));
yogaNode_.setStyle(style);
yogaNode_.setDirty(true);
}
Expand Down Expand Up @@ -873,34 +873,37 @@ void YogaLayoutableShadowNode::swapLeftAndRightInYogaStyleProps(

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

if (yogaStyle.position(YGEdgeLeft).isDefined()) {
yogaStyle.setPosition(YGEdgeStart, yogaStyle.position(YGEdgeLeft));
yogaStyle.setPosition(YGEdgeLeft, yoga::value::undefined());
if (yogaStyle.position(yoga::Edge::Left).isDefined()) {
yogaStyle.setPosition(
yoga::Edge::Start, yogaStyle.position(yoga::Edge::Left));
yogaStyle.setPosition(yoga::Edge::Left, yoga::value::undefined());
}

if (yogaStyle.position(YGEdgeRight).isDefined()) {
yogaStyle.setPosition(YGEdgeEnd, yogaStyle.position(YGEdgeRight));
yogaStyle.setPosition(YGEdgeRight, yoga::value::undefined());
if (yogaStyle.position(yoga::Edge::Right).isDefined()) {
yogaStyle.setPosition(
yoga::Edge::End, yogaStyle.position(yoga::Edge::Right));
yogaStyle.setPosition(yoga::Edge::Right, yoga::value::undefined());
}

if (yogaStyle.padding(YGEdgeLeft).isDefined()) {
yogaStyle.setPadding(YGEdgeStart, yogaStyle.padding(YGEdgeLeft));
yogaStyle.setPadding(YGEdgeLeft, yoga::value::undefined());
if (yogaStyle.padding(yoga::Edge::Left).isDefined()) {
yogaStyle.setPadding(
yoga::Edge::Start, yogaStyle.padding(yoga::Edge::Left));
yogaStyle.setPadding(yoga::Edge::Left, yoga::value::undefined());
}

if (yogaStyle.padding(YGEdgeRight).isDefined()) {
yogaStyle.setPadding(YGEdgeEnd, yogaStyle.padding(YGEdgeRight));
yogaStyle.setPadding(YGEdgeRight, yoga::value::undefined());
if (yogaStyle.padding(yoga::Edge::Right).isDefined()) {
yogaStyle.setPadding(yoga::Edge::End, yogaStyle.padding(yoga::Edge::Right));
yogaStyle.setPadding(yoga::Edge::Right, yoga::value::undefined());
}

if (yogaStyle.margin(YGEdgeLeft).isDefined()) {
yogaStyle.setMargin(YGEdgeStart, yogaStyle.margin(YGEdgeLeft));
yogaStyle.setMargin(YGEdgeLeft, yoga::value::undefined());
if (yogaStyle.margin(yoga::Edge::Left).isDefined()) {
yogaStyle.setMargin(yoga::Edge::Start, yogaStyle.margin(yoga::Edge::Left));
yogaStyle.setMargin(yoga::Edge::Left, yoga::value::undefined());
}

if (yogaStyle.margin(YGEdgeRight).isDefined()) {
yogaStyle.setMargin(YGEdgeEnd, yogaStyle.margin(YGEdgeRight));
yogaStyle.setMargin(YGEdgeRight, yoga::value::undefined());
if (yogaStyle.margin(yoga::Edge::Right).isDefined()) {
yogaStyle.setMargin(yoga::Edge::End, yogaStyle.margin(yoga::Edge::Right));
yogaStyle.setMargin(yoga::Edge::Right, yoga::value::undefined());
}

shadowNode.yogaNode_.setStyle(yogaStyle);
Expand Down Expand Up @@ -953,14 +956,16 @@ void YogaLayoutableShadowNode::swapLeftAndRightInViewProps(
props.borderStyles.right.reset();
}

if (props.yogaStyle.border(YGEdgeLeft).isDefined()) {
props.yogaStyle.setBorder(YGEdgeStart, props.yogaStyle.border(YGEdgeLeft));
props.yogaStyle.setBorder(YGEdgeLeft, yoga::value::undefined());
if (props.yogaStyle.border(yoga::Edge::Left).isDefined()) {
props.yogaStyle.setBorder(
yoga::Edge::Start, props.yogaStyle.border(yoga::Edge::Left));
props.yogaStyle.setBorder(yoga::Edge::Left, yoga::value::undefined());
}

if (props.yogaStyle.border(YGEdgeRight).isDefined()) {
props.yogaStyle.setBorder(YGEdgeEnd, props.yogaStyle.border(YGEdgeRight));
props.yogaStyle.setBorder(YGEdgeRight, yoga::value::undefined());
if (props.yogaStyle.border(yoga::Edge::Right).isDefined()) {
props.yogaStyle.setBorder(
yoga::Edge::End, props.yogaStyle.border(yoga::Edge::Right));
props.yogaStyle.setBorder(yoga::Edge::Right, yoga::value::undefined());
}
}

Expand Down
Loading

0 comments on commit 516021a

Please sign in to comment.