diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSNode.java b/ReactAndroid/src/main/java/com/facebook/csslayout/CSSNode.java index 3bdcba338..a06639aec 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSNode.java +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/CSSNode.java @@ -378,11 +378,11 @@ public class CSSNode { /** * Get this node's position, as defined by style. */ - public Spacing getPosition() { + public Spacing getPositionValue() { return style.position; } - public void setPosition(int spacingType, float position) { + public void setPositionValue(int spacingType, float position) { if (style.position.set(spacingType, position)) { dirty(); } @@ -396,9 +396,7 @@ public class CSSNode { } public void setPositionTop(float positionTop) { - if (style.position.set(TOP, positionTop)) { - dirty(); - } + setPositionValue(TOP, positionTop); } /** @@ -409,9 +407,7 @@ public class CSSNode { } public void setPositionBottom(float positionBottom) { - if (style.position.set(BOTTOM, positionBottom)) { - dirty(); - } + setPositionValue(BOTTOM, positionBottom); } /** @@ -422,9 +418,7 @@ public class CSSNode { } public void setPositionLeft(float positionLeft) { - if (style.position.set(LEFT, positionLeft)) { - dirty(); - } + setPositionValue(LEFT, positionLeft); } /** @@ -435,9 +429,7 @@ public class CSSNode { } public void setPositionRight(float positionRight) { - if (style.position.set(RIGHT, positionRight)) { - dirty(); - } + setPositionValue(RIGHT, positionRight); } /** diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java index a4e021132..6b48667a2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java @@ -51,26 +51,6 @@ public class LayoutShadowNode extends ReactShadowNode { setStyleMaxHeight(CSSConstants.isUndefined(maxHeight) ? maxHeight : PixelUtil.toPixelFromDIP(maxHeight)); } - @ReactProp(name = ViewProps.LEFT, defaultFloat = CSSConstants.UNDEFINED) - public void setLeft(float left) { - setPositionLeft(CSSConstants.isUndefined(left) ? left : PixelUtil.toPixelFromDIP(left)); - } - - @ReactProp(name = ViewProps.TOP, defaultFloat = CSSConstants.UNDEFINED) - public void setTop(float top) { - setPositionTop(CSSConstants.isUndefined(top) ? top : PixelUtil.toPixelFromDIP(top)); - } - - @ReactProp(name = ViewProps.BOTTOM, defaultFloat = CSSConstants.UNDEFINED) - public void setBottom(float bottom) { - setPositionBottom(CSSConstants.isUndefined(bottom) ? bottom : PixelUtil.toPixelFromDIP(bottom)); - } - - @ReactProp(name = ViewProps.RIGHT, defaultFloat = CSSConstants.UNDEFINED) - public void setRight(float right) { - setPositionRight(CSSConstants.isUndefined(right) ? right : PixelUtil.toPixelFromDIP(right)); - } - @ReactProp(name = ViewProps.FLEX, defaultFloat = 0f) public void setFlex(float flex) { super.setFlex(flex); @@ -146,6 +126,19 @@ public class LayoutShadowNode extends ReactShadowNode { setBorder(ViewProps.BORDER_SPACING_TYPES[index], PixelUtil.toPixelFromDIP(borderWidth)); } + @ReactPropGroup(names = { + ViewProps.LEFT, + ViewProps.RIGHT, + ViewProps.TOP, + ViewProps.BOTTOM, + }, defaultFloat = CSSConstants.UNDEFINED) + public void setPositionValues(int index, float position) { + setPositionValue( + ViewProps.POSITION_SPACING_TYPES[index], + CSSConstants.isUndefined(position) ? position : PixelUtil.toPixelFromDIP(position) + ); + } + @ReactProp(name = ViewProps.POSITION) public void setPosition(@Nullable String position) { CSSPositionType positionType = position == null ? diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewProps.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewProps.java index 6f1be09e8..c344e0fd7 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewProps.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewProps.java @@ -90,12 +90,15 @@ public class ViewProps { public static final String BORDER_BOTTOM_LEFT_RADIUS = "borderBottomLeftRadius"; public static final String BORDER_BOTTOM_RIGHT_RADIUS = "borderBottomRightRadius"; public static final int[] BORDER_SPACING_TYPES = { - Spacing.ALL, Spacing.LEFT, Spacing.RIGHT, Spacing.TOP, Spacing.BOTTOM + Spacing.ALL, Spacing.START, Spacing.END, Spacing.TOP, Spacing.BOTTOM }; public static final int[] PADDING_MARGIN_SPACING_TYPES = { - Spacing.ALL, Spacing.VERTICAL, Spacing.HORIZONTAL, Spacing.LEFT, Spacing.RIGHT, Spacing.TOP, + Spacing.ALL, Spacing.VERTICAL, Spacing.HORIZONTAL, Spacing.START, Spacing.END, Spacing.TOP, Spacing.BOTTOM }; + public static final int[] POSITION_SPACING_TYPES = { + Spacing.START, Spacing.END, Spacing.TOP, Spacing.BOTTOM + }; private static final HashSet LAYOUT_ONLY_PROPS = new HashSet<>( Arrays.asList( diff --git a/ReactAndroid/src/test/java/com/facebook/react/uimanager/LayoutPropertyApplicatorTest.java b/ReactAndroid/src/test/java/com/facebook/react/uimanager/LayoutPropertyApplicatorTest.java index f1944ec12..453e0943c 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/uimanager/LayoutPropertyApplicatorTest.java +++ b/ReactAndroid/src/test/java/com/facebook/react/uimanager/LayoutPropertyApplicatorTest.java @@ -83,9 +83,9 @@ public class LayoutPropertyApplicatorTest { verify(map).getFloat(eq("width"), anyFloat()); verify(reactShadowNode).setStyleHeight(anyFloat()); verify(map).getFloat(eq("height"), anyFloat()); - verify(reactShadowNode).setPositionLeft(anyFloat()); + verify(reactShadowNode).setPositionValue(eq(Spacing.START), anyFloat()); verify(map).getFloat(eq("left"), anyFloat()); - verify(reactShadowNode).setPositionTop(anyFloat()); + verify(reactShadowNode).setPositionValue(eq(Spacing.TOP), anyFloat()); verify(map).getFloat(eq("top"), anyFloat()); reactShadowNode = spy(new LayoutShadowNode()); @@ -96,9 +96,9 @@ public class LayoutPropertyApplicatorTest { verify(map, never()).getFloat(eq("width"), anyFloat()); verify(reactShadowNode, never()).setStyleHeight(anyFloat()); verify(map, never()).getFloat(eq("height"), anyFloat()); - verify(reactShadowNode, never()).setPositionLeft(anyFloat()); + verify(reactShadowNode, never()).setPositionValue(eq(Spacing.START), anyFloat()); verify(map, never()).getFloat(eq("left"), anyFloat()); - verify(reactShadowNode, never()).setPositionTop(anyFloat()); + verify(reactShadowNode, never()).setPositionValue(eq(Spacing.TOP), anyFloat()); verify(map, never()).getFloat(eq("top"), anyFloat()); } @@ -128,8 +128,8 @@ public class LayoutPropertyApplicatorTest { "right", 5.0)); reactShadowNode.updateProperties(map); - verify(reactShadowNode).setPositionBottom(anyFloat()); - verify(reactShadowNode).setPositionRight(anyFloat()); + verify(reactShadowNode).setPositionValue(eq(Spacing.BOTTOM), anyFloat()); + verify(reactShadowNode).setPositionValue(eq(Spacing.END), anyFloat()); verify(reactShadowNode).setPositionType(any(CSSPositionType.class)); verify(map).getFloat("bottom", Float.NaN); verify(map).getFloat("right", Float.NaN); @@ -138,8 +138,8 @@ public class LayoutPropertyApplicatorTest { map = spy(buildStyles()); reactShadowNode.updateProperties(map); - verify(reactShadowNode, never()).setPositionBottom(anyFloat()); - verify(reactShadowNode, never()).setPositionRight(anyFloat()); + verify(reactShadowNode, never()).setPositionValue(eq(Spacing.BOTTOM), anyFloat()); + verify(reactShadowNode, never()).setPositionValue(eq(Spacing.END), anyFloat()); verify(reactShadowNode, never()).setPositionType(any(CSSPositionType.class)); verify(map, never()).getFloat("bottom", Float.NaN); verify(map, never()).getFloat("right", Float.NaN); @@ -192,7 +192,7 @@ public class LayoutPropertyApplicatorTest { map = spy(buildStyles("marginLeft", 10.0)); reactShadowNode.updateProperties(map); - verify(reactShadowNode).setMargin(eq(Spacing.LEFT), anyFloat()); + verify(reactShadowNode).setMargin(eq(Spacing.START), anyFloat()); verify(map).getFloat("marginLeft", CSSConstants.UNDEFINED); // marginRight @@ -200,7 +200,7 @@ public class LayoutPropertyApplicatorTest { map = spy(buildStyles("marginRight", 10.0)); reactShadowNode.updateProperties(map); - verify(reactShadowNode).setMargin(eq(Spacing.RIGHT), anyFloat()); + verify(reactShadowNode).setMargin(eq(Spacing.END), anyFloat()); verify(map).getFloat("marginRight", CSSConstants.UNDEFINED); // no margin @@ -259,7 +259,7 @@ public class LayoutPropertyApplicatorTest { map = spy(buildStyles("paddingLeft", 10.0)); reactShadowNode.updateProperties(map); - verify(reactShadowNode).setPadding(eq(Spacing.LEFT), anyFloat()); + verify(reactShadowNode).setPadding(eq(Spacing.START), anyFloat()); verify(map).getFloat("paddingLeft", CSSConstants.UNDEFINED); // paddingRight @@ -267,7 +267,7 @@ public class LayoutPropertyApplicatorTest { map = spy(buildStyles("paddingRight", 10.0)); reactShadowNode.updateProperties(map); - verify(reactShadowNode).setPadding(eq(Spacing.RIGHT), anyFloat()); + verify(reactShadowNode).setPadding(eq(Spacing.END), anyFloat()); verify(map).getFloat("paddingRight", CSSConstants.UNDEFINED); // no padding @@ -332,11 +332,11 @@ public class LayoutPropertyApplicatorTest { 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).setPositionValue(Spacing.START, 10.f); + verify(reactShadowNode).setPositionValue(Spacing.TOP, 10.f); verify(reactShadowNode).setFlex(1.0f); verify(reactShadowNode).setPadding(Spacing.ALL, 10.f); - verify(reactShadowNode).setMargin(Spacing.LEFT, 10.f); + verify(reactShadowNode).setMargin(Spacing.START, 10.f); verify(reactShadowNode).setBorder(Spacing.TOP, 10.f); verify(reactShadowNode).setFlexDirection(CSSFlexDirection.ROW); verify(reactShadowNode).setAlignSelf(CSSAlign.STRETCH); @@ -363,11 +363,11 @@ public class LayoutPropertyApplicatorTest { 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).setPositionValue(Spacing.START, CSSConstants.UNDEFINED); + verify(reactShadowNode).setPositionValue(Spacing.TOP, CSSConstants.UNDEFINED); verify(reactShadowNode).setFlex(0.f); verify(reactShadowNode).setPadding(Spacing.ALL, CSSConstants.UNDEFINED); - verify(reactShadowNode).setMargin(Spacing.LEFT, CSSConstants.UNDEFINED); + verify(reactShadowNode).setMargin(Spacing.START, CSSConstants.UNDEFINED); verify(reactShadowNode).setBorder(Spacing.TOP, CSSConstants.UNDEFINED); verify(reactShadowNode).setFlexDirection(CSSFlexDirection.COLUMN); verify(reactShadowNode).setAlignSelf(CSSAlign.AUTO); @@ -391,9 +391,9 @@ public class LayoutPropertyApplicatorTest { LayoutShadowNode[] nodes = new LayoutShadowNode[7]; for (int idx = 0; idx < nodes.length; idx++) { nodes[idx] = new LayoutShadowNode(); - nodes[idx].setDefaultPadding(Spacing.LEFT, 15); + nodes[idx].setDefaultPadding(Spacing.START, 15); nodes[idx].setDefaultPadding(Spacing.TOP, 25); - nodes[idx].setDefaultPadding(Spacing.RIGHT, 35); + nodes[idx].setDefaultPadding(Spacing.END, 35); nodes[idx].setDefaultPadding(Spacing.BOTTOM, 45); } @@ -413,39 +413,39 @@ public class LayoutPropertyApplicatorTest { nodes[idx].updateProperties(mapNodes[idx]); } - assertEquals(10.0, nodes[0].getPadding().get(Spacing.LEFT), .0001); + assertEquals(10.0, nodes[0].getPadding().get(Spacing.START), .0001); assertEquals(25.0, nodes[0].getPadding().get(Spacing.TOP), .0001); - assertEquals(5.0, nodes[0].getPadding().get(Spacing.RIGHT), .0001); + assertEquals(5.0, nodes[0].getPadding().get(Spacing.END), .0001); assertEquals(45.0, nodes[0].getPadding().get(Spacing.BOTTOM), .0001); - assertEquals(10.0, nodes[1].getPadding().get(Spacing.LEFT), .0001); + assertEquals(10.0, nodes[1].getPadding().get(Spacing.START), .0001); assertEquals(5.0, nodes[1].getPadding().get(Spacing.TOP), .0001); - assertEquals(10.0, nodes[1].getPadding().get(Spacing.RIGHT), .0001); + assertEquals(10.0, nodes[1].getPadding().get(Spacing.END), .0001); assertEquals(10.0, nodes[1].getPadding().get(Spacing.BOTTOM), .0001); - assertEquals(10.0, nodes[2].getPadding().get(Spacing.LEFT), .0001); + assertEquals(10.0, nodes[2].getPadding().get(Spacing.START), .0001); assertEquals(5.0, nodes[2].getPadding().get(Spacing.TOP), .0001); - assertEquals(35.0, nodes[2].getPadding().get(Spacing.RIGHT), .0001); + assertEquals(35.0, nodes[2].getPadding().get(Spacing.END), .0001); assertEquals(5.0, nodes[2].getPadding().get(Spacing.BOTTOM), .0001); - assertEquals(5.0, nodes[3].getPadding().get(Spacing.LEFT), .0001); + assertEquals(5.0, nodes[3].getPadding().get(Spacing.START), .0001); assertEquals(25.0, nodes[3].getPadding().get(Spacing.TOP), .0001); - assertEquals(5.0, nodes[3].getPadding().get(Spacing.RIGHT), .0001); + assertEquals(5.0, nodes[3].getPadding().get(Spacing.END), .0001); assertEquals(10.0, nodes[3].getPadding().get(Spacing.BOTTOM), .0001); - assertEquals(15.0, nodes[4].getPadding().get(Spacing.LEFT), .0001); + assertEquals(15.0, nodes[4].getPadding().get(Spacing.START), .0001); assertEquals(5.0, nodes[4].getPadding().get(Spacing.TOP), .0001); - assertEquals(35.0, nodes[4].getPadding().get(Spacing.RIGHT), .0001); + assertEquals(35.0, nodes[4].getPadding().get(Spacing.END), .0001); assertEquals(45.0, nodes[4].getPadding().get(Spacing.BOTTOM), .0001); - assertEquals(15.0, nodes[5].getPadding().get(Spacing.LEFT), .0001); + assertEquals(15.0, nodes[5].getPadding().get(Spacing.START), .0001); assertEquals(7.0, nodes[5].getPadding().get(Spacing.TOP), .0001); - assertEquals(10.0, nodes[5].getPadding().get(Spacing.RIGHT), .0001); + assertEquals(10.0, nodes[5].getPadding().get(Spacing.END), .0001); assertEquals(7.0, nodes[5].getPadding().get(Spacing.BOTTOM), .0001); - assertEquals(15.0, nodes[6].getPadding().get(Spacing.LEFT), .0001); + assertEquals(15.0, nodes[6].getPadding().get(Spacing.START), .0001); assertEquals(25.0, nodes[6].getPadding().get(Spacing.TOP), .0001); - assertEquals(35.0, nodes[6].getPadding().get(Spacing.RIGHT), .0001); + assertEquals(35.0, nodes[6].getPadding().get(Spacing.END), .0001); assertEquals(45.0, nodes[6].getPadding().get(Spacing.BOTTOM), .0001); } }