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

[Android] Fix shadow in Thumb setting a custom color #13166

Merged
merged 1 commit into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
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
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