private void addNonLayoutOnlyNodeToLayoutOnlyNode(
      ReactShadowNode layoutOnlyNode, ReactShadowNode nonLayoutOnlyNode, int index) {
    ReactShadowNode parent = layoutOnlyNode.getParent();

    // If the parent hasn't been attached to its parent yet, don't issue commands to the native
    // hierarchy. We'll do that when the parent node actually gets attached somewhere.
    if (parent == null) {
      return;
    }

    int transformedIndex = index + parent.getNativeOffsetForChild(layoutOnlyNode);
    if (parent.isLayoutOnly()) {
      addNonLayoutOnlyNodeToLayoutOnlyNode(parent, nonLayoutOnlyNode, transformedIndex);
    } else {
      addNonLayoutNodeToNonLayoutNode(parent, nonLayoutOnlyNode, transformedIndex);
    }
  }
  private void addNodeToNode(ReactShadowNode parent, ReactShadowNode child, int index) {
    int indexInNativeChildren = parent.getNativeOffsetForChild(parent.getChildAt(index));
    boolean parentIsLayoutOnly = parent.isLayoutOnly();
    boolean childIsLayoutOnly = child.isLayoutOnly();

    // Switch on the four cases of:
    //   add (layout-only|not layout-only) to (layout-only|not layout-only)
    if (!parentIsLayoutOnly && !childIsLayoutOnly) {
      addNonLayoutNodeToNonLayoutNode(parent, child, indexInNativeChildren);
    } else if (!childIsLayoutOnly) {
      addNonLayoutOnlyNodeToLayoutOnlyNode(parent, child, indexInNativeChildren);
    } else if (!parentIsLayoutOnly) {
      addLayoutOnlyNodeToNonLayoutOnlyNode(parent, child, indexInNativeChildren);
    } else {
      addLayoutOnlyNodeToLayoutOnlyNode(parent, child, indexInNativeChildren);
    }
  }
  private void addLayoutOnlyNodeToNonLayoutOnlyNode(
      ReactShadowNode nonLayoutOnlyNode, ReactShadowNode layoutOnlyNode, int index) {
    // Add all of the layout-only node's children to its parent instead
    int currentIndex = index;
    for (int i = 0; i < layoutOnlyNode.getChildCount(); i++) {
      ReactShadowNode childToAdd = layoutOnlyNode.getChildAt(i);
      Assertions.assertCondition(childToAdd.getNativeParent() == null);

      if (childToAdd.isLayoutOnly()) {
        // Adding this layout-only child could result in adding multiple native views
        int childCountBefore = nonLayoutOnlyNode.getNativeChildCount();
        addLayoutOnlyNodeToNonLayoutOnlyNode(nonLayoutOnlyNode, childToAdd, currentIndex);
        int childCountAfter = nonLayoutOnlyNode.getNativeChildCount();
        currentIndex += childCountAfter - childCountBefore;
      } else {
        addNonLayoutNodeToNonLayoutNode(nonLayoutOnlyNode, childToAdd, currentIndex);
        currentIndex++;
      }
    }
  }