Cleanup YGNode for explicit per-node config
Summary: Cleans up some of the changes to UseWebDefaults that were made in the interest of moving it outside of YGConfig. It still exists in YGConfig, but also exists on the node. We also assert on null config, or when someone tries to change UseWebDefaults after creating a node (since right now YGStyle does not know the difference between unset vs set explicitly to what would normally be default). Removes a peculiar constructor which was added to avoid config setting. Reviewed By: rshest Differential Revision: D45133644 fbshipit-source-id: 2b5e2baeb826653133df9b1175cf5c194e342e3e
This commit is contained in:
committed by
Facebook GitHub Bot
parent
85ff2f06c2
commit
b15894b70a
@@ -13,6 +13,27 @@
|
|||||||
using namespace facebook;
|
using namespace facebook;
|
||||||
using facebook::yoga::detail::CompactValue;
|
using facebook::yoga::detail::CompactValue;
|
||||||
|
|
||||||
|
YGNode::YGNode(const YGConfigRef config) : config_{config} {
|
||||||
|
YGAssert(
|
||||||
|
config != nullptr, "Attempting to construct YGNode with null config");
|
||||||
|
|
||||||
|
flags_.hasNewLayout = true;
|
||||||
|
if (config->useWebDefaults) {
|
||||||
|
useWebDefaults();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
YGNode::YGNode(const YGNode& node, YGConfigRef config) : YGNode{node} {
|
||||||
|
YGAssert(
|
||||||
|
config != nullptr, "Attempting to construct YGNode with null config");
|
||||||
|
|
||||||
|
config_ = config;
|
||||||
|
flags_.hasNewLayout = true;
|
||||||
|
if (config->useWebDefaults) {
|
||||||
|
useWebDefaults();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
YGNode::YGNode(YGNode&& node) {
|
YGNode::YGNode(YGNode&& node) {
|
||||||
context_ = node.context_;
|
context_ = node.context_;
|
||||||
flags_ = node.flags_;
|
flags_ = node.flags_;
|
||||||
@@ -32,13 +53,6 @@ YGNode::YGNode(YGNode&& node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YGNode::YGNode(const YGNode& node, YGConfigRef config) : YGNode{node} {
|
|
||||||
config_ = config;
|
|
||||||
if (config->useWebDefaults) {
|
|
||||||
useWebDefaults();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void YGNode::print(void* printContext) {
|
void YGNode::print(void* printContext) {
|
||||||
if (print_.noContext != nullptr) {
|
if (print_.noContext != nullptr) {
|
||||||
if (flags_.printUsesContext) {
|
if (flags_.printUsesContext) {
|
||||||
@@ -260,6 +274,15 @@ void YGNode::insertChild(YGNodeRef child, uint32_t index) {
|
|||||||
children_.insert(children_.begin() + index, child);
|
children_.insert(children_.begin() + index, child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void YGNode::setConfig(YGConfigRef config) {
|
||||||
|
YGAssert(config != nullptr, "Attempting to set a null config on a YGNode");
|
||||||
|
YGAssertWithConfig(
|
||||||
|
config,
|
||||||
|
config->useWebDefaults == config_->useWebDefaults,
|
||||||
|
"UseWebDefaults may not be changed after constructing a YGNode");
|
||||||
|
config_ = config;
|
||||||
|
}
|
||||||
|
|
||||||
void YGNode::setDirty(bool isDirty) {
|
void YGNode::setDirty(bool isDirty) {
|
||||||
if (isDirty == flags_.isDirty) {
|
if (isDirty == flags_.isDirty) {
|
||||||
return;
|
return;
|
||||||
@@ -407,7 +430,7 @@ YGValue YGNode::resolveFlexBasisPtr() const {
|
|||||||
return flexBasis;
|
return flexBasis;
|
||||||
}
|
}
|
||||||
if (!style_.flex().isUndefined() && style_.flex().unwrap() > 0.0f) {
|
if (!style_.flex().isUndefined() && style_.flex().unwrap() > 0.0f) {
|
||||||
return flags_.useWebDefaults ? YGValueAuto : YGValueZero;
|
return config_->useWebDefaults ? YGValueAuto : YGValueZero;
|
||||||
}
|
}
|
||||||
return YGValueAuto;
|
return YGValueAuto;
|
||||||
}
|
}
|
||||||
@@ -483,11 +506,11 @@ float YGNode::resolveFlexShrink() const {
|
|||||||
if (!style_.flexShrink().isUndefined()) {
|
if (!style_.flexShrink().isUndefined()) {
|
||||||
return style_.flexShrink().unwrap();
|
return style_.flexShrink().unwrap();
|
||||||
}
|
}
|
||||||
if (!flags_.useWebDefaults && !style_.flex().isUndefined() &&
|
if (!config_->useWebDefaults && !style_.flex().isUndefined() &&
|
||||||
style_.flex().unwrap() < 0.0f) {
|
style_.flex().unwrap() < 0.0f) {
|
||||||
return -style_.flex().unwrap();
|
return -style_.flex().unwrap();
|
||||||
}
|
}
|
||||||
return flags_.useWebDefaults ? kWebDefaultFlexShrink : kDefaultFlexShrink;
|
return config_->useWebDefaults ? kWebDefaultFlexShrink : kDefaultFlexShrink;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YGNode::isNodeFlexible() {
|
bool YGNode::isNodeFlexible() {
|
||||||
@@ -563,11 +586,5 @@ void YGNode::reset() {
|
|||||||
YGAssertWithNode(
|
YGAssertWithNode(
|
||||||
this, owner_ == nullptr, "Cannot reset a node still attached to a owner");
|
this, owner_ == nullptr, "Cannot reset a node still attached to a owner");
|
||||||
|
|
||||||
clearChildren();
|
|
||||||
|
|
||||||
auto webDefaults = flags_.useWebDefaults;
|
|
||||||
*this = YGNode{getConfig()};
|
*this = YGNode{getConfig()};
|
||||||
if (webDefaults) {
|
|
||||||
useWebDefaults();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -29,7 +29,6 @@ struct YGNodeFlags {
|
|||||||
bool measureUsesContext : 1;
|
bool measureUsesContext : 1;
|
||||||
bool baselineUsesContext : 1;
|
bool baselineUsesContext : 1;
|
||||||
bool printUsesContext : 1;
|
bool printUsesContext : 1;
|
||||||
bool useWebDefaults : 1;
|
|
||||||
};
|
};
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
@@ -72,7 +71,6 @@ private:
|
|||||||
void setBaselineFunc(decltype(baseline_));
|
void setBaselineFunc(decltype(baseline_));
|
||||||
|
|
||||||
void useWebDefaults() {
|
void useWebDefaults() {
|
||||||
flags_.useWebDefaults = true;
|
|
||||||
style_.flexDirection() = YGFlexDirectionRow;
|
style_.flexDirection() = YGFlexDirectionRow;
|
||||||
style_.alignContent() = YGAlignStretch;
|
style_.alignContent() = YGAlignStretch;
|
||||||
}
|
}
|
||||||
@@ -87,14 +85,8 @@ private:
|
|||||||
using CompactValue = facebook::yoga::detail::CompactValue;
|
using CompactValue = facebook::yoga::detail::CompactValue;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
YGNode() : YGNode{YGConfigGetDefault()} {}
|
YGNode() : YGNode{YGConfigGetDefault()} { flags_.hasNewLayout = true; }
|
||||||
explicit YGNode(const YGConfigRef config) : config_{config} {
|
explicit YGNode(const YGConfigRef config);
|
||||||
flags_.hasNewLayout = true;
|
|
||||||
|
|
||||||
if (config->useWebDefaults) {
|
|
||||||
useWebDefaults();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
~YGNode() = default; // cleanup of owner/children relationships in YGNodeFree
|
~YGNode() = default; // cleanup of owner/children relationships in YGNodeFree
|
||||||
|
|
||||||
YGNode(YGNode&&);
|
YGNode(YGNode&&);
|
||||||
@@ -103,8 +95,9 @@ public:
|
|||||||
// Should we remove this?
|
// Should we remove this?
|
||||||
YGNode(const YGNode& node) = default;
|
YGNode(const YGNode& node) = default;
|
||||||
|
|
||||||
// for RB fabric
|
[[deprecated("Will be removed imminently")]] YGNode(
|
||||||
YGNode(const YGNode& node, YGConfigRef config);
|
const YGNode& node,
|
||||||
|
YGConfigRef config);
|
||||||
|
|
||||||
// assignment means potential leaks of existing children, or alternatively
|
// assignment means potential leaks of existing children, or alternatively
|
||||||
// freeing unowned memory, double free, or freeing stack memory.
|
// freeing unowned memory, double free, or freeing stack memory.
|
||||||
@@ -300,7 +293,7 @@ public:
|
|||||||
|
|
||||||
// TODO: rvalue override for setChildren
|
// TODO: rvalue override for setChildren
|
||||||
|
|
||||||
void setConfig(YGConfigRef config) { config_ = config; }
|
void setConfig(YGConfigRef config);
|
||||||
|
|
||||||
void setDirty(bool isDirty);
|
void setDirty(bool isDirty);
|
||||||
void setLayoutLastOwnerDirection(YGDirection direction);
|
void setLayoutLastOwnerDirection(YGDirection direction);
|
||||||
|
Reference in New Issue
Block a user