Add Style to VisualElement as TizenSpecific
authorKangho Hur <kangho.hur@samsung.com>
Wed, 8 Feb 2017 05:54:28 +0000 (14:54 +0900)
committerKangho Hur <kangho.hur@samsung.com>
Mon, 10 Jul 2017 02:11:19 +0000 (11:11 +0900)
- Implement the change proposed in RFC-17

Change-Id: I96431b3a32358be6f32e7acdeb0cbc6a27a98ec4

Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/ButtonStyle.cs [deleted file]
Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/ProgressBar.cs
Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/StyleValues.cs [new file with mode: 0644]
Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Switch.cs [deleted file]
Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/SwitchStyle.cs [deleted file]
Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/VisualElement.cs [new file with mode: 0644]
Xamarin.Forms.Core/Xamarin.Forms.Core.csproj
Xamarin.Forms.Platform.Tizen/Renderers/ButtonRenderer.cs
Xamarin.Forms.Platform.Tizen/Renderers/ProgressBarRenderer.cs
Xamarin.Forms.Platform.Tizen/Renderers/SwitchRenderer.cs
Xamarin.Forms.Platform.Tizen/Renderers/VisualElementRenderer.cs

diff --git a/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/ButtonStyle.cs b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/ButtonStyle.cs
deleted file mode 100644 (file)
index abe7bd8..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-namespace Xamarin.Forms.PlatformConfiguration.TizenSpecific
-{
-       public enum ButtonStyle
-       {
-               Default,
-               Circle,
-               Bottom
-       }
-}
index 8267ca0..3ed287d 100644 (file)
@@ -5,28 +5,10 @@ namespace Xamarin.Forms.PlatformConfiguration.TizenSpecific
 
        public static class ProgressBar
        {
-               public static readonly BindableProperty ProgressBarPendingModeProperty =
-                       BindableProperty.Create("ProgressBarPendingMode", typeof(bool),
-                       typeof(FormsElement), false);
-
                public static readonly BindableProperty ProgressBarPulsingStatusProperty =
                        BindableProperty.Create("ProgressBarPulsingStatus", typeof(bool),
                        typeof(FormsElement), false);
 
-               public static bool GetPendingMode(BindableObject element)
-               {
-                       return (bool)element.GetValue(ProgressBarPendingModeProperty);
-               }
-
-               public static void SetPendingMode(BindableObject element, bool isPending)
-               {
-                       if (!isPending)
-                       {
-                               SetPulsingStatus(element, false);
-                       }
-                       element.SetValue(ProgressBarPendingModeProperty, isPending);
-               }
-
                public static bool GetPulsingStatus(BindableObject element)
                {
                        return (bool)element.GetValue(ProgressBarPulsingStatusProperty);
@@ -34,23 +16,13 @@ namespace Xamarin.Forms.PlatformConfiguration.TizenSpecific
 
                public static void SetPulsingStatus(BindableObject element, bool isPulsing)
                {
-                       if (GetPendingMode(element))
+                       string style = VisualElement.GetStyle(element);
+                       if (style == ProgressBarStyle.Pending)
                        {
                                element.SetValue(ProgressBarPulsingStatusProperty, isPulsing);
                        }
                }
 
-               public static bool GetPendingMode(this IPlatformElementConfiguration<Tizen, FormsElement> config)
-               {
-                       return GetPendingMode(config.Element);
-               }
-
-               public static IPlatformElementConfiguration<Tizen, FormsElement> SetPendingMode(this IPlatformElementConfiguration<Tizen, FormsElement> config, bool isPending)
-               {
-                       SetPendingMode(config.Element, isPending);
-                       return config;
-               }
-
                public static bool GetPulsingStatus(this IPlatformElementConfiguration<Tizen, FormsElement> config)
                {
                        return GetPulsingStatus(config.Element);
diff --git a/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/StyleValues.cs b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/StyleValues.cs
new file mode 100644 (file)
index 0000000..d4e3c3f
--- /dev/null
@@ -0,0 +1,22 @@
+namespace Xamarin.Forms.PlatformConfiguration.TizenSpecific
+{
+       public static class ButtonStyle
+       {
+               public const string Default = "default";
+               public const string Circle = "circle";
+               public const string Bottom = "bottom";
+       }
+
+       public static class SwitchStyle
+       {
+               public const string CheckBox = "default";
+               public const string Toggle = "toggle";
+               public const string Favorite = "favorite";
+       }
+
+       public static class ProgressBarStyle
+       {
+               public const string Default = "default";
+               public const string Pending = "pending";
+       }
+}
diff --git a/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Switch.cs b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Switch.cs
deleted file mode 100644 (file)
index cef38f3..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-namespace Xamarin.Forms.PlatformConfiguration.TizenSpecific
-{
-       using FormsElement = Forms.Switch;
-
-       public static class Switch
-       {
-               public static readonly BindableProperty SwitchStyleProperty = BindableProperty.Create("SwitchStyle", typeof(SwitchStyle), typeof(FormsElement), SwitchStyle.Default);
-
-               public static SwitchStyle GetSwitchStyle(BindableObject element)
-               {
-                       return (SwitchStyle)element.GetValue(SwitchStyleProperty);
-               }
-
-               public static void SetSwitchStyle(BindableObject element, SwitchStyle value)
-               {
-                       element.SetValue(SwitchStyleProperty, value);
-               }
-
-               public static SwitchStyle GetSwitchStyle(this IPlatformElementConfiguration<Tizen, FormsElement> config)
-               {
-                       return GetSwitchStyle(config.Element);
-               }
-
-               public static IPlatformElementConfiguration<Tizen, FormsElement> SetSwitchStyle(this IPlatformElementConfiguration<Tizen, FormsElement> config, SwitchStyle value)
-               {
-                       SetSwitchStyle(config.Element, value);
-                       return config;
-               }
-       }
-}
diff --git a/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/SwitchStyle.cs b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/SwitchStyle.cs
deleted file mode 100644 (file)
index a7980fe..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-namespace Xamarin.Forms.PlatformConfiguration.TizenSpecific
-{
-       public enum SwitchStyle
-       {
-               Default,
-               CheckBox,
-               Favorite
-       }
-}
diff --git a/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/VisualElement.cs b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/VisualElement.cs
new file mode 100644 (file)
index 0000000..7eb4c71
--- /dev/null
@@ -0,0 +1,29 @@
+namespace Xamarin.Forms.PlatformConfiguration.TizenSpecific
+{
+       using FormsElement = Forms.VisualElement;
+       public static class VisualElement
+       {
+               public static readonly BindableProperty StyleProperty = BindableProperty.Create("ThemeStyle", typeof(string), typeof(VisualElement), default(string));
+
+               public static string GetStyle(BindableObject element)
+               {
+                       return (string)element.GetValue(StyleProperty);
+               }
+
+               public static void SetStyle(BindableObject element, string value)
+               {
+                       element.SetValue(StyleProperty, value);
+               }
+
+               public static string GetStyle(this IPlatformElementConfiguration<Tizen, FormsElement> config)
+               {
+                       return GetStyle(config.Element);
+               }
+
+               public static IPlatformElementConfiguration<Tizen, FormsElement> SetStyle(this IPlatformElementConfiguration<Tizen, FormsElement> config, string value)
+               {
+                       SetStyle(config.Element, value);
+                       return config;
+               }
+       }
+}
index a184c38..ca43560 100644 (file)
     <Compile Include="PlatformConfiguration\iOSSpecific\UIStatusBarAnimation.cs" />
     <Compile Include="PlatformConfiguration\iOSSpecific\UpdateMode.cs" />
     <Compile Include="PlatformConfiguration\iOSSpecific\VisualElement.cs" />
+    <Compile Include="PlatformConfiguration\TizenSpecific\StyleValues.cs" />
+    <Compile Include="PlatformConfiguration\TizenSpecific\VisualElement.cs" />
     <Compile Include="PlatformConfiguration\TizenSpecific\Entry.cs" />
     <Compile Include="PlatformConfiguration\TizenSpecific\Label.cs" />
     <Compile Include="PlatformConfiguration\TizenSpecific\Image.cs" />
     <Compile Include="PlatformConfiguration\TizenSpecific\ProgressBar.cs" />
-    <Compile Include="PlatformConfiguration\TizenSpecific\Button.cs" />
-    <Compile Include="PlatformConfiguration\TizenSpecific\ButtonStyle.cs" />
-    <Compile Include="PlatformConfiguration\TizenSpecific\Switch.cs" />
     <Compile Include="PlatformConfiguration\TizenSpecific\FontWeight.cs" />
-    <Compile Include="PlatformConfiguration\TizenSpecific\SwitchStyle.cs" />
     <Compile Include="PlatformConfiguration\WindowsSpecific\MasterDetailPage.cs" />
     <Compile Include="PlatformConfiguration\WindowsSpecific\CollapseStyle.cs" />
     <Compile Include="Configuration.cs" />
       <Name>Xamarin.Forms.Platform</Name>
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup />
   <PropertyGroup>
     <PostBuildEvent>
     </PostBuildEvent>
index def27a9..eea46e8 100644 (file)
@@ -2,7 +2,7 @@ using System;
 using System.ComponentModel;
 using EColor = ElmSharp.Color;
 using Xamarin.Forms.PlatformConfiguration.TizenSpecific;
-using Specific = Xamarin.Forms.PlatformConfiguration.TizenSpecific.Button;
+using Specific = Xamarin.Forms.PlatformConfiguration.TizenSpecific.VisualElement;
 
 namespace Xamarin.Forms.Platform.Tizen
 {
@@ -41,23 +41,11 @@ namespace Xamarin.Forms.Platform.Tizen
 
                        if (e.NewElement != null)
                        {
-                               UpdateStyle();
                                Control.Clicked += ButtonClickedHandler;
                        }
-
                        base.OnElementChanged(e);
                }
 
-               protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
-               {
-                       base.OnElementPropertyChanged(sender, e);
-
-                       if (e.PropertyName == Specific.ButtonStyleProperty.PropertyName)
-                       {
-                               UpdateStyle();
-                       }
-               }
-
                protected override Size MinimumSize()
                {
                        return new Size(Control.MinimumWidth, Control.MinimumHeight);
@@ -98,23 +86,9 @@ namespace Xamarin.Forms.Platform.Tizen
                        }
                }
 
-               void UpdateStyle()
+               protected override void UpdateThemeStyle()
                {
-                       string style;
-                       switch (Specific.GetButtonStyle(Element))
-                       {
-                               case ButtonStyle.Circle:
-                                       style = "circle";
-                                       break;
-                               case ButtonStyle.Bottom:
-                                       style = "bottom";
-                                       break;
-                               default:
-                                       style = "default";
-                                       break;
-                       }
-
-                       Control.UpdateStyle(style);
+                       Control.UpdateStyle(Specific.GetStyle(Element));
                        ((IVisualElementController)Element).NativeSizeChanged();
                }
 
index 6bf86b1..444bc85 100644 (file)
@@ -1,5 +1,6 @@
 using System.ComponentModel;
 
+using SpecificVE = Xamarin.Forms.PlatformConfiguration.TizenSpecific.VisualElement;
 using Specific = Xamarin.Forms.PlatformConfiguration.TizenSpecific.ProgressBar;
 using EProgressBar = ElmSharp.ProgressBar;
 
@@ -46,20 +47,20 @@ namespace Xamarin.Forms.Platform.Tizen
                        {
                                UpdateProgress();
                        }
-                       else if (e.PropertyName == Specific.ProgressBarPendingModeProperty.PropertyName)
-                       {
-                               UpdatePendingMode();
-                       }
                        else if (e.PropertyName == Specific.ProgressBarPulsingStatusProperty.PropertyName)
                        {
                                UpdatePulsingStatus();
                        }
                }
 
+               protected override void UpdateThemeStyle()
+               {
+                       Control.Style = SpecificVE.GetStyle(Element);
+               }
+
                void UpdateAll()
                {
                        UpdateProgress();
-                       UpdatePendingMode();
                        UpdatePulsingStatus();
                }
 
@@ -68,19 +69,6 @@ namespace Xamarin.Forms.Platform.Tizen
                        Control.Value = Element.Progress;
                }
 
