protected Component onCreateLayoutWithSizeSpec( ComponentContext c, int widthSpec, int heightSpec) { if (ComponentsConfiguration.usePlaceholderComponent) { return PlaceholderComponent.createAndBuild(); } return Column.create(c).build(); }
public static Builder create(ComponentContext context, int defStyleAttr, int defStyleRes) { Builder builder = sBuilderPool.acquire(); if (builder == null) { builder = new Builder(); } builder.init(context, defStyleAttr, defStyleRes, new Column()); return builder; }
@Override public boolean isEquivalentTo(Component other) { if (this == other) { return true; } if (other == null || getClass() != other.getClass()) { return false; } Column column = (Column) other; if (this.getId() == column.getId()) { return true; } return true; } }
@Test public void testOwnerGlobalKey() { final Component root = getMultipleChildrenComponent(); final int layoutSpecId = root.getTypeId(); final int nestedLayoutSpecId = layoutSpecId - 1; final int columnSpecId = Column.create(mContext).build().getTypeId(); final LithoView lithoView = getLithoView(root); final String rootGlobalKey = ComponentKeyUtils.getKeyWithSeparator(layoutSpecId); final String nestedLayoutGlobalKey = ComponentKeyUtils.getKeyWithSeparator(layoutSpecId, columnSpecId, nestedLayoutSpecId); // Text Assert.assertEquals(rootGlobalKey, getComponentAt(lithoView, 0).getOwnerGlobalKey()); // TestViewComponent in child layout Assert.assertEquals(nestedLayoutGlobalKey, getComponentAt(lithoView, 1).getOwnerGlobalKey()); // CardClip in child Assert.assertEquals(nestedLayoutGlobalKey, getComponentAt(lithoView, 3).getOwnerGlobalKey()); // Text in child Assert.assertEquals(nestedLayoutGlobalKey, getComponentAt(lithoView, 4).getOwnerGlobalKey()); // CardClip Assert.assertEquals(rootGlobalKey, getComponentAt(lithoView, 6).getOwnerGlobalKey()); // TestViewComponent Assert.assertEquals(rootGlobalKey, getComponentAt(lithoView, 7).getOwnerGlobalKey()); }
@Test public void testNewEmptyLayout() { Column component = Column.create(mContext) .child(TestLayoutComponent.create(mContext)) .child(TestLayoutComponent.create(mContext)) .build(); InternalNode node = (InternalNode) component.resolve(mContext); assertThat(node.getChildCount()).isEqualTo(2); assertThat(node.getChildAt(0).getChildCount()).isEqualTo(0); assertThat(node.getChildAt(1).getChildCount()).isEqualTo(0); } }
@Test public void testOwnerGlobalKey() { final Component root = getMultipleChildrenComponent(); final int layoutSpecId = root.getTypeId(); final int nestedLayoutSpecId = layoutSpecId - 1; final int columnSpecId = Column.create(mContext).build().getTypeId(); final LithoView lithoView = getLithoView(root); final String rootGlobalKey = ComponentKeyUtils.getKeyWithSeparator(layoutSpecId); final String nestedLayoutGlobalKey = ComponentKeyUtils.getKeyWithSeparator(layoutSpecId, columnSpecId, nestedLayoutSpecId); // Text Assert.assertEquals(rootGlobalKey, getComponentAt(lithoView, 0).getOwnerGlobalKey()); // TestViewComponent in child layout Assert.assertEquals(nestedLayoutGlobalKey, getComponentAt(lithoView, 1).getOwnerGlobalKey()); // CardClip in child Assert.assertEquals(nestedLayoutGlobalKey, getComponentAt(lithoView, 3).getOwnerGlobalKey()); // Text in child Assert.assertEquals(nestedLayoutGlobalKey, getComponentAt(lithoView, 4).getOwnerGlobalKey()); // CardClip Assert.assertEquals(rootGlobalKey, getComponentAt(lithoView, 6).getOwnerGlobalKey()); // TestViewComponent Assert.assertEquals(rootGlobalKey, getComponentAt(lithoView, 7).getOwnerGlobalKey()); }
@Override protected Component onCreateLayout(final ComponentContext c) { return create(c).child(innerComponent).build(); } };
@OnCreateLayout static Component onCreateLayout(ComponentContext c) { return Column.create(c) .backgroundColor(Color.WHITE) .child( Text.create(c) .textSizeSp(20) .text("Playground sample")) .build(); } }