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:
parent
7ed7593b2b
commit
0f467a25ed
|
@ -118,6 +118,9 @@ public class ViewProps {
|
||||||
public static final String BORDER_RIGHT_COLOR = "borderRightColor";
|
public static final String BORDER_RIGHT_COLOR = "borderRightColor";
|
||||||
public static final String BORDER_TOP_COLOR = "borderTopColor";
|
public static final String BORDER_TOP_COLOR = "borderTopColor";
|
||||||
public static final String BORDER_BOTTOM_COLOR = "borderBottomColor";
|
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 = {
|
public static final int[] BORDER_SPACING_TYPES = {
|
||||||
Spacing.ALL,
|
Spacing.ALL,
|
||||||
Spacing.START,
|
Spacing.START,
|
||||||
|
|
|
@ -841,6 +841,8 @@ public class ReactViewBackgroundDrawable extends Drawable {
|
||||||
final boolean isRTL = getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
|
final boolean isRTL = getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
|
||||||
int borderStart = getBorderWidth(Spacing.START);
|
int borderStart = getBorderWidth(Spacing.START);
|
||||||
int borderEnd = getBorderWidth(Spacing.END);
|
int borderEnd = getBorderWidth(Spacing.END);
|
||||||
|
int colorStart = getBorderColor(Spacing.START);
|
||||||
|
int colorEnd = getBorderColor(Spacing.END);
|
||||||
|
|
||||||
if (I18nUtil.getInstance().doesRTLFlipLeftAndRightStyles(mContext)) {
|
if (I18nUtil.getInstance().doesRTLFlipLeftAndRightStyles(mContext)) {
|
||||||
if (borderStart < 0) {
|
if (borderStart < 0) {
|
||||||
|
@ -851,14 +853,34 @@ public class ReactViewBackgroundDrawable extends Drawable {
|
||||||
borderEnd = borderRight;
|
borderEnd = borderRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isBorderColorDefined(Spacing.START)) {
|
||||||
|
colorStart = colorLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isBorderColorDefined(Spacing.END)) {
|
||||||
|
colorEnd = colorRight;
|
||||||
|
}
|
||||||
|
|
||||||
final int directionAwareBorderLeft = isRTL ? borderEnd : borderStart;
|
final int directionAwareBorderLeft = isRTL ? borderEnd : borderStart;
|
||||||
final int directionAwareBorderRight = isRTL ? borderStart : borderEnd;
|
final int directionAwareBorderRight = isRTL ? borderStart : borderEnd;
|
||||||
|
|
||||||
|
final int directionAwareColorLeft = isRTL ? colorEnd : colorStart;
|
||||||
|
final int directionAwareColorRight = isRTL ? colorStart : colorEnd;
|
||||||
|
|
||||||
borderLeft = directionAwareBorderLeft;
|
borderLeft = directionAwareBorderLeft;
|
||||||
borderRight = directionAwareBorderRight;
|
borderRight = directionAwareBorderRight;
|
||||||
|
colorLeft = directionAwareColorLeft;
|
||||||
|
colorRight = directionAwareColorRight;
|
||||||
} else {
|
} else {
|
||||||
final int directionAwareBorderLeft = isRTL ? borderEnd : borderStart;
|
final int directionAwareBorderLeft = isRTL ? borderEnd : borderStart;
|
||||||
final int directionAwareBorderRight = isRTL ? borderStart : borderEnd;
|
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) {
|
if (directionAwareBorderLeft >= 0) {
|
||||||
borderLeft = directionAwareBorderLeft;
|
borderLeft = directionAwareBorderLeft;
|
||||||
|
@ -867,6 +889,14 @@ public class ReactViewBackgroundDrawable extends Drawable {
|
||||||
if (directionAwareBorderRight >= 0) {
|
if (directionAwareBorderRight >= 0) {
|
||||||
borderRight = directionAwareBorderRight;
|
borderRight = directionAwareBorderRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isDirectionAwareColorLeftDefined) {
|
||||||
|
colorLeft = directionAwareColorLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDirectionAwareColorRightDefined) {
|
||||||
|
colorRight = directionAwareColorRight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1022,6 +1052,12 @@ public class ReactViewBackgroundDrawable extends Drawable {
|
||||||
return rgbComponent | alphaComponent;
|
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) {
|
private int getBorderColor(int position) {
|
||||||
float rgb = mBorderRGB != null ? mBorderRGB.get(position) : DEFAULT_BORDER_RGB;
|
float rgb = mBorderRGB != null ? mBorderRGB.get(position) : DEFAULT_BORDER_RGB;
|
||||||
float alpha = mBorderAlpha != null ? mBorderAlpha.get(position) : DEFAULT_BORDER_ALPHA;
|
float alpha = mBorderAlpha != null ? mBorderAlpha.get(position) : DEFAULT_BORDER_ALPHA;
|
||||||
|
|
|
@ -158,7 +158,9 @@ public class ReactViewManager extends ViewGroupManager<ReactViewGroup> {
|
||||||
ViewProps.BORDER_LEFT_COLOR,
|
ViewProps.BORDER_LEFT_COLOR,
|
||||||
ViewProps.BORDER_RIGHT_COLOR,
|
ViewProps.BORDER_RIGHT_COLOR,
|
||||||
ViewProps.BORDER_TOP_COLOR,
|
ViewProps.BORDER_TOP_COLOR,
|
||||||
ViewProps.BORDER_BOTTOM_COLOR
|
ViewProps.BORDER_BOTTOM_COLOR,
|
||||||
|
ViewProps.BORDER_START_COLOR,
|
||||||
|
ViewProps.BORDER_END_COLOR
|
||||||
},
|
},
|
||||||
customType = "Color"
|
customType = "Color"
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue