[NUI] Fix to invoke SelectedChanged when IsSelected is changed by setter
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Fri, 11 Mar 2022 10:25:09 +0000 (19:25 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 15 Mar 2022 08:03:22 +0000 (17:03 +0900)
Previously, SelectedChanged was not invoked when IsSelected is changed
by IsSelected's setter.
e.g. checkBox.IsSelected = true;

The issue occurred due to the logic that checked mouse up and key up.

Now, the incorrect logic has been removed and SelectedChanged is invoked
when IsSelected is changed by ISelected's setter.

src/Tizen.NUI.Components/Controls/SelectButton.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/CheckBoxSample.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/MenuSample.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/RadioButtonSample.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/TabViewSample.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Tizen.NUI.Samples.csproj

index 62b10f20720c46aa78178b440ec620ee58622405..1857750db5d1061bea74f13a120e16d161a99fb8 100755 (executable)
@@ -32,8 +32,6 @@ namespace Tizen.NUI.Components
     {
         private SelectGroup itemGroup = null;
 
-        private bool invokeSelectedChanged = false;
-
         /// <summary>
         /// Item group which is used to manager all SelectButton in it.
         /// </summary>
@@ -147,18 +145,6 @@ namespace Tizen.NUI.Components
                 return false;
             }
 
-            if (key.State == Key.StateType.Up)
-            {
-                if (key.KeyPressedName == "Return")
-                {
-                    invokeSelectedChanged = true;
-                }
-            }
-            else
-            {
-                invokeSelectedChanged = false;
-            }
-
             return base.OnKey(key);
         }
 
@@ -185,17 +171,6 @@ namespace Tizen.NUI.Components
                 return false;
             }
 
-            PointStateType state = touch.GetState(0);
-            switch (state)
-            {
-                case PointStateType.Up:
-                    invokeSelectedChanged = true;
-                    break;
-                default:
-                    invokeSelectedChanged = false;
-                    break;
-            }
-
             return base.HandleControlStateOnTouch(touch);
         }
 
@@ -219,12 +194,6 @@ namespace Tizen.NUI.Components
                     EmitAccessibilityStateChangedEvent(AccessibilityState.Checked, info.CurrentState.Contains(ControlState.Selected));
                 }
 
-                // SelectedChanged is invoked when button or key is unpressed.
-                if (invokeSelectedChanged == false)
-                {
-                    return;
-                }
-
                 OnSelectedChanged();
 
                 if (SelectedChanged != null)
