[NUI] Add OnBackNavigation to Page
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Mon, 28 Nov 2022 11:36:53 +0000 (20:36 +0900)
committerJaehyun Cho <jaehyun0cho@gmail.com>
Fri, 10 Mar 2023 07:00:48 +0000 (16:00 +0900)
To enable customization of back navigation per page, OnBackNavigation
is added to Page.
e.g.
class CustomPage : Page
{
    protected override OnBackNavigation(PageBackNavigationEventArgs args)
    {
        // Do something when back navigation is started.
        ...

        // To pop this page, call base.OnBackNavigation().
        // Otherwise, do not call base.OnBackNavigation().
        base.OnBackNavigation(args);
    }
}

src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs
src/Tizen.NUI.Components/Controls/Navigation/Page.cs

index 289e26bda5a3f44c9c39b08bdb224122b59fc2e6..39a8e0922357a6e7bbcb5b181cdfa30f58f170c2 100755 (executable)
@@ -894,10 +894,12 @@ namespace Tizen.NUI.Components
         [EditorBrowsable(EditorBrowsableState.Never)]
         protected virtual void OnBackNavigation(BackNavigationEventArgs eventArgs)
         {
-            if ((PageCount >= 1) && Peek().EnableBackNavigation)
+            if (PageCount >= 1)
             {
-                Tizen.Log.Info("NUI", $"Navigator pops the peek page.\n");
-                Pop();
+                if (Peek().EnableBackNavigation)
+                {
+                    Peek().NavigateBack();
+                }
             }
         }
 
index 6bd365d84004c815b53a0fa2ece12558264f8dd3..f4d1bdeec3f648f1df66c063bd50c7f1283d47bf 100755 (executable)
@@ -374,5 +374,30 @@ namespace Tizen.NUI.Components
             }
         }
 
+        /// <summary>
+        /// Called when the back navigation is started.
+        /// </summary>
+        /// <param name="eventArgs">The back navigation information.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected virtual void OnBackNavigation(PageBackNavigationEventArgs eventArgs)
+        {
+            Navigator.Pop();
+        }
+
+        /// <summary>
+        /// Called when the back navigation is required outside Navigator.
+        /// </summary>
+        internal void NavigateBack()
+        {
+            OnBackNavigation(new PageBackNavigationEventArgs());
+        }
+    }
+
+    /// <summary>
+    /// PageBackNavigationEventArgs is a class to record back navigation event arguments which will sent to user.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class PageBackNavigationEventArgs : EventArgs
+    {
     }
 }