[NUI] Add OnBackNavigation to Navigator
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Fri, 25 Nov 2022 08:18:16 +0000 (17:18 +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, 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 6db2566..f5f65e2 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());
             }
         }
 
@@ -845,6 +841,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>
@@ -1041,4 +1059,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
+    {
+    }
 }