[Tizen] Support to TabbedPage.BarTextColor, SelctedTabColor, UnselectedTabColor ...
authorKangho Hur <rookiejava@gmail.com>
Sat, 8 Jun 2019 01:12:40 +0000 (10:12 +0900)
committerSamantha Houts <samhouts@users.noreply.github.com>
Sat, 8 Jun 2019 01:12:40 +0000 (18:12 -0700)
fixes #3478

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

index e3c2e7c..cb812e6 100644 (file)
@@ -29,6 +29,9 @@ namespace Xamarin.Forms.Platform.Tizen
                        RegisterPropertyHandler(Page.TitleProperty, UpdateTitle);
                        RegisterPropertyHandler(nameof(Element.CurrentPage), OnCurrentPageChanged);
                        RegisterPropertyHandler(TabbedPage.BarBackgroundColorProperty, UpdateBarBackgroundColor);
+                       RegisterPropertyHandler(TabbedPage.BarTextColorProperty, UpdateBarTextColor);
+                       RegisterPropertyHandler(TabbedPage.SelectedTabColorProperty, UpdateSelectedTabColor);
+                       RegisterPropertyHandler(TabbedPage.UnselectedTabColorProperty, UpdateUnselectedTabColor);
                }
 
                protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e)
@@ -202,21 +205,47 @@ namespace Xamarin.Forms.Platform.Tizen
 
                void UpdateBarBackgroundColor(bool initialize)
                {
-                       if (initialize && Element.BackgroundColor.IsDefault)
+                       if (initialize && Element.BarBackgroundColor.IsDefault)
                                return;
 
                        EColor bgColor = Element.BarBackgroundColor.ToNative();
                        _toolbar.BackgroundColor = bgColor;
                        foreach (EToolbarItem item in _itemToItemPage.Keys)
                        {
-                               if (Element.BarBackgroundColor == Color.Default)
-                               {
-                                       item.DeletePartColor("bg");
-                               }
-                               else
-                               {
-                                       item.SetPartColor("bg", bgColor);
-                               }
+                               ApplyBarItemColors(item, BarItemColorType.Background, bgColor);
+                       }
+               }
+
+               void UpdateBarTextColor(bool initialize)
+               {
+                       if (initialize && Element.BarTextColor.IsDefault)
+                               return;
+
+                       foreach (EToolbarItem item in _itemToItemPage.Keys)
+                       {
+                               ApplyBarItemColors(item, BarItemColorType.Text, Element.BarTextColor.ToNative());
+                       }
+               }
+
+               void UpdateSelectedTabColor(bool initialize)
+               {
+                       if (initialize && Element.SelectedTabColor.IsDefault)
+                               return;
+
+                       foreach (EToolbarItem item in _itemToItemPage.Keys)
+                       {
+                               ApplyBarItemColors(item, BarItemColorType.SelectedTab, Element.SelectedTabColor.ToNative());
+                       }
+               }
+
+               void UpdateUnselectedTabColor(bool initialize)
+               {
+                       if (initialize && Element.UnselectedTabColor.IsDefault)
+                               return;
+
+                       foreach (EToolbarItem item in _itemToItemPage.Keys)
+                       {
+                               ApplyBarItemColors(item, BarItemColorType.UnselectedTab, Element.UnselectedTabColor.ToNative());
                        }
                }
 
@@ -288,10 +317,10 @@ namespace Xamarin.Forms.Platform.Tizen
                        _toolbarItemList.Insert(index, toolbarItem);
                        _itemToItemPage.Add(toolbarItem, newItem);
 
-                       if (Element.BarBackgroundColor != Color.Default)
-                       {
-                               toolbarItem.SetPartColor("bg", _toolbar.BackgroundColor);
-                       }
+                       ApplyBarItemColors(toolbarItem, BarItemColorType.Background, Element.BarBackgroundColor.ToNative());
+                       ApplyBarItemColors(toolbarItem, BarItemColorType.Text, Element.BarTextColor.ToNative());
+                       ApplyBarItemColors(toolbarItem, BarItemColorType.SelectedTab, Element.SelectedTabColor.ToNative());
+                       ApplyBarItemColors(toolbarItem, BarItemColorType.UnselectedTab, Element.UnselectedTabColor.ToNative());
 
                        var childContent = Platform.GetOrCreateRenderer(newItem).NativeView;
                        _innerBox.PackEnd(childContent);
