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

Reviewed By: achen1

Differential Revision: D5921865

fbshipit-source-id: ed964291cba0c701de677c24c54f885cda78e7cc
This commit is contained in:
Ramanpreet Nara 2017-10-18 19:29:57 -07:00 committed by Facebook Github Bot
parent 7ed7593b2b
commit 0f467a25ed
3 changed files with 42 additions and 1 deletions

View File

@ -118,6 +118,9 @@ public class ViewProps {
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,

View File

@ -841,6 +841,8 @@ public class ReactViewBackgroundDrawable extends Drawable {
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 @@ public class ReactViewBackgroundDrawable extends Drawable {
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 @@ public class ReactViewBackgroundDrawable extends Drawable {
if (directionAwareBorderRight >= 0) {
borderRight = directionAwareBorderRight;
}
if (isDirectionAwareColorLeftDefined) {
colorLeft = directionAwareColorLeft;
}
if (isDirectionAwareColorRightDefined) {
colorRight = directionAwareColorRight;
}
}
}
@ -1022,6 +1052,12 @@ public class ReactViewBackgroundDrawable extends Drawable {
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;

View File

@ -158,7 +158,9 @@ public class ReactViewManager extends ViewGroupManager<ReactViewGroup> {
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"
)