Skip to content

Commit

Permalink
feat(android): add outlined CardView support
Browse files Browse the repository at this point in the history
  • Loading branch information
jquick-axway authored and sgtcoolguy committed Mar 5, 2021
1 parent f4ca456 commit dc3b279
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ public void processProperties(KrollDict d)
cardview.setCardBackgroundColor(TiConvert.toColor(d, TiC.PROPERTY_BACKGROUND_COLOR));
}

if (d.containsKey(TiC.PROPERTY_BORDER_COLOR)) {
cardview.setStrokeColor(TiConvert.toColor(d, TiC.PROPERTY_BORDER_COLOR));
}

if (d.containsKey(TiC.PROPERTY_BORDER_RADIUS)) {
float radius = 0;
TiDimension radiusDim = TiConvert.toTiDimension(d.get(TiC.PROPERTY_BORDER_RADIUS), TiDimension.TYPE_WIDTH);
Expand All @@ -166,6 +170,12 @@ public void processProperties(KrollDict d)
cardview.setRadius(radius);
}

if (d.containsKey(TiC.PROPERTY_BORDER_WIDTH)) {
TiDimension tiDimension =
TiConvert.toTiDimension(TiConvert.toString(d.get(TiC.PROPERTY_BORDER_WIDTH)), TiDimension.TYPE_WIDTH);
cardview.setStrokeWidth(tiDimension.getAsPixels(cardview));
}

if (d.containsKey(TiC.PROPERTY_USE_COMPAT_PADDING)) {
cardview.setUseCompatPadding(TiConvert.toBoolean(d, TiC.PROPERTY_USE_COMPAT_PADDING, false));
}
Expand Down Expand Up @@ -273,6 +283,8 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
if (key.equals(TiC.PROPERTY_BACKGROUND_COLOR)) {
cardview.setCardBackgroundColor(TiConvert.toColor(TiConvert.toString(newValue)));
cardview.requestLayout();
} else if (key.equals(TiC.PROPERTY_BORDER_COLOR)) {
cardview.setStrokeColor(TiConvert.toColor(TiConvert.toString(newValue)));
} else if (key.equals(TiC.PROPERTY_BORDER_RADIUS)) {
float radius = 0;
TiDimension radiusDim = TiConvert.toTiDimension(newValue, TiDimension.TYPE_WIDTH);
Expand All @@ -281,6 +293,9 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
}
cardview.setRadius(radius);
cardview.requestLayout();
} else if (key.equals(TiC.PROPERTY_BORDER_WIDTH)) {
TiDimension tiDimension = TiConvert.toTiDimension(TiConvert.toString(newValue), TiDimension.TYPE_WIDTH);
cardview.setStrokeWidth(tiDimension.getAsPixels(cardview));
} else if (key.equals(TiC.PROPERTY_ELEVATION)) {
cardview.setCardElevation(TiConvert.toFloat(newValue));
cardview.requestLayout();
Expand Down Expand Up @@ -367,6 +382,8 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
@Override
protected boolean hasBorder(KrollDict d)
{
// This prevents "TiUIView" class from handling the border.
// We apply border properties to CardView ourselves via its stroke methods.
return false;
}
}

0 comments on commit dc3b279

Please sign in to comment.