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: 06554f67bfd7709cbc24fdd9a5474e897e9e95d8
  • Loading branch information
NickGerleman authored and Othinn committed Jan 9, 2024
1 parent ec8355b commit 642530c
Show file tree
Hide file tree
Showing 22 changed files with 575 additions and 527 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 @@ -105,23 +105,23 @@ class AndroidTextInputComponentDescriptor final
!textInputProps.hasPaddingLeft &&
!textInputProps.hasPaddingHorizontal) {
changedPadding = true;
style.setPadding(YGEdgeStart, yoga::value::points(theme.start));
style.setPadding(yoga::Edge::Start, yoga::value::points(theme.start));
}
if (!textInputProps.hasPadding && !textInputProps.hasPaddingEnd &&
!textInputProps.hasPaddingRight &&
!textInputProps.hasPaddingHorizontal) {
changedPadding = true;
style.setPadding(YGEdgeEnd, yoga::value::points(theme.end));
style.setPadding(yoga::Edge::End, yoga::value::points(theme.end));
}
if (!textInputProps.hasPadding && !textInputProps.hasPaddingTop &&
!textInputProps.hasPaddingVertical) {
changedPadding = true;
style.setPadding(YGEdgeTop, yoga::value::points(theme.top));
style.setPadding(yoga::Edge::Top, yoga::value::points(theme.top));
}
if (!textInputProps.hasPadding && !textInputProps.hasPaddingBottom &&
!textInputProps.hasPaddingVertical) {
changedPadding = true;
style.setPadding(YGEdgeBottom, yoga::value::points(theme.bottom));
style.setPadding(yoga::Edge::Bottom, yoga::value::points(theme.bottom));
}

// If the TextInput initially does not have paddingLeft or paddingStart, a
Expand All @@ -132,12 +132,12 @@ class AndroidTextInputComponentDescriptor final
if ((textInputProps.hasPadding || textInputProps.hasPaddingLeft ||
textInputProps.hasPaddingHorizontal) &&
!textInputProps.hasPaddingStart) {
style.setPadding(YGEdgeStart, yoga::value::undefined());
style.setPadding(yoga::Edge::Start, yoga::value::undefined());
}
if ((textInputProps.hasPadding || textInputProps.hasPaddingRight ||
textInputProps.hasPaddingHorizontal) &&
!textInputProps.hasPaddingEnd) {
style.setPadding(YGEdgeEnd, yoga::value::undefined());
style.setPadding(yoga::Edge::End, yoga::value::undefined());
}

// Note that this is expensive: on every adopt, we need to set the Yoga
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 @@ -41,7 +41,7 @@ void ViewShadowNode::initialize() noexcept {

auto hasBorder = [&]() {
for (auto edge : yoga::ordinals<yoga::Edge>()) {
if (viewProps.yogaStyle.border(yoga::unscopedEnum(edge)).isDefined()) {
if (viewProps.yogaStyle.border(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 642530c

Please sign in to comment.