From: Jaehyun Cho Date: Wed, 23 Nov 2022 07:51:49 +0000 (+0900) Subject: [NUI] Add EnableBackNavigation to Navigator X-Git-Tag: submit/tizen_7.0/20230310.150933~1^2~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=854e902c42ff272821393397b693307969cbf3b9;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] Add EnableBackNavigation to Navigator To support back navigation automatically, EnableBackNavigation is added to Navigator. If EnabledBackNavigation is false, then back button and back key do not cause back navigation. --- diff --git a/src/Tizen.NUI.Components/Controls/Navigation/AppBar.cs b/src/Tizen.NUI.Components/Controls/Navigation/AppBar.cs index f7532ba..425c1e1 100755 --- a/src/Tizen.NUI.Components/Controls/Navigation/AppBar.cs +++ b/src/Tizen.NUI.Components/Controls/Navigation/AppBar.cs @@ -672,8 +672,8 @@ namespace Tizen.NUI.Components var page = GetParent() as Page; if (page != null) { - var navigator = page.GetParent() as Navigator; - if (navigator != null) + var navigator = page.Navigator; + if ((navigator != null) && (navigator.EnableBackNavigation)) { navigator.Pop(); } diff --git a/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs b/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs index 998ce03..b86a0d4 100755 --- a/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs +++ b/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs @@ -92,6 +92,24 @@ namespace Tizen.NUI.Components return instance.InternalTransition; }); + /// + /// EnableBackNavigationProperty + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static readonly BindableProperty EnableBackNavigationProperty = BindableProperty.Create(nameof(EnableBackNavigation), typeof(bool), typeof(Navigator), default(bool), propertyChanged: (bindable, oldValue, newValue) => + { + var instance = (Navigator)bindable; + if (newValue != null) + { + instance.InternalEnableBackNavigation = (bool)newValue; + } + }, + defaultValueCreator: (bindable) => + { + var instance = (Navigator)bindable; + return instance.InternalEnableBackNavigation; + }); + private const int DefaultTransitionDuration = 300; //This will be replaced with view transition class instance. @@ -117,9 +135,45 @@ namespace Tizen.NUI.Components private List navigationPages = new List(); + private bool enableBackNavigation = true; + + private Window parentWindow; + + private void OnWindowKeyEvent(object sender, Window.KeyEventArgs e) + { + if (!EnableBackNavigation) + { + return; + } + + 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(); + } + } + } + + private void OnAddedToWindow(object sender, EventArgs e) + { + parentWindow = Window.Get(this); + parentWindow.KeyEvent += OnWindowKeyEvent; + } + + private void OnRemovedFromWindow(object sender, EventArgs e) + { + parentWindow.KeyEvent -= OnWindowKeyEvent; + parentWindow = null; + } + private void Initialize() { Layout = new AbsoluteLayout(); + + AddedToWindow += OnAddedToWindow; + RemovedFromWindow += OnRemovedFromWindow; } /// @@ -466,6 +520,7 @@ namespace Tizen.NUI.Components { //Removes the current top page after transition is finished. Remove(curTop); + curTop.PositionX = 0.0f; //Invoke Page events @@ -708,6 +763,35 @@ namespace Tizen.NUI.Components } /// + /// Gets or sets if Navigator pops the peek page 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; + } + } + + /// /// Disposes Navigator and all children on it. /// /// Dispose type. @@ -734,6 +818,9 @@ namespace Tizen.NUI.Components navigatorWindow.Remove(this); windowNavigator.Remove(window); } + + AddedToWindow -= OnAddedToWindow; + RemovedFromWindow -= OnRemovedFromWindow; } base.Dispose(type);