/** Called to install internal state based on a component's parent context. */ @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE) protected void updateInternalChildState(ComponentContext parentContext) { updateInternalChildState(parentContext, false); }
@Override public InternalNode newLayoutBuilder( Component component, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { if (component.canResolve()) { return super.newLayoutBuilder(component, defStyleAttr, defStyleRes); } final InternalNode node = ComponentsPools.acquireInternalNode(this); component.updateInternalChildState(this); node.appendComponent(new TestComponent(component)); return node; }
@Test public void testWillRenderLayoutsOnceInColumn() { ComponentContext c = new ComponentContext(application); final Component componentSpy = spy(TestLayoutComponent.create(c, 0, 0, true, true, true, false).build()); final Component root = new InlineLayoutSpec() { @Override protected Component onCreateLayout(final ComponentContext c) { Component.willRender(c, componentSpy); return Column.create(c).child(componentSpy).build(); } }; calculateLayoutState( c.getAndroidContext(), root, -1, makeSizeSpec(100, EXACTLY), makeSizeSpec(100, EXACTLY)); verify(componentSpy, times(1)).updateInternalChildState(any(ComponentContext.class)); }
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; }
InternalNode resolveLayout(Component component) { final InternalNode layoutCreatedInWillRender = component.consumeLayoutCreatedInWillRender(); if (layoutCreatedInWillRender != null) { return layoutCreatedInWillRender; } component = component.getThreadSafeInstance(); component.updateInternalChildState(this, true); if (ComponentsConfiguration.isDebugModeEnabled) { DebugComponent.applyOverrides(this, component); } final InternalNode node = (InternalNode) component.resolve(component.getScopedContext()); if (component.canResolve()) { final CommonPropsCopyable props = component.getCommonPropsCopyable(); if (props != null) { props.copyInto(component.getScopedContext(), node); } } return node; }
@Test public void testWillRenderLayoutsOnce() { ComponentContext c = new ComponentContext(application); final Component componentSpy = spy(TestLayoutComponent.create(c, 0, 0, true, true, true, false).build()); Component.willRender(c, componentSpy); final InternalNode cachedLayout = componentSpy.getLayoutCreatedInWillRenderForTesting(); assertThat(cachedLayout).isNotNull(); calculateLayoutState( c.getAndroidContext(), componentSpy, -1, makeSizeSpec(100, EXACTLY), makeSizeSpec(100, EXACTLY)); assertThat(componentSpy.getLayoutCreatedInWillRenderForTesting()).isNull(); verify(componentSpy, times(1)).updateInternalChildState(any(ComponentContext.class)); }
DiffNode diffTreeRoot) { component.updateInternalChildState(c);