mirror of
https://github.com/facebook/react-native.git
synced 2024-11-21 22:10:14 +00:00
Remove trivial private api calls in YogaLayoutableShadowNode.cpp (#47735)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47735 We are trying to remove or minimize private header usage in YogaLayoutableShadowNode.cpp and YogaLayoutableShadowNode.h. There are a few "trivial" ones, meaning some private call maps 1:1 to an existing public API, so I just opt to use that instead Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D66131948 fbshipit-source-id: 7068021513703d1c142d3c298f4804e4e8b81ee2
This commit is contained in:
parent
13780126d3
commit
6d8fd49832
@ -70,18 +70,18 @@ YogaLayoutableShadowNode::YogaLayoutableShadowNode(
|
|||||||
: LayoutableShadowNode(fragment, family, traits),
|
: LayoutableShadowNode(fragment, family, traits),
|
||||||
yogaConfig_(FabricDefaultYogaLog),
|
yogaConfig_(FabricDefaultYogaLog),
|
||||||
yogaNode_(&initializeYogaConfig(yogaConfig_)) {
|
yogaNode_(&initializeYogaConfig(yogaConfig_)) {
|
||||||
yogaNode_.setContext(this);
|
YGNodeSetContext(&yogaNode_, this);
|
||||||
|
|
||||||
if (getTraits().check(ShadowNodeTraits::Trait::MeasurableYogaNode)) {
|
if (getTraits().check(ShadowNodeTraits::Trait::MeasurableYogaNode)) {
|
||||||
react_native_assert(
|
react_native_assert(
|
||||||
getTraits().check(ShadowNodeTraits::Trait::LeafYogaNode));
|
getTraits().check(ShadowNodeTraits::Trait::LeafYogaNode));
|
||||||
|
|
||||||
yogaNode_.setMeasureFunc(
|
YGNodeSetMeasureFunc(&yogaNode_, yogaNodeMeasureCallbackConnector);
|
||||||
YogaLayoutableShadowNode::yogaNodeMeasureCallbackConnector);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getTraits().check(ShadowNodeTraits::Trait::BaselineYogaNode)) {
|
if (getTraits().check(ShadowNodeTraits::Trait::BaselineYogaNode)) {
|
||||||
yogaNode_.setBaselineFunc(
|
YGNodeSetBaselineFunc(
|
||||||
|
&yogaNode_,
|
||||||
YogaLayoutableShadowNode::yogaNodeBaselineCallbackConnector);
|
YogaLayoutableShadowNode::yogaNodeBaselineCallbackConnector);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,12 +107,10 @@ YogaLayoutableShadowNode::YogaLayoutableShadowNode(
|
|||||||
// the ShadowTree being created on the JS thread. This assert can be
|
// the ShadowTree being created on the JS thread. This assert can be
|
||||||
// re-enabled after disabling background executor everywhere.
|
// re-enabled after disabling background executor everywhere.
|
||||||
#if 0
|
#if 0
|
||||||
react_native_assert(
|
react_native_assert(YGNodeIsDirty(&static_cast<const YogaLayoutableShadowNode&>(sourceShadowNode)
|
||||||
static_cast<const YogaLayoutableShadowNode&>(sourceShadowNode)
|
.yogaNode_) == YGNodeIsDirty(&yogaNode_) &&
|
||||||
.yogaNode_.isDirty() == yogaNode_.isDirty() &&
|
|
||||||
"Yoga node must inherit dirty flag.");
|
"Yoga node must inherit dirty flag.");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!getTraits().check(ShadowNodeTraits::Trait::LeafYogaNode)) {
|
if (!getTraits().check(ShadowNodeTraits::Trait::LeafYogaNode)) {
|
||||||
for (auto& child : getChildren()) {
|
for (auto& child : getChildren()) {
|
||||||
if (auto layoutableChild =
|
if (auto layoutableChild =
|
||||||
@ -127,9 +125,10 @@ YogaLayoutableShadowNode::YogaLayoutableShadowNode(
|
|||||||
&static_cast<const YogaLayoutableShadowNode&>(sourceShadowNode)
|
&static_cast<const YogaLayoutableShadowNode&>(sourceShadowNode)
|
||||||
.yogaConfig_;
|
.yogaConfig_;
|
||||||
|
|
||||||
yogaNode_.setContext(this);
|
YGNodeSetContext(&yogaNode_, this);
|
||||||
yogaNode_.setOwner(nullptr);
|
yogaNode_.setOwner(nullptr);
|
||||||
yogaNode_.setConfig(&initializeYogaConfig(yogaConfig_, previousConfig));
|
YGNodeSetConfig(
|
||||||
|
&yogaNode_, &initializeYogaConfig(yogaConfig_, previousConfig));
|
||||||
updateYogaChildrenOwnersIfNeeded();
|
updateYogaChildrenOwnersIfNeeded();
|
||||||
|
|
||||||
// This is the only legit place where we can dirty cloned Yoga node.
|
// This is the only legit place where we can dirty cloned Yoga node.
|
||||||
@ -169,7 +168,7 @@ void YogaLayoutableShadowNode::dirtyLayout() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool YogaLayoutableShadowNode::getIsLayoutClean() const {
|
bool YogaLayoutableShadowNode::getIsLayoutClean() const {
|
||||||
return !yogaNode_.isDirty();
|
return !YGNodeIsDirty(&yogaNode_);
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Mutating Methods
|
#pragma mark - Mutating Methods
|
||||||
@ -177,8 +176,8 @@ bool YogaLayoutableShadowNode::getIsLayoutClean() const {
|
|||||||
void YogaLayoutableShadowNode::enableMeasurement() {
|
void YogaLayoutableShadowNode::enableMeasurement() {
|
||||||
ensureUnsealed();
|
ensureUnsealed();
|
||||||
|
|
||||||
yogaNode_.setMeasureFunc(
|
YGNodeSetMeasureFunc(
|
||||||
YogaLayoutableShadowNode::yogaNodeMeasureCallbackConnector);
|
&yogaNode_, YogaLayoutableShadowNode::yogaNodeMeasureCallbackConnector);
|
||||||
}
|
}
|
||||||
|
|
||||||
void YogaLayoutableShadowNode::appendYogaChild(
|
void YogaLayoutableShadowNode::appendYogaChild(
|
||||||
@ -190,7 +189,7 @@ void YogaLayoutableShadowNode::appendYogaChild(
|
|||||||
ensureYogaChildrenLookFine();
|
ensureYogaChildrenLookFine();
|
||||||
|
|
||||||
yogaLayoutableChildren_.push_back(childNode);
|
yogaLayoutableChildren_.push_back(childNode);
|
||||||
yogaNode_.insertChild(&childNode->yogaNode_, yogaNode_.getChildren().size());
|
yogaNode_.insertChild(&childNode->yogaNode_, YGNodeGetChildCount(&yogaNode_));
|
||||||
|
|
||||||
ensureYogaChildrenLookFine();
|
ensureYogaChildrenLookFine();
|
||||||
}
|
}
|
||||||
@ -206,7 +205,7 @@ void YogaLayoutableShadowNode::adoptYogaChild(size_t index) {
|
|||||||
auto& childNode =
|
auto& childNode =
|
||||||
dynamic_cast<const YogaLayoutableShadowNode&>(*getChildren().at(index));
|
dynamic_cast<const YogaLayoutableShadowNode&>(*getChildren().at(index));
|
||||||
|
|
||||||
if (childNode.yogaNode_.getOwner() == nullptr) {
|
if (YGNodeGetOwner(&childNode.yogaNode_) == nullptr) {
|
||||||
// The child node is not owned.
|
// The child node is not owned.
|
||||||
childNode.yogaNode_.setOwner(&yogaNode_);
|
childNode.yogaNode_.setOwner(&yogaNode_);
|
||||||
// At this point the child yoga node must be already inserted by the caller.
|
// At this point the child yoga node must be already inserted by the caller.
|
||||||
@ -298,7 +297,8 @@ void YogaLayoutableShadowNode::replaceChild(
|
|||||||
|
|
||||||
if (layoutableNewChild) {
|
if (layoutableNewChild) {
|
||||||
// Both children are layoutable, replace the old one with the new one
|
// Both children are layoutable, replace the old one with the new one
|
||||||
react_native_assert(layoutableNewChild->yogaNode_.getOwner() == nullptr);
|
react_native_assert(
|
||||||
|
YGNodeGetOwner(&layoutableNewChild->yogaNode_) == nullptr);
|
||||||
layoutableNewChild->yogaNode_.setOwner(&yogaNode_);
|
layoutableNewChild->yogaNode_.setOwner(&yogaNode_);
|
||||||
yogaNode_.replaceChild(&layoutableNewChild->yogaNode_, oldChildIndex);
|
yogaNode_.replaceChild(&layoutableNewChild->yogaNode_, oldChildIndex);
|
||||||
*oldChildIter = layoutableNewChild;
|
*oldChildIter = layoutableNewChild;
|
||||||
@ -314,12 +314,12 @@ void YogaLayoutableShadowNode::replaceChild(
|
|||||||
|
|
||||||
bool YogaLayoutableShadowNode::doesOwn(
|
bool YogaLayoutableShadowNode::doesOwn(
|
||||||
const YogaLayoutableShadowNode& child) const {
|
const YogaLayoutableShadowNode& child) const {
|
||||||
return child.yogaNode_.getOwner() == &yogaNode_;
|
return YGNodeGetOwner(&child.yogaNode_) == &yogaNode_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void YogaLayoutableShadowNode::updateYogaChildrenOwnersIfNeeded() {
|
void YogaLayoutableShadowNode::updateYogaChildrenOwnersIfNeeded() {
|
||||||
for (auto& childYogaNode : yogaNode_.getChildren()) {
|
for (auto& childYogaNode : yogaNode_.getChildren()) {
|
||||||
if (childYogaNode->getOwner() == &yogaNode_) {
|
if (YGNodeGetOwner(childYogaNode) == &yogaNode_) {
|
||||||
childYogaNode->setOwner(
|
childYogaNode->setOwner(
|
||||||
reinterpret_cast<yoga::Node*>(0xBADC0FFEE0DDF00D));
|
reinterpret_cast<yoga::Node*>(0xBADC0FFEE0DDF00D));
|
||||||
}
|
}
|
||||||
@ -333,8 +333,8 @@ void YogaLayoutableShadowNode::updateYogaChildren() {
|
|||||||
|
|
||||||
ensureUnsealed();
|
ensureUnsealed();
|
||||||
|
|
||||||
bool isClean = !yogaNode_.isDirty() &&
|
bool isClean = !YGNodeIsDirty(&yogaNode_) &&
|
||||||
getChildren().size() == yogaNode_.getChildren().size();
|
getChildren().size() == YGNodeGetChildCount(&yogaNode_);
|
||||||
|
|
||||||
auto oldYogaChildren =
|
auto oldYogaChildren =
|
||||||
isClean ? yogaNode_.getChildren() : std::vector<yoga::Node*>{};
|
isClean ? yogaNode_.getChildren() : std::vector<yoga::Node*>{};
|
||||||
@ -362,7 +362,7 @@ void YogaLayoutableShadowNode::updateYogaChildren() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
react_native_assert(
|
react_native_assert(
|
||||||
yogaLayoutableChildren_.size() == yogaNode_.getChildren().size());
|
yogaLayoutableChildren_.size() == YGNodeGetChildCount(&yogaNode_));
|
||||||
|
|
||||||
yogaNode_.setDirty(!isClean);
|
yogaNode_.setDirty(!isClean);
|
||||||
}
|
}
|
||||||
@ -374,7 +374,7 @@ void YogaLayoutableShadowNode::updateYogaProps() {
|
|||||||
auto styleResult = applyAliasedProps(props.yogaStyle, props);
|
auto styleResult = applyAliasedProps(props.yogaStyle, props);
|
||||||
|
|
||||||
// Resetting `dirty` flag only if `yogaStyle` portion of `Props` was changed.
|
// Resetting `dirty` flag only if `yogaStyle` portion of `Props` was changed.
|
||||||
if (!yogaNode_.isDirty() && (styleResult != yogaNode_.style())) {
|
if (!YGNodeIsDirty(&yogaNode_) && (styleResult != yogaNode_.style())) {
|
||||||
yogaNode_.setDirty(true);
|
yogaNode_.setDirty(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,7 +388,7 @@ void YogaLayoutableShadowNode::updateYogaProps() {
|
|||||||
YGNodeSetAlwaysFormsContainingBlock(&yogaNode_, alwaysFormsContainingBlock);
|
YGNodeSetAlwaysFormsContainingBlock(&yogaNode_, alwaysFormsContainingBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (yogaNode_.style().display() == yoga::Display::Contents) {
|
if (YGNodeStyleGetDisplay(&yogaNode_) == YGDisplayContents) {
|
||||||
ShadowNode::traits_.set(ShadowNodeTraits::ForceFlattenView);
|
ShadowNode::traits_.set(ShadowNodeTraits::ForceFlattenView);
|
||||||
} else {
|
} else {
|
||||||
ShadowNode::traits_.unset(ShadowNodeTraits::ForceFlattenView);
|
ShadowNode::traits_.unset(ShadowNodeTraits::ForceFlattenView);
|
||||||
@ -683,7 +683,7 @@ static EdgeInsets calculateOverflowInset(
|
|||||||
|
|
||||||
void YogaLayoutableShadowNode::layout(LayoutContext layoutContext) {
|
void YogaLayoutableShadowNode::layout(LayoutContext layoutContext) {
|
||||||
// Reading data from a dirtied node does not make sense.
|
// Reading data from a dirtied node does not make sense.
|
||||||
react_native_assert(!yogaNode_.isDirty());
|
react_native_assert(!YGNodeIsDirty(&yogaNode_));
|
||||||
|
|
||||||
for (auto childYogaNode : yogaNode_.getChildren()) {
|
for (auto childYogaNode : yogaNode_.getChildren()) {
|
||||||
auto& childNode = shadowNodeFromContext(childYogaNode);
|
auto& childNode = shadowNodeFromContext(childYogaNode);
|
||||||
@ -699,7 +699,7 @@ void YogaLayoutableShadowNode::layout(LayoutContext layoutContext) {
|
|||||||
|
|
||||||
// We must copy layout metrics from Yoga node only once (when the parent
|
// We must copy layout metrics from Yoga node only once (when the parent
|
||||||
// node exclusively ownes the child node).
|
// node exclusively ownes the child node).
|
||||||
react_native_assert(childYogaNode->getOwner() == &yogaNode_);
|
react_native_assert(YGNodeGetOwner(childYogaNode) == &yogaNode_);
|
||||||
|
|
||||||
// We are about to mutate layout metrics of the node.
|
// We are about to mutate layout metrics of the node.
|
||||||
childNode.ensureUnsealed();
|
childNode.ensureUnsealed();
|
||||||
@ -727,7 +727,7 @@ void YogaLayoutableShadowNode::layout(LayoutContext layoutContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (yogaNode_.style().overflow() == yoga::Overflow::Visible) {
|
if (YGNodeStyleGetOverflow(&yogaNode_) == YGOverflowVisible) {
|
||||||
// Note that the parent node's overflow layout is NOT affected by its
|
// Note that the parent node's overflow layout is NOT affected by its
|
||||||
// transform matrix. That transform matrix is applied on the parent node as
|
// transform matrix. That transform matrix is applied on the parent node as
|
||||||
// well as all of its child nodes, which won't cause changes on the
|
// well as all of its child nodes, which won't cause changes on the
|
||||||
|
Loading…
Reference in New Issue
Block a user