-               void UpdatePendingMode()
-               {
-                       bool isPending = Specific.GetPendingMode(Element);
-                       if (isPending)
-                       {
-                               Control.Style = "pending";
-                       }
-                       else
-                       {
-                               Control.Style = "default";
-                       }
-               }
-
                void UpdatePulsingStatus()
                {
                        bool isPulsing = Specific.GetPulsingStatus(Element);
index c67a69a..da00ef9 100644 (file)
@@ -2,7 +2,7 @@ using System;
 using System.ComponentModel;
 using ElmSharp;
 using Xamarin.Forms.PlatformConfiguration.TizenSpecific;
-using Specific = Xamarin.Forms.PlatformConfiguration.TizenSpecific.Switch;
+using Specific = Xamarin.Forms.PlatformConfiguration.TizenSpecific.VisualElement;
 
 namespace Xamarin.Forms.Platform.Tizen
 {
@@ -31,20 +31,27 @@ namespace Xamarin.Forms.Platform.Tizen
 
                        if (e.NewElement != null)
                        {
-                               UpdateStyle();
                                Control.StateChanged += CheckChangedHandler;
                        }
 
                        base.OnElementChanged(e);
                }
 
-               protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
+               protected override void UpdateThemeStyle()
                {
-                       if (e.PropertyName == Specific.SwitchStyleProperty.PropertyName)
+                       var style = Specific.GetStyle(Element);
+                       switch (style)
                        {
-                               UpdateStyle();
+                               case SwitchStyle.Toggle:
+                               case SwitchStyle.Favorite:
+                               case SwitchStyle.CheckBox:
+                                       Control.Style = style;
+                                       break;
+                               default:
+                                       Control.Style = SwitchStyle.Toggle;
+                                       break;
                        }
-                       base.OnElementPropertyChanged(sender, e);
+                       ((IVisualElementController)Element).NativeSizeChanged();
                }
 
                void CheckChangedHandler(object sender, EventArgs e)
@@ -56,22 +63,5 @@ namespace Xamarin.Forms.Platform.Tizen
                {
                        Control.IsChecked = Element.IsToggled;
                }
-
-               void UpdateStyle()
-               {
-                       switch (Specific.GetSwitchStyle(Element))
-                       {
-                               case SwitchStyle.CheckBox:
-                                       Control.Style = "default";
-                                       break;
-                               case SwitchStyle.Favorite:
-                                       Control.Style = "favorite";
-                                       break;
-                               default:
-                                       Control.Style = "toggle";
-                                       break;
-                       }
-                       ((IVisualElementController)Element).NativeSizeChanged();
-               }
        }
 }
