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

Commit

Permalink
[Android] Fix issue with BoxView Color and CornerRadius (#12069)
Browse files Browse the repository at this point in the history
* Added repro sample

* Fix the issue

* Fixed build error
  • Loading branch information
jsuarezruiz authored Nov 9, 2023
1 parent 6153378 commit 6293975
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Xamarin.Forms.Internals;
using Xamarin.Forms.CustomAttributes;

#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif

namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.BoxView)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 12061,
"[Bug] [Android] BoxView color is cleared when updating corner radius",
PlatformAffected.Android)]
public class Issue12061 : TestContentPage
{
public Issue12061()
{
}

protected override void Init()
{
Title = "Issue 12061";

var layout = new StackLayout();

var instructions = new Label
{
Padding = 12,
BackgroundColor = Color.Black,
TextColor = Color.White,
Text = "Tap the Button. The BoxView must be updated with ConerRadius but without losing the Color. If the BoxView Color is kept, the test has passed."
};

var boxView = new BoxView
{
CornerRadius = 0,
Color = Color.Red,
HeightRequest = 60
};

var button = new Button
{
Text = "Update CornerRadius"
};

layout.Children.Add(instructions);
layout.Children.Add(boxView);
layout.Children.Add(button);

Content = layout;

button.Clicked += (sender, args) =>
{
boxView.CornerRadius = 12;
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,7 @@
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue11869.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11723.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12061.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11155.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11643.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HeaderFooterShellFlyout.cs" />
Expand Down
6 changes: 1 addition & 5 deletions Xamarin.Forms.Platform.Android/Renderers/BoxRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE

base.OnElementPropertyChanged(sender, e);

if (e.IsOneOf(VisualElement.BackgroundColorProperty, VisualElement.BackgroundProperty, BoxView.ColorProperty))
if (e.IsOneOf(VisualElement.BackgroundColorProperty, VisualElement.BackgroundProperty, BoxView.ColorProperty, BoxView.CornerRadiusProperty))
UpdateBoxView();
else if (e.PropertyName == BoxView.CornerRadiusProperty.PropertyName)
UpdateCornerRadius();
}

protected override void UpdateBackgroundColor()
Expand Down Expand Up @@ -179,8 +177,6 @@ void UpdateCornerRadius()
backgroundGradient.SetCornerRadii(cornerRadii);
}
}

UpdateBackgroundColor();
}
}
}

0 comments on commit 6293975

Please sign in to comment.