@Override protected LayoutState calculateLayoutState( ComponentContext context, Component root, int widthSpec, int heightSpec, boolean diffingEnabled, @Nullable LayoutState previousLayoutState, TreeProps treeProps, @LayoutState.CalculateLayoutSource int source, String extraAttribution) { return LayoutState.calculate( new TestComponentContext( ComponentContext.withComponentTree(new TestComponentContext(context), this), new StateHandler()), root, mId, widthSpec, heightSpec, diffingEnabled, previousLayoutState, source, extraAttribution, false); }
protected ComponentTree(Builder builder) { mContext = ComponentContext.withComponentTree(builder.context, this); mRoot = wrapRootInErrorBoundary(builder.root);
@Test public void testBasicComponentTreeDumping() { final Component component = new InlineLayoutSpec() { @Override protected Component onCreateLayout(ComponentContext c) { return TestDrawableComponent.create(c).widthPx(100).heightPx(100).build(); } }; ComponentContext componentContext = new ComponentContext(RuntimeEnvironment.application); final ComponentTree componentTree = ComponentTree.create(componentContext, component).build(); componentContext = ComponentContext.withComponentTree(componentContext, componentTree); final LithoView lithoView = new LithoView(RuntimeEnvironment.application); lithoView.setComponentTree(componentTree); lithoView.measure(makeMeasureSpec(0, UNSPECIFIED), makeMeasureSpec(0, UNSPECIFIED)); final String string = ComponentTreeDumpingHelper.dumpContextTree(componentContext); assertThat(string).containsPattern("InlineLayout\\{V}\n" + " TestDrawableComponent\\{V}"); } }
@Before public void setup() { MockitoAnnotations.initMocks(this); mContext = new ComponentContext(RuntimeEnvironment.application); mComponent = new InlineLayoutSpec() { @Override @OnCreateLayout protected Component onCreateLayout(ComponentContext c) { return Row.create(c) .marginPx(YogaEdge.LEFT, MARGIN_LEFT) .marginPx(YogaEdge.TOP, MARGIN_TOP) .child( TestDrawableComponent.create(c) .key("anchor") .widthPx(ANCHOR_WIDTH) .heightPx(ANCHOR_HEIGHT)) .build(); } }; mComponentTree = ComponentTree.create(mContext, mComponent).build(); Whitebox.setInternalState( mComponent, "mGlobalKey", ComponentKeyUtils.getKeyWithSeparator( mComponent.getTypeId(), Row.create(mContext).build().getTypeId())); mContext = ComponentContext.withComponentTree(mContext, mComponentTree); mContext = ComponentContext.withComponentScope(mContext, mComponent); mLithoView = getLithoView(mComponentTree); }
@Before public void setup() { MockitoAnnotations.initMocks(this); ComponentsConfiguration.isNestedTreeResolutionExperimentEnabled = true; mContext = new ComponentContext(RuntimeEnvironment.application); mComponent = new InlineLayoutSpec() { @Override @OnCreateLayout protected Component onCreateLayout(ComponentContext c) { return Row.create(c) .marginPx(YogaEdge.LEFT, MARGIN_LEFT) .marginPx(YogaEdge.TOP, MARGIN_TOP) .child( TestDrawableComponent.create(c) .key(KEY_ANCHOR) .widthPx(ANCHOR_WIDTH) .heightPx(ANCHOR_HEIGHT)) .build(); } }; mComponentTree = ComponentTree.create(mContext, mComponent).build(); Whitebox.setInternalState(mComponent, "mGlobalKey", mComponent.getKey()); mContext = ComponentContext.withComponentTree(mContext, mComponentTree); mContext = ComponentContext.withComponentScope(mContext, mComponent); mLithoView = getLithoView(mComponentTree); mAnchorGlobalKey = ComponentKeyUtils.getKeyWithSeparator(Row.create(mContext).build().getTypeId(), KEY_ANCHOR); }