@OnCreateLayout static ComponentLayout onCreateLayout( ComponentContext c, @Prop(resType = STRING) String title) { return Text.create(c) .text(title) .textStyle(BOLD) .textSizeDip(24) .withLayout().flexShrink(0) .backgroundColor(0xDDFFFFFF) .positionType(YogaPositionType.ABSOLUTE) .positionDip(YogaEdge.BOTTOM, 4) .positionDip(YogaEdge.LEFT, 4) .paddingDip(YogaEdge.HORIZONTAL, 6) .build(); }
@ReactProp(name = ViewProps.POSITION) public void setPosition(@Nullable String position) { if (isVirtual()) { return; } if (position == null) { setPositionType(YogaPositionType.RELATIVE); return; } switch (position) { case "relative": { setPositionType(YogaPositionType.RELATIVE); break; } case "absolute": { setPositionType(YogaPositionType.ABSOLUTE); break; } default: { throw new JSApplicationIllegalArgumentException( "invalid value for position: " + position); } } }
@OnCreateLayout static ComponentLayout 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(); }
@Test public void testPosition() { LayoutShadowNode reactShadowNode = spy(new LayoutShadowNode()); ReactStylesDiffMap map = spy(buildStyles( "position", "absolute", "bottom", 10.0, "right", 5.0)); reactShadowNode.updateProperties(map); verify(reactShadowNode).setPosition(eq(Spacing.BOTTOM), anyFloat()); verify(reactShadowNode).setPosition(eq(Spacing.END), anyFloat()); verify(reactShadowNode).setPositionType(any(YogaPositionType.class)); verify(map).getFloat("bottom", Float.NaN); verify(map).getFloat("right", Float.NaN); reactShadowNode = spy(new LayoutShadowNode()); map = spy(buildStyles()); reactShadowNode.updateProperties(map); verify(reactShadowNode, never()).setPosition(eq(Spacing.BOTTOM), anyFloat()); verify(reactShadowNode, never()).setPosition(eq(Spacing.END), anyFloat()); verify(reactShadowNode, never()).setPositionType(any(YogaPositionType.class)); verify(map, never()).getFloat("bottom", Float.NaN); verify(map, never()).getFloat("right", Float.NaN); }
@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)); }
public void setPositionType(YogaPositionType positionType) { mYogaNode.setPositionType(positionType); }