Add Switch Style
authorSeunghyun Choi <sh4682.choi@samsung.com>
Thu, 12 Jan 2017 11:12:18 +0000 (20:12 +0900)
committerKangho Hur <kangho.hur@samsung.com>
Mon, 10 Jul 2017 02:11:16 +0000 (11:11 +0900)
 - Add Switch Style(CheckBox, Favorite)
 - Approval of the RFC is required.
   (http://suprem.sec.samsung.net/confluence/display/SPTDTLC/%5BFormsTizen%5D+RFC+5+-+Switch)

Change-Id: If98be73fc84633b670328f723e0e4aa7ccebc82f
Signed-off-by: Seunghyun Choi <sh4682.choi@samsung.com>
Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Switch.cs [new file with mode: 0644]
Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/SwitchStyle.cs [new file with mode: 0644]
Xamarin.Forms.Core/Xamarin.Forms.Core.csproj
Xamarin.Forms.Platform.Tizen/Renderers/SwitchRenderer.cs

diff --git a/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Switch.cs b/Xamarin.Forms.Core/PlatformConfiguration/TizenSpecific/Switch.cs
new file mode 100644 (file)
index 0000000..cef38f3
--- /dev/null
@@ -0,0 +1,30 @@
+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
new file mode 100644 (file)
index 0000000..a7980fe
--- /dev/null
@@ -0,0 +1,9 @@
+namespace Xamarin.Forms.PlatformConfiguration.TizenSpecific
+{
+       public enum SwitchStyle
+       {
+               Default,
+               CheckBox,
+               Favorite
+       }
+}
index 3c03d62..84f132d 100644 (file)
     <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\SwitchStyle.cs" />
     <Compile Include="PlatformConfiguration\WindowsSpecific\MasterDetailPage.cs" />
     <Compile Include="PlatformConfiguration\WindowsSpecific\CollapseStyle.cs" />
     <Compile Include="Configuration.cs" />
index b3539e6..c67a69a 100644 (file)
@@ -1,5 +1,8 @@
 using System;
+using System.ComponentModel;
 using ElmSharp;
+using Xamarin.Forms.PlatformConfiguration.TizenSpecific;
+using Specific = Xamarin.Forms.PlatformConfiguration.TizenSpecific.Switch;
 
 namespace Xamarin.Forms.Platform.Tizen
 {
@@ -28,14 +31,22 @@ namespace Xamarin.Forms.Platform.Tizen
 
                        if (e.NewElement != null)
                        {
-                               Control.Style = "toggle";
-
+                               UpdateStyle();
                                Control.StateChanged += CheckChangedHandler;
                        }
 
                        base.OnElementChanged(e);
                }
 
+               protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
+               {
+                       if (e.PropertyName == Specific.SwitchStyleProperty.PropertyName)
+                       {
+                               UpdateStyle();
+                       }
+                       base.OnElementPropertyChanged(sender, e);
+               }
+
                void CheckChangedHandler(object sender, EventArgs e)
                {
                        Element.SetValue(Switch.IsToggledProperty, Control.IsChecked);
@@ -46,5 +57,21 @@ 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();
+               }
        }
 }