diff options
author | adrianknight89 <adrianknight89@outlook.com> | 2016-11-16 14:55:15 -0600 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-11-16 12:55:15 -0800 |
commit | eb243bcea492088f07934409f047d05ecd2aea45 (patch) | |
tree | b718e1e9b26142dd66d3e6998beae9884d94b094 /Xamarin.Forms.Platform.iOS/Renderers | |
parent | 9bf923a3dd893b4629bc0c59acf1e84298e60b2b (diff) | |
download | xamarin-forms-eb243bcea492088f07934409f047d05ecd2aea45.tar.gz xamarin-forms-eb243bcea492088f07934409f047d05ecd2aea45.tar.bz2 xamarin-forms-eb243bcea492088f07934409f047d05ecd2aea45.zip |
Set TabBarItem properly (#530)
Diffstat (limited to 'Xamarin.Forms.Platform.iOS/Renderers')
-rw-r--r-- | Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs index 25527dfb..c6c07370 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs @@ -193,22 +193,12 @@ namespace Xamarin.Forms.Platform.iOS { var page = (Page)sender; - var renderer = Platform.GetRenderer(page); - if (renderer == null) - return; + IVisualElementRenderer renderer = Platform.GetRenderer(page); - if (renderer.ViewController.TabBarItem == null) + if (renderer?.ViewController.TabBarItem == null) return; - UIImage image = null; - if (!string.IsNullOrEmpty(page.Icon)) - image = new UIImage(page.Icon); - - // the new UITabBarItem forces redraw, setting the UITabBarItem.Image does not - renderer.ViewController.TabBarItem = new UITabBarItem(page.Title, image, 0); - - if (image != null) - image.Dispose(); + SetTabBarItem(renderer); } } @@ -292,7 +282,7 @@ namespace Xamarin.Forms.Platform.iOS void SetupPage(Page page, int index) { - var renderer = Platform.GetRenderer(page); + IVisualElementRenderer renderer = Platform.GetRenderer(page); if (renderer == null) { renderer = Platform.CreateRenderer(page); @@ -301,15 +291,7 @@ namespace Xamarin.Forms.Platform.iOS page.PropertyChanged += OnPagePropertyChanged; - UIImage icon = null; - if (page.Icon != null) - icon = new UIImage(page.Icon); - - renderer.ViewController.TabBarItem = new UITabBarItem(page.Title, icon, 0); - if (icon != null) - icon.Dispose(); - - renderer.ViewController.TabBarItem.Tag = index; + SetTabBarItem(renderer); } void TeardownPage(Page page, int index) @@ -418,5 +400,24 @@ namespace Xamarin.Forms.Platform.iOS if (platformEffect != null) platformEffect.Container = View; } + + void SetTabBarItem(IVisualElementRenderer renderer) + { + var page = renderer.Element as Page; + 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) + { + Tag = Tabbed.Children.IndexOf(page), + AccessibilityIdentifier = page.AutomationId + }; + + icon?.Dispose(); + } } }
\ No newline at end of file |