private static void setAlignItems() { String alignItems = mInlineMap.get(ALIGNITEMS); if (alignItems != null) { CSSAlign align = alignMap.get(alignItems); if (align != null) { mNode.setAlignItems(align); } } }
private static void setAlignSelf() { String alignSelf = mInlineMap.get(ALIGNSELF); if (alignSelf != null) { CSSAlign align = alignMap.get(alignSelf); if (align != null) { mNode.setAlignSelf(align); } } }
private static void setAlignContent() { String alignContent = mInlineMap.get(ALIGNCONTENT); if (alignContent != null) { CSSAlign align = alignMap.get(alignContent); if (align != null) { mNode.setAlignContent(align); } } }
@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(CSSFlexDirection.COLUMN); verify(reactShadowNode).setAlignSelf(CSSAlign.STRETCH); verify(reactShadowNode).setAlignItems(CSSAlign.CENTER); verify(reactShadowNode).setJustifyContent(CSSJustify.SPACE_BETWEEN); verify(reactShadowNode).setPositionType(CSSPositionType.RELATIVE); reactShadowNode = spy(new LayoutShadowNode()); map = buildStyles(); reactShadowNode.updateProperties(map); verify(reactShadowNode, never()).setFlexDirection(any(CSSFlexDirection.class)); verify(reactShadowNode, never()).setAlignSelf(any(CSSAlign.class)); verify(reactShadowNode, never()).setAlignItems(any(CSSAlign.class)); verify(reactShadowNode, never()).setJustifyContent(any(CSSJustify.class)); verify(reactShadowNode, never()).setPositionType(any(CSSPositionType.class)); }
public void clear() { style.direction = CSSDirection.INHERIT; style.flexDirection = CSSFlexDirection.COLUMN; style.justifyContent = CSSJustify.FLEX_START; style.alignContent = CSSAlign.FLEX_START; style.alignItems = CSSAlign.STRETCH; style.alignSelf = CSSAlign.AUTO; style.positionType = CSSPositionType.RELATIVE; style.flexWrap = CSSWrap.NOWRAP; style.flex = 0; style.margin = new Spacing(); style.padding = new Spacing(); style.border = new Spacing(); style.positionTop = CSSConstants.UNDEFINED; style.positionBottom = CSSConstants.UNDEFINED; style.positionLeft = CSSConstants.UNDEFINED; style.positionRight = CSSConstants.UNDEFINED; style.width = CSSConstants.UNDEFINED; style.height = CSSConstants.UNDEFINED; style.minWidth = CSSConstants.UNDEFINED; style.minHeight = CSSConstants.UNDEFINED; style.maxWidth = CSSConstants.UNDEFINED; style.maxHeight = CSSConstants.UNDEFINED; }
@ReactProp(name = ViewProps.ALIGN_SELF) public void setAlignSelf(@Nullable String alignSelf) { setAlignSelf(alignSelf == null ? CSSAlign.AUTO : CSSAlign.valueOf( alignSelf.toUpperCase(Locale.US).replace("-", "_"))); }
@ReactProp(name = ViewProps.ALIGN_ITEMS) public void setAlignItems(@Nullable String alignItems) { setAlignItems( alignItems == null ? CSSAlign.STRETCH : CSSAlign.valueOf( alignItems.toUpperCase(Locale.US).replace("-", "_"))); }
@Test public void testPropertiesResetToDefault() { DisplayMetrics displayMetrics = new DisplayMetrics(); displayMetrics.density = 1.0f; DisplayMetricsHolder.setWindowDisplayMetrics(displayMetrics); LayoutShadowNode reactShadowNode = spy(new LayoutShadowNode()); ReactStylesDiffMap map = buildStyles( "width", 10.0, "height", 10.0, "left", 10.0, "top", 10.0, "flex", 1.0, "padding", 10.0, "marginLeft", 10.0, "borderTopWidth", 10.0, "flexDirection", "row", "alignSelf", "stretch", "alignItems", "center", "justifyContent", "space_between", "position", "absolute"); reactShadowNode.updateProperties(map); verify(reactShadowNode).setStyleWidth(10.f); verify(reactShadowNode).setStyleHeight(10.f); verify(reactShadowNode).setPositionLeft(10.f); verify(reactShadowNode).setPositionTop(10.f); verify(reactShadowNode).setFlex(1.0f); verify(reactShadowNode).setPadding(Spacing.ALL, 10.f); verify(reactShadowNode).setMargin(Spacing.LEFT, 10.f); verify(reactShadowNode).setBorder(Spacing.TOP, 10.f); verify(reactShadowNode).setFlexDirection(CSSFlexDirection.ROW); verify(reactShadowNode).setAlignSelf(CSSAlign.STRETCH); verify(reactShadowNode).setAlignItems(CSSAlign.CENTER); verify(reactShadowNode).setJustifyContent(CSSJustify.SPACE_BETWEEN); verify(reactShadowNode).setPositionType(CSSPositionType.ABSOLUTE); map = buildStyles( "width", null, "height", null, "left", null, "top", null, "flex", null, "padding", null, "marginLeft", null, "borderTopWidth", null, "flexDirection", null, "alignSelf", null, "alignItems", null, "justifyContent", null, "position", null); reset(reactShadowNode); reactShadowNode.updateProperties(map); verify(reactShadowNode).setStyleWidth(CSSConstants.UNDEFINED); verify(reactShadowNode).setStyleHeight(CSSConstants.UNDEFINED); verify(reactShadowNode).setPositionLeft(CSSConstants.UNDEFINED); verify(reactShadowNode).setPositionTop(CSSConstants.UNDEFINED); verify(reactShadowNode).setFlex(0.f); verify(reactShadowNode).setPadding(Spacing.ALL, CSSConstants.UNDEFINED); verify(reactShadowNode).setMargin(Spacing.LEFT, CSSConstants.UNDEFINED); verify(reactShadowNode).setBorder(Spacing.TOP, CSSConstants.UNDEFINED); verify(reactShadowNode).setFlexDirection(CSSFlexDirection.COLUMN); verify(reactShadowNode).setAlignSelf(CSSAlign.AUTO); verify(reactShadowNode).setAlignItems(CSSAlign.STRETCH); verify(reactShadowNode).setJustifyContent(CSSJustify.FLEX_START); verify(reactShadowNode).setPositionType(CSSPositionType.RELATIVE); }
private void parseCssAttribute(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CSSLayout); final int N = a.getIndexCount(); for (int i = 0; i < N; i++) { int attr = a.getIndex(i); switch (attr) { case R.styleable.CSSLayout_direction: setDirection(getEnum(a.getInt(attr, 0), CSSDirection.class)); break; case R.styleable.CSSLayout_flexDirection: setFlexDirection(getEnum(a.getInt(attr, 0), CSSFlexDirection.class)); break; case R.styleable.CSSLayout_justifyContent: setJustifyContent(getEnum(a.getInt(attr, 0), CSSJustify.class)); break; case R.styleable.CSSLayout_alignContent: setAlignContent(getEnum(a.getInt(attr, 0), CSSAlign.class)); break; case R.styleable.CSSLayout_alignItems: setAlignItems(getEnum(a.getInt(attr, 0), CSSAlign.class)); break; case R.styleable.CSSLayout_flexWrap: setFlexWrap(getEnum(a.getInt(attr, 0), CSSWrap.class)); break; case R.styleable.CSSLayout_padding: setPadding(a.getDimension(attr, 0)); break; case R.styleable.CSSLayout_paddingLeft: setPaddingLeft(a.getDimension(attr, 0)); break; case R.styleable.CSSLayout_paddingRight: setPaddingRight(a.getDimension(attr, 0)); break; case R.styleable.CSSLayout_paddingTop: setPaddingTop(a.getDimension(attr, 0)); break; case R.styleable.CSSLayout_paddingBottom: setPaddingBottom(a.getDimension(attr, 0)); break; case R.styleable.CSSLayout_borderWidth: setBorderWidth(a.getDimension(attr, 0)); break; case R.styleable.CSSLayout_borderLeftWidth: setBorderLeftWidth(a.getDimension(attr, 0)); break; case R.styleable.CSSLayout_borderRightWidth: setBorderRightWidth(a.getDimension(attr, 0)); break; case R.styleable.CSSLayout_borderTopWidth: setBorderTopWidth(a.getDimension(attr, 0)); break; case R.styleable.CSSLayout_borderBottomWidth: setBorderBottomWidth(a.getDimension(attr, 0)); break; } } a.recycle(); }
public void setAlignContent(CSSAlign alignContent) { mCSSNode.setAlignContent(alignContent); requestLayoutWhithoutDirty(); }
public void setAlignItems(CSSAlign alignItems) { mCSSNode.setAlignItems(alignItems); requestLayoutWhithoutDirty(); }
public void setAlignContent(CSSAlign alignContent) { if (!valuesEqual(style.alignContent, alignContent)) { style.alignContent = alignContent; dirty(); } }
private void parseCssAttribute(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CSSLayout_LayoutParams); final int N = a.getIndexCount(); for (int i = 0; i < N; i++) { int attr = a.getIndex(i); switch (attr) { //case R.styleable.CSSLayout_LayoutParams_layout_width: // node.setStyleWidth(a.getDimension(attr, 0)); // break; //case R.styleable.CSSLayout_LayoutParams_layout_height: // node.setStyleHeight(a.getDimension(attr, 0)); // break; case R.styleable.CSSLayout_LayoutParams_layout_minWidth: minHeight = a.getDimension(attr, 0); break; case R.styleable.CSSLayout_LayoutParams_layout_minHeight: minHeight = a.getDimension(attr, 0); break; case R.styleable.CSSLayout_LayoutParams_layout_maxWidth: maxWidth = a.getDimension(attr, 0); break; case R.styleable.CSSLayout_LayoutParams_layout_maxHeight: maxHeight = a.getDimension(attr, 0); break; case R.styleable.CSSLayout_LayoutParams_layout_left: left = a.getDimension(attr, 0); break; case R.styleable.CSSLayout_LayoutParams_layout_right: right = a.getDimension(attr, 0); break; case R.styleable.CSSLayout_LayoutParams_layout_top: top = a.getDimension(attr, 0); break; case R.styleable.CSSLayout_LayoutParams_layout_bottom: bottom = a.getDimension(attr, 0); break; case R.styleable.CSSLayout_LayoutParams_layout_margin: margin = a.getDimension(attr, 0); break; case R.styleable.CSSLayout_LayoutParams_layout_marginLeft: marginLeft = a.getDimension(attr, 0); break; case R.styleable.CSSLayout_LayoutParams_layout_marginRight: marginRight = a.getDimension(attr, 0); break; case R.styleable.CSSLayout_LayoutParams_layout_marginTop: marginTop = a.getDimension(attr, 0); break; case R.styleable.CSSLayout_LayoutParams_layout_marginBottom: marginBottom = a.getDimension(attr, 0); break; case R.styleable.CSSLayout_LayoutParams_layout_alignSelf: alignSelf = getEnum(a.getInt(attr, 0), CSSAlign.class); break; case R.styleable.CSSLayout_LayoutParams_layout_flex: flex = a.getFloat(attr, 0); break; case R.styleable.CSSLayout_LayoutParams_layout_position: position = getEnum(a.getInt(attr, 0), CSSPositionType.class); break; } } a.recycle(); }