Skip to content

Commit

Permalink
Move markDirtyInternal as a method in YGNode
Browse files Browse the repository at this point in the history
Reviewed By: emilsjolander

Differential Revision: D6611287

fbshipit-source-id: 54402145d51ea717553ea136be739b9880a79817
  • Loading branch information
priteshrnandgaonkar authored and facebook-github-bot committed Jan 8, 2018
1 parent 28968e2 commit 0a9e652
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
12 changes: 12 additions & 0 deletions ReactCommon/yoga/yoga/YGNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ YGNode::~YGNode() {
// deallocate here
}

// Other Methods

void YGNode::cloneChildrenIfNeeded() {
// YGNodeRemoveChild in yoga.cpp has a forked variant of this algorithm
// optimized for deletions.
Expand Down Expand Up @@ -409,3 +411,13 @@ void YGNode::cloneChildrenIfNeeded() {
}
}
}

void YGNode::markDirtyAndPropogate() {
if (!isDirty_) {
isDirty_ = true;
setLayoutComputedFlexBasis(YGUndefined);
if (parent_) {
parent_->markDirtyAndPropogate();
}
}
}
1 change: 1 addition & 0 deletions ReactCommon/yoga/yoga/YGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,5 @@ struct YGNode {

// Other methods
void cloneChildrenIfNeeded();
void markDirtyAndPropogate();
};
46 changes: 17 additions & 29 deletions ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ const YGValue YGValueZero = {.value = 0, .unit = YGUnitPoint};
const YGValue YGValueUndefined = {YGUndefined, YGUnitUndefined};
const YGValue YGValueAuto = {YGUndefined, YGUnitAuto};

static void YGNodeMarkDirtyInternal(const YGNodeRef node);

#ifdef ANDROID
#include <android/log.h>
static int YGAndroidLog(const YGConfigRef config,
Expand Down Expand Up @@ -338,16 +336,6 @@ void YGConfigCopy(const YGConfigRef dest, const YGConfigRef src) {
memcpy(dest, src, sizeof(YGConfig));
}

static void YGNodeMarkDirtyInternal(const YGNodeRef node) {
if (!node->isDirty()) {
node->setDirty(true);
node->setLayoutComputedFlexBasis(YGUndefined);
if (node->getParent()) {
YGNodeMarkDirtyInternal(node->getParent());
}
}
}

void YGNodeInsertChild(const YGNodeRef node, const YGNodeRef child, const uint32_t index) {
YGAssertWithNode(
node,
Expand All @@ -361,7 +349,7 @@ void YGNodeInsertChild(const YGNodeRef node, const YGNodeRef child, const uint32
node->cloneChildrenIfNeeded();
node->insertChild(child, index);
child->setParent(node);
YGNodeMarkDirtyInternal(node);
node->markDirtyAndPropogate();
}

void YGNodeRemoveChild(const YGNodeRef parent, const YGNodeRef excludedChild) {
Expand All @@ -381,7 +369,7 @@ void YGNodeRemoveChild(const YGNodeRef parent, const YGNodeRef excludedChild) {
excludedChild->setLayout(
YGNode().getLayout()); // layout is no longer valid
excludedChild->setParent(nullptr);
YGNodeMarkDirtyInternal(parent);
parent->markDirtyAndPropogate();
}
return;
}
Expand All @@ -397,7 +385,7 @@ void YGNodeRemoveChild(const YGNodeRef parent, const YGNodeRef excludedChild) {
// Ignore the deleted child. Don't reset its layout or parent since it is still valid
// in the other parent. However, since this parent has now changed, we need to mark it
// as dirty.
YGNodeMarkDirtyInternal(parent);
parent->markDirtyAndPropogate();
continue;
}
const YGNodeRef newChild = YGNodeClone(oldChild);
Expand Down Expand Up @@ -429,12 +417,12 @@ void YGNodeRemoveAllChildren(const YGNodeRef parent) {
oldChild->setParent(nullptr);
}
parent->clearChildren();
YGNodeMarkDirtyInternal(parent);
parent->markDirtyAndPropogate();
return;
}
// Otherwise, we are not the owner of the child set. We don't have to do anything to clear it.
parent->setChildren(YGVector());
YGNodeMarkDirtyInternal(parent);
parent->markDirtyAndPropogate();
}

YGNodeRef YGNodeGetChild(const YGNodeRef node, const uint32_t index) {
Expand All @@ -459,13 +447,13 @@ void YGNodeMarkDirty(const YGNodeRef node) {
"Only leaf nodes with custom measure functions"
"should manually mark themselves as dirty");

YGNodeMarkDirtyInternal(node);
node->markDirtyAndPropogate();
}

void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode) {
if (!(dstNode->getStyle() == srcNode->getStyle())) {
dstNode->setStyle(srcNode->getStyle());
YGNodeMarkDirtyInternal(dstNode);
dstNode->markDirtyAndPropogate();
}
}

