Android: Implement margin(Start|End) styles for RN
Reviewed By: achen1 Differential Revision: D5907651 fbshipit-source-id: 4df7583483e6f10b5433b9fa9d9345e00ccedd20
This commit is contained in:
parent
1ed08d3c01
commit
04a8c62313
|
@ -551,31 +551,38 @@ public class LayoutShadowNode extends ReactShadowNodeImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactPropGroup(names = {
|
@ReactPropGroup(
|
||||||
|
names = {
|
||||||
ViewProps.MARGIN,
|
ViewProps.MARGIN,
|
||||||
ViewProps.MARGIN_VERTICAL,
|
ViewProps.MARGIN_VERTICAL,
|
||||||
ViewProps.MARGIN_HORIZONTAL,
|
ViewProps.MARGIN_HORIZONTAL,
|
||||||
ViewProps.MARGIN_LEFT,
|
ViewProps.MARGIN_START,
|
||||||
ViewProps.MARGIN_RIGHT,
|
ViewProps.MARGIN_END,
|
||||||
ViewProps.MARGIN_TOP,
|
ViewProps.MARGIN_TOP,
|
||||||
ViewProps.MARGIN_BOTTOM,
|
ViewProps.MARGIN_BOTTOM,
|
||||||
})
|
ViewProps.MARGIN_LEFT,
|
||||||
|
ViewProps.MARGIN_RIGHT,
|
||||||
|
}
|
||||||
|
)
|
||||||
public void setMargins(int index, Dynamic margin) {
|
public void setMargins(int index, Dynamic margin) {
|
||||||
if (isVirtual()) {
|
if (isVirtual()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int spacingType =
|
||||||
|
maybeTransformLeftRightToStartEnd(ViewProps.PADDING_MARGIN_SPACING_TYPES[index]);
|
||||||
|
|
||||||
mTempYogaValue.setFromDynamic(margin);
|
mTempYogaValue.setFromDynamic(margin);
|
||||||
switch (mTempYogaValue.unit) {
|
switch (mTempYogaValue.unit) {
|
||||||
case POINT:
|
case POINT:
|
||||||
case UNDEFINED:
|
case UNDEFINED:
|
||||||
setMargin(ViewProps.PADDING_MARGIN_SPACING_TYPES[index], mTempYogaValue.value);
|
setMargin(spacingType, mTempYogaValue.value);
|
||||||
break;
|
break;
|
||||||
case AUTO:
|
case AUTO:
|
||||||
setMarginAuto(ViewProps.PADDING_MARGIN_SPACING_TYPES[index]);
|
setMarginAuto(spacingType);
|
||||||
break;
|
break;
|
||||||
case PERCENT:
|
case PERCENT:
|
||||||
setMarginPercent(ViewProps.PADDING_MARGIN_SPACING_TYPES[index], mTempYogaValue.value);
|
setMarginPercent(spacingType, mTempYogaValue.value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -600,20 +607,8 @@ public class LayoutShadowNode extends ReactShadowNodeImpl {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int spacingType = ViewProps.PADDING_MARGIN_SPACING_TYPES[index];
|
int spacingType =
|
||||||
|
maybeTransformLeftRightToStartEnd(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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mTempYogaValue.setFromDynamic(padding);
|
mTempYogaValue.setFromDynamic(padding);
|
||||||
switch (mTempYogaValue.unit) {
|
switch (mTempYogaValue.unit) {
|
||||||
|
@ -662,20 +657,7 @@ public class LayoutShadowNode extends ReactShadowNodeImpl {
|
||||||
Spacing.START, Spacing.END, Spacing.LEFT, Spacing.RIGHT, Spacing.TOP, Spacing.BOTTOM
|
Spacing.START, Spacing.END, Spacing.LEFT, Spacing.RIGHT, Spacing.TOP, Spacing.BOTTOM
|
||||||
};
|
};
|
||||||
|
|
||||||
int spacingType = POSITION_SPACING_TYPES[index];
|
int spacingType = maybeTransformLeftRightToStartEnd(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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mTempYogaValue.setFromDynamic(position);
|
mTempYogaValue.setFromDynamic(position);
|
||||||
switch (mTempYogaValue.unit) {
|
switch (mTempYogaValue.unit) {
|
||||||
|
@ -691,6 +673,21 @@ public class LayoutShadowNode extends ReactShadowNodeImpl {
|
||||||
position.recycle();
|
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)
|
@ReactProp(name = ViewProps.POSITION)
|
||||||
public void setPosition(@Nullable String position) {
|
public void setPosition(@Nullable String position) {
|
||||||
if (isVirtual()) {
|
if (isVirtual()) {
|
||||||
|
|
|
@ -47,6 +47,8 @@ public class ViewProps {
|
||||||
public static final String MARGIN_RIGHT = "marginRight";
|
public static final String MARGIN_RIGHT = "marginRight";
|
||||||
public static final String MARGIN_TOP = "marginTop";
|
public static final String MARGIN_TOP = "marginTop";
|
||||||
public static final String MARGIN_BOTTOM = "marginBottom";
|
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 = "padding";
|
||||||
public static final String PADDING_VERTICAL = "paddingVertical";
|
public static final String PADDING_VERTICAL = "paddingVertical";
|
||||||
|
@ -174,6 +176,8 @@ public class ViewProps {
|
||||||
MARGIN_RIGHT,
|
MARGIN_RIGHT,
|
||||||
MARGIN_TOP,
|
MARGIN_TOP,
|
||||||
MARGIN_BOTTOM,
|
MARGIN_BOTTOM,
|
||||||
|
MARGIN_START,
|
||||||
|
MARGIN_END,
|
||||||
|
|
||||||
/* paddings */
|
/* paddings */
|
||||||
PADDING,
|
PADDING,
|
||||||
|
|
Loading…
Reference in New Issue