下面列出了com.facebook.react.uimanager.ReactShadowNode#addChildAt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Appends the child {@link ReactShadowNode} to the children set of the parent {@link
* ReactShadowNode}.
*/
@Nullable
@DoNotStrip
public void appendChild(ReactShadowNode parent, ReactShadowNode child) {
if (DEBUG) {
FLog.d(TAG, "appendChild \n\tparent: " + parent + "\n\tchild: " + child);
}
SystraceMessage.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
"FabricUIManager.appendChild")
.flush();
try {
// If the child to append was already committed (child.isSealed()),
// then we add a mutation of it. In the future this will be performed by FabricJS / Fiber.
//TODO: T27926878 avoid cloning shared child
if (child.isSealed()) {
child = child.mutableCopy(child.getInstanceHandle());
}
parent.addChildAt(child, parent.getChildCount());
} catch (Throwable t) {
handleException(parent, t);
} finally{
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
}
}
@Test
public void testCloneNode() {
ReactShadowNode node = createViewNode();
ReactShadowNode child = createViewNode();
node.addChildAt(child, 0);
ReactShadowNode clonedNode = mFabricUIManager.cloneNode(node);
assertThat(clonedNode).isNotSameAs(node);
assertThat(clonedNode.getOriginalReactShadowNode()).isSameAs(node);
assertSameFields(clonedNode, node);
assertSameChildren(clonedNode, node);
assertThat(clonedNode.getChildAt(0)).isEqualTo(child);
}
@Test
public void testCloneNodeWithNewChildren() {
ReactShadowNode node = createViewNode();
ReactShadowNode child = createViewNode();
node.addChildAt(child, 0);
ReactShadowNode clonedNode = mFabricUIManager.cloneNodeWithNewChildren(node);
assertThat(clonedNode.getChildCount()).isZero();
assertSameFields(clonedNode, node);
}