[NUI] Fix StyleGuide examples (#4178)
authorSeoyeon2Kim <34738918+Seoyeon2Kim@users.noreply.github.com>
Thu, 28 Apr 2022 05:58:56 +0000 (14:58 +0900)
committerTaehyub Kim <taehyub.kim@samsung.com>
Tue, 3 May 2022 09:00:21 +0000 (02:00 -0700)
- `MenuItem` : Need to call Dispose() for all items when the app disposes
- `ScrollableBase` : All items should get focused
- `Switch` : Feedback property is only for mobile target

Signed-off-by: Seoyeon Kim <seoyeon2.kim@samsung.com>
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/MenuSample.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/SwitchSample.cs
test/Tizen.NUI.StyleGuide/Examples/MenuExample.cs
test/Tizen.NUI.StyleGuide/Examples/ScrollableBase/ScrollableBaseDirectionExample.cs
test/Tizen.NUI.StyleGuide/Examples/ScrollableBase/ScrollableBaseExample.cs
test/Tizen.NUI.StyleGuide/Examples/SwitchExample.cs

index 478d305..6f41cce 100755 (executable)
@@ -6,6 +6,7 @@ namespace Tizen.NUI.Samples
     public class MenuSample : IExample
     {
         private static readonly int itemCount = 20;
+        private MenuItem[] menuItems = new MenuItem[itemCount];
 
         public void Activate()
         {
@@ -39,8 +40,6 @@ namespace Tizen.NUI.Samples
             };
             navigator.Push(page);
 
-            MenuItem[] menuItems = new MenuItem[itemCount];
-
             for (int i = 0; i < itemCount; i++)
             {
                 menuItems[i] = new MenuItem() { Text = "Menu" + (i + 1) };
@@ -66,6 +65,15 @@ namespace Tizen.NUI.Samples
 
         public void Deactivate()
         {
+            for (int i = 0; i < itemCount; i++)
+            {
+                if (menuItems[i] != null)
+                {
+                    menuItems[i].Dispose();
+                    menuItems[i] = null;
+                }
+            }
+
             var window = NUIApplication.GetDefaultWindow();
             var navigator = window.GetDefaultNavigator();
             var newPageCount = window.GetDefaultNavigator().PageCount;
index cad4b99..adc0539 100755 (executable)
@@ -225,7 +225,9 @@ namespace Tizen.NUI.Samples
                 utilitySwitch[i].ApplyStyle(utilitySt);
                 utilitySwitch[i].Size = new Size(96, 60);
                 utilitySwitch[i].Margin = new Extents(100, 0, 20, 0);
+#if PROFILE_MOBILE
                 utilitySwitch[i].Feedback = true;
+#endif
                 parentView[2].Add(utilitySwitch[i]);
             }
             for (i = 0; i < 4; i++)
@@ -233,7 +235,9 @@ namespace Tizen.NUI.Samples
                 familySwitch[i] = new Switch();
                 familySwitch[i].ApplyStyle(familySt);
                 familySwitch[i].Size = new Size(96, 60);
+#if PROFILE_MOBILE
                 familySwitch[i].Feedback = true;
+#endif
                 parentView[2].Add(familySwitch[i]);
             }
             for (i = 0; i < 4; i++)
@@ -241,7 +245,9 @@ namespace Tizen.NUI.Samples
                 foodSwitch[i] = new Switch();
                 foodSwitch[i].ApplyStyle(foodSt);
                 foodSwitch[i].Size = new Size(96, 60);
+#if PROFILE_MOBILE
                 foodSwitch[i].Feedback = true;
+#endif
                 parentView[2].Add(foodSwitch[i]);
             }
             for (i = 0; i < 4; i++)
@@ -249,7 +255,9 @@ namespace Tizen.NUI.Samples
                 kitchenSwitch[i] = new Switch();
                 kitchenSwitch[i].ApplyStyle(kitchenSt);
                 kitchenSwitch[i].Size = new Size(96, 60);
+#if PROFILE_MOBILE
                 kitchenSwitch[i].Feedback = true;
+#endif
                 parentView[2].Add(kitchenSwitch[i]);
             }
 
@@ -259,7 +267,9 @@ namespace Tizen.NUI.Samples
                 utilitySwitch2[i] = new Switch();
                 utilitySwitch2[i].ApplyStyle(utilitySt);
                 utilitySwitch2[i].Size = new Size(96, 60);
+#if PROFILE_MOBILE
                 utilitySwitch2[i].Feedback = true;
+#endif
                 parentView[2].Add(utilitySwitch2[i]);
             }
             for (i = 0; i < 4; i++)
@@ -267,7 +277,9 @@ namespace Tizen.NUI.Samples
                 familySwitch2[i] = new Switch();
                 familySwitch2[i].ApplyStyle(familySt);
                 familySwitch2[i].Size = new Size(96, 60);