index 8c5c0be..4bde705 100644 (file)
@@ -3,12 +3,12 @@ using System.Collections.Generic;
 using System.Diagnostics;
 using System.ComponentModel;
 using ElmSharp;
-using ELayout = ElmSharp.Layout;
 using EColor = ElmSharp.Color;
 using ESize = ElmSharp.Size;
 using ERect = ElmSharp.Rect;
 using ERectangle = ElmSharp.Rectangle;
-using EBox = ElmSharp.Box;
+using Specific = Xamarin.Forms.PlatformConfiguration.TizenSpecific.VisualElement;
+
 
 namespace Xamarin.Forms.Platform.Tizen
 {
@@ -59,6 +59,7 @@ namespace Xamarin.Forms.Platform.Tizen
                        RegisterPropertyHandler(VisualElement.IsEnabledProperty, UpdateIsEnabled);
                        RegisterPropertyHandler(VisualElement.InputTransparentProperty, UpdateInputTransparent);
                        RegisterPropertyHandler(VisualElement.BackgroundColorProperty, UpdateBackgroundColor);
+                       RegisterPropertyHandler(Specific.StyleProperty, UpdateThemeStyle);
 
                        RegisterPropertyHandler(VisualElement.AnchorXProperty, ApplyTransformation);
                        RegisterPropertyHandler(VisualElement.AnchorYProperty, ApplyTransformation);
@@ -794,6 +795,8 @@ namespace Xamarin.Forms.Platform.Tizen
                        NativeView.PassEvents = Element.InputTransparent;
                }
 
+               protected virtual void UpdateThemeStyle() {}
+
                void ApplyRotation(EvasMap map, ERect geometry, ref bool changed)
                {
                        var rotationX = Element.RotationX;