bitwarden-android/src/iOS/Controls/ExtendedTabbedPageRenderer.cs

72 lines
2 KiB
C#
Raw Normal View History

2016-05-10 06:25:37 +03:00
using System;
using Bit.App.Controls;
using Bit.iOS.Controls;
2016-06-14 07:19:18 +03:00
using Foundation;
using UIKit;
2016-05-10 06:25:37 +03:00
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(ExtendedTabbedPage), typeof(ExtendedTabbedPageRenderer))]
namespace Bit.iOS.Controls
{
2016-05-12 00:30:09 +03:00
public class ExtendedTabbedPageRenderer : TabbedRenderer
2016-05-10 06:25:37 +03:00
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
var page = (ExtendedTabbedPage)Element;
TabBar.TintColor = page.TintColor.ToUIColor();
TabBar.BackgroundColor = page.BackgroundColor.ToUIColor();
2016-06-14 07:19:18 +03:00
if(page.NoBorder)
{
// remove top border
// ref: http://stackoverflow.com/questions/14371343/ios-uitabbar-remove-top-shadow-gradient-line
TabBar.SetValueForKeyPath(FromObject(true), new NSString("_hidesShadow"));
}
2016-05-10 06:25:37 +03:00
}
public override void ViewWillAppear(bool animated)
{
if(TabBar?.Items == null)
{
return;
}
var tabs = Element as TabbedPage;
if(tabs != null)
{
for(int i = 0; i < TabBar.Items.Length; i++)
{
UpdateItem(TabBar.Items[i], tabs.Children[i].Icon);
}
}
base.ViewWillAppear(animated);
}
private void UpdateItem(UITabBarItem item, string icon)
{
if(item == null)
{
return;
}
try
{
icon = string.Concat(icon, "_selected");
if(item?.SelectedImage?.AccessibilityIdentifier == icon)
{
return;
}
item.SelectedImage = UIImage.FromBundle(icon);
item.SelectedImage.AccessibilityIdentifier = icon;
}
catch { }
}
2016-05-10 06:25:37 +03:00
}
}