Refactor cloning of YogaNode
Summary: see Test Plan Reviewed By: priteshrnandgaonkar Differential Revision: D7339832 fbshipit-source-id: 2de6f47ae7601ac083d3b9fbe10ffaf6307ae760
This commit is contained in:
committed by
Facebook Github Bot
parent
187fc54596
commit
17901ea5c2
@@ -558,15 +558,18 @@ void YGNode::cloneChildrenIfNeeded() {
|
||||
return;
|
||||
}
|
||||
|
||||
const YGNodeClonedFunc cloneNodeCallback = config_->cloneNodeCallback;
|
||||
const YGCloneNodeFunc cloneNodeCallback = config_->cloneNodeCallback;
|
||||
for (uint32_t i = 0; i < childCount; ++i) {
|
||||
const YGNodeRef oldChild = children_[i];
|
||||
const YGNodeRef newChild = YGNodeClone(oldChild);
|
||||
YGNodeRef newChild = nullptr;
|
||||
if (cloneNodeCallback) {
|
||||
newChild = cloneNodeCallback(oldChild, this, i);
|
||||
}
|
||||
if (newChild == nullptr) {
|
||||
newChild = YGNodeClone(oldChild);
|
||||
}
|
||||
replaceChild(newChild, i);
|
||||
newChild->setParent(this);
|
||||
if (cloneNodeCallback) {
|
||||
cloneNodeCallback(oldChild, newChild, this, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -94,7 +94,7 @@ struct YGConfig {
|
||||
bool shouldDiffLayoutWithoutLegacyStretchBehaviour;
|
||||
float pointScaleFactor;
|
||||
YGLogger logger;
|
||||
YGNodeClonedFunc cloneNodeCallback;
|
||||
YGCloneNodeFunc cloneNodeCallback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
|
@@ -428,7 +428,7 @@ void YGNodeRemoveChild(const YGNodeRef parent, const YGNodeRef excludedChild) {
|
||||
// Otherwise we have to clone the node list except for the child we're trying to delete.
|
||||
// We don't want to simply clone all children, because then the host will need to free
|
||||
// the clone of the child that was just deleted.
|
||||
const YGNodeClonedFunc cloneNodeCallback =
|
||||
const YGCloneNodeFunc cloneNodeCallback =
|
||||
parent->getConfig()->cloneNodeCallback;
|
||||
uint32_t nextInsertIndex = 0;
|
||||
for (uint32_t i = 0; i < childCount; i++) {
|
||||
@@ -440,12 +440,16 @@ void YGNodeRemoveChild(const YGNodeRef parent, const YGNodeRef excludedChild) {
|
||||
parent->markDirtyAndPropogate();
|
||||
continue;
|
||||
}
|
||||
const YGNodeRef newChild = YGNodeClone(oldChild);
|
||||
YGNodeRef newChild = nullptr;
|
||||
if (cloneNodeCallback) {
|
||||
newChild = cloneNodeCallback(oldChild, parent, nextInsertIndex);
|
||||
}
|
||||
if (newChild == nullptr) {
|
||||
newChild = YGNodeClone(oldChild);
|
||||
}
|
||||
parent->replaceChild(newChild, nextInsertIndex);
|
||||
newChild->setParent(parent);
|
||||
if (cloneNodeCallback) {
|
||||
cloneNodeCallback(oldChild, newChild, parent, nextInsertIndex);
|
||||
}
|
||||
|
||||
nextInsertIndex++;
|
||||
}
|
||||
while (nextInsertIndex < childCount) {
|
||||
@@ -3964,7 +3968,7 @@ void *YGConfigGetContext(const YGConfigRef config) {
|
||||
return config->context;
|
||||
}
|
||||
|
||||
void YGConfigSetNodeClonedFunc(const YGConfigRef config, const YGNodeClonedFunc callback) {
|
||||
void YGConfigSetCloneNodeFunc(const YGConfigRef config, const YGCloneNodeFunc callback) {
|
||||
config->cloneNodeCallback = callback;
|
||||
}
|
||||
|
||||
|
@@ -62,8 +62,7 @@ typedef int (*YGLogger)(const YGConfigRef config,
|
||||
YGLogLevel level,
|
||||
const char *format,
|
||||
va_list args);
|
||||
typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
|
||||
YGNodeRef newNode,
|
||||
typedef YGNodeRef (*YGCloneNodeFunc)(YGNodeRef oldNode,
|
||||
YGNodeRef parent,
|
||||
int childIndex);
|
||||
|
||||
@@ -283,8 +282,8 @@ WIN_EXPORT bool YGConfigIsExperimentalFeatureEnabled(const YGConfigRef config,
|
||||
WIN_EXPORT void YGConfigSetUseWebDefaults(const YGConfigRef config, const bool enabled);
|
||||
WIN_EXPORT bool YGConfigGetUseWebDefaults(const YGConfigRef config);
|
||||
|
||||
WIN_EXPORT void YGConfigSetNodeClonedFunc(const YGConfigRef config,
|
||||
const YGNodeClonedFunc callback);
|
||||
WIN_EXPORT void YGConfigSetCloneNodeFunc(const YGConfigRef config,
|
||||
const YGCloneNodeFunc callback);
|
||||
|
||||
// Export only for C#
|
||||
WIN_EXPORT YGConfigRef YGConfigGetDefault(void);
|
||||
|
Reference in New Issue
Block a user