Skip to content

Commit

Permalink
Sunset the value namespace (facebook#46930)
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/yoga#1720

Pull Request resolved: facebook#46930

This is not really needed anymore, we can just use `StyleLength` statics instead

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D63922280

fbshipit-source-id: cd953bae8e9f68574463eafc49c33c2e85ac1856
  • Loading branch information
joevilches authored and facebook-github-bot committed Oct 10, 2024
1 parent b70709d commit 0d6908f
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ - (void)setUp
auto &props = *sharedProps;
props.layoutConstraints = LayoutConstraints{{0, 0}, {500, 500}};
auto &yogaStyle = props.yogaStyle;
yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(200));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(200));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(200));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(200));
return sharedProps;
})
.children({
Expand All @@ -134,10 +134,10 @@ - (void)setUp
props.accessible = true;
auto &yogaStyle = props.yogaStyle;
yogaStyle.setPositionType(yoga::PositionType::Absolute);
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));
yogaStyle.setPosition(yoga::Edge::Left, yoga::StyleLength::points(0));
yogaStyle.setPosition(yoga::Edge::Top, yoga::StyleLength::points(0));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(200));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(200));
return sharedProps;
})
.children({
Expand Down Expand Up @@ -214,10 +214,10 @@ - (void)setUp
props.accessible = true;
auto &yogaStyle = props.yogaStyle;
yogaStyle.setPositionType(yoga::PositionType::Absolute);
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));
yogaStyle.setPosition(yoga::Edge::Left, yoga::StyleLength::points(0));
yogaStyle.setPosition(yoga::Edge::Top, yoga::StyleLength::points(30));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(200));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(50));
return sharedProps;
})
.children({
Expand Down Expand Up @@ -258,10 +258,10 @@ - (void)setUp
props.accessible = true;
auto &yogaStyle = props.yogaStyle;
yogaStyle.setPositionType(yoga::PositionType::Absolute);
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));
yogaStyle.setPosition(yoga::Edge::Left, yoga::StyleLength::points(0));
yogaStyle.setPosition(yoga::Edge::Top, yoga::StyleLength::points(90));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(200));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(50));
return sharedProps;
})
.children({
Expand Down Expand Up @@ -418,8 +418,8 @@ - (void)testEntireParagraphLink
auto &props = *sharedProps;
props.layoutConstraints = LayoutConstraints{{0, 0}, {500, 500}};
auto &yogaStyle = props.yogaStyle;
yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(200));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(200));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(200));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(200));
return sharedProps;
})
.children({
Expand All @@ -432,10 +432,10 @@ - (void)testEntireParagraphLink
props.accessibilityTraits = AccessibilityTraits::Link;
auto &yogaStyle = props.yogaStyle;
yogaStyle.setPositionType(yoga::PositionType::Absolute);
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));
yogaStyle.setPosition(yoga::Edge::Left, yoga::StyleLength::points(0));
yogaStyle.setPosition(yoga::Edge::Top, yoga::StyleLength::points(90));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(200));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(20));
return sharedProps;
})
.children({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,25 @@ class AndroidTextInputComponentDescriptor final
!textInputProps.hasPaddingLeft &&
!textInputProps.hasPaddingHorizontal) {
changedPadding = true;
style.setPadding(yoga::Edge::Start, yoga::value::points(theme.start));
style.setPadding(
yoga::Edge::Start, yoga::StyleLength::points(theme.start));
}
if (!textInputProps.hasPadding && !textInputProps.hasPaddingEnd &&
!textInputProps.hasPaddingRight &&
!textInputProps.hasPaddingHorizontal) {
changedPadding = true;
style.setPadding(yoga::Edge::End, yoga::value::points(theme.end));
style.setPadding(yoga::Edge::End, yoga::StyleLength::points(theme.end));
}
if (!textInputProps.hasPadding && !textInputProps.hasPaddingTop &&
!textInputProps.hasPaddingVertical) {
changedPadding = true;
style.setPadding(yoga::Edge::Top, yoga::value::points(theme.top));
style.setPadding(yoga::Edge::Top, yoga::StyleLength::points(theme.top));
}
if (!textInputProps.hasPadding && !textInputProps.hasPaddingBottom &&
!textInputProps.hasPaddingVertical) {
changedPadding = true;
style.setPadding(yoga::Edge::Bottom, yoga::value::points(theme.bottom));
style.setPadding(
yoga::Edge::Bottom, yoga::StyleLength::points(theme.bottom));
}

// If the TextInput initially does not have paddingLeft or paddingStart, a
Expand All @@ -132,12 +134,12 @@ class AndroidTextInputComponentDescriptor final
if ((textInputProps.hasPadding || textInputProps.hasPaddingLeft ||
textInputProps.hasPaddingHorizontal) &&
!textInputProps.hasPaddingStart) {
style.setPadding(yoga::Edge::Start, yoga::value::undefined());
style.setPadding(yoga::Edge::Start, yoga::StyleLength::undefined());
}
if ((textInputProps.hasPadding || textInputProps.hasPaddingRight ||
textInputProps.hasPaddingHorizontal) &&
!textInputProps.hasPaddingEnd) {
style.setPadding(yoga::Edge::End, yoga::value::undefined());
style.setPadding(yoga::Edge::End, yoga::StyleLength::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 @@ -532,8 +532,10 @@ void YogaLayoutableShadowNode::setSize(Size size) const {
ensureUnsealed();

auto style = yogaNode_.style();
style.setDimension(yoga::Dimension::Width, yoga::value::points(size.width));
style.setDimension(yoga::Dimension::Height, yoga::value::points(size.height));
style.setDimension(
yoga::Dimension::Width, yoga::StyleLength::points(size.width));
style.setDimension(
yoga::Dimension::Height, yoga::StyleLength::points(size.height));
yogaNode_.setStyle(style);
yogaNode_.setDirty(true);
}
Expand All @@ -543,19 +545,21 @@ void YogaLayoutableShadowNode::setPadding(RectangleEdges<Float> padding) const {

auto style = yogaNode_.style();

auto leftPadding = yoga::value::points(padding.left);
auto topPadding = yoga::value::points(padding.top);
auto rightPadding = yoga::value::points(padding.right);
auto bottomPadding = yoga::value::points(padding.bottom);
auto leftPadding = yoga::StyleLength::points(padding.left);
auto topPadding = yoga::StyleLength::points(padding.top);
auto rightPadding = yoga::StyleLength::points(padding.right);
auto bottomPadding = yoga::StyleLength::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));
style.setPadding(yoga::Edge::Top, yoga::StyleLength::points(padding.top));
style.setPadding(yoga::Edge::Left, yoga::StyleLength::points(padding.left));
style.setPadding(
yoga::Edge::Right, yoga::StyleLength::points(padding.right));
style.setPadding(
yoga::Edge::Bottom, yoga::StyleLength::points(padding.bottom));
yogaNode_.setStyle(style);
yogaNode_.setDirty(true);
}
Expand Down Expand Up @@ -622,16 +626,16 @@ void YogaLayoutableShadowNode::layoutTree(
auto ownerHeight = yogaFloatFromFloat(maximumSize.height);

yogaStyle.setMaxDimension(
yoga::Dimension::Width, yoga::value::points(maximumSize.width));
yoga::Dimension::Width, yoga::StyleLength::points(maximumSize.width));

yogaStyle.setMaxDimension(
yoga::Dimension::Height, yoga::value::points(maximumSize.height));
yoga::Dimension::Height, yoga::StyleLength::points(maximumSize.height));

