public static Builder create(ComponentContext context) { return create(context, 0, 0); }
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 Row()); return builder; }
@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); }
@Override protected Component onCreateLayout(ComponentContext c) { return Row.create(c).build(); } };
@OnCreateLayout static Component onCreateLayout( ComponentContext c, @Prop(optional = true) ComponentWrapper wrapper, @Prop(optional = true) List<Component> componentList) { if (wrapper != null) { return Row.create(c).child(wrapper.mComponent).build(); } final Row.Builder builder = Row.create(c); for (Component component : componentList) { builder.child(component); } return builder.build(); } }
@Override protected Component onCreateLayoutWithSizeSpec( ComponentContext c, int widthSpec, int heightSpec) { return Row.create(c) .widthDip(View.MeasureSpec.getSize(widthSpec)) .heightDip(View.MeasureSpec.getSize(heightSpec)) .build(); } };
@Override protected Component onCreateLayout(ComponentContext c) { return Row.create(c) .child(Row.create(c).transitionKey("test").transitionKeyType(Transition.TransitionKeyType.GLOBAL)) .child(Row.create(c).transitionKey("test2").transitionKeyType(Transition.TransitionKeyType.GLOBAL)) .build(); } };
@Override protected Component onCreateLayout(ComponentContext c) { return Row.create(c) .child(Row.create(c).transitionKey("test")) .transitionKeyType(Transition.TransitionKeyType.GLOBAL) .child(Row.create(c).transitionKey("test2")) .transitionKeyType(Transition.TransitionKeyType.GLOBAL) .build(); }
@Override protected Component onCreateLayout(ComponentContext c) { return Row.create(c) .child(Row.create(c).transitionKey("test").transitionKeyType(Transition.TransitionKeyType.GLOBAL)) .child(Row.create(c).transitionKey("test").transitionKeyType(Transition.TransitionKeyType.GLOBAL)) .build(); } };
static Component.Builder createSenderTile(ComponentContext c) { return Row.create(c) .marginDip(YogaEdge.ALL, 5) .alignSelf(YogaAlign.CENTER) .widthDip(55) .heightDip(55) .flexShrink(0) .background(getCircle(c)); }
private static Component buildRow(ComponentContext c, int color, String key) { return Row.create(c) .child(buildCell(c, color, key + 0)) .child(buildCell(c, color, key + 1)) .child(buildCell(c, color, key + 2)) .build(); }
@OnCreateLayout static Component onCreateLayout(ComponentContext c, @State int state) { final boolean expanded1 = state == 1 || state == 2; final boolean expanded2 = state == 2 || state == 3; return Column.create(c) .paddingDip(YogaEdge.ALL, 8) .child(Row.create(c).marginDip(YogaEdge.TOP, 8).child(buildComment1(c, expanded1))) .child(Row.create(c).marginDip(YogaEdge.TOP, 16).child(buildComment2(c, expanded2))) .clickHandler(AnimatedBadge.onClick(c)) .build(); }
@OnCreateLayout static Component onCreateLayout(ComponentContext c, @State boolean top) { return Row.create(c) .heightDip(200) .alignItems(top ? YogaAlign.FLEX_START : YogaAlign.FLEX_END) .child( Row.create(c) .heightDip(40) .flexGrow(1) .backgroundColor(Color.parseColor("#ee1111")) .transitionKey("red") .build()) .child( Row.create(c) .heightDip(40) .flexGrow(1) .backgroundColor(Color.parseColor("#1111ee")) .transitionKey("blue") .build()) .child( Row.create(c) .heightDip(40) .flexGrow(1) .backgroundColor(Color.parseColor("#11ee11")) .transitionKey("green") .build()) .clickHandler(UpDownBlocksComponent.onClick(c)) .build(); }
@OnCreateLayout static Component onCreateLayout(ComponentContext c, @State boolean favourited) { return Row.create(c) .backgroundRes(favourited ? star_on : star_off) .widthDip(32) .heightDip(32) .clickHandler(FavouriteButton.onClick(c)) .build(); }
@OnCreateLayout static Component onCreateLayout( ComponentContext c, @Prop(resType = ResType.DIMEN_SIZE) int radius, @Prop(resType = ResType.COLOR) int color) { final int dim = 2 * radius; return Row.create(c) .heightPx(dim) .widthPx(dim) .background(buildRoundedRect(radius, color)) .build(); }
@OnCreateLayout static Component onCreateLayout(ComponentContext c, @Prop final Decade decade) { return Row.create(c) .alignItems(YogaAlign.CENTER) .paddingDip(YogaEdge.ALL, 16) .child( Row.create(c) .heightPx(1) .backgroundColor(0xFFAAAAAA) .flex(1)) .child( Text.create(c) .text(String.valueOf(decade.year)) .textSizeDip(14) .textColor(0xFFAAAAAA) .marginDip(YogaEdge.HORIZONTAL, 10) .flex(0)) .child( Row.create(c) .heightPx(1) .backgroundColor(0xFFAAAAAA) .flex(1)) .backgroundColor(0xFFFAFAFA) .build(); } }
@OnCreateLayout static Component onCreateLayout(ComponentContext c) { return Row.create(c) .backgroundColor(0xDDFFFFFF) .positionType(YogaPositionType.ABSOLUTE) .positionDip(YogaEdge.RIGHT, 4) .positionDip(YogaEdge.TOP, 4) .paddingDip(YogaEdge.ALL, 2) .child(FavouriteButton.create(c)) .build(); } }
static Component.Builder createMessageContent(ComponentContext c, String messageText) { return Row.create(c) .paddingDip(YogaEdge.ALL, 8) .marginDip(YogaEdge.ALL, 8) .background(ExpandableElementUtil.getMessageBackground(c, 0xFFEAEAEA)) .child(Text.create(c).textSizeDip(18).textColor(Color.BLACK).text(messageText)); } }