mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Fabric: ShadowTree::completeByReplacingShadowNode
Summary: This method is the core of the future features: `setNativeProps` and `LocalState`. Reviewed By: sahrens Differential Revision: D13114789 fbshipit-source-id: 2138496c43c171fe27784b1959d86d6eec4638ee
This commit is contained in:
committed by
Facebook Github Bot
parent
d594d5a4e5
commit
f42d2b9e32
@@ -98,6 +98,35 @@ bool ShadowTree::complete(
|
||||
return complete(oldRootShadowNode, newRootShadowNode);
|
||||
}
|
||||
|
||||
bool ShadowTree::completeByReplacingShadowNode(
|
||||
const SharedShadowNode &oldShadowNode,
|
||||
const SharedShadowNode &newShadowNode) const {
|
||||
auto rootShadowNode = getRootShadowNode();
|
||||
std::vector<std::reference_wrapper<const ShadowNode>> ancestors;
|
||||
oldShadowNode->constructAncestorPath(*rootShadowNode, ancestors);
|
||||
|
||||
if (ancestors.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto oldChild = oldShadowNode;
|
||||
auto newChild = newShadowNode;
|
||||
|
||||
SharedShadowNodeUnsharedList sharedChildren;
|
||||
|
||||
for (const auto &ancestor : ancestors) {
|
||||
auto children = ancestor.get().getChildren();
|
||||
std::replace(children.begin(), children.end(), oldChild, newChild);
|
||||
|
||||
sharedChildren = std::make_shared<SharedShadowNodeList>(children);
|
||||
|
||||
oldChild = ancestor.get().shared_from_this();
|
||||
newChild = oldChild->clone(ShadowNodeFragment{.children = sharedChildren});
|
||||
}
|
||||
|
||||
return complete(sharedChildren);
|
||||
}
|
||||
|
||||
bool ShadowTree::complete(
|
||||
const SharedRootShadowNode &oldRootShadowNode,
|
||||
const UnsharedRootShadowNode &newRootShadowNode) const {
|
||||
|
||||
@@ -77,6 +77,16 @@ class ShadowTree final {
|
||||
*/
|
||||
bool complete(const SharedShadowNodeUnsharedList &rootChildNodes) const;
|
||||
|
||||
/*
|
||||
* Replaces a given old shadow node with a new one in the tree by cloning all
|
||||
* nodes on the path to the root node and then complete the tree.
|
||||
* Can be called from any thread.
|
||||
* Returns `true` if the operation finished successfully.
|
||||
*/
|
||||
bool completeByReplacingShadowNode(
|
||||
const SharedShadowNode &oldShadowNode,
|
||||
const SharedShadowNode &newShadowNode) const;
|
||||
|
||||
/*
|
||||
* Returns a root shadow node that represents the last committed three.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user