@@ -403,5 +432,126 @@ namespace Xamarin.Forms.Platform.Tizen
                        Element.UpdateFocusTreePolicy();
                        _isUpdateByCurrentPage = false;
                }
+
+               void ApplyBarItemColors(EToolbarItem item, BarItemColorType type, EColor color)
+               {
+                       if (color.IsDefault)
+                       {
+                               ClearBarItemColors(item, type);
+                       }
+                       else
+                       {
+                               switch (type)
+                               {
+                                       case BarItemColorType.Background:
+                                               item.SetPartColor("bg", color);
+                                               break;
+                                       case BarItemColorType.Text:
+                                               if (string.IsNullOrEmpty(item.Icon))
+                                               {
+                                                       item.SetPartColor("text", color);
+                                                       item.SetPartColor("text_pressed", color);
+                                                       item.SetPartColor("text_selected", color);
+                                               }
+                                               else
+                                               {
+                                                       item.SetPartColor("text_under_icon", color);
+                                                       item.SetPartColor("text_under_icon_pressed", color);
+                                                       item.SetPartColor("text_under_icon_selected", color);
+                                               }
+                                               item.SetPartColor("underline", color);
+                                               break;
+                                       case BarItemColorType.SelectedTab:
+                                               if (string.IsNullOrEmpty(item.Icon))
+                                               {
+                                                       item.SetPartColor("text_selected", color);
+                                               }
+                                               else
+                                               {
+                                                       item.SetPartColor("text_under_icon_selected", color);
+                                                       item.SetPartColor("icon_selected", color);
+                                               }
+                                               item.SetPartColor("underline", color);
+                                               break;
+                                       case BarItemColorType.UnselectedTab:
+                                               if (string.IsNullOrEmpty(item.Icon))
+                                               {
+                                                       item.SetPartColor("text", color);
+                                                       item.SetPartColor("text_pressed", color);
+                                               }
+                                               else
+                                               {
+                                                       item.SetPartColor("text_under_icon", color);
+                                                       item.SetPartColor("text_under_icon_pressed", color);
+                                                       item.SetPartColor("icon", color);
+                                                       item.SetPartColor("icon_pressed", color);
+                                               }
+                                               break;
+                                       default:
+                                               break;
+                               }
+                       }
+               }
+
+               void ClearBarItemColors(EToolbarItem item, BarItemColorType type)
+               {
+                       switch (type)
+                       {
+                               case BarItemColorType.Background:
+                                       item.DeletePartColor("bg");
+                                       break;
+                               case BarItemColorType.Text:
+                                       if (string.IsNullOrEmpty(item.Icon))
+                                       {
+                                               item.DeletePartColor("text");
+                                               item.DeletePartColor("text_pressed");
+                                               item.DeletePartColor("text_selected");
+                                       }
+                                       else
+                                       {
+                                               item.DeletePartColor("text_under_icon");
+                                               item.DeletePartColor("text_under_icon_pressed");
+                                               item.DeletePartColor("text_under_icon_selected");
+                                       }
+                                       item.DeletePartColor("underline");
+                                       break;
+                               case BarItemColorType.SelectedTab:
+                                       if (string.IsNullOrEmpty(item.Icon))
+                                       {
+                                               item.DeletePartColor("text_selected");
+                                       }
+                                       else
+                                       {
+                                               item.DeletePartColor("text_under_icon_selected");
+                                               item.DeletePartColor("icon_selected");
+                                       }
+                                       item.DeletePartColor("underline");
+                                       break;
+                               case BarItemColorType.UnselectedTab:
+                                       if (string.IsNullOrEmpty(item.Icon))
+                                       {
+                                               item.DeletePartColor("text");
+                                               item.DeletePartColor("text_pressed");
+                                       }
+                                       else
+                                       {
+                                               item.DeletePartColor("text_under_icon");
+                                               item.DeletePartColor("text_under_icon_pressed");
+                                               item.DeletePartColor("icon");
+                                               item.DeletePartColor("icon_pressed");
+                                       }
+                                       break;
+                               default:
+                                       break;
+                       }
+               }
+       }
+
+       enum BarItemColorType
+       {
+               Background,
+               Text,
+               SelectedTab,
+               UnselectedTab
        }
 }