1
0
mirror of https://github.com/bitwarden/mobile synced 2026-02-12 22:33:20 +00:00

WIP Fix toolbar item avatar update issue iOS

This commit is contained in:
Federico Maccaroni
2022-01-21 11:08:12 -03:00
parent d41e1a0bc3
commit a4e599f680
2 changed files with 41 additions and 18 deletions

View File

@@ -103,11 +103,11 @@ namespace Bit.App.Controls
var base16 = "00" + Convert.ToString(value, 16);
color += base16.Substring(base16.Length - 2);
}
if (Device.RuntimePlatform == Device.iOS)
{
// TODO remove this once iOS ToolbarItem tint issue is solved
return Color.FromHex("#33ffffff");
}
//if (Device.RuntimePlatform == Device.iOS)
//{
// // TODO remove this once iOS ToolbarItem tint issue is solved
// return Color.FromHex("#33ffffff");
//}
return Color.FromHex(color);
}
}

View File

@@ -1,6 +1,11 @@
using System.Linq;
using System;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Bit.App.Controls;
using Bit.iOS.Core.Renderers;
using CoreFoundation;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
@@ -30,24 +35,42 @@ namespace Bit.iOS.Core.Renderers
return;
}
foreach (var toolbarItem in toolbarItems)
foreach (var toolbarItem in toolbarItems.Where(t => t is ExtendedToolbarItem eti && eti.UseOriginalImage))
{
if (!(toolbarItem is ExtendedToolbarItem extendedToolbarItem) || !extendedToolbarItem.UseOriginalImage)
{
continue;
}
var index = currentPage.ToolbarItems.IndexOf(extendedToolbarItem) + 1;
var index = currentPage.ToolbarItems.IndexOf(toolbarItem) + 1;
if (index < 0 || index >= uiBarButtonItems.Length)
{
continue;
}
var uiBarButtonItem = uiBarButtonItems[index];
if (uiBarButtonItem.Image == null)
// HACK: XF PimaryToolbarItem is sealed so we can't override it, and also it doesn't provide any
// direct way to replace it with our custom one (we can but we need to rewrite several parts of the NavigationRenderer)
// So I think this is the easiest soolution for now to set UIImageRenderingMode.AlwaysOriginal
// on the toolbar item image
void ToolbarItem_PropertyChanged(object s, PropertyChangedEventArgs e)
{
continue;
}
var originalImage = uiBarButtonItem.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
uiBarButtonItem.Image = originalImage;
if (e.PropertyName == nameof(ExtendedToolbarItem.IconImageSource))
{
var uiBarButtonItems = TopViewController.NavigationItem.RightBarButtonItems;
if (uiBarButtonItems == null)
{
return;
}
var uiBarButtonItem = uiBarButtonItems[index];
Task.Run(async () => {
await Task.Delay(1000);
DispatchQueue.MainQueue.DispatchAsync(() =>
//uiBarButtonItem.Image = UIImage.FromBundle("info"));
uiBarButtonItem.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal));
});
toolbarItem.PropertyChanged -= ToolbarItem_PropertyChanged;
}
};
toolbarItem.PropertyChanged += ToolbarItem_PropertyChanged;
}
}
}