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

Commit 6293975

Browse files
authored
[Android] Fix issue with BoxView Color and CornerRadius (#12069)
* Added repro sample * Fix the issue * Fixed build error
1 parent 6153378 commit 6293975

File tree

3 files changed

+65
-5
lines changed

3 files changed

+65
-5
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using Xamarin.Forms.Internals;
2+
using Xamarin.Forms.CustomAttributes;
3+
4+
#if UITEST
5+
using Xamarin.UITest;
6+
using NUnit.Framework;
7+
using Xamarin.Forms.Core.UITests;
8+
#endif
9+
10+
namespace Xamarin.Forms.Controls.Issues
11+
{
12+
#if UITEST
13+
[Category(UITestCategories.BoxView)]
14+
#endif
15+
[Preserve(AllMembers = true)]
16+
[Issue(IssueTracker.Github, 12061,
17+
"[Bug] [Android] BoxView color is cleared when updating corner radius",
18+
PlatformAffected.Android)]
19+
public class Issue12061 : TestContentPage
20+
{
21+
public Issue12061()
22+
{
23+
}
24+
25+
protected override void Init()
26+
{
27+
Title = "Issue 12061";
28+
29+
var layout = new StackLayout();
30+
31+
var instructions = new Label
32+
{
33+
Padding = 12,
34+
BackgroundColor = Color.Black,
35+
TextColor = Color.White,
36+
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."
37+
};
38+
39+
var boxView = new BoxView
40+
{
41+
CornerRadius = 0,
42+
Color = Color.Red,
43+
HeightRequest = 60
44+
};
45+
46+
var button = new Button
47+
{
48+
Text = "Update CornerRadius"
49+
};
50+
51+
layout.Children.Add(instructions);
52+
layout.Children.Add(boxView);
53+
layout.Children.Add(button);
54+
55+
Content = layout;
56+
57+
button.Clicked += (sender, args) =>
58+
{
59+
boxView.CornerRadius = 12;
60+
};
61+
}
62+
}
63+
}

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,6 +1732,7 @@
17321732
</Compile>
17331733
<Compile Include="$(MSBuildThisFileDirectory)Issue11869.cs" />
17341734
<Compile Include="$(MSBuildThisFileDirectory)Issue11723.cs" />
1735+
<Compile Include="$(MSBuildThisFileDirectory)Issue12061.cs" />
17351736
<Compile Include="$(MSBuildThisFileDirectory)Issue11155.cs" />
17361737
<Compile Include="$(MSBuildThisFileDirectory)Issue11643.xaml.cs" />
17371738
<Compile Include="$(MSBuildThisFileDirectory)HeaderFooterShellFlyout.cs" />

Xamarin.Forms.Platform.Android/Renderers/BoxRenderer.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE
5252

5353
base.OnElementPropertyChanged(sender, e);
5454

55-
if (e.IsOneOf(VisualElement.BackgroundColorProperty, VisualElement.BackgroundProperty, BoxView.ColorProperty))
55+
if (e.IsOneOf(VisualElement.BackgroundColorProperty, VisualElement.BackgroundProperty, BoxView.ColorProperty, BoxView.CornerRadiusProperty))
5656
UpdateBoxView();
57-
else if (e.PropertyName == BoxView.CornerRadiusProperty.PropertyName)
58-
UpdateCornerRadius();
5957
}
6058

6159
protected override void UpdateBackgroundColor()
@@ -179,8 +177,6 @@ void UpdateCornerRadius()
179177
backgroundGradient.SetCornerRadii(cornerRadii);
180178
}
181179
}
182-
183-
UpdateBackgroundColor();
184180
}
185181
}
186182
}

0 commit comments

Comments
 (0)