yogaStyle.setMinDimension(
yoga::Dimension::Width, yoga::value::points(minimumSize.width));
yoga::Dimension::Width, yoga::StyleLength::points(minimumSize.width));

yogaStyle.setMinDimension(
yoga::Dimension::Height, yoga::value::points(minimumSize.height));
yoga::Dimension::Height, yoga::StyleLength::points(minimumSize.height));

auto direction =
yogaDirectionFromLayoutDirection(layoutConstraints.layoutDirection);
Expand Down Expand Up @@ -894,44 +898,44 @@ void YogaLayoutableShadowNode::swapLeftAndRightInYogaStyleProps() {
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());
yogaStyle.setPosition(yoga::Edge::Left, yoga::StyleLength::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());
yogaStyle.setPosition(yoga::Edge::Right, yoga::StyleLength::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());
yogaStyle.setPadding(yoga::Edge::Left, yoga::StyleLength::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());
yogaStyle.setPadding(yoga::Edge::Right, yoga::StyleLength::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());
yogaStyle.setMargin(yoga::Edge::Left, yoga::StyleLength::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());
yogaStyle.setMargin(yoga::Edge::Right, yoga::StyleLength::undefined());
}

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

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

yogaNode_.setStyle(yogaStyle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,98 +790,98 @@ void YogaStylableProps::convertRawPropAliases(
rawProps,
"insetBlockEnd",
sourceProps.insetBlockEnd,
yoga::value::undefined());
yoga::StyleLength::undefined());
insetBlockStart = convertRawProp(
context,
rawProps,
"insetBlockStart",
sourceProps.insetBlockStart,
yoga::value::undefined());
yoga::StyleLength::undefined());
insetInlineEnd = convertRawProp(
context,
rawProps,
"insetInlineEnd",
sourceProps.insetInlineEnd,
yoga::value::undefined());
yoga::StyleLength::undefined());
insetInlineStart = convertRawProp(
context,
rawProps,
"insetInlineStart",
sourceProps.insetInlineStart,
yoga::value::undefined());
yoga::StyleLength::undefined());
marginInline = convertRawProp(
context,
rawProps,
"marginInline",
sourceProps.marginInline,
yoga::value::undefined());
yoga::StyleLength::undefined());
marginInlineStart = convertRawProp(
context,
rawProps,
"marginInlineStart",
sourceProps.marginInlineStart,
yoga::value::undefined());
yoga::StyleLength::undefined());
marginInlineEnd = convertRawProp(
context,
rawProps,
"marginInlineEnd",
sourceProps.marginInlineEnd,
yoga::value::undefined());
yoga::StyleLength::undefined());
marginBlock = convertRawProp(
context,
rawProps,
"marginBlock",
sourceProps.marginBlock,
yoga::value::undefined());
yoga::StyleLength::undefined());
marginBlockStart = convertRawProp(
context,
rawProps,
"marginBlockStart",
sourceProps.marginBlockStart,
yoga::value::undefined());
yoga::StyleLength::undefined());
marginBlockEnd = convertRawProp(
context,
rawProps,
"marginBlockEnd",
sourceProps.marginBlockEnd,
yoga::value::undefined());
yoga::StyleLength::undefined());

