From 437bc4c434e27359c5e67df238823eefcd9f6eda Mon Sep 17 00:00:00 2001 From: chungryeol lim Date: Mon, 19 Dec 2016 13:22:27 +0900 Subject: Fixed NavigationPage.BarBackgroundColor Property - Apply whole area "BarBackgroundColor" - Property values for page push & pop Signed-off-by: chungryeol lim Change-Id: I8082be5d57cbea2b3a5b9a1cc533429d080b50c6 --- .../Renderers/NavigationPageRenderer.cs | 54 ++++++++++++++-------- 1 file changed, 34 insertions(+), 20 deletions(-) (limited to 'Xamarin.Forms.Platform.Tizen') diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/NavigationPageRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/NavigationPageRenderer.cs index e760489d..c8f8606a 100644 --- a/Xamarin.Forms.Platform.Tizen/Renderers/NavigationPageRenderer.cs +++ b/Xamarin.Forms.Platform.Tizen/Renderers/NavigationPageRenderer.cs @@ -22,6 +22,11 @@ namespace Xamarin.Forms.Platform.Tizen readonly List _naviItemContentPartList = new List(); ToolbarTracker _toolbarTracker = null; + Page CurrentPage => Element.CurrentPage; + Page PreviousPage => Element.Navigation.NavigationStack.Count > 1 ? Element.Navigation.NavigationStack[Element.Navigation.NavigationStack.Count - 2] : null; + NaviItem CurrentNaviItem => _naviFrame.NavigationStack.Count > 0 ? _naviFrame.NavigationStack.Last() : null; + NaviItem PreviousNaviItem => _naviFrame.NavigationStack.Count > 1 ? _naviFrame.NavigationStack[_naviFrame.NavigationStack.Count - 2] : null; + public NavigationPageRenderer() { } @@ -99,6 +104,11 @@ namespace Xamarin.Forms.Platform.Tizen _previousPage = Element.CurrentPage; (_previousPage as IPageController)?.SendAppearing(); } + else if (e.PropertyName == NavigationPage.BarTextColorProperty.PropertyName) + UpdateTitle(CurrentPage); + // Tizen does not support 'Tint', but only 'BarBackgroundColor' + else if (e.PropertyName == NavigationPage.BarBackgroundColorProperty.PropertyName) + UpdateBarBackgroundColor(CurrentNaviItem); } void PageCollectionChangedHandler(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) @@ -124,10 +134,7 @@ namespace Xamarin.Forms.Platform.Tizen else if (e.PropertyName == NavigationPage.HasBackButtonProperty.PropertyName || e.PropertyName == NavigationPage.BackButtonTitleProperty.PropertyName) UpdateHasBackButton(sender as Page); - else if (e.PropertyName == Page.TitleProperty.PropertyName || - e.PropertyName == NavigationPage.BarBackgroundColorProperty.PropertyName || - e.PropertyName == NavigationPage.BarTextColorProperty.PropertyName || - e.PropertyName == NavigationPage.TintProperty.PropertyName) + else if (e.PropertyName == Page.TitleProperty.PropertyName) UpdateTitle(sender as Page); } @@ -136,6 +143,7 @@ namespace Xamarin.Forms.Platform.Tizen NaviItem item = GetNaviItemForPage(page); item.TitleBarVisible = (bool)page.GetValue(NavigationPage.HasNavigationBarProperty); UpdateToolbarItem(page, item); + UpdateBarBackgroundColor(item); } void UpdateToolbarItem(Page page, NaviItem item = null) @@ -171,9 +179,11 @@ namespace Xamarin.Forms.Platform.Tizen item.SetPartContent(_partBackButton, button); } - void UpdateTitle(Page page) + void UpdateTitle(Page page, NaviItem item = null) { - NaviItem item = GetNaviItemForPage(page); + if (item == null) + item = GetNaviItemForPage(page); + item.SetPartText(_partTitle, SpanTitle(page.Title)); } @@ -185,21 +195,23 @@ namespace Xamarin.Forms.Platform.Tizen HorizontalTextAlignment = Native.TextAlignment.Center, ForegroundColor = Element.BarTextColor.ToNative() }; - - //TODO: changes only background of title not all bar - if (Element.BarBackgroundColor != Color.Default) - { - span.BackgroundColor = Element.BarBackgroundColor.ToNative(); - } - else if (Element.Tint != Color.Default) - { - //TODO: This is only for backward compatibility - //- remove when Tint is no longer in Xamarin API - span.BackgroundColor = Element.Tint.ToNative(); - } return span.GetMarkupText(); } + void UpdateBarBackgroundColor(NaviItem item) + { + item.TitleBarBackgroundColor = Element.BarBackgroundColor.ToNative(); + } + + void UpdateNavigationBar(Page page, NaviItem item = null) + { + if (item == null) + item = GetNaviItemForPage(page); + + UpdateTitle(page, item); + UpdateBarBackgroundColor(item); + } + EButton CreateNavigationButton(string text) { EButton button = new EButton(Forms.Context.MainWindow); @@ -289,6 +301,8 @@ namespace Xamarin.Forms.Platform.Tizen { if ((Element as IPageController).InternalChildren.Count == _naviFrame.NavigationStack.Count) { + UpdateNavigationBar(PreviousPage, PreviousNaviItem); + if (nre.Animated) { _naviFrame.Pop(); @@ -301,7 +315,7 @@ namespace Xamarin.Forms.Platform.Tizen CompleteCurrentNavigationTask(); } else - _naviFrame.NavigationStack.Last().Delete(); + CurrentNaviItem?.Delete(); } } @@ -318,6 +332,7 @@ namespace Xamarin.Forms.Platform.Tizen if (topItem != rootItem) { + UpdateNavigationBar(Element.Navigation.NavigationStack.Last(), rootItem); if (nre.Animated) { _naviFrame.Pop(); @@ -369,7 +384,6 @@ namespace Xamarin.Forms.Platform.Tizen tcs.SetResult(true); UpdateHasNavigationBar(nre.Page); - return false; }); } -- cgit v1.2.3