From 04a8c623132dc9505158f36fc2b08b1e301dd534 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Wed, 18 Oct 2017 19:29:53 -0700 Subject: [PATCH] Android: Implement margin(Start|End) styles for RN Reviewed By: achen1 Differential Revision: D5907651 fbshipit-source-id: 4df7583483e6f10b5433b9fa9d9345e00ccedd20 --- .../react/uimanager/LayoutShadowNode.java | 67 +++++++++---------- .../facebook/react/uimanager/ViewProps.java | 4 ++ 2 files changed, 36 insertions(+), 35 deletions(-) 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 c3e9e3e4e..559f35848 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java @@ -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()) { 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 101df29f9..2ca7428e8 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewProps.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewProps.java @@ -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,