From 1ed08d3c011f56f72bb9fa59e24583350108bf5d Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Wed, 18 Oct 2017 19:29:51 -0700 Subject: [PATCH] Android: Implement padding(Start|End) styles for RN Reviewed By: AaaChiuuu Differential Revision: D5907207 fbshipit-source-id: c9bb322f94d701463be35fb1ca92aab80f47d8ab --- .../react/uimanager/LayoutShadowNode.java | 31 +++++++++++++++---- .../facebook/react/uimanager/ViewProps.java | 18 +++++++++-- 2 files changed, 40 insertions(+), 9 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 788f85df2..c3e9e3e4e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java @@ -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; } 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 97075e8c5..101df29f9 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewProps.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewProps.java @@ -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;