update navigate-to method
authorYurii Zinchuk/Tizen Services & IoT (PLT) /SRPOL/Engineer/Samsung Electronics <y.zinchuk@samsung.com>
Thu, 29 Jun 2023 07:57:27 +0000 (09:57 +0200)
committerYurii Zinchuk/Tizen Services & IoT (PLT) /SRPOL/Engineer/Samsung Electronics <y.zinchuk@samsung.com>
Fri, 30 Jun 2023 09:56:54 +0000 (11:56 +0200)
SettingCore/GadgetNavigation.cs

index 0a6a4c8874c41f32c02f78e62d20d6f65bfbdc0b..d74d0f2cdf6cc4d1b130ebe4399a22ca50a63f6c 100644 (file)
@@ -45,8 +45,6 @@ namespace SettingCore
                 }
                 NUIApplication.GetDefaultWindow().GetDefaultNavigator().EnableBackNavigation = true;
             };
-
-            NUIApplication.GetDefaultWindow().KeyEvent += GadgetNavigation_KeyEvent;
         }
 
         public static void SetFullScreenMode(bool fullScreen)
@@ -71,35 +69,49 @@ namespace SettingCore
 
         public static void NavigateTo(string menuPath)
         {
-            semaphore.Wait();
-
-            var info = GadgetManager.Instance.GetGadgetInfoFromPath(menuPath);
-            if (info == null)
+            try
             {
-                Logger.Warn($"could not find gadget for menupath: {menuPath}");
-                semaphore.Release();
-                return;
-            }
+                semaphore.Wait();
 
-            if (gadgetPages.Values.Select(x => x.ClassName).Contains(info.ClassName))
-            {
-                Logger.Verbose($"Already navigated to menupath: {menuPath}");
-                semaphore.Release();
-                return;
-            }
+                var info = GadgetManager.Instance.GetGadgetInfoFromPath(menuPath);
+                if (info == null)
+                {
+                    Logger.Warn($"could not find gadget for menupath: {menuPath}");
+                    return;
+                }
 
-            try
-            {
-                var gadget = NUIGadgetManager.Add(info.Pkg.ResourceType, info.ClassName) as MenuGadget;
+                if (gadgetPages.Values.Select(x => x.ClassName).Contains(info.ClassName))
+                {
+                    Logger.Verbose($"Already navigated to menupath: {menuPath}");
+                    return;
+                }
 
+                var gadget = NUIGadgetManager.Add(info.Pkg.ResourceType, info.ClassName) as MenuGadget;
                 var title = gadget.ProvideTitle();
                 var content = gadget.MainView;
 
+                if (info.IsFullScreenMode)
+                {
+                    SetFullScreenMode(true);
+
+                    var contentPage = new ContentPage
+                    {
+                        CornerRadius = 0.SpToPx(),
+                        Content = content,
+                        ThemeChangeSensitive = true,
+                    };
+
+                    NUIApplication.GetDefaultWindow().GetDefaultNavigator().PushWithTransition(contentPage);
+                    gadgetPages.Add(contentPage, gadget);
+                    return;
+                }
+
                 // TODO: remove style customization with scalable unit, when merged to TizenFX
                 var appBarStyle = ThemeManager.GetStyle("Tizen.NUI.Components.AppBar") as AppBarStyle;
                 appBarStyle.TitleTextLabel.PixelSize = 24f.SpToPx();
 
-                var backButton = new Views.BackButton();            
+                var backButton = new BackButton();
+                backButton.Margin = new Extents(0, 8, 0, 0).SpToPx();
                 backButton.Clicked += (s, e) => NavigateBack();
 
                 var moreItems = new List<View>();
@@ -116,52 +128,34 @@ namespace SettingCore
                     moreItems.Add(moreButton);
                 }
 
-                if (info.IsFullScreenMode)
-                {
-                    SetFullScreenMode(true);
-
-                    var contentPage = new ContentPage
-                    {
-                        CornerRadius = 0.SpToPx(),
-                        Content = content,
-                        ThemeChangeSensitive = true,
-                    };
-
-                    NUIApplication.GetDefaultWindow().GetDefaultNavigator().PushWithTransition(contentPage);
-                    gadgetPages.Add(contentPage, gadget);
-                }
-                else
+                var page = new BaseContentPage
                 {
-                    backButton.Margin = new Extents(0, 8, 0, 0).SpToPx();
-
-                    var page = new BaseContentPage
+                    // TODO: CornerRadius depends on SettingViewBorder.CornerRadius - SettingViewBorder.BorderLineThickness, which is defined at SettingView project.
+                    CornerRadius = (26.0f - 6.0f).SpToPx(),
+                    ClippingMode = ClippingModeType.ClipChildren,
+                    AppBar = new AppBar(appBarStyle)
                     {
-                        // TODO: CornerRadius depends on SettingViewBorder.CornerRadius - SettingViewBorder.BorderLineThickness, which is defined at SettingView project.
-                        CornerRadius = (26.0f - 6.0f).SpToPx(),
-                        ClippingMode = ClippingModeType.ClipChildren,
-                        AppBar = new AppBar(appBarStyle)
-                        {
-                            Size = new Size(-1, 64).SpToPx(),
-                            Title = title,
-                            NavigationContent = backButton,
-                            ThemeChangeSensitive = true,
-                        },
-                        Content = content,
+                        Size = new Size(-1, 64).SpToPx(),
+                        Title = title,
+                        NavigationContent = backButton,
                         ThemeChangeSensitive = true,
-                    };
-
-                    page.AppBar.Actions = moreItems;
+                        Actions = moreItems,
+                    },
+                    Content = content,
+                    ThemeChangeSensitive = true,
+                };
 
-                    NUIApplication.GetDefaultWindow().GetDefaultNavigator().Push(page);
-                    gadgetPages.Add(page, gadget);
-                }
+                NUIApplication.GetDefaultWindow().GetDefaultNavigator().Push(page);
+                gadgetPages.Add(page, gadget);
             }
-            catch (System.Exception e) // TODO: add separate catch blocks for specific exceptions?
+            catch (Exception e)
             {
                 Logger.Error($"could not create gadget for menu path: {menuPath} => {e}");
             }
-
-            semaphore.Release();
+            finally
+            {
+                semaphore.Release();
+            }
         }
 
         private static Button GetMoreButton(IEnumerable<MoreMenuItem> moreMenu)
@@ -217,26 +211,5 @@ namespace SettingCore
 
             return moreButton;
         }
-
-        private static void GadgetNavigation_KeyEvent(object sender, Window.KeyEventArgs e)
-        {
-            if (NUIApplication.GetDefaultWindow().GetDefaultNavigator().ChildCount == 1)
-            {
-                return;
-            }
-
-            if (e.Key.State == Key.StateType.Down && e.Key.KeyPressedName == "XF86Back")
-            {
-                NUIApplication.GetDefaultWindow().GetDefaultNavigator().EnableBackNavigation = false;
-            }
-            else if (e.Key.State == Key.StateType.Up && e.Key.KeyPressedName == "XF86Back")
-            {
-                NavigateBack();
-            }
-            else
-            {
-                NUIApplication.GetDefaultWindow().GetDefaultNavigator().EnableBackNavigation = true;
-            }
-        }
     }
 }