feature: custom dynamic tab icon

This commit is contained in:
2020-05-22 20:11:30 +08:00
parent 9ca58cc814
commit b97e07e1ab
25 changed files with 303 additions and 74 deletions

View File

@ -32,7 +32,7 @@ namespace Pixiview.iOS.Renderers
protected override IShellTabBarAppearanceTracker CreateTabBarAppearanceTracker()
{
return new AppShellTabBarAppearanceTracker();
return new AppShellTabBarAppearanceTracker((AppShell)Element);
}
protected override IShellNavBarAppearanceTracker CreateNavBarAppearanceTracker()

View File

@ -1,4 +1,5 @@
using CoreGraphics;
using System.Linq;
using CoreGraphics;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
@ -99,6 +100,14 @@ namespace Pixiview.iOS.Renderers.AppShellSection
UIColor _defaultTint;
UIColor _defaultUnselectedTint;
private readonly AppShell appShell;
private bool initIcons;
public AppShellTabBarAppearanceTracker(AppShell shell)
{
appShell = shell;
}
public void ResetAppearance(UITabBarController controller)
{
if (_defaultTint == null)
@ -118,6 +127,34 @@ namespace Pixiview.iOS.Renderers.AppShellSection
var tintColor = appearanceElement.EffectiveTabBarForegroundColor; // appearanceElement.EffectiveTabBarTitleColor;
var tabBar = controller.TabBar;
if (tabBar.Items != null && !initIcons)
{
initIcons = true;
var sources = appShell.CurrentItem.Items.Select(i => (FontImageSource)i.Icon).ToArray();
var images = new UIImage[sources.Length];
var handler = new FontImageSourceHandler();
for (var i = 0; i < images.Length; i++)
{
var font = sources[i];
if (font != null)
{
images[i] = handler.LoadImageAsync(new FontImageSource
{
FontFamily = "FontAwesome5Pro-Solid",
Glyph = font.Glyph,
Size = font.Size
}).Result;
}
}
for (var i = 0; i < tabBar.Items.Length; i++)
{
var image = images[i];
if (image != null)
{
tabBar.Items[i].SelectedImage = image;
}
}
}
if (_defaultTint == null)
{