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 873c7d09f..788f85df2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java @@ -5,6 +5,7 @@ package com.facebook.react.uimanager; import com.facebook.react.bridge.Dynamic; import com.facebook.react.bridge.JSApplicationIllegalArgumentException; import com.facebook.react.bridge.ReadableType; +import com.facebook.react.modules.i18nmanager.I18nUtil; import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.react.uimanager.annotations.ReactPropGroup; import com.facebook.yoga.YogaAlign; @@ -623,25 +624,48 @@ public class LayoutShadowNode extends ReactShadowNodeImpl { setBorder(ViewProps.BORDER_SPACING_TYPES[index], PixelUtil.toPixelFromDIP(borderWidth)); } - @ReactPropGroup(names = { + @ReactPropGroup( + names = { + ViewProps.START, + ViewProps.END, ViewProps.LEFT, ViewProps.RIGHT, ViewProps.TOP, ViewProps.BOTTOM, - }) + } + ) public void setPositionValues(int index, Dynamic position) { if (isVirtual()) { return; } + final int[] POSITION_SPACING_TYPES = { + 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; + } + } + mTempYogaValue.setFromDynamic(position); switch (mTempYogaValue.unit) { case POINT: case UNDEFINED: - setPosition(ViewProps.POSITION_SPACING_TYPES[index], mTempYogaValue.value); + setPosition(spacingType, mTempYogaValue.value); break; case PERCENT: - setPositionPercent(ViewProps.POSITION_SPACING_TYPES[index], mTempYogaValue.value); + setPositionPercent(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 9ddcb416e..97075e8c5 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewProps.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewProps.java @@ -60,6 +60,8 @@ public class ViewProps { public static final String RIGHT = "right"; public static final String TOP = "top"; public static final String WIDTH = "width"; + public static final String START = "start"; + public static final String END = "end"; public static final String MIN_WIDTH = "minWidth"; public static final String MAX_WIDTH = "maxWidth"; @@ -118,57 +120,60 @@ public class ViewProps { Spacing.BOTTOM }; public static final int[] POSITION_SPACING_TYPES = { - Spacing.START, Spacing.END, Spacing.TOP, Spacing.BOTTOM + Spacing.START, Spacing.END, Spacing.TOP, Spacing.BOTTOM }; - private static final HashSet LAYOUT_ONLY_PROPS = new HashSet<>( - Arrays.asList( - ALIGN_SELF, - ALIGN_ITEMS, - COLLAPSABLE, - FLEX, - FLEX_BASIS, - FLEX_DIRECTION, - FLEX_GROW, - FLEX_SHRINK, - FLEX_WRAP, - JUSTIFY_CONTENT, - OVERFLOW, - ALIGN_CONTENT, - DISPLAY, + private static final HashSet LAYOUT_ONLY_PROPS = + new HashSet<>( + Arrays.asList( + ALIGN_SELF, + ALIGN_ITEMS, + COLLAPSABLE, + FLEX, + FLEX_BASIS, + FLEX_DIRECTION, + FLEX_GROW, + FLEX_SHRINK, + FLEX_WRAP, + JUSTIFY_CONTENT, + OVERFLOW, + ALIGN_CONTENT, + DISPLAY, - /* position */ - POSITION, - RIGHT, - TOP, - BOTTOM, - LEFT, + /* position */ + POSITION, + RIGHT, + TOP, + BOTTOM, + LEFT, + START, + END, - /* dimensions */ - WIDTH, - HEIGHT, - MIN_WIDTH, - MAX_WIDTH, - MIN_HEIGHT, - MAX_HEIGHT, + /* dimensions */ + WIDTH, + HEIGHT, + MIN_WIDTH, + MAX_WIDTH, + MIN_HEIGHT, + MAX_HEIGHT, - /* margins */ - MARGIN, - MARGIN_VERTICAL, - MARGIN_HORIZONTAL, - MARGIN_LEFT, - MARGIN_RIGHT, - MARGIN_TOP, - MARGIN_BOTTOM, + /* margins */ + MARGIN, + MARGIN_VERTICAL, + MARGIN_HORIZONTAL, + MARGIN_LEFT, + MARGIN_RIGHT, + MARGIN_TOP, + MARGIN_BOTTOM, - /* paddings */ - PADDING, - PADDING_VERTICAL, - PADDING_HORIZONTAL, - PADDING_LEFT, - PADDING_RIGHT, - PADDING_TOP, - PADDING_BOTTOM)); + /* paddings */ + PADDING, + PADDING_VERTICAL, + PADDING_HORIZONTAL, + PADDING_LEFT, + PADDING_RIGHT, + PADDING_TOP, + PADDING_BOTTOM)); public static boolean sIsOptimizationsEnabled;