Expand Down Expand Up @@ -521,7 +509,7 @@ static inline float YGNodeResolveFlexShrink(const YGNodeRef node) {
YGStyle style = node->getStyle(); \
style.instanceName = paramName; \
node->setStyle(style); \
YGNodeMarkDirtyInternal(node); \
node->markDirtyAndPropogate(); \
} \
}

Expand All @@ -538,7 +526,7 @@ static inline float YGNodeResolveFlexShrink(const YGNodeRef node) {
YGStyle style = node->getStyle(); \
style.instanceName = value; \
node->setStyle(style); \
YGNodeMarkDirtyInternal(node); \
node->markDirtyAndPropogate(); \
} \
} \
\
Expand All @@ -556,7 +544,7 @@ static inline float YGNodeResolveFlexShrink(const YGNodeRef node) {
\
style.instanceName = value; \
node->setStyle(style); \
YGNodeMarkDirtyInternal(node); \
node->markDirtyAndPropogate(); \
} \
}

Expand All @@ -573,7 +561,7 @@ static inline float YGNodeResolveFlexShrink(const YGNodeRef node) {
YGStyle style = node->getStyle(); \
style.instanceName = value; \
node->setStyle(style); \
YGNodeMarkDirtyInternal(node); \
node->markDirtyAndPropogate(); \
} \
} \
\
Expand All @@ -586,7 +574,7 @@ static inline float YGNodeResolveFlexShrink(const YGNodeRef node) {
style.instanceName.unit = \
YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPercent; \
node->setStyle(style); \
YGNodeMarkDirtyInternal(node); \
node->markDirtyAndPropogate(); \
} \
} \
\
Expand All @@ -596,7 +584,7 @@ static inline float YGNodeResolveFlexShrink(const YGNodeRef node) {
style.instanceName.value = YGUndefined; \
style.instanceName.unit = YGUnitAuto; \
node->setStyle(style); \
YGNodeMarkDirtyInternal(node); \
node->markDirtyAndPropogate(); \
} \
}

Expand Down Expand Up @@ -631,7 +619,7 @@ static inline float YGNodeResolveFlexShrink(const YGNodeRef node) {
style.instanceName[edge].value = YGUndefined; \
style.instanceName[edge].unit = YGUnitAuto; \
node->setStyle(style); \
YGNodeMarkDirtyInternal(node); \
node->markDirtyAndPropogate(); \
} \
}

Expand All @@ -649,7 +637,7 @@ static inline float YGNodeResolveFlexShrink(const YGNodeRef node) {
YGStyle style = node->getStyle(); \
style.instanceName[edge] = value; \
node->setStyle(style); \
YGNodeMarkDirtyInternal(node); \
node->markDirtyAndPropogate(); \
} \
} \
\
Expand All @@ -666,7 +654,7 @@ static inline float YGNodeResolveFlexShrink(const YGNodeRef node) {
YGStyle style = node->getStyle(); \
style.instanceName[edge] = value; \
node->setStyle(style); \
YGNodeMarkDirtyInternal(node); \
node->markDirtyAndPropogate(); \
} \
} \
\
Expand All @@ -688,7 +676,7 @@ static inline float YGNodeResolveFlexShrink(const YGNodeRef node) {
YGStyle style = node->getStyle(); \
style.instanceName[edge] = value; \
node->setStyle(style); \
YGNodeMarkDirtyInternal(node); \
node->markDirtyAndPropogate(); \
} \
} \
\
Expand Down

0 comments on commit 0a9e652

Please sign in to comment.