[NUI] Add EnableBackNavigation to Page
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Mon, 28 Nov 2022 08:40:06 +0000 (17:40 +0900)
committerJaehyun Cho <jaehyun0cho@gmail.com>
Fri, 10 Mar 2023 07:00:48 +0000 (16:00 +0900)
To support back navigation automatically, EnableBackNavigation is
added to Page like Navigator.
If EnabledBackNavigation is false, then back button and back key do
not cause back navigation on the page.

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

index 653eb21..289e26b 100755 (executable)
@@ -894,7 +894,7 @@ namespace Tizen.NUI.Components
         [EditorBrowsable(EditorBrowsableState.Never)]
         protected virtual void OnBackNavigation(BackNavigationEventArgs eventArgs)
         {
-            if (PageCount >= 1)
+            if ((PageCount >= 1) && Peek().EnableBackNavigation)
             {
                 Tizen.Log.Info("NUI", $"Navigator pops the peek page.\n");
                 Pop();
index f071859..6bd365d 100755 (executable)
@@ -94,6 +94,24 @@ namespace Tizen.NUI.Components
             return instance.InternalDisappearingTransition;
         });
 
+        /// <summary>
+        /// EnableBackNavigationProperty
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static readonly BindableProperty EnableBackNavigationProperty = BindableProperty.Create(nameof(EnableBackNavigation), typeof(bool), typeof(Page), default(bool), propertyChanged: (bindable, oldValue, newValue) =>
+        {
+            var instance = (Page)bindable;
+            if (newValue != null)
+            {
+                instance.InternalEnableBackNavigation = (bool)newValue;
+            }
+        },
+        defaultValueCreator: (bindable) =>
+        {
+            var instance = (Page)bindable;
+            return instance.InternalEnableBackNavigation;
+        });
+
         /// <inheritdoc/>
         [EditorBrowsable(EditorBrowsableState.Never)]
         protected internal BaseComponents.View LastFocusedView = null;
@@ -105,6 +123,8 @@ namespace Tizen.NUI.Components
 
         private TransitionBase disappearingTransition = null;
 
+        private bool enableBackNavigation = true;
+
         /// <summary>
         /// Creates a new instance of a Page.
         /// </summary>
@@ -233,6 +253,35 @@ namespace Tizen.NUI.Components
         /// <since_tizen> 9 </since_tizen>
         public event EventHandler<PageDisappearedEventArgs> Disappeared;
 
+        /// <summary>
+        /// Gets or sets if this page is popped when back button or back key is pressed and released.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool EnableBackNavigation
+        {
+            get
+            {
+                return (bool)GetValue(EnableBackNavigationProperty);
+            }
+            set
+            {
+                SetValue(EnableBackNavigationProperty, value);
+                NotifyPropertyChanged();
+            }
+        }
+
+        private bool InternalEnableBackNavigation
+        {
+            set
+            {
+                enableBackNavigation = value;
+            }
+            get
+            {
+                return enableBackNavigation;
+            }
+        }
+
         internal void InvokeAppearing()
         {
             Appearing?.Invoke(this, new PageAppearingEventArgs());
@@ -323,7 +372,6 @@ namespace Tizen.NUI.Components
                     FocusManager.Instance.SetFocusFinderRootView(this);
                 }
             }
-
         }
 
     }