Fixed NavigationPage.BarBackgroundColor Property
authorchungryeol lim <cdark.lim@samsung.com>
Mon, 19 Dec 2016 04:22:27 +0000 (13:22 +0900)
committerKangho Hur <kangho.hur@samsung.com>
Fri, 24 Mar 2017 04:18:58 +0000 (13:18 +0900)
- Apply whole area "BarBackgroundColor"
- Property values for page push & pop

Signed-off-by: chungryeol lim <cdark.lim@samsung.com>
Change-Id: I8082be5d57cbea2b3a5b9a1cc533429d080b50c6

Xamarin.Forms.Platform.Tizen/Renderers/NavigationPageRenderer.cs

index e760489..c8f8606 100644 (file)
@@ -22,6 +22,11 @@ namespace Xamarin.Forms.Platform.Tizen
                readonly List<Widget> _naviItemContentPartList = new List<Widget>();
                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;
                        });
                }