private boolean isLayoutRoot(InternalNode node) { return mLayoutRoot.isNestedTreeHolder() ? node == mLayoutRoot.getNestedTree() : node == mLayoutRoot; }
/** * Get the list of components composed by this component. This will not include any {@link View}s * that are mounted by this component as those are not components. * Use {@link this#getMountedView} for that. * * @return A list of child components. */ public List<DebugComponent> getChildComponents() { if (!isLayoutNode()) { final int nextComponentIndex = mComponentIndex - 1; return Arrays.asList(getInstance(mNode, nextComponentIndex)); } final List<DebugComponent> children = new ArrayList<>(); for (int i = 0, count = mNode.getChildCount(); i < count; i++) { final InternalNode childNode = mNode.getChildAt(i); final int outerWrapperComponentIndex = Math.max(0, childNode.getComponents().size() - 1); children.add(getInstance(childNode, outerWrapperComponentIndex)); } final InternalNode nestedTree = mNode.getNestedTree(); if (nestedTree != null && nestedTree.isInitialized()) { for (int i = 0, count = nestedTree.getChildCount(); i < count; i++) { final InternalNode childNode = nestedTree.getChildAt(i); children.add(getInstance(childNode, Math.max(0, childNode.getComponents().size() - 1))); } } return children; }
static void releaseNodeTree(InternalNode node, boolean isNestedTree) { if (node == NULL_LAYOUT) { throw new IllegalArgumentException("Cannot release a null node tree"); } for (int i = node.getChildCount() - 1; i >= 0; i--) { final InternalNode child = node.getChildAt(i); if (isNestedTree && node.hasNewLayout()) { node.markLayoutSeen(); } // A node must be detached from its parent *before* being released (otherwise the parent would // retain a reference to a node that may get re-used by another thread) node.removeChildAt(i); releaseNodeTree(child, isNestedTree); } if (node.hasNestedTree() && node.getNestedTree() != NULL_LAYOUT) { releaseNodeTree(node.getNestedTree(), true); } node.release(); }
private void applyOverridesRecursive(InternalNode node) { if (ComponentsConfiguration.isDebugModeEnabled) { DebugComponent.applyOverrides(mComponentContext, node); for (int i = 0, count = node.getChildCount(); i < count; i++) { applyOverridesRecursive(node.getChildAt(i)); } if (node.hasNestedTree()) { applyOverridesRecursive(node.getNestedTree()); } } }
@Test public void testLayoutOutputForRootNestedTreeComponentWithPercentPadding() { final Component component = new InlineLayoutSpec() { @Override protected Component onCreateLayout(final ComponentContext c) { return create(c) .alignItems(FLEX_START) .widthPx(50) .heightPx(50) .child( TestSizeDependentComponent.create(c) .setFixSizes(true) .paddingPercent(ALL, 10) .backgroundColor(0xFFFF0000)) .build(); } }; final InternalNode root = createAndMeasureTreeForComponent( new ComponentContext(application), component, makeSizeSpec(0, UNSPECIFIED), makeSizeSpec(0, UNSPECIFIED)); assertThat(root.getChildAt(0).getNestedTree().getPaddingLeft()).isEqualTo(5); assertThat(root.getChildAt(0).getNestedTree().getPaddingTop()).isEqualTo(5); assertThat(root.getChildAt(0).getNestedTree().getPaddingRight()).isEqualTo(5); assertThat(root.getChildAt(0).getNestedTree().getPaddingBottom()).isEqualTo(5); }
when(holder.getNestedTree()).thenReturn(result);
when(holder.getNestedTree()).thenReturn(result);
final InternalNode layoutFromWillRender = component.consumeLayoutCreatedInWillRender(); final InternalNode nestedTree = layoutFromWillRender == null ? holder.getNestedTree() : layoutFromWillRender;