+#if PROFILE_MOBILE
                 familySwitch2[i].Feedback = true;
+#endif
                 parentView[2].Add(familySwitch2[i]);
             }
             for (i = 0; i < 4; i++)
@@ -275,7 +287,9 @@ namespace Tizen.NUI.Samples
                 foodSwitch2[i] = new Switch();
                 foodSwitch2[i].ApplyStyle(foodSt);
                 foodSwitch2[i].Size = new Size(96, 60);
+#if PROFILE_MOBILE
                 foodSwitch2[i].Feedback = true;
+#endif
                 parentView[2].Add(foodSwitch2[i]);
             }
             for (i = 0; i < 4; i++)
@@ -283,7 +297,9 @@ namespace Tizen.NUI.Samples
                 kitchenSwitch2[i] = new Switch();
                 kitchenSwitch2[i].ApplyStyle(kitchenSt);
                 kitchenSwitch2[i].Size = new Size(96, 60);
+#if PROFILE_MOBILE
                 kitchenSwitch2[i].Feedback = true;
+#endif
                 parentView[2].Add(kitchenSwitch2[i]);
             }
 
index 33ff808..fb401e8 100644 (file)
@@ -26,11 +26,27 @@ namespace Tizen.NUI.StyleGuide
     internal class MenuExample : ContentPage, IExample
     {
         private View rootContent;
+        private MenuItem[] menuItem = new MenuItem[4];
+
         public void Activate()
         {
         }
         public void Deactivate()
         {
+            for (int i = 0; i < 4; i++)
+            {
+                if (menuItem[i] != null)
+                {
+                    menuItem[i].Dispose();
+                    menuItem[i] = null;
+                }
+            }
+
+            if (rootContent != null)
+            {
+                rootContent.Dispose();
+                rootContent = null;
+            }
         }
 
         /// Modify this method for adding other examples.
@@ -92,29 +108,16 @@ namespace Tizen.NUI.StyleGuide
 
             rootContent.Add(page);
 
-            var menuItem = new MenuItem() { Text = "Menu" };
-            menuItem.SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+            for (int i = 0; i < 4; i++)
             {
-                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}.");
-            };
+                menuItem[i] = new MenuItem();
+                menuItem[i].Text = "Menu" + (i + 1);
+                menuItem[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
+                {
+                    var item = sender as MenuItem;
+                    global::System.Console.WriteLine(item.Text + $"'s IsSelected is changed to {args.IsSelected}.");
+                };
+            }
 
             moreButton.Clicked += (object sender, ClickedEventArgs args) =>
             {
@@ -123,7 +126,7 @@ namespace Tizen.NUI.StyleGuide
                     Anchor = moreButton,
                     HorizontalPositionToAnchor = Menu.RelativePosition.Center,
                     VerticalPositionToAnchor = Menu.RelativePosition.End,
-                    Items = new MenuItem[] { menuItem, menuItem2, menuItem3, menuItem4 },
+                    Items = new MenuItem[] { menuItem[0], menuItem[1], menuItem[2], menuItem[3] },
                 };
                 menu.Post();
             };
index 610d0ab..bdcacfb 100644 (file)
@@ -81,10 +81,12 @@ namespace Tizen.NUI.StyleGuide
                 colorView.WidthSpecification = (isHorizontal? 200 : LayoutParamPolicies.MatchParent);
                 colorView.HeightSpecification = (isHorizontal? LayoutParamPolicies.MatchParent : 200);
                 colorView.BackgroundColor = new Color((float)rnd.Next(256)/256f, (float)rnd.Next(256)/256f, (float)rnd.Next(256)/256f, 1);
+                colorView.Focusable = true;
+                colorView.FocusableInTouch = true;
                 scrollView.Add(colorView);
             }
 
             Content = scrollView;
         }
     }
-}
\ No newline at end of file
+}
index 1208fd8..022462e 100644 (file)
@@ -73,6 +73,8 @@ namespace Tizen.NUI.StyleGuide
                     };
                     item.Label.SetBinding(TextLabel.TextProperty, "Direction");
                     item.Label.HorizontalAlignment = HorizontalAlignment.Begin;
+                    item.Focusable = true;
+                    item.FocusableInTouch = true;
                     return item;
                 }),
                 ScrollingDirection = ScrollableBase.Direction.Vertical,
index 75379f6..90a6de0 100644 (file)
@@ -111,7 +111,9 @@ namespace Tizen.NUI.StyleGuide
                 switchTest[i].ApplyStyle(styleTest);
                 switchTest[i].Size = new Size(200, 100);
                 switchTest[i].Margin = new Extents(10, 10, 10, 10);
+#if PROFILE_MOBILE
                 switchTest[i].Feedback = true;
+#endif
                 rootContent.Add(switchTest[i]);
             }
             switchTest[2].IsEnabled = false;