PM-3349 Fixed white tint color not appearing on images added as MAU IImage SVG

PM-3349 PM-3350 Fix for Avatar text not adjusting to white/black color correctly
This commit is contained in:
Dinis Vieira 2023-10-25 22:20:01 +01:00
parent e7aeb08cae
commit aaf082faba
No known key found for this signature in database
GPG key ID: 9389160FF6C295F3
2 changed files with 9 additions and 6 deletions

View file

@ -219,10 +219,10 @@
<MauiImage Include="Resources\more.svg"> <MauiImage Include="Resources\more.svg">
<BaseSize>24,24</BaseSize> <BaseSize>24,24</BaseSize>
</MauiImage> </MauiImage>
<MauiImage Include="Resources\plus.svg"> <MauiImage Include="Resources\plus.svg" TintColor="#FFFFFFFF">
<BaseSize>24,24</BaseSize> <BaseSize>24,24</BaseSize>
</MauiImage> </MauiImage>
<MauiImage Include="Resources\search.svg"> <MauiImage Include="Resources\search.svg" TintColor="#FFFFFFFF">
<BaseSize>24,24</BaseSize> <BaseSize>24,24</BaseSize>
</MauiImage> </MauiImage>
<MauiImage Include="Resources\send.svg"> <MauiImage Include="Resources\send.svg">

View file

@ -267,14 +267,17 @@ namespace Bit.Core.Utilities
public static string TextColorFromBgColor(string hexColor, int threshold = 166) public static string TextColorFromBgColor(string hexColor, int threshold = 166)
{ {
if (new ColorConverter().ConvertFromString(hexColor) is Color bgColor) var isValidColor = Color.TryParse(hexColor, out var bgColor);
if (isValidColor)
{ {
var luminance = bgColor.Red * 0.299 + bgColor.Green * 0.587 + bgColor.Blue * 0.114; var luminance = (bgColor.Red * 255 * 0.299) + (bgColor.Green * 255 * 0.587) + (bgColor.Blue * 255 * 0.114);
return luminance > threshold ? "#ff000000" : "#ffffffff"; return luminance > threshold ? "#ff000000" : "#ffffffff";
} }
else
{
return "#ff000000"; return "#ff000000";
} }
}
public static string StringToColor(string str, string fallback) public static string StringToColor(string str, string fallback)
{ {