Skip to content

Commit

Permalink
Back out "Modify private apis to set, store, and get intrinsic sizing…
Browse files Browse the repository at this point in the history
… keywords" (#1750)

Summary:
X-link: facebook/react-native#47895

Pull Request resolved: #1750

These APIs were only added so that we could do TDD as we work on intrinsic sizing functionality. As of right now they do nothing. We are aiming on publishing a new version of Yoga soon so for the time being we are going to back these out so as not to confuse anyone with this new functionality. Ideally we get to a point where we have some temporary experimental header to stage these in but this is a bit time sensitive so just backing out for now

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D66332307

fbshipit-source-id: 1d596964e0c893091c541988506e8b80fa6d1957
  • Loading branch information
joevilches authored and facebook-github-bot committed Nov 25, 2024
1 parent 0c99549 commit be00354
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 317 deletions.
10 changes: 1 addition & 9 deletions enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@

ENUMS = {
"Direction": ["Inherit", "LTR", "RTL"],
"Unit": [
"Undefined",
"Point",
"Percent",
"Auto",
"MaxContent",
"FitContent",
"Stretch",
],
"Unit": ["Undefined", "Point", "Percent", "Auto"],
"FlexDirection": ["Column", "ColumnReverse", "Row", "RowReverse"],
"Justify": [
"FlexStart",
Expand Down
8 changes: 1 addition & 7 deletions java/com/facebook/yoga/YogaUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ public enum YogaUnit {
UNDEFINED(0),
POINT(1),
PERCENT(2),
AUTO(3),
MAX_CONTENT(4),
FIT_CONTENT(5),
STRETCH(6);
AUTO(3);

private final int mIntValue;

Expand All @@ -34,9 +31,6 @@ public static YogaUnit fromInt(int value) {
case 1: return POINT;
case 2: return PERCENT;
case 3: return AUTO;
case 4: return MAX_CONTENT;
case 5: return FIT_CONTENT;
case 6: return STRETCH;
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
Expand Down
6 changes: 0 additions & 6 deletions javascript/src/generated/YGEnums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ export enum Unit {
Point = 1,
Percent = 2,
Auto = 3,
MaxContent = 4,
FitContent = 5,
Stretch = 6,
}

export enum Wrap {
Expand Down Expand Up @@ -206,9 +203,6 @@ const constants = {
UNIT_POINT: Unit.Point,
UNIT_PERCENT: Unit.Percent,
UNIT_AUTO: Unit.Auto,
UNIT_MAX_CONTENT: Unit.MaxContent,
UNIT_FIT_CONTENT: Unit.FitContent,
UNIT_STRETCH: Unit.Stretch,
WRAP_NO_WRAP: Wrap.NoWrap,
WRAP_WRAP: Wrap.Wrap,
WRAP_WRAP_REVERSE: Wrap.WrapReverse,
Expand Down
15 changes: 0 additions & 15 deletions tests/StyleValuePoolTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,4 @@ TEST(StyleValuePool, store_undefined_after_large_int) {
EXPECT_EQ(pool.getLength(handle), StyleLength::undefined());
}

TEST(StyleValuePool, store_keywords) {
StyleValuePool pool;
StyleValueHandle handleMaxContent;
StyleValueHandle handleFitContent;
StyleValueHandle handleStretch;

pool.store(handleMaxContent, StyleSizeLength::ofMaxContent());
pool.store(handleFitContent, StyleSizeLength::ofFitContent());
pool.store(handleStretch, StyleSizeLength::ofStretch());

EXPECT_EQ(pool.getSize(handleMaxContent), StyleSizeLength::ofMaxContent());
EXPECT_EQ(pool.getSize(handleFitContent), StyleSizeLength::ofFitContent());
EXPECT_EQ(pool.getSize(handleStretch), StyleSizeLength::ofStretch());
}

} // namespace facebook::yoga
6 changes: 0 additions & 6 deletions yoga/YGEnums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,6 @@ const char* YGUnitToString(const YGUnit value) {
return "percent";
case YGUnitAuto:
return "auto";
case YGUnitMaxContent:
return "max-content";
case YGUnitFitContent:
return "fit-content";
case YGUnitStretch:
return "stretch";
}
return "unknown";
}
Expand Down
5 changes: 1 addition & 4 deletions yoga/YGEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ YG_ENUM_DECL(
YGUnitUndefined,
YGUnitPoint,
YGUnitPercent,
YGUnitAuto,
YGUnitMaxContent,
YGUnitFitContent,
YGUnitStretch)
YGUnitAuto)

YG_ENUM_DECL(
YGWrap,
Expand Down
34 changes: 17 additions & 17 deletions yoga/YGNodeStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,19 @@ float YGNodeStyleGetFlexShrink(const YGNodeConstRef nodeRef) {

void YGNodeStyleSetFlexBasis(const YGNodeRef node, const float flexBasis) {
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
node, StyleSizeLength::points(flexBasis));
node, StyleLength::points(flexBasis));
}

void YGNodeStyleSetFlexBasisPercent(
const YGNodeRef node,
const float flexBasisPercent) {
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
node, StyleSizeLength::percent(flexBasisPercent));
node, StyleLength::percent(flexBasisPercent));
}

void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) {
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
node, StyleSizeLength::ofAuto());
node, StyleLength::ofAuto());
}

YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
Expand Down Expand Up @@ -308,17 +308,17 @@ YGBoxSizing YGNodeStyleGetBoxSizing(const YGNodeConstRef node) {

void YGNodeStyleSetWidth(YGNodeRef node, float points) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Width, StyleSizeLength::points(points));
node, Dimension::Width, StyleLength::points(points));
}

void YGNodeStyleSetWidthPercent(YGNodeRef node, float percent) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Width, StyleSizeLength::percent(percent));
node, Dimension::Width, StyleLength::percent(percent));
}

void YGNodeStyleSetWidthAuto(YGNodeRef node) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Width, StyleSizeLength::ofAuto());
node, Dimension::Width, StyleLength::ofAuto());
}

YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {
Expand All @@ -327,17 +327,17 @@ YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {

void YGNodeStyleSetHeight(YGNodeRef node, float points) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Height, StyleSizeLength::points(points));
node, Dimension::Height, StyleLength::points(points));
}

void YGNodeStyleSetHeightPercent(YGNodeRef node, float percent) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Height, StyleSizeLength::percent(percent));
node, Dimension::Height, StyleLength::percent(percent));
}

void YGNodeStyleSetHeightAuto(YGNodeRef node) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Height, StyleSizeLength::ofAuto());
node, Dimension::Height, StyleLength::ofAuto());
}

YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
Expand All @@ -346,12 +346,12 @@ YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {

void YGNodeStyleSetMinWidth(const YGNodeRef node, const float minWidth) {
updateStyle<&Style::minDimension, &Style::setMinDimension>(
node, Dimension::Width, StyleSizeLength::points(minWidth));
node, Dimension::Width, StyleLength::points(minWidth));
}

void YGNodeStyleSetMinWidthPercent(const YGNodeRef node, const float minWidth) {
updateStyle<&Style::minDimension, &Style::setMinDimension>(
node, Dimension::Width, StyleSizeLength::percent(minWidth));
node, Dimension::Width, StyleLength::percent(minWidth));
}

YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
Expand All @@ -360,14 +360,14 @@ YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {

void YGNodeStyleSetMinHeight(const YGNodeRef node, const float minHeight) {
updateStyle<&Style::minDimension, &Style::setMinDimension>(
node, Dimension::Height, StyleSizeLength::points(minHeight));
node, Dimension::Height, StyleLength::points(minHeight));
}

void YGNodeStyleSetMinHeightPercent(
const YGNodeRef node,
const float minHeight) {
updateStyle<&Style::minDimension, &Style::setMinDimension>(
node, Dimension::Height, StyleSizeLength::percent(minHeight));
node, Dimension::Height, StyleLength::percent(minHeight));
}

YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
Expand All @@ -376,12 +376,12 @@ YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {

void YGNodeStyleSetMaxWidth(const YGNodeRef node, const float maxWidth) {
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
node, Dimension::Width, StyleSizeLength::points(maxWidth));
node, Dimension::Width, StyleLength::points(maxWidth));
}

void YGNodeStyleSetMaxWidthPercent(const YGNodeRef node, const float maxWidth) {
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
node, Dimension::Width, StyleSizeLength::percent(maxWidth));
node, Dimension::Width, StyleLength::percent(maxWidth));
}

YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
Expand All @@ -390,14 +390,14 @@ YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {

void YGNodeStyleSetMaxHeight(const YGNodeRef node, const float maxHeight) {
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
node, Dimension::Height, StyleSizeLength::points(maxHeight));
node, Dimension::Height, StyleLength::points(maxHeight));
}

void YGNodeStyleSetMaxHeightPercent(
const YGNodeRef node,
const float maxHeight) {
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
node, Dimension::Height, StyleSizeLength::percent(maxHeight));
node, Dimension::Height, StyleLength::percent(maxHeight));
}

YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) {
Expand Down
3 changes: 0 additions & 3 deletions yoga/YGValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ inline bool operator==(const YGValue& lhs, const YGValue& rhs) {
switch (lhs.unit) {
case YGUnitUndefined:
case YGUnitAuto:
case YGUnitFitContent:
case YGUnitMaxContent:
case YGUnitStretch:
return true;
case YGUnitPoint:
case YGUnitPercent:
Expand Down
2 changes: 1 addition & 1 deletion yoga/algorithm/CalculateLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ static float distributeFreeSpaceSecondPass(
marginCross;
const bool isLoosePercentageMeasurement =
currentLineChild->getProcessedDimension(dimension(crossAxis))
.isPercent() &&
.unit() == Unit::Percent &&
sizingModeCrossDim != SizingMode::StretchFit;
childCrossSizingMode =
yoga::isUndefined(childCrossSize) || isLoosePercentageMeasurement
Expand Down
5 changes: 1 addition & 4 deletions yoga/enums/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ enum class Unit : uint8_t {
Point = YGUnitPoint,
Percent = YGUnitPercent,
Auto = YGUnitAuto,
MaxContent = YGUnitMaxContent,
FitContent = YGUnitFitContent,
Stretch = YGUnitStretch,
};

template <>
constexpr int32_t ordinalCount<Unit>() {
return 7;
return 4;
}

constexpr Unit scopedEnum(YGUnit unscoped) {
Expand Down
12 changes: 6 additions & 6 deletions yoga/node/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,16 @@ void Node::setPosition(
crossAxisTrailingEdge);
}

Style::SizeLength Node::processFlexBasis() const {
Style::SizeLength flexBasis = style_.flexBasis();
if (!flexBasis.isAuto() && !flexBasis.isUndefined()) {
Style::Length Node::processFlexBasis() const {
Style::Length flexBasis = style_.flexBasis();
if (flexBasis.unit() != Unit::Auto && flexBasis.unit() != Unit::Undefined) {
return flexBasis;
}
if (style_.flex().isDefined() && style_.flex().unwrap() > 0.0f) {
return config_->useWebDefaults() ? StyleSizeLength::ofAuto()
: StyleSizeLength::points(0);
return config_->useWebDefaults() ? StyleLength::ofAuto()
: StyleLength::points(0);
}
return StyleSizeLength::ofAuto();
return StyleLength::ofAuto();
}

FloatOptional Node::resolveFlexBasis(
Expand Down
8 changes: 4 additions & 4 deletions yoga/node/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class YG_EXPORT Node : public ::YGNode {
return isDirty_;
}

Style::SizeLength getProcessedDimension(Dimension dimension) const {
Style::Length getProcessedDimension(Dimension dimension) const {
return processedDimensions_[static_cast<size_t>(dimension)];
}

Expand Down Expand Up @@ -268,7 +268,7 @@ class YG_EXPORT Node : public ::YGNode {
void setPosition(Direction direction, float ownerWidth, float ownerHeight);

// Other methods
Style::SizeLength processFlexBasis() const;
Style::Length processFlexBasis() const;
FloatOptional resolveFlexBasis(
Direction direction,
FlexDirection flexDirection,
Expand Down Expand Up @@ -322,8 +322,8 @@ class YG_EXPORT Node : public ::YGNode {
Node* owner_ = nullptr;
std::vector<Node*> children_;
const Config* config_;
std::array<Style::SizeLength, 2> processedDimensions_{
{StyleSizeLength::undefined(), StyleSizeLength::undefined()}};
std::array<Style::Length, 2> processedDimensions_{
{StyleLength::undefined(), StyleLength::undefined()}};
};

inline Node* resolveRef(const YGNodeRef ref) {
Expand Down
26 changes: 12 additions & 14 deletions yoga/style/Style.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@
#include <yoga/enums/Wrap.h>
#include <yoga/numeric/FloatOptional.h>
#include <yoga/style/StyleLength.h>
#include <yoga/style/StyleSizeLength.h>
#include <yoga/style/StyleValuePool.h>

namespace facebook::yoga {

class YG_EXPORT Style {
public:
using Length = StyleLength;
using SizeLength = StyleSizeLength;

static constexpr float DefaultFlexGrow = 0.0f;
static constexpr float DefaultFlexShrink = 0.0f;
Expand Down Expand Up @@ -135,10 +133,10 @@ class YG_EXPORT Style {
pool_.store(flexShrink_, value);
}

Style::SizeLength flexBasis() const {
return pool_.getSize(flexBasis_);
Style::Length flexBasis() const {
return pool_.getLength(flexBasis_);
}
void setFlexBasis(Style::SizeLength value) {
void setFlexBasis(Style::Length value) {
pool_.store(flexBasis_, value);
}

Expand Down Expand Up @@ -177,17 +175,17 @@ class YG_EXPORT Style {
pool_.store(gap_[yoga::to_underlying(gutter)], value);
}

Style::SizeLength dimension(Dimension axis) const {
return pool_.getSize(dimensions_[yoga::to_underlying(axis)]);
Style::Length dimension(Dimension axis) const {
return pool_.getLength(dimensions_[yoga::to_underlying(axis)]);
}
void setDimension(Dimension axis, Style::SizeLength value) {
void setDimension(Dimension axis, Style::Length value) {
pool_.store(dimensions_[yoga::to_underlying(axis)], value);
}

Style::SizeLength minDimension(Dimension axis) const {
return pool_.getSize(minDimensions_[yoga::to_underlying(axis)]);
Style::Length minDimension(Dimension axis) const {
return pool_.getLength(minDimensions_[yoga::to_underlying(axis)]);
}
void setMinDimension(Dimension axis, Style::SizeLength value) {
void setMinDimension(Dimension axis, Style::Length value) {
pool_.store(minDimensions_[yoga::to_underlying(axis)], value);
}

Expand All @@ -209,10 +207,10 @@ class YG_EXPORT Style {
: FloatOptional{0.0});
}

Style::SizeLength maxDimension(Dimension axis) const {
return pool_.getSize(maxDimensions_[yoga::to_underlying(axis)]);
Style::Length maxDimension(Dimension axis) const {
return pool_.getLength(maxDimensions_[yoga::to_underlying(axis)]);
}
void setMaxDimension(Dimension axis, Style::SizeLength value) {
void setMaxDimension(Dimension axis, Style::Length value) {
pool_.store(maxDimensions_[yoga::to_underlying(axis)], value);
}

Expand Down
Loading

0 comments on commit be00354

Please sign in to comment.