diff --git a/lib/yoga/src/main/cpp/yoga/Yoga.cpp b/lib/yoga/src/main/cpp/yoga/Yoga.cpp index 80d7b257d20..d1f9a4f8610 100644 --- a/lib/yoga/src/main/cpp/yoga/Yoga.cpp +++ b/lib/yoga/src/main/cpp/yoga/Yoga.cpp @@ -851,13 +851,14 @@ void YGConfigSetExperimentalFeatureEnabled( const YGConfigRef config, const YGExperimentalFeature feature, const bool enabled) { - resolveRef(config)->setExperimentalFeatureEnabled(feature, enabled); + resolveRef(config)->setExperimentalFeatureEnabled( + scopedEnum(feature), enabled); } bool YGConfigIsExperimentalFeatureEnabled( const YGConfigConstRef config, const YGExperimentalFeature feature) { - return resolveRef(config)->isExperimentalFeatureEnabled(feature); + return resolveRef(config)->isExperimentalFeatureEnabled(scopedEnum(feature)); } void YGConfigSetUseWebDefaults(const YGConfigRef config, const bool enabled) { diff --git a/lib/yoga/src/main/cpp/yoga/algorithm/CalculateLayout.cpp b/lib/yoga/src/main/cpp/yoga/algorithm/CalculateLayout.cpp index a8cb925f5f0..55fb9cd8eb8 100644 --- a/lib/yoga/src/main/cpp/yoga/algorithm/CalculateLayout.cpp +++ b/lib/yoga/src/main/cpp/yoga/algorithm/CalculateLayout.cpp @@ -154,7 +154,7 @@ static void computeFlexBasisForChild( if (!resolvedFlexBasis.isUndefined() && !yoga::isUndefined(mainAxisSize)) { if (child->getLayout().computedFlexBasis.isUndefined() || (child->getConfig()->isExperimentalFeatureEnabled( - YGExperimentalFeatureWebFlexBasis) && + ExperimentalFeature::WebFlexBasis) && child->getLayout().computedFlexBasisGeneration != generationCount)) { const FloatOptional paddingAndBorder = FloatOptional(paddingAndBorderForAxis(child, mainAxis, ownerWidth)); @@ -479,7 +479,7 @@ static void layoutAbsoluteChild( leadingEdge(mainAxis)); } else if ( node->getConfig()->isExperimentalFeatureEnabled( - YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge) && + ExperimentalFeature::AbsolutePercentageAgainstPaddingEdge) && child->isLeadingPositionDefined(mainAxis)) { child->setLayoutPosition( child->getLeadingPosition( @@ -526,7 +526,7 @@ static void layoutAbsoluteChild( leadingEdge(crossAxis)); } else if ( node->getConfig()->isExperimentalFeatureEnabled( - YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge) && + ExperimentalFeature::AbsolutePercentageAgainstPaddingEdge) && child->isLeadingPositionDefined(crossAxis)) { child->setLayoutPosition( child->getLeadingPosition( @@ -2323,7 +2323,7 @@ static void calculateLayoutImpl( } const bool absolutePercentageAgainstPaddingEdge = node->getConfig()->isExperimentalFeatureEnabled( - YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge); + ExperimentalFeature::AbsolutePercentageAgainstPaddingEdge); layoutAbsoluteChild( node, diff --git a/lib/yoga/src/main/cpp/yoga/bits/EnumBitset.h b/lib/yoga/src/main/cpp/yoga/bits/EnumBitset.h deleted file mode 100644 index 79ee1e7446f..00000000000 --- a/lib/yoga/src/main/cpp/yoga/bits/EnumBitset.h +++ /dev/null @@ -1,19 +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 { - -// std::bitset with one bit for each option defined in YG_ENUM_SEQ_DECL -template -using EnumBitset = std::bitset()>; - -} // namespace facebook::yoga diff --git a/lib/yoga/src/main/cpp/yoga/config/Config.cpp b/lib/yoga/src/main/cpp/yoga/config/Config.cpp index e86c76017bb..a3e48d34369 100644 --- a/lib/yoga/src/main/cpp/yoga/config/Config.cpp +++ b/lib/yoga/src/main/cpp/yoga/config/Config.cpp @@ -41,16 +41,16 @@ bool Config::shouldPrintTree() const { } void Config::setExperimentalFeatureEnabled( - YGExperimentalFeature feature, + ExperimentalFeature feature, bool enabled) { - experimentalFeatures_.set(feature, enabled); + experimentalFeatures_.set(static_cast(feature), enabled); } -bool Config::isExperimentalFeatureEnabled(YGExperimentalFeature feature) const { - return experimentalFeatures_.test(feature); +bool Config::isExperimentalFeatureEnabled(ExperimentalFeature feature) const { + return experimentalFeatures_.test(static_cast(feature)); } -EnumBitset Config::getEnabledExperiments() const { +ExperimentalFeatureSet Config::getEnabledExperiments() const { return experimentalFeatures_; } diff --git a/lib/yoga/src/main/cpp/yoga/config/Config.h b/lib/yoga/src/main/cpp/yoga/config/Config.h index 4590fcdf2fc..bc5a0ef2e9e 100644 --- a/lib/yoga/src/main/cpp/yoga/config/Config.h +++ b/lib/yoga/src/main/cpp/yoga/config/Config.h @@ -7,8 +7,10 @@ #pragma once +#include + #include -#include +#include // Tag struct used to form the opaque YGConfigRef for the public C API struct YGConfig {}; @@ -18,6 +20,8 @@ namespace facebook::yoga { class Config; class Node; +using ExperimentalFeatureSet = std::bitset()>; + // Whether moving a node from an old to new config should dirty previously // calculated layout results. bool configUpdateInvalidatesLayout( @@ -43,11 +47,9 @@ class YG_EXPORT Config : public ::YGConfig { void setShouldPrintTree(bool printTree); bool shouldPrintTree() const; - void setExperimentalFeatureEnabled( - YGExperimentalFeature feature, - bool enabled); - bool isExperimentalFeatureEnabled(YGExperimentalFeature feature) const; - EnumBitset getEnabledExperiments() const; + void setExperimentalFeatureEnabled(ExperimentalFeature feature, bool enabled); + bool isExperimentalFeatureEnabled(ExperimentalFeature feature) const; + ExperimentalFeatureSet getEnabledExperiments() const; void setErrata(YGErrata errata); void addErrata(YGErrata errata); @@ -79,7 +81,7 @@ class YG_EXPORT Config : public ::YGConfig { YGLogger logger_; ConfigFlags flags_{}; - EnumBitset experimentalFeatures_{}; + ExperimentalFeatureSet experimentalFeatures_{}; YGErrata errata_ = YGErrataNone; float pointScaleFactor_ = 1.0f; void* context_ = nullptr; diff --git a/lib/yoga/src/main/cpp/yoga/enums/YogaEnums.h b/lib/yoga/src/main/cpp/yoga/enums/YogaEnums.h index cc7223bf9c1..9621244813e 100644 --- a/lib/yoga/src/main/cpp/yoga/enums/YogaEnums.h +++ b/lib/yoga/src/main/cpp/yoga/enums/YogaEnums.h @@ -10,9 +10,9 @@ namespace facebook::yoga { template -constexpr inline int32_t ordinalCount() = delete; +constexpr inline int32_t ordinalCount(); template -constexpr inline int32_t bitCount() = delete; +constexpr inline int32_t bitCount(); } // namespace facebook::yoga