From a28ef5bb503e5afea4324414cb7ff24577902832 Mon Sep 17 00:00:00 2001 From: Jaehyun Cho Date: Mon, 28 Nov 2022 17:40:06 +0900 Subject: [PATCH] [NUI] Add EnableBackNavigation to Page 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. --- .../Controls/Navigation/Navigator.cs | 2 +- .../Controls/Navigation/Page.cs | 50 +++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs b/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs index 653eb21..289e26b 100755 --- a/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs +++ b/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs @@ -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(); diff --git a/src/Tizen.NUI.Components/Controls/Navigation/Page.cs b/src/Tizen.NUI.Components/Controls/Navigation/Page.cs index f071859..6bd365d 100755 --- a/src/Tizen.NUI.Components/Controls/Navigation/Page.cs +++ b/src/Tizen.NUI.Components/Controls/Navigation/Page.cs @@ -94,6 +94,24 @@ namespace Tizen.NUI.Components return instance.InternalDisappearingTransition; }); + /// + /// EnableBackNavigationProperty + /// + [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; + }); + /// [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; + /// /// Creates a new instance of a Page. /// @@ -233,6 +253,35 @@ namespace Tizen.NUI.Components /// 9 public event EventHandler Disappeared; + /// + /// Gets or sets if this page is popped when back button or back key is pressed and released. + /// + [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); } } - } } -- 2.7.4