Permalink
Browse files

Android: Implement border(Start|End)Color for RN non-rounded borders

Reviewed By: achen1

Differential Revision: D5921865

fbshipit-source-id: ed964291cba0c701de677c24c54f885cda78e7cc
  • Loading branch information...
RSNara authored and facebook-github-bot committed Oct 19, 2017
1 parent 7ed7593 commit 0f467a25ed97e0bbf932cd94c527f42d7877dfea
@@ -118,6 +118,9 @@
public static final String BORDER_RIGHT_COLOR = "borderRightColor";
public static final String BORDER_TOP_COLOR = "borderTopColor";
public static final String BORDER_BOTTOM_COLOR = "borderBottomColor";
public static final String BORDER_START_COLOR = "borderStartColor";
public static final String BORDER_END_COLOR = "borderEndColor";
public static final int[] BORDER_SPACING_TYPES = {
Spacing.ALL,
Spacing.START,
@@ -841,6 +841,8 @@ private void drawRectangularBackgroundWithBorders(Canvas canvas) {
final boolean isRTL = getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
int borderStart = getBorderWidth(Spacing.START);
int borderEnd = getBorderWidth(Spacing.END);
int colorStart = getBorderColor(Spacing.START);
int colorEnd = getBorderColor(Spacing.END);
if (I18nUtil.getInstance().doesRTLFlipLeftAndRightStyles(mContext)) {
if (borderStart < 0) {
@@ -851,14 +853,34 @@ private void drawRectangularBackgroundWithBorders(Canvas canvas) {
borderEnd = borderRight;
}
if (!isBorderColorDefined(Spacing.START)) {
colorStart = colorLeft;
}
if (!isBorderColorDefined(Spacing.END)) {
colorEnd = colorRight;
}
final int directionAwareBorderLeft = isRTL ? borderEnd : borderStart;
final int directionAwareBorderRight = isRTL ? borderStart : borderEnd;
final int directionAwareColorLeft = isRTL ? colorEnd : colorStart;
final int directionAwareColorRight = isRTL ? colorStart : colorEnd;
borderLeft = directionAwareBorderLeft;
borderRight = directionAwareBorderRight;
colorLeft = directionAwareColorLeft;
colorRight = directionAwareColorRight;
} else {
final int directionAwareBorderLeft = isRTL ? borderEnd : borderStart;
final int directionAwareBorderRight = isRTL ? borderStart : borderEnd;
final int directionAwareColorLeft = isRTL ? colorEnd : colorStart;
final int directionAwareColorRight = isRTL ? colorStart : colorEnd;
final boolean isColorStartDefined = isBorderColorDefined(Spacing.START);
final boolean isColorEndDefined = isBorderColorDefined(Spacing.END);
final boolean isDirectionAwareColorLeftDefined = isRTL ? isColorEndDefined : isColorStartDefined;
final boolean isDirectionAwareColorRightDefined = isRTL ? isColorStartDefined : isColorEndDefined;
if (directionAwareBorderLeft >= 0) {
borderLeft = directionAwareBorderLeft;
@@ -867,6 +889,14 @@ private void drawRectangularBackgroundWithBorders(Canvas canvas) {
if (directionAwareBorderRight >= 0) {
borderRight = directionAwareBorderRight;
}
if (isDirectionAwareColorLeftDefined) {
colorLeft = directionAwareColorLeft;
}
if (isDirectionAwareColorRightDefined) {
colorRight = directionAwareColorRight;
}
}
}
@@ -1022,6 +1052,12 @@ private static int colorFromAlphaAndRGBComponents(float alpha, float rgb) {
return rgbComponent | alphaComponent;
}
private boolean isBorderColorDefined(int position) {
final float rgb = mBorderRGB != null ? mBorderRGB.get(position) : YogaConstants.UNDEFINED;
final float alpha = mBorderAlpha != null ? mBorderAlpha.get(position) : YogaConstants.UNDEFINED;
return !YogaConstants.isUndefined(rgb) && !YogaConstants.isUndefined(alpha);
}
private int getBorderColor(int position) {
float rgb = mBorderRGB != null ? mBorderRGB.get(position) : DEFAULT_BORDER_RGB;
float alpha = mBorderAlpha != null ? mBorderAlpha.get(position) : DEFAULT_BORDER_ALPHA;
@@ -158,7 +158,9 @@ public void setBorderWidth(ReactViewGroup view, int index, float width) {
ViewProps.BORDER_LEFT_COLOR,
ViewProps.BORDER_RIGHT_COLOR,
ViewProps.BORDER_TOP_COLOR,
ViewProps.BORDER_BOTTOM_COLOR
ViewProps.BORDER_BOTTOM_COLOR,
ViewProps.BORDER_START_COLOR,
ViewProps.BORDER_END_COLOR
},
customType = "Color"
)

0 comments on commit 0f467a2

Please sign in to comment.