[NUI] Add EnableBackNavigation to Page
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Controls / Navigation / Page.cs
index 983d923..f26a3a4 100755 (executable)
@@ -94,6 +94,26 @@ 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;
 
         private Navigator navigator = null;
@@ -103,6 +123,8 @@ namespace Tizen.NUI.Components
 
         private TransitionBase disappearingTransition = null;
 
+        private bool enableBackNavigation = true;
+
         /// <summary>
         /// Creates a new instance of a Page.
         /// </summary>
@@ -112,6 +134,15 @@ namespace Tizen.NUI.Components
         }
 
         /// <summary>
+        /// Creates a new instance of a Page with style.
+        /// </summary>
+        /// <param name="style">A style applied to the newly created Page.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Page(ControlStyle style) : base(style)
+        {
+        }
+
+        /// <summary>
         /// Navigator which has pushed the Page into its stack.
         /// If this Page has not been pushed into any Navigator, then Navigator is null.
         /// </summary>
@@ -213,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());
@@ -235,24 +295,29 @@ namespace Tizen.NUI.Components
 
         /// <summary>
         /// works only when DefaultAlgorithm is enabled.
-        /// to save the currentl focused View when disappeared.
+        /// to save the currently focused View when disappeared.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
         protected internal virtual void SaveKeyFocus()
         {
             if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
             {
+                if (this is DialogPage)
+                {
+                    FocusManager.Instance.ResetFocusFinderRootView();
+                }
+
                 var currentFocusedView = FocusManager.Instance.GetCurrentFocusView();
                 if (currentFocusedView)
                 {
-                    var findChild = this.FindDescendantByID(currentFocusedView.ID);
+                    var findChild = FindDescendantByID(currentFocusedView.ID);
                     if (findChild)
                     {
-                        this.LastFocusedView = findChild;
+                        LastFocusedView = findChild;
                         return;
                     }
                 }
-                this.LastFocusedView = null;
+                LastFocusedView = null;
             }
         }
 
@@ -265,9 +330,9 @@ namespace Tizen.NUI.Components
         {
             if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
             {
-                if (this.LastFocusedView)
+                if (LastFocusedView)
                 {
-                    FocusManager.Instance.SetCurrentFocusView(this.LastFocusedView);
+                    FocusManager.Instance.SetCurrentFocusView(LastFocusedView);
                 }
                 else
                 {
@@ -292,8 +357,12 @@ namespace Tizen.NUI.Components
                     temp.Unparent();
                     temp.Dispose();
                 }
-            }
 
+                if (this is DialogPage)
+                {
+                    FocusManager.Instance.SetFocusFinderRootView(this);
+                }
+            }
         }
 
     }