[NUI] Add EnableBackNavigation to Page
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Mon, 28 Nov 2022 08:40:06 +0000 (17:40 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 6 Dec 2022 08:08:09 +0000 (17:08 +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 e483a2a..e452a6c 100755 (executable)
@@ -884,7 +884,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 e2227c4..f26a3a4 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>
@@ -224,6 +244,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());
@@ -314,7 +363,6 @@ namespace Tizen.NUI.Components
                     FocusManager.Instance.SetFocusFinderRootView(this);
                 }
             }
-
         }
 
     }