Revert "Revert "[NUI] Add ContentPage class""
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Wed, 14 Apr 2021 07:56:12 +0000 (16:56 +0900)
committerbshsqa <32317749+bshsqa@users.noreply.github.com>
Wed, 14 Apr 2021 11:53:58 +0000 (20:53 +0900)
This reverts commit 3a0f69a36aa1812040731237d4a9aeefd4c4a2a8.

src/Tizen.NUI.Components/Controls/Navigation/ContentPage.cs [new file with mode: 0755]
src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs
src/Tizen.NUI.Components/Controls/Navigation/Page.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/AlertDialogSample.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/AppBarSample.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/DialogSample.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/NavigatorSample.cs

diff --git a/src/Tizen.NUI.Components/Controls/Navigation/ContentPage.cs b/src/Tizen.NUI.Components/Controls/Navigation/ContentPage.cs
new file mode 100755 (executable)
index 0000000..2bcdbb8
--- /dev/null
@@ -0,0 +1,170 @@
+/*
+ * Copyright(c) 2021 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.ComponentModel;
+using Tizen.NUI.BaseComponents;
+
+namespace Tizen.NUI.Components
+{
+    /// <summary>
+    /// The ContentPage class is a class which is a formatted full screen page.
+    /// ContentPage contains title app bar and content.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class ContentPage : Page
+    {
+        private AppBar appBar = null;
+        private View content = null;
+
+        /// <summary>
+        /// Creates a new instance of a ContentPage.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public ContentPage() : base()
+        {
+            // AppBar and Content are located vertically.
+            Layout = new LinearLayout()
+            {
+                LinearOrientation = LinearLayout.Orientation.Vertical,
+            };
+
+            // ContentPage fills to parent by default.
+            WidthResizePolicy = ResizePolicyType.FillToParent;
+            HeightResizePolicy = ResizePolicyType.FillToParent;
+        }
+
+        /// <summary>
+        /// Dispose ContentPage and all children on it.
+        /// </summary>
+        /// <param name="type">Dispose type.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected override void Dispose(DisposeTypes type)
+        {
+            if (disposed)
+            {
+                return;
+            }
+
+            if (type == DisposeTypes.Explicit)
+            {
+                if (appBar != null)
+                {
+                    Utility.Dispose(appBar);
+                }
+
+                if (content != null)
+                {
+                    Utility.Dispose(content);
+                }
+            }
+
+            base.Dispose(type);
+        }
+
+        /// <summary>
+        /// AppBar of ContentPage. AppBar is added to Children automatically.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public AppBar AppBar
+        {
+            get
+            {
+                return appBar;
+            }
+            set
+            {
+                if (appBar == value)
+                {
+                    return;
+                }
+
+                if (appBar != null)
+                {
+                    Remove(appBar);
+                }
+
+                appBar = value;
+                if (appBar == null)
+                {
+                    return;
+                }
+
+                appBar.Weight = 0.0f;
+
+                ResetContent();
+            }
+        }
+
+        /// <summary>
+        /// Content of ContentPage. Content is added to Children automatically.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public View Content
+        {
+            get
+            {
+                return content;
+            }
+            set
+            {
+                if (content == value)
+                {
+                    return;
+                }
+
+                if (content != null)
+                {
+                    Remove(content);
+                }
+
+                content = value;
+                if (content == null)
+                {
+                    return;
+                }
+
+                content.Weight = 1.0f;
+
+                ResetContent();
+            }
+        }
+
+        private void ResetContent()
+        {
+            // To keep the order of AppBar and Content, the existing contents are
+            // removed and added again.
+            if ((appBar != null) && Children.Contains(appBar))
+            {
+                Remove(appBar);
+            }
+
+            if ((content != null) && Children.Contains(content))
+            {
+                Remove(content);
+            }
+
+            if (appBar != null)
+            {
+                Add(appBar);
+            }
+
+            if (content != null)
+            {
+                Add(content);
+            }
+        }
+    }
+}
index 4df540a..65105bd 100755 (executable)
@@ -232,6 +232,7 @@ namespace Tizen.NUI.Components
 
             NavigationPages.Add(page);
             Add(page);
+            page.Navigator = this;
 
             //Invoke Page events
             page.InvokeAppearing();
@@ -386,6 +387,7 @@ namespace Tizen.NUI.Components
 
             NavigationPages.Insert(index, page);
             Add(page);
+            page.Navigator = this;
         }
 
         /// <summary>
@@ -435,6 +437,7 @@ namespace Tizen.NUI.Components
                 throw new ArgumentNullException(nameof(page), "page should not be null.");
             }
 
+            page.Navigator = null;
             NavigationPages.Remove(page);
             base.Remove(page);
         }
@@ -543,7 +546,11 @@ namespace Tizen.NUI.Components
             var dialog = new Dialog(content);
             SetDialogScrim(dialog);
 
-            var dialogPage = new Page(dialog);
+            // FIXME: Needs to use DialogPage.
+            var dialogPage = new ContentPage()
+            {
+                Content = dialog,
+            };
             defaultNavigator.Push(dialogPage);
         }
 
@@ -566,7 +573,11 @@ namespace Tizen.NUI.Components
             var dialog = new AlertDialog(titleContent, content, actionContent);
             SetDialogScrim(dialog);
 
-            var dialogPage = new Page(dialog);
+            // FIXME: Needs to use DialogPage.
+            var dialogPage = new ContentPage()
+            {
+                Content = dialog,
+            };
             defaultNavigator.Push(dialogPage);
         }
 
@@ -592,7 +603,11 @@ namespace Tizen.NUI.Components
             var dialog = new AlertDialog(title, message, positiveButtonText, positiveButtonClickedHandler, negativeButtonText, negativeButtonClickedHandler);
             SetDialogScrim(dialog);
 
-            var dialogPage = new Page(dialog);
+            // FIXME: Needs to use DialogPage.
+            var dialogPage = new ContentPage()
+            {
+                Content = dialog,
+            };
             defaultNavigator.Push(dialogPage);
         }
 
index 9be8a77..5601fad 100755 (executable)
@@ -16,7 +16,6 @@
  */
 using System;
 using System.ComponentModel;
