[NUI] Add Window extension method GetDefaultNavigator
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Fri, 20 Nov 2020 02:53:16 +0000 (11:53 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 8 Dec 2020 06:23:12 +0000 (15:23 +0900)
To provide default navigator of window, Window extension method
GetDefaultNavigator is added.

src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs
src/Tizen.NUI.Components/Utils/NUIWindowExtensions.cs [new file with mode: 0755]

index 202554c..a75d344 100755 (executable)
@@ -37,6 +37,8 @@ namespace Tizen.NUI.Components
         //This will be replaced with view transition class instance.
         private Animation _newAnimation = null;
 
+        private static Dictionary<Window, Navigator> windowNavigator = new Dictionary<Window, Navigator>();
+
         /// <summary>
         /// Creates a new instance of a Navigator.
         /// </summary>
@@ -306,5 +308,32 @@ namespace Tizen.NUI.Components
 
             return NavigationPages[NavigationPages.Count - 1];
         }
+
+        /// <summary>
+        /// Returns the default navigator of the given window.
+        /// </summary>
+        /// <returns>The default navigator of the given window.</returns>
+        /// <exception cref="ArgumentNullException">Thrown when the argument window is null.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static Navigator GetDefaultNavigator(Window window)
+        {
+            if (window == null)
+            {
+                throw new ArgumentNullException(nameof(window), "window should not be null.");
+            }
+
+            if (windowNavigator.ContainsKey(window) == true)
+            {
+                return windowNavigator[window];
+            }
+
+            var defaultNavigator = new Navigator();
+            defaultNavigator.WidthResizePolicy = ResizePolicyType.FillToParent;
+            defaultNavigator.HeightResizePolicy = ResizePolicyType.FillToParent;
+            window.Add(defaultNavigator);
+            windowNavigator.Add(window, defaultNavigator);
+
+            return defaultNavigator;
+        }
     }
 } //namespace Tizen.NUI
diff --git a/src/Tizen.NUI.Components/Utils/NUIWindowExtensions.cs b/src/Tizen.NUI.Components/Utils/NUIWindowExtensions.cs
new file mode 100755 (executable)
index 0000000..84bf8b3
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright(c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+using System;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Components
+{
+    /// <summary>
+    /// Extension class which provides extension methods of Tizen.NUI.Window to
+    /// use Tizen.NUI.Components classes in Tizen.NUI.Window class' methods.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public static class NUIWindowExtentions
+    {
+        /// <summary>
+        /// Returns the default navigator of the given window.
+        /// </summary>
+        /// <returns>The default navigator of the given window.</returns>
+        /// <exception cref="ArgumentNullException">Thrown when the argument window is null.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static Navigator GetDefaultNavigator(this Window window)
+        {
+            return Navigator.GetDefaultNavigator(window);
+        }
+    }
+}