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

Reviewed By: achen1

Differential Revision: D5907651

fbshipit-source-id: 4df7583483e6f10b5433b9fa9d9345e00ccedd20
This commit is contained in:
Ramanpreet Nara 2017-10-18 19:29:53 -07:00 коммит произвёл Facebook Github Bot
Родитель 1ed08d3c01
Коммит 04a8c62313
2 изменённых файлов: 36 добавлений и 35 удалений

Просмотреть файл

@ -551,31 +551,38 @@ public class LayoutShadowNode extends ReactShadowNodeImpl {
}
}
@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 class LayoutShadowNode extends ReactShadowNodeImpl {
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 class LayoutShadowNode extends ReactShadowNodeImpl {
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 class LayoutShadowNode extends ReactShadowNodeImpl {
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 class ViewProps {
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 @@ public class ViewProps {
MARGIN_RIGHT,
MARGIN_TOP,
MARGIN_BOTTOM,
MARGIN_START,
MARGIN_END,
/* paddings */
PADDING,