-using Tizen.NUI.BaseComponents;
 
 namespace Tizen.NUI.Components
 {
@@ -40,166 +39,37 @@ namespace Tizen.NUI.Components
     /// The Page class is a class which is an element of navigation.
     /// </summary>
     [EditorBrowsable(EditorBrowsableState.Never)]
-    public class Page : Control
+    public abstract class Page : Control
     {
-        private AppBar appBar = null;
-        private View content = null;
+        private Navigator navigator = null;
 
         /// <summary>
         /// Creates a new instance of a Page.
         /// </summary>
-        /// <param name="content">The content to set to Content of Page.</param>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public Page(View content = null) : this(null, content)
+        public Page() : base()
         {
         }
 
         /// <summary>
-        /// Creates a new instance of a Page.
-        /// </summary>
-        /// <param name="appBar">The content to set to AppBar of Page.</param>
-        /// <param name="content">The content to set to Content of Page.</param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public Page(AppBar appBar, View content = null) : base()
-        {
-            //AppBar and Content are located vertically.
-            var linearLayout = new LinearLayout();
-            linearLayout.LinearOrientation = LinearLayout.Orientation.Vertical;
-            Layout = linearLayout;
-
-            //Page fills to parent by default.
-            WidthResizePolicy = ResizePolicyType.FillToParent;
-            HeightResizePolicy = ResizePolicyType.FillToParent;
-
-            if (appBar)
-            {
-                AppBar = appBar;
-            }
-
-            if (content)
-            {
-                Content = content;
-            }
-        }
-
-        /// <summary>
-        /// Dispose Page and all children on it.
-        /// </summary>
-        /// <param name="type">Dispose type.</param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        protected override void Dispose(DisposeTypes type)
-        {
-            if (disposed)
-            {
-                return;
-            }
-
-            if (type == DisposeTypes.Explicit)
-            {
-                if (appBar != null)
-                {
-                    Utility.Dispose(appBar);
-                }
-
-                if (content != null)
-                {
-                    Utility.Dispose(content);
-                }
-            }
-
-            base.Dispose(type);
-        }
-
-        /// <summary>
-        /// AppBar of Page. AppBar is added to Children automatically.
-        /// </summary>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public AppBar AppBar
-        {
-            get
-            {
-                return appBar;
-            }
-            set
-            {
-                if (appBar == value)
-                {
-                    return;
-                }
-
-                if (appBar != null)
-                {
-                    Remove(appBar);
-                }
-
-                appBar = value;
-                if (appBar == null)
-                {
-                    return;
-                }
-
-                appBar.Weight = 0.0f;
-
-                ResetContent();
-            }
-        }
-
-        /// <summary>
-        /// Content of Page. Content is added to Children automatically.
+        /// Navigator which has pushed the Page into its stack.
+        /// If this Page has not been pushed into any Navigator, then Navigator is null.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public View Content
+        public Navigator Navigator
         {
             get
             {
-                return content;
+                return navigator;
             }
-            set
+            internal set
             {
-                if (content == value)
-                {
-                    return;
-                }
-
-                if (content != null)
-                {
-                    Remove(content);
-                }
-
-                content = value;
-                if (content == null)
+                if (navigator == value)
                 {
                     return;
                 }
 
-                content.Weight = 1.0f;
-
-                ResetContent();
-            }
-        }
-
-        private void ResetContent()
-        {
-            //To keep the order of AppBar and Content, the existing contents are
-            //removed and added again.
-            if ((appBar != null) && Children.Contains(appBar))
-            {
-                Remove(appBar);
-            }
-
-            if ((content != null) && Children.Contains(content))
-            {
-                Remove(content);
-            }
-
-            if (appBar != null)
-            {
-                Add(appBar);
-            }
-
-            if (content != null)
-            {
-                Add(content);
+                navigator = value;
             }
         }
 
index 5f6c536..a29559b 100755 (executable)
@@ -27,7 +27,11 @@ namespace Tizen.NUI.Samples
                     "No", (object sender2, ClickedEventArgs e2) => { window.GetDefaultNavigator().Pop(); });
             };
 
