diff --git a/packages/react-native/React/Tests/Text/RCTParagraphComponentViewTests.mm b/packages/react-native/React/Tests/Text/RCTParagraphComponentViewTests.mm index 0284859a16e046..d94ca995977e5c 100644 --- a/packages/react-native/React/Tests/Text/RCTParagraphComponentViewTests.mm +++ b/packages/react-native/React/Tests/Text/RCTParagraphComponentViewTests.mm @@ -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::StyleSizeLength::points(200)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(200)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(200)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(200)); return sharedProps; }) .children({ @@ -136,8 +136,8 @@ - (void)setUp yogaStyle.setPositionType(yoga::PositionType::Absolute); yogaStyle.setPosition(yoga::Edge::Left, yoga::StyleLength::points(0)); yogaStyle.setPosition(yoga::Edge::Top, yoga::StyleLength::points(0)); - yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleSizeLength::points(200)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(200)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(200)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(200)); return sharedProps; }) .children({ @@ -216,8 +216,8 @@ - (void)setUp yogaStyle.setPositionType(yoga::PositionType::Absolute); yogaStyle.setPosition(yoga::Edge::Left, yoga::StyleLength::points(0)); yogaStyle.setPosition(yoga::Edge::Top, yoga::StyleLength::points(30)); - yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleSizeLength::points(200)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(50)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(200)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(50)); return sharedProps; }) .children({ @@ -260,8 +260,8 @@ - (void)setUp yogaStyle.setPositionType(yoga::PositionType::Absolute); yogaStyle.setPosition(yoga::Edge::Left, yoga::StyleLength::points(0)); yogaStyle.setPosition(yoga::Edge::Top, yoga::StyleLength::points(90)); - yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleSizeLength::points(200)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(50)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(200)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(50)); return sharedProps; }) .children({ @@ -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::StyleSizeLength::points(200)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(200)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(200)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(200)); return sharedProps; }) .children({ @@ -434,8 +434,8 @@ - (void)testEntireParagraphLink yogaStyle.setPositionType(yoga::PositionType::Absolute); yogaStyle.setPosition(yoga::Edge::Left, yoga::StyleLength::points(0)); yogaStyle.setPosition(yoga::Edge::Top, yoga::StyleLength::points(90)); - yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleSizeLength::points(200)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(20)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(200)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(20)); return sharedProps; }) .children({ diff --git a/packages/react-native/React/Views/RCTLayout.m b/packages/react-native/React/Views/RCTLayout.m index 0d16f955960c6e..85c8994511a032 100644 --- a/packages/react-native/React/Views/RCTLayout.m +++ b/packages/react-native/React/Views/RCTLayout.m @@ -87,9 +87,6 @@ CGFloat RCTCoreGraphicsFloatFromYogaValue(YGValue value, CGFloat baseFloatValue) return RCTCoreGraphicsFloatFromYogaFloat(value.value) * baseFloatValue; case YGUnitAuto: case YGUnitUndefined: - case YGUnitMaxContent: - case YGUnitFitContent: - case YGUnitStretch: return baseFloatValue; } } diff --git a/packages/react-native/React/Views/RCTShadowView.m b/packages/react-native/React/Views/RCTShadowView.m index 66385dba06ffd4..b893cfe5c26785 100644 --- a/packages/react-native/React/Views/RCTShadowView.m +++ b/packages/react-native/React/Views/RCTShadowView.m @@ -63,9 +63,6 @@ + (YGConfigRef)yogaConfig #define RCT_SET_YGVALUE(ygvalue, setter, ...) \ switch (ygvalue.unit) { \ case YGUnitAuto: \ - case YGUnitMaxContent: \ - case YGUnitFitContent: \ - case YGUnitStretch: \ case YGUnitUndefined: \ setter(__VA_ARGS__, YGUndefined); \ break; \ @@ -91,10 +88,6 @@ + (YGConfigRef)yogaConfig case YGUnitPercent: \ setter##Percent(__VA_ARGS__, ygvalue.value); \ break; \ - case YGUnitMaxContent: \ - case YGUnitFitContent: \ - case YGUnitStretch: \ - break; \ } static void RCTProcessMetaPropsPadding(const YGValue metaProps[META_PROP_COUNT], YGNodeRef node) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaUnit.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaUnit.java index 5731a040d93d80..3614ec1059d2a7 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaUnit.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaUnit.java @@ -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; @@ -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); } } diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp index 89b16b71b617d1..20b92e97ac59af 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp @@ -538,9 +538,9 @@ void YogaLayoutableShadowNode::setSize(Size size) const { auto style = yogaNode_.style(); style.setDimension( - yoga::Dimension::Width, yoga::StyleSizeLength::points(size.width)); + yoga::Dimension::Width, yoga::StyleLength::points(size.width)); style.setDimension( - yoga::Dimension::Height, yoga::StyleSizeLength::points(size.height)); + yoga::Dimension::Height, yoga::StyleLength::points(size.height)); yogaNode_.setStyle(style); yogaNode_.setDirty(true); } @@ -631,18 +631,16 @@ void YogaLayoutableShadowNode::layoutTree( auto ownerHeight = yogaFloatFromFloat(maximumSize.height); yogaStyle.setMaxDimension( - yoga::Dimension::Width, yoga::StyleSizeLength::points(maximumSize.width)); + yoga::Dimension::Width, yoga::StyleLength::points(maximumSize.width)); yogaStyle.setMaxDimension( - yoga::Dimension::Height, - yoga::StyleSizeLength::points(maximumSize.height)); + yoga::Dimension::Height, yoga::StyleLength::points(maximumSize.height)); yogaStyle.setMinDimension( - yoga::Dimension::Width, yoga::StyleSizeLength::points(minimumSize.width)); + yoga::Dimension::Width, yoga::StyleLength::points(minimumSize.width)); yogaStyle.setMinDimension( - yoga::Dimension::Height, - yoga::StyleSizeLength::points(minimumSize.height)); + yoga::Dimension::Height, yoga::StyleLength::points(minimumSize.height)); auto direction = yogaDirectionFromLayoutDirection(layoutConstraints.layoutDirection); diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/conversions.h b/packages/react-native/ReactCommon/react/renderer/components/view/conversions.h index 66fdd78acc6fdb..0b442550e02610 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/conversions.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/conversions.h @@ -93,15 +93,18 @@ inline yoga::FloatOptional yogaOptionalFloatFromFloat(Float value) { inline std::optional optionalFloatFromYogaValue( const yoga::Style::Length& length, std::optional base = {}) { - if (length.isPoints()) { - return floatFromYogaOptionalFloat(length.value()); - } else if (length.isPercent()) { - return base.has_value() - ? std::optional( - base.value() * floatFromYogaOptionalFloat(length.value())) - : std::optional(); - } else { - return {}; + switch (length.unit()) { + case yoga::Unit::Undefined: + return {}; + case yoga::Unit::Point: + return floatFromYogaOptionalFloat(length.value()); + case yoga::Unit::Percent: + return base.has_value() + ? std::optional( + base.value() * floatFromYogaOptionalFloat(length.value())) + : std::optional(); + case yoga::Unit::Auto: + return {}; } } @@ -444,47 +447,6 @@ inline void fromRawValue( LOG(ERROR) << "Could not parse yoga::Display: " << stringValue; } -inline void fromRawValue( - const PropsParserContext& /*context*/, - const RawValue& value, - yoga::Style::SizeLength& result) { - if (value.hasType()) { - result = yoga::StyleSizeLength::points((float)value); - return; - } else if (value.hasType()) { - const auto stringValue = (std::string)value; - if (stringValue == "auto") { - result = yoga::StyleSizeLength::ofAuto(); - return; - } else if (stringValue == "max-content") { - result = yoga::StyleSizeLength::ofMaxContent(); - return; - } else if (stringValue == "stretch") { - result = yoga::StyleSizeLength::ofStretch(); - return; - } else if (stringValue == "fit-content") { - result = yoga::StyleSizeLength::ofFitContent(); - return; - } else { - if (stringValue.back() == '%') { - auto tryValue = folly::tryTo( - std::string_view(stringValue).substr(0, stringValue.length() - 1)); - if (tryValue.hasValue()) { - result = yoga::StyleSizeLength::percent(tryValue.value()); - return; - } - } else { - auto tryValue = folly::tryTo(stringValue); - if (tryValue.hasValue()) { - result = yoga::StyleSizeLength::points(tryValue.value()); - return; - } - } - } - } - result = yoga::StyleSizeLength::undefined(); -} - inline void fromRawValue( const PropsParserContext& context, const RawValue& value, @@ -1414,36 +1376,15 @@ inline std::string toString(const yoga::Display& value) { } inline std::string toString(const yoga::Style::Length& length) { - if (length.isUndefined()) { - return "undefined"; - } else if (length.isAuto()) { - return "auto"; - } else if (length.isPoints()) { - return std::to_string(length.value().unwrap()); - } else if (length.isPercent()) { - return std::to_string(length.value().unwrap()) + "%"; - } else { - return "unknown"; - } -} - -inline std::string toString(const yoga::Style::SizeLength& length) { - if (length.isUndefined()) { - return "undefined"; - } else if (length.isAuto()) { - return "auto"; - } else if (length.isPoints()) { - return std::to_string(length.value().unwrap()); - } else if (length.isPercent()) { - return std::to_string(length.value().unwrap()) + "%"; - } else if (length.isMaxContent()) { - return "max-content"; - } else if (length.isFitContent()) { - return "fit-content"; - } else if (length.isStretch()) { - return "stretch"; - } else { - return "unknown"; + switch (length.unit()) { + case yoga::Unit::Undefined: + return "undefined"; + 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"; } } diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/tests/LayoutTest.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/tests/LayoutTest.cpp index d722f674135494..5277a2b153401d 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/tests/LayoutTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/tests/LayoutTest.cpp @@ -77,8 +77,8 @@ class LayoutTest : public ::testing::Test { auto &props = *sharedProps; props.layoutConstraints = LayoutConstraints{{0,0}, {500, 500}}; auto &yogaStyle = props.yogaStyle; - yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleSizeLength::points(200)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(200)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(200)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(200)); return sharedProps; }) .children({ @@ -90,8 +90,8 @@ class LayoutTest : public ::testing::Test { auto &props = *sharedProps; auto &yogaStyle = props.yogaStyle; yogaStyle.setPositionType(yoga::PositionType::Absolute); - yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleSizeLength::points(50)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(50)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(50)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(50)); return sharedProps; }) .children({ @@ -105,8 +105,8 @@ class LayoutTest : public ::testing::Test { yogaStyle.setPositionType(yoga::PositionType::Absolute); yogaStyle.setPosition(yoga::Edge::Left, yoga::StyleLength::points(10)); yogaStyle.setPosition(yoga::Edge::Top, yoga::StyleLength::points(10)); - yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleSizeLength::points(30)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(90)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(30)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(90)); if (testCase == TRANSFORM_SCALE) { props.transform = props.transform * Transform::Scale(2, 2, 1); @@ -138,8 +138,8 @@ class LayoutTest : public ::testing::Test { yogaStyle.setPositionType(yoga::PositionType::Absolute); yogaStyle.setPosition(yoga::Edge::Left, yoga::StyleLength::points(10)); yogaStyle.setPosition(yoga::Edge::Top, yoga::StyleLength::points(10)); - yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleSizeLength::points(110)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(20)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(110)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(20)); return sharedProps; }) .children({ @@ -153,8 +153,8 @@ class LayoutTest : public ::testing::Test { yogaStyle.setPositionType(yoga::PositionType::Absolute); yogaStyle.setPosition(yoga::Edge::Left, yoga::StyleLength::points(70)); yogaStyle.setPosition(yoga::Edge::Top, yoga::StyleLength::points(-50)); - yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleSizeLength::points(30)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(60)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(30)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(60)); return sharedProps; }) }), @@ -168,8 +168,8 @@ class LayoutTest : public ::testing::Test { yogaStyle.setPositionType(yoga::PositionType::Absolute); yogaStyle.setPosition(yoga::Edge::Left, yoga::StyleLength::points(-60)); yogaStyle.setPosition(yoga::Edge::Top, yoga::StyleLength::points(50)); - yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleSizeLength::points(70)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(20)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(70)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(20)); return sharedProps; }) }) diff --git a/packages/react-native/ReactCommon/react/renderer/uimanager/tests/PointerEventsProcessorTest.cpp b/packages/react-native/ReactCommon/react/renderer/uimanager/tests/PointerEventsProcessorTest.cpp index 3f19e4f7934199..d51547f310f073 100644 --- a/packages/react-native/ReactCommon/react/renderer/uimanager/tests/PointerEventsProcessorTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/uimanager/tests/PointerEventsProcessorTest.cpp @@ -87,8 +87,8 @@ class PointerEventsProcessorTest : public ::testing::Test { listenToAllPointerEvents(props); props.layoutConstraints = LayoutConstraints{{0,0}, {500, 500}}; auto &yogaStyle = props.yogaStyle; - yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleSizeLength::points(400)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(400)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(400)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(400)); yogaStyle.setDisplay(yoga::Display::Flex); yogaStyle.setFlexDirection(yoga::FlexDirection::Row); yogaStyle.setAlignItems(yoga::Align::Center); @@ -109,8 +109,8 @@ class PointerEventsProcessorTest : public ::testing::Test { yogaStyle.setFlexDirection(yoga::FlexDirection::Column); yogaStyle.setAlignItems(yoga::Align::FlexEnd); yogaStyle.setJustifyContent(yoga::Justify::Center); - yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleSizeLength::points(150)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(300)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(150)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(300)); return sharedProps; }) .children({ @@ -123,8 +123,8 @@ class PointerEventsProcessorTest : public ::testing::Test { auto &props = *sharedProps; listenToAllPointerEvents(props); auto &yogaStyle = props.yogaStyle; - yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleSizeLength::points(100)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(200)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(100)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(200)); return sharedProps; }) }), @@ -141,8 +141,8 @@ class PointerEventsProcessorTest : public ::testing::Test { yogaStyle.setFlexDirection(yoga::FlexDirection::Column); yogaStyle.setAlignItems(yoga::Align::FlexStart); yogaStyle.setJustifyContent(yoga::Justify::Center); - yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleSizeLength::points(150)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(300)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(150)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(300)); return sharedProps; }) .children({ @@ -155,8 +155,8 @@ class PointerEventsProcessorTest : public ::testing::Test { auto &props = *sharedProps; listenToAllPointerEvents(props); auto &yogaStyle = props.yogaStyle; - yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleSizeLength::points(100)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleSizeLength::points(200)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::StyleLength::points(100)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::StyleLength::points(200)); return sharedProps; }) }) diff --git a/packages/react-native/ReactCommon/yoga/yoga/YGEnums.cpp b/packages/react-native/ReactCommon/yoga/yoga/YGEnums.cpp index 4bdace6b7a5e90..cddd5d5849ff83 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/YGEnums.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/YGEnums.cpp @@ -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"; } diff --git a/packages/react-native/ReactCommon/yoga/yoga/YGEnums.h b/packages/react-native/ReactCommon/yoga/yoga/YGEnums.h index bb83bcfac949fa..27f0426f450ec4 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/YGEnums.h +++ b/packages/react-native/ReactCommon/yoga/yoga/YGEnums.h @@ -131,10 +131,7 @@ YG_ENUM_DECL( YGUnitUndefined, YGUnitPoint, YGUnitPercent, - YGUnitAuto, - YGUnitMaxContent, - YGUnitFitContent, - YGUnitStretch) + YGUnitAuto) YG_ENUM_DECL( YGWrap, diff --git a/packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp b/packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp index 1309117af42cbb..8664b53ec81518 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { diff --git a/packages/react-native/ReactCommon/yoga/yoga/YGValue.h b/packages/react-native/ReactCommon/yoga/yoga/YGValue.h index 63c82f3da86e0b..7fa6fd918e5dc3 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/YGValue.h +++ b/packages/react-native/ReactCommon/yoga/yoga/YGValue.h @@ -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: diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp index 8dc078afebbfb9..a10b22151c74a0 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp @@ -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 diff --git a/packages/react-native/ReactCommon/yoga/yoga/enums/Unit.h b/packages/react-native/ReactCommon/yoga/yoga/enums/Unit.h index 685b1caecee627..57bd1969708361 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/enums/Unit.h +++ b/packages/react-native/ReactCommon/yoga/yoga/enums/Unit.h @@ -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() { - return 7; + return 4; } constexpr Unit scopedEnum(YGUnit unscoped) { diff --git a/packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp b/packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp index e647a47b91d260..cf36ab09a49ea3 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp @@ -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( diff --git a/packages/react-native/ReactCommon/yoga/yoga/node/Node.h b/packages/react-native/ReactCommon/yoga/yoga/node/Node.h index b3444c41180a8a..d596c564cf26e6 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/node/Node.h +++ b/packages/react-native/ReactCommon/yoga/yoga/node/Node.h @@ -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(dimension)]; } @@ -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, @@ -322,8 +322,8 @@ class YG_EXPORT Node : public ::YGNode { Node* owner_ = nullptr; std::vector children_; const Config* config_; - std::array processedDimensions_{ - {StyleSizeLength::undefined(), StyleSizeLength::undefined()}}; + std::array processedDimensions_{ + {StyleLength::undefined(), StyleLength::undefined()}}; }; inline Node* resolveRef(const YGNodeRef ref) { diff --git a/packages/react-native/ReactCommon/yoga/yoga/style/Style.h b/packages/react-native/ReactCommon/yoga/yoga/style/Style.h index 923b268bf8f27d..73203e6cca3c7c 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/style/Style.h +++ b/packages/react-native/ReactCommon/yoga/yoga/style/Style.h @@ -30,7 +30,6 @@ #include #include #include -#include #include namespace facebook::yoga { @@ -38,7 +37,6 @@ 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; @@ -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); } @@ -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); } @@ -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); } diff --git a/packages/react-native/ReactCommon/yoga/yoga/style/StyleLength.h b/packages/react-native/ReactCommon/yoga/yoga/style/StyleLength.h index 01e69718b2bc2c..7cc42d9eb5c8d0 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/style/StyleLength.h +++ b/packages/react-native/ReactCommon/yoga/yoga/style/StyleLength.h @@ -19,11 +19,13 @@ namespace facebook::yoga { * 3. A CSS value: * a. value (e.g. 10px) * b. value of a reference + * 4. (soon) A math function which returns a value * * References: * 1. https://www.w3.org/TR/css-values-4/#lengths * 2. https://www.w3.org/TR/css-values-4/#percentage-value * 3. https://www.w3.org/TR/css-values-4/#mixed-percentages + * 4. https://www.w3.org/TR/css-values-4/#math */ class StyleLength { public: @@ -57,14 +59,6 @@ class StyleLength { return unit_ == Unit::Undefined; } - constexpr bool isPoints() const { - return unit_ == Unit::Point; - } - - constexpr bool isPercent() const { - return unit_ == Unit::Percent; - } - constexpr bool isDefined() const { return !isUndefined(); } @@ -73,6 +67,10 @@ class StyleLength { return value_; } + constexpr Unit unit() const { + return unit_; + } + constexpr FloatOptional resolve(float referenceLength) { switch (unit_) { case Unit::Point: @@ -92,11 +90,6 @@ class StyleLength { return value_ == rhs.value_ && unit_ == rhs.unit_; } - constexpr bool inexactEquals(const StyleLength& other) const { - return unit_ == other.unit_ && - facebook::yoga::inexactEquals(value_, other.value_); - } - private: // We intentionally do not allow direct construction using value and unit, to // avoid invalid, or redundant combinations. @@ -108,7 +101,7 @@ class StyleLength { }; inline bool inexactEquals(const StyleLength& a, const StyleLength& b) { - return a.inexactEquals(b); + return a.unit() == b.unit() && inexactEquals(a.value(), b.value()); } } // namespace facebook::yoga diff --git a/packages/react-native/ReactCommon/yoga/yoga/style/StyleSizeLength.h b/packages/react-native/ReactCommon/yoga/yoga/style/StyleSizeLength.h deleted file mode 100644 index 8dc4f2401320ad..00000000000000 --- a/packages/react-native/ReactCommon/yoga/yoga/style/StyleSizeLength.h +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include - -namespace facebook::yoga { - -/** - * This class represents a CSS Value for sizes (e.g. width, height, min-width, - * etc.). It may be one of: - * 1. Undefined - * 2. A keyword (e.g. auto, max-content, stretch, etc.) - * 3. A CSS value: - * a. value (e.g. 10px) - * b. value of a reference - * - * References: - * 1. https://www.w3.org/TR/css-values-4/#lengths - * 2. https://www.w3.org/TR/css-values-4/#percentage-value - * 3. https://www.w3.org/TR/css-values-4/#mixed-percentages - */ -class StyleSizeLength { - public: - constexpr StyleSizeLength() = default; - - constexpr static StyleSizeLength points(float value) { - return yoga::isUndefined(value) || yoga::isinf(value) - ? undefined() - : StyleSizeLength{FloatOptional{value}, Unit::Point}; - } - - constexpr static StyleSizeLength percent(float value) { - return yoga::isUndefined(value) || yoga::isinf(value) - ? undefined() - : StyleSizeLength{FloatOptional{value}, Unit::Percent}; - } - - constexpr static StyleSizeLength ofAuto() { - return StyleSizeLength{{}, Unit::Auto}; - } - - constexpr static StyleSizeLength ofMaxContent() { - return StyleSizeLength{{}, Unit::MaxContent}; - } - - constexpr static StyleSizeLength ofFitContent() { - return StyleSizeLength{{}, Unit::FitContent}; - } - - constexpr static StyleSizeLength ofStretch() { - return StyleSizeLength{{}, Unit::Stretch}; - } - - constexpr static StyleSizeLength undefined() { - return StyleSizeLength{{}, Unit::Undefined}; - } - - constexpr bool isAuto() const { - return unit_ == Unit::Auto; - } - - constexpr bool isMaxContent() const { - return unit_ == Unit::MaxContent; - } - - constexpr bool isFitContent() const { - return unit_ == Unit::FitContent; - } - - constexpr bool isStretch() const { - return unit_ == Unit::Stretch; - } - - constexpr bool isUndefined() const { - return unit_ == Unit::Undefined; - } - - constexpr bool isDefined() const { - return !isUndefined(); - } - - constexpr bool isPoints() const { - return unit_ == Unit::Point; - } - - constexpr bool isPercent() const { - return unit_ == Unit::Percent; - } - - constexpr FloatOptional value() const { - return value_; - } - - constexpr FloatOptional resolve(float referenceLength) { - switch (unit_) { - case Unit::Point: - return value_; - case Unit::Percent: - return FloatOptional{value_.unwrap() * referenceLength * 0.01f}; - default: - return FloatOptional{}; - } - } - - explicit constexpr operator YGValue() const { - return YGValue{value_.unwrap(), unscopedEnum(unit_)}; - } - - constexpr bool operator==(const StyleSizeLength& rhs) const { - return value_ == rhs.value_ && unit_ == rhs.unit_; - } - - constexpr bool inexactEquals(const StyleSizeLength& other) const { - return unit_ == other.unit_ && - facebook::yoga::inexactEquals(value_, other.value_); - } - - private: - // We intentionally do not allow direct construction using value and unit, to - // avoid invalid, or redundant combinations. - constexpr StyleSizeLength(FloatOptional value, Unit unit) - : value_(value), unit_(unit) {} - - FloatOptional value_{}; - Unit unit_{Unit::Undefined}; -}; - -inline bool inexactEquals(const StyleSizeLength& a, const StyleSizeLength& b) { - return a.inexactEquals(b); -} - -} // namespace facebook::yoga diff --git a/packages/react-native/ReactCommon/yoga/yoga/style/StyleValueHandle.h b/packages/react-native/ReactCommon/yoga/yoga/style/StyleValueHandle.h index d9c6ae05791ee5..f4b97f0a9f7d00 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/style/StyleValueHandle.h +++ b/packages/react-native/ReactCommon/yoga/yoga/style/StyleValueHandle.h @@ -62,16 +62,8 @@ class StyleValueHandle { Percent, Number, Auto, - Keyword }; - // Intentionally leaving out auto as a fast path - enum class Keyword : uint8_t { MaxContent, FitContent, Stretch }; - - constexpr bool isKeyword(Keyword keyword) const { - return type() == Type::Keyword && value() == static_cast(keyword); - } - constexpr Type type() const { return static_cast(repr_ & kHandleTypeMask); } diff --git a/packages/react-native/ReactCommon/yoga/yoga/style/StyleValuePool.h b/packages/react-native/ReactCommon/yoga/yoga/style/StyleValuePool.h index dfee30ade9f1b0..597eae4c4374a9 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/style/StyleValuePool.h +++ b/packages/react-native/ReactCommon/yoga/yoga/style/StyleValuePool.h @@ -13,7 +13,6 @@ #include #include #include -#include #include namespace facebook::yoga { @@ -33,30 +32,13 @@ class StyleValuePool { } else if (length.isAuto()) { handle.setType(StyleValueHandle::Type::Auto); } else { - auto type = length.isPoints() ? StyleValueHandle::Type::Point - : StyleValueHandle::Type::Percent; + auto type = length.unit() == Unit::Point + ? StyleValueHandle::Type::Point + : StyleValueHandle::Type::Percent; storeValue(handle, length.value().unwrap(), type); } } - void store(StyleValueHandle& handle, StyleSizeLength sizeValue) { - if (sizeValue.isUndefined()) { - handle.setType(StyleValueHandle::Type::Undefined); - } else if (sizeValue.isAuto()) { - handle.setType(StyleValueHandle::Type::Auto); - } else if (sizeValue.isMaxContent()) { - storeKeyword(handle, StyleValueHandle::Keyword::MaxContent); - } else if (sizeValue.isStretch()) { - storeKeyword(handle, StyleValueHandle::Keyword::Stretch); - } else if (sizeValue.isFitContent()) { - storeKeyword(handle, StyleValueHandle::Keyword::FitContent); - } else { - auto type = sizeValue.isPoints() ? StyleValueHandle::Type::Point - : StyleValueHandle::Type::Percent; - storeValue(handle, sizeValue.value().unwrap(), type); - } - } - void store(StyleValueHandle& handle, FloatOptional number) { if (number.isUndefined()) { handle.setType(StyleValueHandle::Type::Undefined); @@ -84,31 +66,6 @@ class StyleValuePool { } } - StyleSizeLength getSize(StyleValueHandle handle) const { - if (handle.isUndefined()) { - return StyleSizeLength::undefined(); - } else if (handle.isAuto()) { - return StyleSizeLength::ofAuto(); - } else if (handle.isKeyword(StyleValueHandle::Keyword::MaxContent)) { - return StyleSizeLength::ofMaxContent(); - } else if (handle.isKeyword(StyleValueHandle::Keyword::FitContent)) { - return StyleSizeLength::ofFitContent(); - } else if (handle.isKeyword(StyleValueHandle::Keyword::Stretch)) { - return StyleSizeLength::ofStretch(); - } else { - assert( - handle.type() == StyleValueHandle::Type::Point || - handle.type() == StyleValueHandle::Type::Percent); - float value = (handle.isValueIndexed()) - ? std::bit_cast(buffer_.get32(handle.value())) - : unpackInlineInteger(handle.value()); - - return handle.type() == StyleValueHandle::Type::Point - ? StyleSizeLength::points(value) - : StyleSizeLength::percent(value); - } - } - FloatOptional getNumber(StyleValueHandle handle) const { if (handle.isUndefined()) { return FloatOptional{}; @@ -141,20 +98,6 @@ class StyleValuePool { } } - void storeKeyword( - StyleValueHandle& handle, - StyleValueHandle::Keyword keyword) { - handle.setType(StyleValueHandle::Type::Keyword); - - if (handle.isValueIndexed()) { - auto newIndex = - buffer_.replace(handle.value(), static_cast(keyword)); - handle.setValue(newIndex); - } else { - handle.setValue(static_cast(keyword)); - } - } - static constexpr bool isIntegerPackable(float f) { constexpr uint16_t kMaxInlineAbsValue = (1 << 11) - 1;