[NUI] Add OnBackNavigation to Page
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Mon, 28 Nov 2022 11:36:53 +0000 (20:36 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 6 Dec 2022 08:08:09 +0000 (17:08 +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 e452a6c..0f9d047 100755 (executable)
@@ -884,10 +884,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 f26a3a4..287d8d8 100755 (executable)
@@ -365,5 +365,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
+    {
     }
 }