TabbedRenderer / load icons from custom sources (from embbedded svg for example) (#574)

* Enable ios tab bar icons to be set by a custom renderer (using xamsvg for example)

* Fix space => tabs

* space => tabs / newline

* space / newlines
This commit is contained in:
Softlion (Benjamin Mayrargue) 2017-02-06 12:53:44 +01:00 коммит произвёл Rui Marinho
Родитель bfb5de5676
Коммит c29403ac31
1 изменённых файлов: 24 добавлений и 8 удалений

Просмотреть файл

@ -370,7 +370,8 @@ namespace Xamarin.Forms.Platform.iOS
void UpdateCurrentPage()
{
var count = ((IPageController)Tabbed).InternalChildren.Count;
((TabbedPage)Element).CurrentPage = SelectedIndex >= 0 && SelectedIndex < count ? Tabbed.GetPageByIndex((int)SelectedIndex) : null;
var index = (int)SelectedIndex;
((TabbedPage)Element).CurrentPage = index >= 0 && index < count ? Tabbed.GetPageByIndex(index) : null;
}
void IEffectControlProvider.RegisterEffect(Effect effect)
@ -384,17 +385,32 @@ namespace Xamarin.Forms.Platform.iOS
if(page == null)
throw new InvalidCastException($"{nameof(renderer)} must be a {nameof(Page)} renderer.");
UIImage icon = null;
if (!string.IsNullOrEmpty(page.Icon))
icon = new UIImage(page.Icon);
renderer.ViewController.TabBarItem = new UITabBarItem(page.Title, icon, 0)
var icons = GetIcon(page);
renderer.ViewController.TabBarItem = new UITabBarItem(page.Title, icons?.Item1, icons?.Item2)
{
Tag = Tabbed.Children.IndexOf(page),
AccessibilityIdentifier = page.AutomationId
};
icon?.Dispose();
icons?.Item1?.Dispose();
icons?.Item2?.Dispose();
}
/// <summary>
/// Get the icon for the tab bar item of this page
/// </summary>
/// <returns>
/// A tuple containing as item1: the unselected version of the icon, item2: the selected version of the icon (item2 can be null),
/// or null if no icon should be set.
/// </returns>
protected virtual Tuple<UIImage, UIImage> GetIcon(Page page)
{
if (!string.IsNullOrEmpty(page.Icon))
{
var icon = new UIImage(page.Icon);
return Tuple.Create(icon, (UIImage)null);
}
return null;
}
}
}