Skip to content

Commit

Permalink
C++ style enums 4/N: Errata (facebook#39451)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#39451

X-link: facebook/yoga#1388

This converts usages of YGErrata to Errata

Differential Revision: D49270354

fbshipit-source-id: 94c4474933e2b67838abf829029bb1eea4a893f7
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 14, 2023
1 parent 98dbc44 commit 5ad7b63
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions packages/react-native/ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,11 +878,11 @@ void* YGConfigGetContext(const YGConfigConstRef config) {
}

void YGConfigSetErrata(YGConfigRef config, YGErrata errata) {
resolveRef(config)->setErrata(errata);
resolveRef(config)->setErrata(scopedEnum(errata));
}

YGErrata YGConfigGetErrata(YGConfigConstRef config) {
return resolveRef(config)->getErrata();
return unscopedEnum(resolveRef(config)->getErrata());
}

void YGConfigSetCloneNodeFunc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,7 @@ static void calculateLayoutImpl(
availableInnerMainDim = maxInnerMainDim;
} else {
bool useLegacyStretchBehaviour =
node->hasErrata(YGErrataStretchFlexBasis);
node->hasErrata(Errata::StretchFlexBasis);

if (!useLegacyStretchBehaviour &&
((!yoga::isUndefined(flexLine.layout.totalFlexGrowFactors) &&
Expand Down
12 changes: 6 additions & 6 deletions packages/react-native/ReactCommon/yoga/yoga/config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,24 @@ ExperimentalFeatureSet Config::getEnabledExperiments() const {
return experimentalFeatures_;
}

void Config::setErrata(YGErrata errata) {
void Config::setErrata(Errata errata) {
errata_ = errata;
}

void Config::addErrata(YGErrata errata) {
void Config::addErrata(Errata errata) {
errata_ |= errata;
}

void Config::removeErrata(YGErrata errata) {
void Config::removeErrata(Errata errata) {
errata_ &= (~errata);
}

YGErrata Config::getErrata() const {
Errata Config::getErrata() const {
return errata_;
}

bool Config::hasErrata(YGErrata errata) const {
return (errata_ & errata) != YGErrataNone;
bool Config::hasErrata(Errata errata) const {
return (errata_ & errata) != Errata::None;
}

void Config::setPointScaleFactor(float pointScaleFactor) {
Expand Down
13 changes: 7 additions & 6 deletions packages/react-native/ReactCommon/yoga/yoga/config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <bitset>

#include <yoga/Yoga.h>
#include <yoga/enums/Errata.h>
#include <yoga/enums/ExperimentalFeature.h>

// Tag struct used to form the opaque YGConfigRef for the public C API
Expand Down Expand Up @@ -51,11 +52,11 @@ class YG_EXPORT Config : public ::YGConfig {
bool isExperimentalFeatureEnabled(ExperimentalFeature feature) const;
ExperimentalFeatureSet getEnabledExperiments() const;

void setErrata(YGErrata errata);
void addErrata(YGErrata errata);
void removeErrata(YGErrata errata);
YGErrata getErrata() const;
bool hasErrata(YGErrata errata) const;
void setErrata(Errata errata);
void addErrata(Errata errata);
void removeErrata(Errata errata);
Errata getErrata() const;
bool hasErrata(Errata errata) const;

void setPointScaleFactor(float pointScaleFactor);
float getPointScaleFactor() const;
Expand All @@ -82,7 +83,7 @@ class YG_EXPORT Config : public ::YGConfig {

ConfigFlags flags_{};
ExperimentalFeatureSet experimentalFeatures_{};
YGErrata errata_ = YGErrataNone;
Errata errata_ = Errata::None;
float pointScaleFactor_ = 1.0f;
void* context_ = nullptr;
};
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/ReactCommon/yoga/yoga/enums/Errata.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ enum class Errata : uint32_t {
Classic = YGErrataClassic,
};

YG_DEFINE_ENUM_FLAG_OPERATORS(Errata)

template <>
constexpr inline int32_t ordinalCount<Errata>() {
return 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ enum class PrintOptions : uint32_t {
Children = YGPrintOptionsChildren,
};

YG_DEFINE_ENUM_FLAG_OPERATORS(PrintOptions)

template <>
constexpr inline int32_t ordinalCount<PrintOptions>() {
return 3;
Expand Down
3 changes: 2 additions & 1 deletion packages/react-native/ReactCommon/yoga/yoga/node/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <yoga/Yoga.h>

#include <yoga/config/Config.h>
#include <yoga/enums/Errata.h>
#include <yoga/enums/NodeType.h>
#include <yoga/node/LayoutResults.h>
#include <yoga/style/CompactValue.h>
Expand Down Expand Up @@ -109,7 +110,7 @@ class YG_EXPORT Node : public ::YGNode {

float baseline(float width, float height) const;

bool hasErrata(YGErrata errata) const {
bool hasErrata(Errata errata) const {
return config_->hasErrata(errata);
}

Expand Down

0 comments on commit 5ad7b63

Please sign in to comment.