[NUI] Add Popped event to Navigator
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Tue, 20 Jul 2021 08:10:16 +0000 (17:10 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Wed, 21 Jul 2021 06:41:03 +0000 (15:41 +0900)
Popped event is added to Navigator.
Popped event passes Page handle popped by Navigator.

By using Popped event, for example, user can dispose the popped page.

src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/NavigatorSample.cs

index a736988..755313c 100755 (executable)
@@ -23,6 +23,19 @@ using Tizen.NUI.BaseComponents;
 namespace Tizen.NUI.Components
 {
     /// <summary>
+    /// PoppedEventArgs is a class to record popped event arguments which will be sent to user.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class PoppedEventArgs : EventArgs
+    {
+        /// <summary>
+        /// Page popped by Navigator.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Page Page { get; internal set; }
+    }
+
+    /// <summary>
     /// The Navigator is a class which navigates pages with stack methods such as Push and Pop.
     /// </summary>
     /// <remarks>
@@ -101,6 +114,13 @@ namespace Tizen.NUI.Components
         public event EventHandler<EventArgs> TransitionFinished;
 
         /// <summary>
+        /// An event fired when Pop of a page has been finished.
+        /// Notice that Popped event handler should be removed when it is called not to call it duplicate.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler<PoppedEventArgs> Popped;
+
+        /// <summary>
         /// Returns the count of pages in Navigator.
         /// </summary>
         /// <since_tizen> 9 </since_tizen>
@@ -200,6 +220,10 @@ namespace Tizen.NUI.Components
             if (navigationPages.Count == 1)
             {
                 Remove(topPage);
+
+                //Invoke Popped event
+                Popped?.Invoke(this, new PoppedEventArgs() { Page = topPage });
+
                 return topPage;
             }
             var newTopPage = navigationPages[navigationPages.Count - 2];
@@ -219,6 +243,9 @@ namespace Tizen.NUI.Components
                 //Invoke Page events
                 newTopPage.InvokeAppeared();
                 topPage.InvokeDisappeared();
+
+                //Invoke Popped event
+                Popped?.Invoke(this, new PoppedEventArgs() { Page = topPage });
             };
             transitionFinished = false;
 
@@ -319,6 +346,10 @@ namespace Tizen.NUI.Components
             if (navigationPages.Count == 1)
             {
                 Remove(curTop);
+
+                //Invoke Popped event
+                Popped?.Invoke(this, new PoppedEventArgs() { Page = curTop });
+
                 return curTop;
             }
 
@@ -344,6 +375,9 @@ namespace Tizen.NUI.Components
 
                     //Invoke Page events
                     curTop.InvokeDisappeared();
+
+                    //Invoke Popped event
+                    Popped?.Invoke(this, new PoppedEventArgs() { Page = curTop });
                 };
                 curAnimation.Play();
 
index 83ad660..a8dfb52 100644 (file)
@@ -9,6 +9,23 @@ namespace Tizen.NUI.Samples
         private ContentPage firstPage, secondPage;
         private Button firstButton, secondButton;
 
+        private void Popped(object sender, PoppedEventArgs args)
+        {
+            global::System.Console.WriteLine("Page is popped!");
+            args.page.Dispose();
+
+            if (args.page == firstPage)
+            {
+                firstPage = null;
+            }
+            else
+            {
+                secondPage = null;
+            }
+
+            navigator.Popped -= Popped;
+        }
+
         public void Activate()
         {
             Window window = NUIApplication.GetDefaultWindow();
@@ -38,6 +55,11 @@ namespace Tizen.NUI.Samples
 
             firstPage = new ContentPage()
             {
+                AppBar = new AppBar()
+                {
+                    AutoNavigationContent = false,
+                    Title = "FirstPage",
+                },
                 Content = firstButton,
             };
             firstPage.Appearing += (object sender, PageAppearingEventArgs e) =>
@@ -67,6 +89,10 @@ namespace Tizen.NUI.Samples
 
             secondPage = new ContentPage()
             {
+                AppBar = new AppBar()
+                {
+                    Title = "SecondPage",
+                },
                 Content = secondButton,
             };
             secondPage.Appearing += (object sender, PageAppearingEventArgs e) =>