Skip to content

Commit

Permalink
Add hasErrata(), addErrata(), removeErrata() (#37375)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #37375

Adds internal helpers to YGConfig to make bit manipulation more readable. We also expose `hasErrata()` to YGNode beacuse checking that will be a common pattern. We intentionally don't add mutating functions to the node, since current model is to inval a node on commiting whole config.

This is not exposed via the C ABI.

Reviewed By: yungsters

Differential Revision: D45765971

fbshipit-source-id: eadaee4b9cf5204ac4984ecc52cc08650d144a30
  • Loading branch information
NickGerleman authored and facebook-github-bot committed May 11, 2023
1 parent 65b792c commit 3de44e7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
12 changes: 12 additions & 0 deletions packages/react-native/ReactCommon/yoga/yoga/YGConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,22 @@ void YGConfig::setErrata(YGErrata errata) {
errata_ = errata;
}

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

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

YGErrata YGConfig::getErrata() const {
return errata_;
}

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

void YGConfig::setPointScaleFactor(float pointScaleFactor) {
pointScaleFactor_ = pointScaleFactor;
}
Expand Down
3 changes: 3 additions & 0 deletions packages/react-native/ReactCommon/yoga/yoga/YGConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ struct YOGA_EXPORT YGConfig {
facebook::yoga::ExperimentalFeatureSet getEnabledExperiments() const;

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

void setPointScaleFactor(float pointScaleFactor);
float getPointScaleFactor() const;
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/ReactCommon/yoga/yoga/YGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ struct YOGA_EXPORT YGNode {

float baseline(float width, float height, void* layoutContext);

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

YGDirtiedFunc getDirtied() const { return dirtied_; }

// For Performance reasons passing as reference.
Expand Down
8 changes: 4 additions & 4 deletions packages/react-native/ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2984,7 +2984,7 @@ static void YGNodelayoutImpl(
availableInnerMainDim = maxInnerMainDim;
} else {
bool useLegacyStretchBehaviour =
node->getConfig()->getErrata() & YGErrataStretchFlexBasis;
node->hasErrata(YGErrataStretchFlexBasis);

if (!useLegacyStretchBehaviour &&
((!YGFloatIsUndefined(
Expand Down Expand Up @@ -4313,16 +4313,16 @@ YOGA_EXPORT void YGConfigSetUseWebDefaults(

YOGA_EXPORT bool YGConfigGetUseLegacyStretchBehaviour(
const YGConfigRef config) {
return config->getErrata() & YGErrataStretchFlexBasis;
return config->hasErrata(YGErrataStretchFlexBasis);
}

YOGA_EXPORT void YGConfigSetUseLegacyStretchBehaviour(
const YGConfigRef config,
const bool useLegacyStretchBehaviour) {
if (useLegacyStretchBehaviour) {
config->setErrata(config->getErrata() | YGErrataStretchFlexBasis);
config->addErrata(YGErrataStretchFlexBasis);
} else {
config->setErrata(config->getErrata() & ~YGErrataStretchFlexBasis);
config->removeErrata(YGErrataStretchFlexBasis);
}
}

Expand Down

0 comments on commit 3de44e7

Please sign in to comment.