[NUI] Fix Switch bugs (#1984)
authorJiyun Yang <ji.yang@samsung.com>
Mon, 7 Sep 2020 11:30:58 +0000 (20:30 +0900)
committerGitHub <noreply@github.com>
Mon, 7 Sep 2020 11:30:58 +0000 (20:30 +0900)
* Change ControlState propagation sequence
* Remove setting border property in default switch style

This fixes an error of the following code,

```
protected override void OnCreate()
{
  //...
  var button = new Switch();
  button.SelectedChanged += OnSelected;
  root.Add(button);
}

void OnSelected(object target, SelectedChangedEventArgs args)
{
  if (args.IsSelected)
  {
     (target as Switch).IsSelected = false;
  }
}
```

Signed-off-by: Jiyun Yang <ji.yang@samsung.com>
src/Tizen.NUI.Components/Controls/Extension/SlidingSwitchExtension.cs
src/Tizen.NUI.Components/res/Theme/Tizen.NUI.Components_Tizen.NUI.Theme.Common.xaml
src/Tizen.NUI/src/public/BaseComponents/View.cs

index 775f2f8..68c6156 100644 (file)
@@ -54,7 +54,7 @@ namespace Tizen.NUI.Components.Extension
             }
 
             slidingAnimation.Clear();
-            slidingAnimation.AnimateTo(thumb, "PositionX", track.Size.Width - thumb.Size.Width - thumb.Position.X);
+            slidingAnimation.AnimateTo(thumb, "PositionX", switchButton.IsSelected ? track.Size.Width - thumb.Size.Width : 0);
             slidingAnimation.EndAction = Animation.EndActions.StopFinal;
             slidingAnimation.Play();
         }
index 1b7307a..44a882c 100644 (file)
   <!--Switch-->
   <c:SwitchStyle x:Key="Switch" Size="96, 60">
     <c:Switch.Track>
-      <b:ImageViewStyle Size="96, 60" WidthResizePolicy="Fixed" HeightResizePolicy="Fixed" Border="30, 30, 30, 30">
+      <b:ImageViewStyle Size="96, 60" WidthResizePolicy="Fixed" HeightResizePolicy="Fixed">
         <b:ImageViewStyle.ResourceUrl>
           <b:Selector x:TypeArguments="x:String" Normal="{nx:NUIResourcePath nui_component_default_switch_track_n.png}" Selected="{nx:NUIResourcePath nui_component_default_switch_track_s.png}" Disabled="{nx:NUIResourcePath nui_component_default_switch_track_d.png}" DisabledSelected="{nx:NUIResourcePath nui_component_default_switch_track_ds.png}" />
         </b:ImageViewStyle.ResourceUrl>
index 432312c..1f59293 100755 (executable)
@@ -187,8 +187,6 @@ namespace Tizen.NUI.BaseComponents
 
                 ControlStateChangeEventInternal?.Invoke(this, changeInfo);
 
-                OnControlStateChanged(changeInfo);
-
                 if (controlStatePropagation)
                 {
                     foreach (View child in Children)
@@ -197,6 +195,8 @@ namespace Tizen.NUI.BaseComponents
                     }
                 }
 
+                OnControlStateChanged(changeInfo);
+
                 ControlStateChangedEvent?.Invoke(this, changeInfo);
             }
         }