summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android
diff options
context:
space:
mode:
authorJimmy Garrido <jimmygarrido@outlook.com>2016-11-02 18:09:55 (GMT)
committerE.Z. Hart <hartez@users.noreply.github.com>2016-11-02 18:09:55 (GMT)
commit7afe69e932543e96fd9557f8a6d4bf75b36b4489 (patch)
treee61b9a266f605192258698751f7be93a5750a058 /Xamarin.Forms.Platform.Android
parent0d6a6c5f17eb4e50ad7b96a7e4ae1e24c6fc3c18 (diff)
downloadxamarin-forms-7afe69e932543e96fd9557f8a6d4bf75b36b4489.zip
xamarin-forms-7afe69e932543e96fd9557f8a6d4bf75b36b4489.tar.gz
xamarin-forms-7afe69e932543e96fd9557f8a6d4bf75b36b4489.tar.bz2
Fixed tab not updating when page title is changed (#327)
* Fixed tab not updating when page title is changed * Remove OnPagePropertyChanged Event From Pages When Disposing * Meet coding standards and remove unnecessary parameters
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r--Xamarin.Forms.Platform.Android/AppCompat/TabbedPageRenderer.cs38
1 files changed, 33 insertions, 5 deletions
diff --git a/Xamarin.Forms.Platform.Android/AppCompat/TabbedPageRenderer.cs b/Xamarin.Forms.Platform.Android/AppCompat/TabbedPageRenderer.cs
index 2fa1e44..211d248 100644
--- a/Xamarin.Forms.Platform.Android/AppCompat/TabbedPageRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/AppCompat/TabbedPageRenderer.cs
@@ -11,6 +11,7 @@ using Android.Support.Design.Widget;
using Android.Support.V4.App;
using Android.Support.V4.View;
using Android.Views;
+using Xamarin.Forms.Internals;
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
namespace Xamarin.Forms.Platform.Android.AppCompat
@@ -99,6 +100,7 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
pageRenderer.ViewGroup.RemoveFromParent();
pageRenderer.Dispose();
}
+ pageToRemove.PropertyChanged -= OnPagePropertyChanged;
pageToRemove.ClearValue(Android.Platform.RendererProperty);
}
@@ -167,19 +169,16 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
pager.Id = FormsAppCompatActivity.GetUniqueId();
pager.AddOnPageChangeListener(this);
- tabs.SetupWithViewPager(pager);
- UpdateTabIcons();
- tabs.SetOnTabSelectedListener(this);
-
AddView(pager);
AddView(tabs);
+
+ OnChildrenCollectionChanged(null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
TabbedPage tabbedPage = e.NewElement;
if (tabbedPage.CurrentPage != null)
ScrollToCurrentPage();
- UpdateIgnoreContainerAreas();
((IPageController)tabbedPage).InternalChildren.CollectionChanged += OnChildrenCollectionChanged;
UpdateBarBackgroundColor();
UpdateBarTextColor();
@@ -255,6 +254,8 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
void OnChildrenCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
+ e.Apply((o, i, c) => SetupPage((Page)o), (o, i) => TeardownPage((Page)o), Reset);
+
FormsViewPager pager = _viewPager;
TabLayout tabs = _tabLayout;
@@ -277,6 +278,33 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
UpdateIgnoreContainerAreas();
}
+ void TeardownPage(Page page)
+ {
+ page.PropertyChanged -= OnPagePropertyChanged;
+ }
+
+ void SetupPage(Page page)
+ {
+ page.PropertyChanged += OnPagePropertyChanged;
+ }
+
+ void Reset()
+ {
+ foreach (var page in Element.Children)
+ SetupPage(page);
+ }
+
+ void OnPagePropertyChanged(object sender, PropertyChangedEventArgs e)
+ {
+ if (e.PropertyName == Page.TitleProperty.PropertyName)
+ {
+ var page = (Page)sender;
+ var index = Element.Children.IndexOf(page);
+ TabLayout.Tab tab = _tabLayout.GetTabAt(index);
+ tab.SetText(page.Title);
+ }
+ }
+
void ScrollToCurrentPage()
{
((Platform)Element.Platform).NavAnimationInProgress = true;