Fabric: Removed last two plactical usages of `ShadowNode::sourceNode_`

Summary:
@public
 * In case of `ShadowTree` we just pass original old node as a `commit` method argument;
 * In case of `ConcreteViewShadowNode` we just don't need that because diffing algorithm does not use that information anymore.

Reviewed By: mdvacca

Differential Revision: D8753906

fbshipit-source-id: b8555083c7e72e9b3c0f9a8065745946d4cf44c7
This commit is contained in:
Valentin Shergin 2018-07-15 16:46:17 -07:00 committed by Facebook Github Bot
parent fcd72bf34a
commit e78bf723bf
3 changed files with 4 additions and 19 deletions

View File

@ -78,7 +78,7 @@ void ShadowTree::complete(UnsharedRootShadowNode newRootShadowNode) {
newRootShadowNode
);
if (commit(newRootShadowNode)) {
if (commit(oldRootShadowNode, newRootShadowNode)) {
emitLayoutEvents(instructions);
if (delegate_) {
@ -87,10 +87,10 @@ void ShadowTree::complete(UnsharedRootShadowNode newRootShadowNode) {
}
}
bool ShadowTree::commit(const SharedRootShadowNode &newRootShadowNode) {
bool ShadowTree::commit(const SharedRootShadowNode &oldRootShadowNode, const SharedRootShadowNode &newRootShadowNode) {
std::lock_guard<std::mutex> lock(commitMutex_);
if (newRootShadowNode->getSourceNode() != rootShadowNode_) {
if (oldRootShadowNode != rootShadowNode_) {
return false;
}

View File

@ -77,7 +77,7 @@ private:
UnsharedRootShadowNode cloneRootShadowNode(const LayoutConstraints &layoutConstraints, const LayoutContext &layoutContext) const;
void complete(UnsharedRootShadowNode newRootShadowNode);
bool commit(const SharedRootShadowNode &newRootShadowNode);
bool commit(const SharedRootShadowNode &oldRootShadowNode, const SharedRootShadowNode &newRootShadowNode);
void emitLayoutEvents(const TreeMutationInstructionList &instructions);
const Tag rootTag_;

View File

@ -105,21 +105,6 @@ public:
auto childShadowNode = std::dynamic_pointer_cast<const ShadowNode>(child);
assert(childShadowNode);
auto childShadowNodeClone = childShadowNode->clone();
// This is overloading of `SharedLayoutableShadowNode::cloneAndReplaceChild`,
// the method is used to clone some node as a preparation for future mutation
// caused by relayout.
// Because those changes are not requested by UIManager, they add a layer
// of node generation (between the committed stage and new proposed stage).
// That additional layer confuses the Diffing algorithm which uses
// `sourceNode` for referencing the previous (aka committed) stage
// of the tree to produce mutation instructions.
// In other words, if we don't compensate this change here,
// the Diffing algorithm will compare wrong trees
// ("new-but-not-laid-out-yet vs. new" instead of "committed vs. new").
auto nonConstChildShadowNodeClone = std::const_pointer_cast<ShadowNode>(childShadowNodeClone);
nonConstChildShadowNodeClone->shallowSourceNode();
ShadowNode::replaceChild(childShadowNode, childShadowNodeClone);
return std::dynamic_pointer_cast<const LayoutableShadowNode>(childShadowNodeClone);
}