[NUI] Add OnBackNavigation to Navigator
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Fri, 25 Nov 2022 08:18:16 +0000 (17:18 +0900)
committerJaehyun Cho <jaehyun0cho@gmail.com>
Fri, 10 Mar 2023 07:00:48 +0000 (16:00 +0900)
To enable customization of back navigation, OnBackNavigation is added
to Navigator.
e.g.
class CustomNavigator : Navigator
{
    protected override OnBackNavigation(BackNavigationEventArgs args)
    {
        // Do something when back navigation is started.
        ...

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

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

index 425c1e1..de632cd 100755 (executable)
@@ -675,7 +675,7 @@ namespace Tizen.NUI.Components
                     var navigator = page.Navigator;
                     if ((navigator != null) && (navigator.EnableBackNavigation))
                     {
-                        navigator.Pop();
+                        navigator.NavigateBack();
                     }
                 }
             };
index b86a0d4..c17cfe8 100755 (executable)
@@ -148,11 +148,7 @@ namespace Tizen.NUI.Components
 
             if ((e.Key.State == Key.StateType.Up) && ((e.Key.KeyPressedName == "Escape") || (e.Key.KeyPressedName == "BackSpace") || (e.Key.KeyPressedName == "XF86Back")))
             {
-                if (PageCount >= 1)
-                {
-                    Tizen.Log.Info("NUI", $"Navigator pops the peek page by {e.Key.KeyPressedName}.\n");
-                    Pop();
-                }
+                OnBackNavigation(new BackNavigationEventArgs());
             }
         }
 
@@ -855,6 +851,28 @@ 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(BackNavigationEventArgs eventArgs)
+        {
+            if (PageCount >= 1)
+            {
+                Tizen.Log.Info("NUI", $"Navigator pops the peek page.\n");
+                Pop();
+            }
+        }
+
+        /// <summary>
+        /// Called when the back navigation is required outside Navigator.
+        /// </summary>
+        internal void NavigateBack()
+        {
+            OnBackNavigation(new BackNavigationEventArgs());
+        }
+
+        /// <summary>
         /// Create Transitions between currentTopPage and newTopPage
         /// </summary>
         /// <param name="currentTopPage">The top page of Navigator.</param>
@@ -1051,4 +1069,12 @@ namespace Tizen.NUI.Components
             }
         }
     }
+
+    /// <summary>
+    /// BackNavigationEventArgs is a class to record back navigation event arguments which will sent to user.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class BackNavigationEventArgs : EventArgs
+    {
+    }
 }