@OnCreateLayout static ComponentLayout onCreateLayout(ComponentContext c, @Prop final ArtistDatum artist, @Prop final RecyclerBinder binder) { return Column.create(c) .flexShrink(0) .alignContent(YogaAlign.FLEX_START) .paddingDip(VERTICAL, 8) .paddingDip(HORIZONTAL, 16) .child(Card.create(c) .content(FeedItemComponent.create(c).artist(artist).binder(binder))) .build(); }
@OnCreateLayout static ComponentLayout 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) .withLayout() .marginDip(YogaEdge.HORIZONTAL, 10) .flex(0)) .child( Row.create(c) .heightPx(1) .backgroundColor(0xFFAAAAAA) .flex(1)) .backgroundColor(0xFFFAFAFA) .build(); }
@OnCreateLayout static ComponentLayout onCreateLayout( ComponentContext c, @Prop(resType = STRING) String text) { return Column.create(c).flexShrink(0).alignContent(YogaAlign.FLEX_START) .paddingDip(YogaEdge.ALL, 8) .child( Text.create(c) .text(text) .textSizeDip(14) .textColor(GRAY) .textStyle(ITALIC)) .build(); }
@OnCreateLayout static ComponentLayout onCreateLayout( ComponentContext c, @Prop final String name) { return Column.create(c).flexShrink(0).alignContent(YogaAlign.FLEX_START) .paddingDip(ALL, 16) .child( Text.create(c) .text(name) .textSizeSp(18) .build()) .clickHandler(DemoListItemComponent.onClick(c)) .build(); }
@OnCreateLayout static ComponentLayout onCreateLayout(ComponentContext c) { return Column.create(c).flexShrink(0).alignContent(YogaAlign.FLEX_START) .backgroundColor(Color.WHITE) .child( Text.create(c) .textSizeSp(20) .text("Playground sample")) .build(); }
@Test public void testEnumerations() { LayoutShadowNode reactShadowNode = spy(new LayoutShadowNode()); ReactStylesDiffMap map = buildStyles( "flexDirection", "column", "alignSelf", "stretch", "alignItems", "center", "justifyContent", "space_between", "position", "relative"); reactShadowNode.updateProperties(map); verify(reactShadowNode).setFlexDirection(YogaFlexDirection.COLUMN); verify(reactShadowNode).setAlignSelf(YogaAlign.STRETCH); verify(reactShadowNode).setAlignItems(YogaAlign.CENTER); verify(reactShadowNode).setJustifyContent(YogaJustify.SPACE_BETWEEN); verify(reactShadowNode).setPositionType(YogaPositionType.RELATIVE); reactShadowNode = spy(new LayoutShadowNode()); map = buildStyles(); reactShadowNode.updateProperties(map); verify(reactShadowNode, never()).setFlexDirection(any(YogaFlexDirection.class)); verify(reactShadowNode, never()).setAlignSelf(any(YogaAlign.class)); verify(reactShadowNode, never()).setAlignItems(any(YogaAlign.class)); verify(reactShadowNode, never()).setJustifyContent(any(YogaJustify.class)); verify(reactShadowNode, never()).setPositionType(any(YogaPositionType.class)); }
@OnCreateLayout static ComponentLayout onCreateLayout(ComponentContext c, @Prop Product product) { final DraweeController controller = Fresco.newDraweeControllerBuilder() .setUri(product.imageUrl()) .build(); return Column.create(c) .backgroundColor(Color.WHITE) .child( FrescoImage.create(c) .controller(controller) .actualImageScaleType( ScalingUtils .ScaleType .CENTER_CROP ) .withLayout() .heightDip(96) .widthDip(96) .alignSelf(YogaAlign.CENTER) ).child( Text.create(c) .text(product.name()) .maxLines(2) .minLines(2) .ellipsize(TextUtils.TruncateAt.MIDDLE) .glyphWarming(true) .textAlignment(Layout.Alignment.ALIGN_CENTER) .textSizeSp(14) .withLayout() .widthDip(128) .paddingDip(TOP, 8) ) .child( Text.create(c) .text(FormatUtil.getFormattedCurrency(product.price())) .glyphWarming(true) .textSizeSp(14) .withLayout() .paddingDip(TOP, 8) ).child( Text.create(c) .text(FormatUtil.getFormattedCurrency(product.originalPrice())) .glyphWarming(true) .textSizeSp(12) .withLayout() .paddingDip(BOTTOM, 8) ).clickHandler(ProductComponent.onClick(c)) .paddingDip(ALL, 8) .build(); }
@ReactProp(name = ViewProps.ALIGN_SELF) public void setAlignSelf(@Nullable String alignSelf) { if (isVirtual()) { return; } if (alignSelf == null) { setAlignSelf(YogaAlign.AUTO); return; } switch (alignSelf) { case "auto": { setAlignSelf(YogaAlign.AUTO); return; } case "flex-start": { setAlignSelf(YogaAlign.FLEX_START); return; } case "center": { setAlignSelf(YogaAlign.CENTER); return; } case "flex-end": { setAlignSelf(YogaAlign.FLEX_END); return; } case "stretch": { setAlignSelf(YogaAlign.STRETCH); return; } case "baseline": { setAlignSelf(YogaAlign.BASELINE); return; } case "space-between": { setAlignSelf(YogaAlign.SPACE_BETWEEN); return; } case "space-around": { setAlignSelf(YogaAlign.SPACE_AROUND); return; } default: { throw new JSApplicationIllegalArgumentException( "invalid value for alignSelf: " + alignSelf); } } }
@ReactProp(name = ViewProps.ALIGN_ITEMS) public void setAlignItems(@Nullable String alignItems) { if (isVirtual()) { return; } if (alignItems == null) { setAlignItems(YogaAlign.STRETCH); return; } switch (alignItems) { case "auto": { setAlignItems(YogaAlign.AUTO); return; } case "flex-start": { setAlignItems(YogaAlign.FLEX_START); return; } case "center": { setAlignItems(YogaAlign.CENTER); return; } case "flex-end": { setAlignItems(YogaAlign.FLEX_END); return; } case "stretch": { setAlignItems(YogaAlign.STRETCH); return; } case "baseline": { setAlignItems(YogaAlign.BASELINE); return; } case "space-between": { setAlignItems(YogaAlign.SPACE_BETWEEN); return; } case "space-around": { setAlignItems(YogaAlign.SPACE_AROUND); return; } default: { throw new JSApplicationIllegalArgumentException( "invalid value for alignItems: " + alignItems); } } }
@ReactProp(name = ViewProps.ALIGN_CONTENT) public void setAlignContent(@Nullable String alignContent) { if (isVirtual()) { return; } if (alignContent == null) { setAlignContent(YogaAlign.FLEX_START); return; } switch (alignContent) { case "auto": { setAlignContent(YogaAlign.AUTO); return; } case "flex-start": { setAlignContent(YogaAlign.FLEX_START); return; } case "center": { setAlignContent(YogaAlign.CENTER); return; } case "flex-end": { setAlignContent(YogaAlign.FLEX_END); return; } case "stretch": { setAlignContent(YogaAlign.STRETCH); return; } case "baseline": { setAlignContent(YogaAlign.BASELINE); return; } case "space-between": { setAlignContent(YogaAlign.SPACE_BETWEEN); return; } case "space-around": { setAlignContent(YogaAlign.SPACE_AROUND); return; } default: { throw new JSApplicationIllegalArgumentException( "invalid value for alignContent: " + alignContent); } } }
public void setAlignSelf(YogaAlign alignSelf) { mYogaNode.setAlignSelf(alignSelf); }
public void setAlignItems(YogaAlign alignItems) { mYogaNode.setAlignItems(alignItems); }
public void setAlignContent(YogaAlign alignContent) { mYogaNode.setAlignContent(alignContent); }