Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

[A] do not draw gradient for empty CornerRadius #3786

Merged
merged 1 commit into from
Sep 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 33 additions & 22 deletions Xamarin.Forms.Platform.Android/Renderers/BoxRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,20 @@ protected override void UpdateBackgroundColor()
if (colorToSet == Color.Default)
colorToSet = Element.BackgroundColor;

if (_backgroundDrawable == null)
_backgroundDrawable = new GradientDrawable();
if (_backgroundDrawable != null) {

if (colorToSet != Color.Default)
_backgroundDrawable.SetColor(colorToSet.ToAndroid());
else
_backgroundDrawable.SetColor(colorToSet.ToAndroid(Color.Transparent));
if (colorToSet != Color.Default)
_backgroundDrawable.SetColor(colorToSet.ToAndroid());
else
_backgroundDrawable.SetColor(colorToSet.ToAndroid(Color.Transparent));

this.SetBackground(_backgroundDrawable);
this.SetBackground(_backgroundDrawable);
}
else {
if (colorToSet == Color.Default)
colorToSet = Element.BackgroundColor;
SetBackgroundColor(colorToSet.ToAndroid(Color.Transparent));
}
}

protected override void Dispose(bool disposing)
Expand Down Expand Up @@ -101,26 +106,32 @@ protected override void Dispose(bool disposing)
void UpdateCornerRadius()
{
var cornerRadius = Element.CornerRadius;
if (cornerRadius == new CornerRadius(0d)) {
_backgroundDrawable?.Dispose();
_backgroundDrawable = null;
}
else {
this.SetBackground(_backgroundDrawable = new GradientDrawable());
if (Background is GradientDrawable backgroundGradient) {
var cornerRadii = new[] {
(float)(cornerRadius.TopLeft),
(float)(cornerRadius.TopLeft),

if (Background is GradientDrawable backgroundGradient)
{
var cornerRadii = new[]
{
(float)(cornerRadius.TopLeft),
(float)(cornerRadius.TopLeft),

(float)(cornerRadius.TopRight),
(float)(cornerRadius.TopRight),
(float)(cornerRadius.TopRight),
(float)(cornerRadius.TopRight),

(float)(cornerRadius.BottomRight),
(float)(cornerRadius.BottomRight),
(float)(cornerRadius.BottomRight),
(float)(cornerRadius.BottomRight),

(float)(cornerRadius.BottomLeft),
(float)(cornerRadius.BottomLeft)
};
(float)(cornerRadius.BottomLeft),
(float)(cornerRadius.BottomLeft)
};

backgroundGradient.SetCornerRadii(cornerRadii);
backgroundGradient.SetCornerRadii(cornerRadii);
}
}

UpdateBackgroundColor();
}
}
}