PM-3349 Changed the "track color" for the Android switch so that the color is different from the "thumb"

This commit is contained in:
Dinis Vieira 2023-12-23 23:09:11 +00:00
parent 5d2fc4530f
commit fa4a2247e3
No known key found for this signature in database
GPG key ID: 9389160FF6C295F3
2 changed files with 28 additions and 5 deletions

View file

@ -2,7 +2,10 @@
using Android.Graphics.Drawables;
using Android.OS;
using AndroidX.Core.Content.Resources;
using AndroidX.Core.Graphics;
using Bit.App.Droid.Utilities;
using Bit.App.Utilities;
using Microsoft.Maui.Platform;
namespace Bit.App.Handlers
{
@ -37,6 +40,31 @@ namespace Bit.App.Handlers
};
handler.PlatformView.ThumbTintList = new ColorStateList(thumbStates, thumbColors);
});
Microsoft.Maui.Handlers.SwitchHandler.Mapper.AppendToMapping(nameof(ISwitch.TrackColor), (handler, mauiSwitch) =>
{
var trackStates = new[]
{
new[] { Android.Resource.Attribute.StateChecked }, // checked
new[] { -Android.Resource.Attribute.StateChecked }, // unchecked
};
var selectedColor = ColorUtils.BlendARGB(ThemeHelpers.SwitchOnColor.ToArgb(), Colors.Black.ToPlatform().ToArgb(), 0.5f);
var unselectedColor = ColorUtils.BlendARGB(ThemeHelpers.SwitchThumbColor.ToArgb(), Colors.Black.ToPlatform().ToArgb(), 0.7f);
if (ThemeManager.UsingLightTheme)
{
selectedColor = ColorUtils.BlendARGB(ThemeHelpers.SwitchOnColor.ToArgb(), Colors.White.ToPlatform().ToArgb(), 0.7f);
unselectedColor = ColorUtils.BlendARGB(ThemeHelpers.SwitchThumbColor.ToArgb(), Colors.Black.ToPlatform().ToArgb(), 0.3f);
}
var trackColors = new int[]
{
selectedColor,
unselectedColor
};
handler.PlatformView.TrackTintList = new ColorStateList(trackStates, trackColors);
});
}
}
}

View file

@ -42,11 +42,6 @@
<Setter Property="Margin"
Value="-4, 0, -4, -4" />
</Style>
<Style TargetType="Switch"
ApplyToDerivedTypes="True">
<Setter Property="OnColor"
Value="{DynamicResource SwitchOnColor}" />
</Style>
<Style TargetType="SearchBar"
ApplyToDerivedTypes="True">
<Setter Property="BackgroundColor"