Permalink
Browse files

Android: Implement margin(Start|End) styles for RN

Reviewed By: achen1

Differential Revision: D5907651

fbshipit-source-id: 4df7583483e6f10b5433b9fa9d9345e00ccedd20
  • Loading branch information...
RSNara authored and facebook-github-bot committed Oct 19, 2017
1 parent 1ed08d3 commit 04a8c623132dc9505158f36fc2b08b1e301dd534
@@ -551,31 +551,38 @@ public void setDisplay(@Nullable String display) {
}
}
@ReactPropGroup(names = {
@ReactPropGroup(
names = {
ViewProps.MARGIN,
ViewProps.MARGIN_VERTICAL,
ViewProps.MARGIN_HORIZONTAL,
ViewProps.MARGIN_LEFT,
ViewProps.MARGIN_RIGHT,
ViewProps.MARGIN_START,
ViewProps.MARGIN_END,
ViewProps.MARGIN_TOP,
ViewProps.MARGIN_BOTTOM,
})
ViewProps.MARGIN_LEFT,
ViewProps.MARGIN_RIGHT,
}
)
public void setMargins(int index, Dynamic margin) {
if (isVirtual()) {
return;
}
int spacingType =
maybeTransformLeftRightToStartEnd(ViewProps.PADDING_MARGIN_SPACING_TYPES[index]);
mTempYogaValue.setFromDynamic(margin);
switch (mTempYogaValue.unit) {
case POINT:
case UNDEFINED:
setMargin(ViewProps.PADDING_MARGIN_SPACING_TYPES[index], mTempYogaValue.value);
setMargin(spacingType, mTempYogaValue.value);
break;
case AUTO:
setMarginAuto(ViewProps.PADDING_MARGIN_SPACING_TYPES[index]);
setMarginAuto(spacingType);
break;
case PERCENT:
setMarginPercent(ViewProps.PADDING_MARGIN_SPACING_TYPES[index], mTempYogaValue.value);
setMarginPercent(spacingType, mTempYogaValue.value);
break;
}
@@ -600,20 +607,8 @@ public void setPaddings(int index, Dynamic padding) {
return;
}
int spacingType = ViewProps.PADDING_MARGIN_SPACING_TYPES[index];
if (I18nUtil.getInstance().doesRTLFlipLeftAndRightStyles(getThemedContext())) {
switch (spacingType) {
case Spacing.LEFT:
spacingType = Spacing.START;
break;
case Spacing.RIGHT:
spacingType = Spacing.END;
break;
default:
break;
}
}
int spacingType =
maybeTransformLeftRightToStartEnd(ViewProps.PADDING_MARGIN_SPACING_TYPES[index]);
mTempYogaValue.setFromDynamic(padding);
switch (mTempYogaValue.unit) {
@@ -662,20 +657,7 @@ public void setPositionValues(int index, Dynamic position) {
Spacing.START, Spacing.END, Spacing.LEFT, Spacing.RIGHT, Spacing.TOP, Spacing.BOTTOM
};
int spacingType = POSITION_SPACING_TYPES[index];
if (I18nUtil.getInstance().doesRTLFlipLeftAndRightStyles(getThemedContext())) {
switch (spacingType) {
case Spacing.LEFT:
spacingType = Spacing.START;
break;
case Spacing.RIGHT:
spacingType = Spacing.END;
break;
default:
break;
}
}
int spacingType = maybeTransformLeftRightToStartEnd(POSITION_SPACING_TYPES[index]);
mTempYogaValue.setFromDynamic(position);
switch (mTempYogaValue.unit) {
@@ -691,6 +673,21 @@ public void setPositionValues(int index, Dynamic position) {
position.recycle();
}
private int maybeTransformLeftRightToStartEnd(int spacingType) {
if (!I18nUtil.getInstance().doesRTLFlipLeftAndRightStyles(getThemedContext())) {
return spacingType;
}
switch (spacingType) {
case Spacing.LEFT:
return Spacing.START;
case Spacing.RIGHT:
return Spacing.END;
default:
return spacingType;
}
}
@ReactProp(name = ViewProps.POSITION)
public void setPosition(@Nullable String position) {
if (isVirtual()) {
@@ -47,6 +47,8 @@
public static final String MARGIN_RIGHT = "marginRight";
public static final String MARGIN_TOP = "marginTop";
public static final String MARGIN_BOTTOM = "marginBottom";
public static final String MARGIN_START = "marginStart";
public static final String MARGIN_END = "marginEnd";
public static final String PADDING = "padding";
public static final String PADDING_VERTICAL = "paddingVertical";
@@ -174,6 +176,8 @@
MARGIN_RIGHT,
MARGIN_TOP,
MARGIN_BOTTOM,
MARGIN_START,
MARGIN_END,
/* paddings */
PADDING,

0 comments on commit 04a8c62

Please sign in to comment.