boolean canUsePreviousLayout(ComponentContext context) { return ComponentsConfiguration.enableShouldCreateLayoutWithNewSizeSpec && !onShouldCreateLayoutWithNewSizeSpec( context, context.getWidthSpec(), context.getHeightSpec()); }
@ThreadSafe(enableChecks = false) private Component createComponentLayout(ComponentContext context) { Component layoutComponent = null; if (Component.isLayoutSpecWithSizeSpec(((Component) this))) { try { layoutComponent = onCreateLayoutWithSizeSpec(context, context.getWidthSpec(), context.getHeightSpec()); } catch (Exception e) { dispatchErrorEvent(context, e); } } else { try { layoutComponent = onCreateLayout(context); } catch (Exception e) { dispatchErrorEvent(context, e); } } return layoutComponent; }
@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; }
final int previousHeightSpec = c.getHeightSpec();