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

Commit

Permalink
Fix removed shadow in Thumb setting a custom color
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuarezruiz authored and jfversluis committed Aug 27, 2021
1 parent 64ab1c3 commit 60b82c1
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

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

namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.Switch)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 12150, "[Bug] Switch control not respecting Material Design on Android",
PlatformAffected.Android)]
public class Issue12150 : TestContentPage
{
public Issue12150()
{
}

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

var layout = new StackLayout();

var instructions = new Label
{
Padding = 12,
BackgroundColor = Color.Black,
TextColor = Color.White,
Text = "If each Switch has a shadow on the Thumb, the test has passed."
};

var defaultRadioButton = new Switch
{
HorizontalOptions = LayoutOptions.Center
};

var thumbColorRadioButton = new Switch
{
HorizontalOptions = LayoutOptions.Center,
ThumbColor = Color.White
};

var onColorRadioButton = new Switch
{
HorizontalOptions = LayoutOptions.Center,
OnColor = Color.Red,
ThumbColor = Color.White
};

layout.Children.Add(instructions);
layout.Children.Add(defaultRadioButton);
layout.Children.Add(thumbColorRadioButton);
layout.Children.Add(onColorRadioButton);

Content = layout;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1749,6 +1749,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue13616.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13670.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13684.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12150.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Forms.Platform.Android/AppCompat/SwitchRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void UpdateThumbColor()

if (Element.ThumbColor != Color.Default)
{
Control.ThumbDrawable?.SetColorFilter(Element.ThumbColor, FilterMode.SrcAtop);
Control.ThumbDrawable?.SetColorFilter(Element.ThumbColor, FilterMode.Multiply);
_changedThumbColor = true;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ public static void SetColorFilter(this ADrawable drawable, Color color, FilterMo
public static void SetColorFilter(this ADrawable drawable, AColor color, FilterMode mode)
{
if (Forms.Is29OrNewer)
drawable.SetColorFilter(new BlendModeColorFilter(color, GetFilterMode(mode)));
{
if(mode == FilterMode.Multiply)
#pragma warning disable CS0612 // Type or member is obsolete
drawable.SetColorFilter(new PorterDuffColorFilter(color, GetFilterModePre29(mode)));
#pragma warning restore CS0612 // Type or member is obsolete
else
drawable.SetColorFilter(new BlendModeColorFilter(color, GetFilterMode(mode)));
}
else
#pragma warning disable CS0612 // Type or member is obsolete
#pragma warning disable CS0618 // Type or member is obsolete
Expand Down

0 comments on commit 60b82c1

Please sign in to comment.