-            window.GetDefaultNavigator().Push(new Page(button));
+            var dialogPage = new ContentPage()
+            {
+                Content = button,
+            };
+            window.GetDefaultNavigator().Push(dialogPage);
         }
 
         public void Deactivate()
index e0584d9..4e85182 100755 (executable)
@@ -5,7 +5,7 @@ namespace Tizen.NUI.Samples
 {
     public class AppBarSample : IExample
     {
-        private Page firstPage, secondPage;
+        private ContentPage firstPage, secondPage;
         private AppBar firstAppBar, secondAppBar;
         private Button firstActionButton, secondActionButton;
         private Button firstButton, secondButton;
@@ -44,7 +44,11 @@ namespace Tizen.NUI.Samples
                 CreateSecondPage();
             };
 
-            firstPage = new Page(firstAppBar, firstButton);
+            firstPage = new ContentPage()
+            {
+                AppBar = firstAppBar,
+                Content = firstButton,
+            };
 
             NUIApplication.GetDefaultWindow().GetDefaultNavigator().Push(firstPage);
         }
@@ -75,7 +79,11 @@ namespace Tizen.NUI.Samples
                 NUIApplication.GetDefaultWindow().GetDefaultNavigator().Pop();
             };
 
-            secondPage = new Page(secondAppBar, secondButton);
+            secondPage = new ContentPage()
+            {
+                AppBar = secondAppBar,
+                Content = secondButton,
+            };
 
             NUIApplication.GetDefaultWindow().GetDefaultNavigator().Push(secondPage);
         }
index 812d556..4cc24b6 100755 (executable)
@@ -33,7 +33,11 @@ namespace Tizen.NUI.Samples
                 Navigator.ShowDialog(textLabel);
             };
 
-            window.GetDefaultNavigator().Push(new Page(button));
+            var dialogPage = new ContentPage()
+            {
+                Content = button,
+            };
+            window.GetDefaultNavigator().Push(dialogPage);
         }
 
         public void Deactivate()
index 6eea4be..83ad660 100755 (executable)
@@ -6,7 +6,7 @@ namespace Tizen.NUI.Samples
     public class NavigatorSample : IExample
     {
         private Navigator navigator;
-        private Page firstPage, secondPage;
+        private ContentPage firstPage, secondPage;
         private Button firstButton, secondButton;
 
         public void Activate()
@@ -36,7 +36,10 @@ namespace Tizen.NUI.Samples
                 CreateSecondPage();
             };
 
-            firstPage = new Page(firstButton);
+            firstPage = new ContentPage()
+            {
+                Content = firstButton,
+            };
             firstPage.Appearing += (object sender, PageAppearingEventArgs e) =>
             {
                 global::System.Console.WriteLine("First Page is appearing!");
@@ -62,7 +65,10 @@ namespace Tizen.NUI.Samples
                 navigator.Pop();
             };
 
-            secondPage = new Page(secondButton);
+            secondPage = new ContentPage()
+            {
+                Content = secondButton,
+            };
             secondPage.Appearing += (object sender, PageAppearingEventArgs e) =>
             {
                 global::System.Console.WriteLine("Second Page is appearing!");