Java Code Examples for com.facebook.react.uimanager.ReactShadowNode#addChildAt()

The following examples show how to use com.facebook.react.uimanager.ReactShadowNode#addChildAt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FabricUIManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * 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);
  }
}
 
Example 2
Source File: FabricUIManagerTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
@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);
}
 
Example 3
Source File: FabricUIManagerTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
@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);
}