Skip to content

Commit

Permalink
CustomTab moved to LocalizableTab
Browse files Browse the repository at this point in the history
  • Loading branch information
unchase committed Mar 24, 2020
1 parent a7f9181 commit 708ac60
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 36 deletions.
29 changes: 15 additions & 14 deletions DotNetRu.Clients.UI/AppShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:about="clr-namespace:DotNetRu.Clients.UI.Pages.About;assembly=DotNetRu.Clients.UI"
xmlns:home="clr-namespace:DotNetRu.Clients.UI.Pages.Home;assembly=DotNetRu.Clients.UI"
xmlns:localization="clr-namespace:DotNetRu.Clients.UI.Localization;assembly=DotNetRu.Clients.UI"
xmlns:meetups="clr-namespace:DotNetRu.Clients.UI.Pages.Meetups;assembly=DotNetRu.Clients.UI"
xmlns:speakers="clr-namespace:DotNetRu.Clients.UI.Pages.Speakers;assembly=DotNetRu.Clients.UI" xmlns:ui="clr-namespace:DotNetRu.Clients.UI"
xmlns:speakers="clr-namespace:DotNetRu.Clients.UI.Pages.Speakers;assembly=DotNetRu.Clients.UI"
FlyoutBehavior="Disabled">

<Shell.Resources>
Expand All @@ -24,34 +25,34 @@
</ResourceDictionary>
</Shell.Resources>

<TabBar Route="root">
<ui:CustomTab
x:Name="NewsTab"
<TabBar x:Name="TabBar" Route="root">
<localization:LocalizableTab
Title="{Binding Resources[News]}"
Icon="tab_feed.png"
ResourceName="News"
Route="news">
<ShellContent ContentTemplate="{DataTemplate home:NewsPage}" />
</ui:CustomTab>
<ui:CustomTab
x:Name="SpeakersTab"
</localization:LocalizableTab>
<localization:LocalizableTab
Title="{Binding Resources[Speakers]}"
Icon="tab_speakers.png"
ResourceName="Speakers"
Route="speakers">
<ShellContent ContentTemplate="{DataTemplate speakers:SpeakersPage}" />
</ui:CustomTab>
<ui:CustomTab
x:Name="MeetupsTab"
</localization:LocalizableTab>
<localization:LocalizableTab
Title="{Binding Resources[Meetups]}"
Icon="tab_events.png"
ResourceName="Meetups"
Route="meetups">
<ShellContent ContentTemplate="{DataTemplate meetups:MeetupsPage}" />
</ui:CustomTab>
<ui:CustomTab
x:Name="AboutTab"
</localization:LocalizableTab>
<localization:LocalizableTab
Title="{Binding Resources[About]}"
Icon="tab_about.png"
ResourceName="About"
Route="about">
<ShellContent ContentTemplate="{DataTemplate about:AboutPage}" />
</ui:CustomTab>
</localization:LocalizableTab>
</TabBar>
</Shell>
12 changes: 4 additions & 8 deletions DotNetRu.Clients.UI/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Linq;
using DotNetRu.Clients.Portable.Helpers;
using DotNetRu.Clients.Portable.ViewModel;
using DotNetRu.Clients.UI.Localization;
using DotNetRu.Utils.Helpers;
using Xamarin.Forms;
using Xamarin.Forms.Internals;

namespace DotNetRu.Clients.UI
{
Expand All @@ -26,13 +28,7 @@ public void UpdateTabBarLocalization()
{
Device.BeginInvokeOnMainThread(() =>
{
if (this.BindingContext is ViewModelBase viewModel)
{
this.NewsTab.Title = viewModel.Resources["News"] ?? this.NewsTab.Title;
this.SpeakersTab.Title = viewModel.Resources["Speakers"] ?? this.SpeakersTab.Title;
this.MeetupsTab.Title = viewModel.Resources["Meetups"] ?? this.MeetupsTab.Title;
this.AboutTab.Title = viewModel.Resources["About"] ?? this.AboutTab.Title;
}
this.TabBar.Items.Where(i => i is LocalizableTab).Cast<LocalizableTab>().ForEach(x => x.Update());
});
}
}
Expand Down
14 changes: 0 additions & 14 deletions DotNetRu.Clients.UI/CustomTab.cs

This file was deleted.

31 changes: 31 additions & 0 deletions DotNetRu.Clients.UI/Localization/LocalizableTab.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Threading.Tasks;
using Xamarin.Forms;

namespace DotNetRu.Clients.UI.Localization
{
public class LocalizableTab : Tab
{
private string resourceName;

public string ResourceName
{
get => this.resourceName;
set
{
this.resourceName = value;
this.Update();
}
}

public void Update()
{
this.Title = AppResources.ResourceManager.GetString(this.ResourceName);
}

protected override Task<Page> OnPopAsync(bool animated)
{
// temporary workaround while https://github.com/xamarin/Xamarin.Forms/issues/8581 not fixed
return base.OnPopAsync(animated: false);
}
}
}

0 comments on commit 708ac60

Please sign in to comment.