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

Reviewed By: AaaChiuuu

Differential Revision: D5907207

fbshipit-source-id: c9bb322f94d701463be35fb1ca92aab80f47d8ab
This commit is contained in:
Ramanpreet Nara 2017-10-18 19:29:51 -07:00 committed by Facebook Github Bot
parent dc92e69867
commit 1ed08d3c01
2 changed files with 40 additions and 9 deletions

View File

@ -582,28 +582,47 @@ public class LayoutShadowNode extends ReactShadowNodeImpl {
margin.recycle();
}
@ReactPropGroup(names = {
@ReactPropGroup(
names = {
ViewProps.PADDING,
ViewProps.PADDING_VERTICAL,
ViewProps.PADDING_HORIZONTAL,
ViewProps.PADDING_LEFT,
ViewProps.PADDING_RIGHT,
ViewProps.PADDING_START,
ViewProps.PADDING_END,
ViewProps.PADDING_TOP,
ViewProps.PADDING_BOTTOM,
})
ViewProps.PADDING_LEFT,
ViewProps.PADDING_RIGHT,
}
)
public void setPaddings(int index, Dynamic padding) {
if (isVirtual()) {
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;
}
}
mTempYogaValue.setFromDynamic(padding);
switch (mTempYogaValue.unit) {
case POINT:
case UNDEFINED:
setPadding(ViewProps.PADDING_MARGIN_SPACING_TYPES[index], mTempYogaValue.value);
setPadding(spacingType, mTempYogaValue.value);
break;
case PERCENT:
setPaddingPercent(ViewProps.PADDING_MARGIN_SPACING_TYPES[index], mTempYogaValue.value);
setPaddingPercent(spacingType, mTempYogaValue.value);
break;
}

View File

@ -55,6 +55,8 @@ public class ViewProps {
public static final String PADDING_RIGHT = "paddingRight";
public static final String PADDING_TOP = "paddingTop";
public static final String PADDING_BOTTOM = "paddingBottom";
public static final String PADDING_START = "paddingStart";
public static final String PADDING_END = "paddingEnd";
public static final String POSITION = "position";
public static final String RIGHT = "right";
@ -116,8 +118,15 @@ public class ViewProps {
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.START, Spacing.END, Spacing.TOP,
Spacing.BOTTOM
Spacing.ALL,
Spacing.VERTICAL,
Spacing.HORIZONTAL,
Spacing.START,
Spacing.END,
Spacing.TOP,
Spacing.BOTTOM,
Spacing.LEFT,
Spacing.RIGHT,
};
public static final int[] POSITION_SPACING_TYPES = {
Spacing.START, Spacing.END, Spacing.TOP, Spacing.BOTTOM
@ -173,7 +182,10 @@ public class ViewProps {
PADDING_LEFT,
PADDING_RIGHT,
PADDING_TOP,
PADDING_BOTTOM));
PADDING_BOTTOM,
PADDING_START,
PADDING_END));
public static boolean sIsOptimizationsEnabled;