paddingInline = convertRawProp(
context,
rawProps,
"paddingInline",
sourceProps.paddingInline,
yoga::value::undefined());
yoga::StyleLength::undefined());
paddingInlineStart = convertRawProp(
context,
rawProps,
"paddingInlineStart",
sourceProps.paddingInlineStart,
yoga::value::undefined());
yoga::StyleLength::undefined());
paddingInlineEnd = convertRawProp(
context,
rawProps,
"paddingInlineEnd",
sourceProps.paddingInlineEnd,
yoga::value::undefined());
yoga::StyleLength::undefined());
paddingBlock = convertRawProp(
context,
rawProps,
"paddingBlock",
sourceProps.paddingBlock,
yoga::value::undefined());
yoga::StyleLength::undefined());
paddingBlockStart = convertRawProp(
context,
rawProps,
"paddingBlockStart",
sourceProps.paddingBlockStart,
yoga::value::undefined());
yoga::StyleLength::undefined());
paddingBlockEnd = convertRawProp(
context,
rawProps,
"paddingBlockEnd",
sourceProps.paddingBlockEnd,
yoga::value::undefined());
yoga::StyleLength::undefined());
}

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -437,31 +437,31 @@ inline void fromRawValue(
const RawValue& value,
yoga::Style::Length& result) {
if (value.hasType<Float>()) {
result = yoga::value::points((float)value);
result = yoga::StyleLength::points((float)value);
return;
} else if (value.hasType<std::string>()) {
const auto stringValue = (std::string)value;
if (stringValue == "auto") {
result = yoga::value::ofAuto();
result = yoga::StyleLength::ofAuto();
return;
} else {
if (stringValue.back() == '%') {
auto tryValue = folly::tryTo<float>(
std::string_view(stringValue).substr(0, stringValue.length() - 1));
if (tryValue.hasValue()) {
result = yoga::value::percent(tryValue.value());
result = yoga::StyleLength::percent(tryValue.value());
return;
}
} else {
auto tryValue = folly::tryTo<float>(stringValue);
if (tryValue.hasValue()) {
result = yoga::value::points(tryValue.value());
result = yoga::StyleLength::points(tryValue.value());
return;
}
}
}
}
result = yoga::value::undefined();
result = yoga::StyleLength::undefined();
}

inline void fromRawValue(
Expand Down
Loading

0 comments on commit 0d6908f

Please sign in to comment.