Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[iOS] Fix extra tab icon appearing in iOS for TabbedPage (was #448) #720

Merged
merged 3 commits into from Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Title="Repro"
ItemsSource="{Binding Tabs}"
x:Class="Xamarin.Forms.Controls.Issues.Bugzilla45284">
<TabbedPage.ItemTemplate>
<DataTemplate>
<ContentPage Title="{Binding Title}" Icon="{Binding Icon}">
<Label>Hello</Label>
</ContentPage>
</DataTemplate>
</TabbedPage.ItemTemplate>
</TabbedPage>
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Xamarin.Forms;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Controls.Issues
{
#if APP
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Bugzilla, 45284, "[iOS10] Extra tab icons display in iOS when binding Title on TabbedPage", PlatformAffected.iOS)]
public partial class Bugzilla45284 : TabbedPage
{
public Bugzilla45284()
{
var model = new Bugzilla45284Model();
InitializeComponent();
BindingContext = model;
model.Change();
}
}

public class Bugzilla45284Model : INotifyPropertyChanged
{
public List<Bugzilla45284TabModel> Tabs => new List<Bugzilla45284TabModel> {
new Bugzilla45284TabModel(),
new Bugzilla45284TabModel(),
new Bugzilla45284TabModel(),
new Bugzilla45284TabModel(),
new Bugzilla45284TabModel(),
new Bugzilla45284TabModel(),
new Bugzilla45284TabModel(),
};

public event PropertyChangedEventHandler PropertyChanged;
public void Change()
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Tabs)));
}
}

public class Bugzilla45284TabModel
{
public string Title { get; set; } = "Title";
public string Icon { get; set; } = "bank.png";
}
#endif
}
Expand Up @@ -484,6 +484,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla35736.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla48158.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla45926.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla45284.xaml.cs">
<DependentUpon>Bugzilla45284.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">
Expand Down Expand Up @@ -593,6 +596,9 @@
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla39378.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla45284.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla27417Xaml.xaml">
Expand Down
12 changes: 12 additions & 0 deletions Xamarin.Forms.Platform.iOS/Forms.cs
Expand Up @@ -26,6 +26,8 @@ public static class Forms

static bool? s_isiOS9OrNewer;

static bool? s_isiOS10OrNewer;

static Forms()
{
if (nevertrue)
Expand All @@ -44,6 +46,16 @@ internal static bool IsiOS9OrNewer
}
}

internal static bool IsiOS10OrNewer
{
get
{
if (!s_isiOS10OrNewer.HasValue)
s_isiOS10OrNewer = UIDevice.CurrentDevice.CheckSystemVersion(10, 0);
return s_isiOS10OrNewer.Value;
}
}

public static void Init()
{
if (IsInitialized)
Expand Down
6 changes: 4 additions & 2 deletions Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs
Expand Up @@ -171,7 +171,9 @@ void HandleFinishedCustomizingViewControllers(object sender, UITabBarCustomizeCh

void OnPagePropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == Page.TitleProperty.PropertyName)
// Setting TabBarItem.Title in iOS 10 causes rendering bugs
// Work around this by creating a new UITabBarItem on each change
if (e.PropertyName == Page.TitleProperty.PropertyName && !Forms.IsiOS10OrNewer)
{
var page = (Page)sender;
var renderer = Platform.GetRenderer(page);
Expand All @@ -181,7 +183,7 @@ void OnPagePropertyChanged(object sender, PropertyChangedEventArgs e)
if (renderer.ViewController.TabBarItem != null)
renderer.ViewController.TabBarItem.Title = page.Title;
}
else if (e.PropertyName == Page.IconProperty.PropertyName)
else if (e.PropertyName == Page.IconProperty.PropertyName || e.PropertyName == Page.TitleProperty.PropertyName && Forms.IsiOS10OrNewer)
{
var page = (Page)sender;

Expand Down