[NUI] Add SetDefaultNavigator
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Mon, 28 Nov 2022 08:25:27 +0000 (17:25 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 6 Dec 2022 08:08:09 +0000 (17:08 +0900)
To use customized Navigator as default navigator, SetDefaultNavigator
is added.

src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs
src/Tizen.NUI.Components/Utils/NUIWindowExtensions.cs

index f5f65e2..e483a2a 100755 (executable)
@@ -841,6 +841,43 @@ namespace Tizen.NUI.Components
         }
 
         /// <summary>
+        /// Sets the default navigator of the given window.
+        /// SetDefaultNavigator does not remove the previous default navigator from the window.
+        /// Therefore, if a user does not want to show the previous default navigator, then it should be removed from the window manually.
+        /// </summary>
+        /// <exception cref="ArgumentNullException">Thrown when the argument window is null.</exception>
+        /// <exception cref="ArgumentNullException">Thrown when the argument newNavigator is null.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void SetDefaultNavigator(Window window, Navigator newNavigator)
+        {
+            if (window == null)
+            {
+                throw new ArgumentNullException(nameof(window), "window should not be null.");
+            }
+
+            if (newNavigator == null)
+            {
+                throw new ArgumentNullException(nameof(newNavigator), "newNavigator should not be null.");
+            }
+
+            if (windowNavigator.ContainsKey(window) == true)
+            {
+                var oldNavigator = windowNavigator[window];
+                if (oldNavigator == newNavigator)
+                {
+                    return;
+                }
+
+                navigatorWindow.Remove(oldNavigator);
+                windowNavigator.Remove(window);
+            }
+
+            window.Add(newNavigator);
+            windowNavigator.Add(window, newNavigator);
+            navigatorWindow.Add(newNavigator, window);
+        }
+
+        /// <summary>
         /// Called when the back navigation is started.
         /// </summary>
         /// <param name="eventArgs">The back navigation information.</param>
index 84bf8b3..7e113a0 100755 (executable)
@@ -37,5 +37,15 @@ namespace Tizen.NUI.Components
         {
             return Navigator.GetDefaultNavigator(window);
         }
+
+        /// <summary>
+        /// Sets the default navigator of the given window.
+        /// </summary>
+        /// <exception cref="ArgumentNullException">Thrown when the argument window is null.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void SetDefaultNavigator(this Window window, Navigator navigator)
+        {
+            Navigator.SetDefaultNavigator(window, navigator);
+        }
     }
 }