@Test public void testCreateLayoutAndResolveNestedTreeWithLayoutSpecCannotMeasure() { Component component = setUpSpyComponentForCreateLayout( false /* isMountSpec */, false /* canMeasure */); component.createLayout(mContext, true); verify(component).onCreateLayout(mContext); verify(mNode).appendComponent(component); verify(mNode, never()).setMeasureFunction(any(YogaMeasureFunction.class)); verify(component).onPrepare(mContext); }
@Test public void testCreateLayoutWithNullComponentWithMountSpecCanMeasure() { Component component = setUpSpyLayoutSpecWithNullLayout(); component.createLayout(mContext, false); verify(component).onCreateLayout(mContext); verify(component, never()).onPrepare(mContext); }
@Test public void testCreateLayoutWithNullComponentWithMountSpecCannotMeasure() { Component component = setUpSpyLayoutSpecWithNullLayout(); component.createLayout(mContext, false); verify(component).onCreateLayout(mContext); verify(component, never()).onPrepare(mContext); }
@Test public void testCreateLayoutWithNullComponentWithLayoutSpecCannotMeasure() { Component component = setUpSpyLayoutSpecWithNullLayout(); component.createLayout(mContext, false); verify(component).onCreateLayout(mContext); verify(component, never()).onPrepare(mContext); }
@Test public void testCreateLayoutAndDontResolveNestedTreeWithLayoutSpecCannotMeasure() { Component component = setUpSpyComponentForCreateLayout( false /* isMountSpec */, false /* canMeasure */); component.createLayout(mContext, false); verify(component).onCreateLayout(mContext); verify(mNode).appendComponent(component); verify(mNode, never()).setMeasureFunction(any(YogaMeasureFunction.class)); verify(component).onPrepare(mContext); }
@Test public void testCreateLayoutWithNullComponentWithLayoutSpecCanMeasure() { Component component = setUpSpyLayoutSpecWithNullLayout(); component.createLayout(mContext, false); verify(component).onCreateLayout(mContext); verify(component, never()).onPrepare(mContext); }
@Test public void testCreateLayoutAndResolveNestedTreeWithMountSpecCannotMeasure() { Component component = setUpSpyComponentForCreateLayout( true /* isMountSpec */, false /* canMeasure */); component.createLayout(mContext, true); verify(component).onCreateLayout(mContext); verify(mNode).appendComponent(component); verify(mNode, never()).setMeasureFunction(any(YogaMeasureFunction.class)); verify(component).onPrepare(mContext); }
@Test public void testCreateLayoutAndDontResolveNestedTreeWithMountSpecCannotMeasure() { Component component = setUpSpyComponentForCreateLayout( true /* isMountSpec */, false /* canMeasure */); component.createLayout(mContext, false); verify(component).onCreateLayout(mContext); verify(mNode).appendComponent(component); verify(mNode, never()).setMeasureFunction(any(YogaMeasureFunction.class)); verify(component).onPrepare(mContext); }
@Test public void testCreateLayoutAndResolveNestedTreeWithMountSpecCanMeasure() { Component component = setUpSpyComponentForCreateLayout( true /* isMountSpec */, true /* canMeasure */); component.createLayout(mContext, true); verify(component).onCreateLayout(mContext); verify(mNode).appendComponent(component); verify(mNode).setMeasureFunction(any(YogaMeasureFunction.class)); verify(component).onPrepare(mContext); }
@Test public void testCreateLayoutAndDontResolveNestedTreeWithMountSpecCanMeasure() { Component component = setUpSpyComponentForCreateLayout( true /* isMountSpec */, true /* canMeasure */); component.createLayout(mContext, false); verify(component).onCreateLayout(mContext); verify(mNode).appendComponent(component); verify(mNode).setMeasureFunction(any(YogaMeasureFunction.class)); verify(component).onPrepare(mContext); }
@Test public void testCreateLayoutAndDontResolveNestedTreeWithLayoutSpecCanMeasure() { Component component = setUpSpyComponentForCreateLayout( false /* isMountSpec */, true /* canMeasure */); component.createLayout(mContext, false); PowerMockito.verifyStatic(); // Calling here to verify static call. ComponentsPools.acquireInternalNode(mContext); verify(component, never()).onCreateLayout( any(ComponentContext.class)); verify(component, never()).onCreateLayoutWithSizeSpec( any(ComponentContext.class), anyInt(), anyInt()); verify(mNode).appendComponent(component); verify(mNode).setMeasureFunction(any(YogaMeasureFunction.class)); verify(component, never()) .onPrepare(any(ComponentContext.class)); }
@Test public void testCreateLayoutAndResolveNestedTreeWithLayoutSpecCanMeasure() { Component component = setUpSpyComponentForCreateLayout( false /* isMountSpec */, true /* canMeasure */); mContext.setWidthSpec(mNestedTreeWidthSpec); mContext.setHeightSpec(mNestedTreeHeightSpec); component.createLayout(mContext, true); verify(component).onCreateLayoutWithSizeSpec( mContext, mNestedTreeWidthSpec, mNestedTreeHeightSpec); verify(mNode).appendComponent(component); verify(mNode, never()).setMeasureFunction(any(YogaMeasureFunction.class)); verify(component).onPrepare(mContext); }
@VisibleForTesting static InternalNode createTree( Component component, ComponentContext context) { final ComponentsLogger logger = context.getLogger(); final PerfEvent createLayoutPerfEvent = logger != null ? LogTreePopulator.populatePerfEventFromLogger( context, logger, logger.newPerformanceEvent(EVENT_CREATE_LAYOUT)) : null; if (createLayoutPerfEvent != null) { createLayoutPerfEvent.markerAnnotate(PARAM_COMPONENT, component.getSimpleName()); } final InternalNode root = component.createLayout(context, true /* resolveNestedTree */); if (createLayoutPerfEvent != null) { logger.logPerfEvent(createLayoutPerfEvent); } return root; }
InternalNode newLayoutBuilder( Component component, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { final InternalNode layoutCreatedInWillRender = component.consumeLayoutCreatedInWillRender(); if (layoutCreatedInWillRender != null) { return layoutCreatedInWillRender; } component = component.getThreadSafeInstance(); component.updateInternalChildState(this); if (ComponentsConfiguration.isDebugModeEnabled) { DebugComponent.applyOverrides(this, component); } final InternalNode node = component.createLayout(component.getScopedContext(), false); if (node != NULL_LAYOUT) { applyStyle(node, defStyleAttr, defStyleRes); } return node; }
@Test public void testOnShouldCreateLayoutWithNewSizeSpec_FirstCall() { ComponentsConfiguration.isNestedTreeResolutionExperimentEnabled = true; ComponentsConfiguration.enableShouldCreateLayoutWithNewSizeSpec = true; Component component; component = new SpyComponentBuilder() .setNode(mNode) .canMeasure(true) .isMountSpec(false) .hasState(true) .isLayoutSpecWithSizeSpecCheck(true) .build(mContext); component.createLayout(mContext, true); // onShouldCreateLayoutWithNewSizeSpec should not be called the first time verify(component, never()) .onShouldCreateLayoutWithNewSizeSpec(any(ComponentContext.class), anyInt(), anyInt()); verify(component) .onCreateLayoutWithSizeSpec(mContext, mContext.getWidthSpec(), mContext.getHeightSpec()); ComponentsConfiguration.enableShouldCreateLayoutWithNewSizeSpec = false; ComponentsConfiguration.isNestedTreeResolutionExperimentEnabled = false; }
@Test public void testCreateLayoutUsesWillRenderResult() { ComponentContext c = new ComponentContext(application); final Component component = TestLayoutComponent.create(c, 0, 0, true, true, true, false).build(); Component.willRender(c, component); final InternalNode cachedLayout = component.getLayoutCreatedInWillRenderForTesting(); assertThat(cachedLayout).isNotNull(); InternalNode result = component.createLayout(c, false); assertThat(result).isEqualTo(cachedLayout); assertThat(component.getLayoutCreatedInWillRenderForTesting()).isNull(); }