Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yoga::resolveValue -> Length::resolve #41939

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,19 @@ inline yoga::FloatOptional yogaOptionalFloatFromFloat(Float value) {
}

inline std::optional<Float> optionalFloatFromYogaValue(
const YGValue value,
const yoga::Style::Length& length,
std::optional<Float> base = {}) {
switch (value.unit) {
case YGUnitUndefined:
switch (length.unit()) {
case yoga::Unit::Undefined:
return {};
case YGUnitPoint:
return floatFromYogaFloat(value.value);
case YGUnitPercent:
case yoga::Unit::Point:
return floatFromYogaOptionalFloat(length.value());
case yoga::Unit::Percent:
return base.has_value()
? std::optional<Float>(base.value() * floatFromYogaFloat(value.value))
? std::optional<Float>(
base.value() * floatFromYogaOptionalFloat(length.value()))
: std::optional<Float>();
case YGUnitAuto:
case yoga::Unit::Auto:
return {};
}
}
Expand Down Expand Up @@ -417,7 +418,7 @@ inline void fromRawValue(
} else if (value.hasType<std::string>()) {
const auto stringValue = (std::string)value;
if (stringValue == "auto") {
result = YGValueAuto;
result = yoga::value::ofAuto();
return;
} else {
if (stringValue.back() == '%') {
Expand All @@ -436,16 +437,16 @@ inline void fromRawValue(
}
}
}
result = YGValueUndefined;
result = yoga::value::undefined();
}

inline void fromRawValue(
const PropsParserContext& context,
const RawValue& value,
YGValue& result) {
yoga::Style::Length ygValue{};
fromRawValue(context, value, ygValue);
result = ygValue;
yoga::Style::Length length{};
fromRawValue(context, value, length);
result = (YGValue)length;
}

inline void fromRawValue(
Expand Down Expand Up @@ -772,15 +773,15 @@ inline std::string toString(const yoga::Display& value) {
return YGDisplayToString(yoga::unscopedEnum(value));
}

inline std::string toString(const YGValue& value) {
switch (value.unit) {
case YGUnitUndefined:
inline std::string toString(const yoga::Style::Length& length) {
switch (length.unit()) {
case yoga::Unit::Undefined:
return "undefined";
case YGUnitPoint:
return folly::to<std::string>(value.value);
case YGUnitPercent:
return folly::to<std::string>(value.value) + "%";
case YGUnitAuto:
case yoga::Unit::Point:
return std::to_string(length.value().unwrap());
case yoga::Unit::Percent:
return std::to_string(length.value().unwrap()) + "%";
case yoga::Unit::Auto:
return "auto";
}
}
Expand All @@ -790,7 +791,7 @@ inline std::string toString(const yoga::FloatOptional& value) {
return "undefined";
}

return folly::to<std::string>(floatFromYogaFloat(value.unwrap()));
return std::to_string(value.unwrap());
}

inline std::string toString(const LayoutConformance& value) {
Expand Down
24 changes: 10 additions & 14 deletions packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,7 @@ void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) {
}

YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
YGValue flexBasis = resolveRef(node)->getStyle().flexBasis();
if (flexBasis.unit == YGUnitUndefined || flexBasis.unit == YGUnitAuto) {
flexBasis.value = YGUndefined;
}
return flexBasis;
return (YGValue)resolveRef(node)->getStyle().flexBasis();
}

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

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

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

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

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

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

void YGNodeStyleSetBorder(
Expand Down Expand Up @@ -309,7 +305,7 @@ void YGNodeStyleSetWidthAuto(YGNodeRef node) {
}

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

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

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

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

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

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

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

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

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

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

YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) {
return resolveRef(node)->getStyle().maxDimension(Dimension::Height);
return (YGValue)resolveRef(node)->getStyle().maxDimension(Dimension::Height);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <yoga/algorithm/Align.h>
#include <yoga/algorithm/BoundAxis.h>
#include <yoga/algorithm/CalculateLayout.h>
#include <yoga/algorithm/ResolveValue.h>

namespace facebook::yoga {

Expand Down Expand Up @@ -323,10 +322,9 @@ void layoutAbsoluteChild(
child->getMarginForAxis(FlexDirection::Column, containingBlockWidth);

if (child->styleDefinesDimension(FlexDirection::Row, containingBlockWidth)) {
childWidth =
yoga::resolveValue(
child->getResolvedDimension(Dimension::Width), containingBlockWidth)
.unwrap() +
childWidth = child->getResolvedDimension(Dimension::Width)
.resolve(containingBlockWidth)
.unwrap() +
marginRow;
} else {
// If the child doesn't have a specified width, compute the width based on
Expand All @@ -352,9 +350,8 @@ void layoutAbsoluteChild(

if (child->styleDefinesDimension(
FlexDirection::Column, containingBlockHeight)) {
childHeight = yoga::resolveValue(
child->getResolvedDimension(Dimension::Height),
containingBlockHeight)
childHeight = child->getResolvedDimension(Dimension::Height)
.resolve(containingBlockHeight)
.unwrap() +
marginColumn;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#pragma once

#include <yoga/algorithm/FlexDirection.h>
#include <yoga/algorithm/ResolveValue.h>
#include <yoga/enums/Dimension.h>
#include <yoga/enums/FlexDirection.h>
#include <yoga/node/Node.h>
Expand Down Expand Up @@ -36,15 +35,11 @@ inline FloatOptional boundAxisWithinMinAndMax(
FloatOptional max;

if (isColumn(axis)) {
min = yoga::resolveValue(
node->getStyle().minDimension(Dimension::Height), axisSize);
max = yoga::resolveValue(
node->getStyle().maxDimension(Dimension::Height), axisSize);
min = node->getStyle().minDimension(Dimension::Height).resolve(axisSize);
max = node->getStyle().maxDimension(Dimension::Height).resolve(axisSize);
} else if (isRow(axis)) {
min = yoga::resolveValue(
node->getStyle().minDimension(Dimension::Width), axisSize);
max = yoga::resolveValue(
node->getStyle().maxDimension(Dimension::Width), axisSize);
min = node->getStyle().minDimension(Dimension::Width).resolve(axisSize);
max = node->getStyle().maxDimension(Dimension::Width).resolve(axisSize);
}

if (max >= FloatOptional{0} && value > max) {
Expand Down
Loading
Loading