index b15ceaa7a9c3a2f3aae146761cd7f111b67e2ad3..1e20f4a01f3db6ec4d9c0be1bbd0dea26628d37a 100755 (executable)
@@ -85,8 +85,14 @@ namespace Tizen.NUI.Samples
 
             for (int i = 0; i < num; i++)
             {
+                int index = i + 1;
+
                 //Create utility radio button.
                 utilityCheckBox[i] = new CheckBox();
+                utilityCheckBox[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+                {
+                    global::System.Console.WriteLine($"Left {index}th Utility CheckBox's IsSelected is changed to {args.IsSelected}.");
+                };
                 var utilityStyle = utilityCheckBox[i].Style;
                 utilityStyle.Icon.Opacity = new Selector<float?>
                 {
@@ -125,6 +131,10 @@ namespace Tizen.NUI.Samples
                 group[0].Add(utilityCheckBox[i]);
                 //Create family radio button.
                 familyCheckBox[i] = new CheckBox();
+                familyCheckBox[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+                {
+                    global::System.Console.WriteLine($"Left {index}th Family CheckBox's IsSelected is changed to {args.IsSelected}.");
+                };
                 var familyStyle = familyCheckBox[i].Style;
                 familyStyle.Icon.Opacity = new Selector<float?>
                 {
@@ -149,6 +159,10 @@ namespace Tizen.NUI.Samples
                 group[1].Add(familyCheckBox[i]);
                 //Create food radio button.
                 foodCheckBox[i] = new CheckBox();
+                foodCheckBox[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+                {
+                    global::System.Console.WriteLine($"Left {index}th Food CheckBox's IsSelected is changed to {args.IsSelected}.");
+                };
                 var foodStyle = foodCheckBox[i].Style;
                 foodStyle.Icon.Opacity = new Selector<float?>
                 {
@@ -173,6 +187,10 @@ namespace Tizen.NUI.Samples
                 group[2].Add(foodCheckBox[i]);
                 //Create kitchen radio button.
                 kitchenCheckBox[i] = new CheckBox();
+                kitchenCheckBox[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+                {
+                    global::System.Console.WriteLine($"Left {index}th Kitchen CheckBox's IsSelected is changed to {args.IsSelected}.");
+                };
                 var kitchenStyle = kitchenCheckBox[i].Style;
                 kitchenStyle.Icon.Opacity = new Selector<float?>
                 {
@@ -338,22 +356,40 @@ namespace Tizen.NUI.Samples
             };
             for (int i = 0; i < num; i++)
             {
+                int index = i + 1;
+
                 utilityCheckBox2[i] = new CheckBox(utilityStyle2);
+                utilityCheckBox2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+                {
+                    global::System.Console.WriteLine($"Right {index}th Utility CheckBox's IsSelected is changed to {args.IsSelected}.");
+                };
                 utilityCheckBox2[i].Size = new Size(48, 48);
                 utilityCheckBox2[i].Margin = new Extents(76, 76, 25, 25);
                 group2[0].Add(utilityCheckBox2[i]);
 
                 familyCheckBox2[i] = new CheckBox(familyStyle2);
+                familyCheckBox2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+                {
+                    global::System.Console.WriteLine($"Right {index}th Family CheckBox's IsSelected is changed to {args.IsSelected}.");
+                };
                 familyCheckBox2[i].Size = new Size(48, 48);
                 familyCheckBox2[i].Margin = new Extents(76, 76, 25, 25);
                 group2[1].Add(familyCheckBox2[i]);
 
                 foodCheckBox2[i] = new CheckBox(foodStyle2);
+                foodCheckBox2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+                {
+                    global::System.Console.WriteLine($"Right {index}th Food CheckBox's IsSelected is changed to {args.IsSelected}.");
+                };
                 foodCheckBox2[i].Size = new Size(48, 48);
                 foodCheckBox2[i].Margin = new Extents(76, 76, 25, 25);
                 group2[2].Add(foodCheckBox2[i]);
 
                 kitchenCheckBox2[i] = new CheckBox(kitchenStyle2);
+                kitchenCheckBox2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+                {
+                    global::System.Console.WriteLine($"Right {index}th Kitchen CheckBox's IsSelected is changed to {args.IsSelected}.");
+                };
                 kitchenCheckBox2[i].Size = new Size(48, 48);
                 kitchenCheckBox2[i].Margin = new Extents(76, 76, 25, 25);
                 group2[3].Add(kitchenCheckBox2[i]);
index 5573dfd79057836a0c7ddb414314980be2ba9438..196a046e9b7ebabfa84b28ec1acc29cf27c5162b 100755 (executable)
@@ -38,9 +38,28 @@ namespace Tizen.NUI.Samples
             navigator.Push(page);
 
             var menuItem = new MenuItem() { Text = "Menu" };
+            menuItem.SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+            {
+                global::System.Console.WriteLine($"1st MenuItem's IsSelected is changed to {args.IsSelected}.");
+            };
+
             var menuItem2 = new MenuItem() { Text = "Menu2" };
+            menuItem2.SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+            {
+                global::System.Console.WriteLine($"2nd MenuItem's IsSelected is changed to {args.IsSelected}.");
+            };
+
             var menuItem3 = new MenuItem() { Text = "Menu3" };
+            menuItem3.SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+            {
+                global::System.Console.WriteLine($"3rd MenuItem's IsSelected is changed to {args.IsSelected}.");
+            };
+
             var menuItem4 = new MenuItem() { Text = "Menu4" };
+            menuItem4.SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+            {
+                global::System.Console.WriteLine($"4th MenuItem's IsSelected is changed to {args.IsSelected}.");
+            };
 
             moreButton.Clicked += (object sender, ClickedEventArgs args) =>
             {
index ec4170a641673bc13d0eb42274fd29dbea292199..3b9311cd5d1ce215fe6e878d6e2dfb358b1302bd 100755 (executable)
@@ -87,8 +87,14 @@ namespace Tizen.NUI.Samples
 
             for (int i = 0; i < num; i++)
             {
+                int index = i + 1;
+
                 // create utility radio button.
                 utilityRadioButton[i] = new RadioButton();
+                utilityRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+                {
+                    global::System.Console.WriteLine($"Left {index}th Utility RadioButton's IsSelected is changed to {args.IsSelected}.");
+                };
                 var utilityStyle = utilityRadioButton[i].Style;
                 utilityStyle.Icon.Opacity = new Selector<float?>
                 {
@@ -112,6 +118,10 @@ namespace Tizen.NUI.Samples
 
                 // create family radio button.
                 familyRadioButton[i] = new RadioButton();
+                familyRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+                {
+                    global::System.Console.WriteLine($"Left {index}th Family RadioButton's IsSelected is changed to {args.IsSelected}.");
+                };
                 var familyStyle = familyRadioButton[i].Style;
                 familyStyle.Icon.Opacity = new Selector<float?>
                 {
@@ -136,6 +146,10 @@ namespace Tizen.NUI.Samples
 
                 // create food radio button.
                 foodRadioButton[i] = new RadioButton();
+                foodRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+                {
+                    global::System.Console.WriteLine($"Left {index}th Food RadioButton's IsSelected is changed to {args.IsSelected}.");
+                };
                 var foodStyle = foodRadioButton[i].Style;
                 foodStyle.Icon.Opacity = new Selector<float?>
                 {
@@ -160,6 +174,10 @@ namespace Tizen.NUI.Samples
 
                 // create kitchen radio button.
                 kitchenRadioButton[i] = new RadioButton();
+                kitchenRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+                {
+                    global::System.Console.WriteLine($"Left {index}th Kitchen RadioButton's IsSelected is changed to {args.IsSelected}.");
+                };
                 var kitchenStyle = kitchenRadioButton[i].Style;
                 kitchenStyle.Icon.Opacity = new Selector<float?>
                 {
@@ -307,19 +325,37 @@ namespace Tizen.NUI.Samples
             };
             for (int i = 0; i < num; i++)
             {
+                int index = i + 1;
+
                 utilityRadioButton2[i] = new RadioButton(utilityStyle2);
+                utilityRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+                {
+                    global::System.Console.WriteLine($"Right {index}th Utility RadioButton's IsSelected is changed to {args.IsSelected}.");
+                };
                 utilityRadioButton2[i].Size = new Size(48, 48);
                 group2[0].Add(utilityRadioButton2[i]);
 
                 familyRadioButton2[i] = new RadioButton(familyStyle2);
+                familyRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+                {
+                    global::System.Console.WriteLine($"Right {index}th Family RadioButton's IsSelected is changed to {args.IsSelected}.");
+                };
                 familyRadioButton2[i].Size = new Size(48, 48);
                 group2[1].Add(familyRadioButton2[i]);
 
                 foodRadioButton2[i] = new RadioButton(foodStyle2);
+                foodRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+                {
+                    global::System.Console.WriteLine($"Right {index}th Food RadioButton's IsSelected is changed to {args.IsSelected}.");
+                };
                 foodRadioButton2[i].Size = new Size(48, 48);
                 group2[2].Add(foodRadioButton2[i]);
 
                 kitchenRadioButton2[i] = new RadioButton(kitchenStyle2);
+                kitchenRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+                {
+                    global::System.Console.WriteLine($"Right {index}th Kitchen RadioButton's IsSelected is changed to {args.IsSelected}.");
+                };
                 kitchenRadioButton2[i].Size = new Size(48, 48);
                 group2[3].Add(kitchenRadioButton2[i]);
 
index 1c0d9260673bfe58a2021309f5ddd67a20a15ddc..2ad01a4dca49b610770021ca16afe3913529ae9f 100644 (file)
@@ -29,6 +29,10 @@ namespace Tizen.NUI.Samples
             {
                 Text = "Tab#1"
             };
+            tabButton.SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+            {
+                global::System.Console.WriteLine($"1st TabButton's IsSelected is changed to {args.IsSelected}.");
+            };
 
             content = new TextLabel()
             {
@@ -47,6 +51,10 @@ namespace Tizen.NUI.Samples
             {
                 Text = "Tab#2"
             };
+            tabButton2.SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+            {
+                global::System.Console.WriteLine($"2nd TabButton's IsSelected is changed to {args.IsSelected}.");
+            };
 
             content2 = new TextLabel()
             {
@@ -65,6 +73,10 @@ namespace Tizen.NUI.Samples
             {
                 Text = "Tab#3"
             };
+            tabButton3.SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+            {
+                global::System.Console.WriteLine($"3rd TabButton's IsSelected is changed to {args.IsSelected}.");
+            };
 
             content3 = new TextLabel()
             {
@@ -99,6 +111,12 @@ namespace Tizen.NUI.Samples
                         Text = "Tab#" + tabCount.ToString()
                     };
 
+                    int curCount = tabCount;
+                    newTabButton.SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+                    {
+                        global::System.Console.WriteLine($"{curCount}th TabButton's IsSelected is changed to {args.IsSelected}.");
+                    };
+
                     var newContent = new TextLabel()
                     {
                         Text = "Content#" + tabCount.ToString(),
index 0ddd18fecac3fb2bd6179a176c9f8146b9fe77ce..e4b2193d67718dab57690527a3e5f39aea641e9b 100755 (executable)
   <ItemGroup>
     <Compile Remove="Samples\AnimatedVectorImageViewTest.cs" />
     <Compile Remove="Samples\ButtonSample.cs" />
-    <Compile Remove="Samples\CheckBoxSample.cs" />
     <Compile Remove="Samples\DropDownSample.cs" />
     <Compile Remove="Samples\PopupSample.cs" />
-    <Compile Remove="Samples\RadioButtonSample.cs" />
     <Compile Remove="Samples\ThemeResourceSample.cs" />
   </ItemGroup>