2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.ComponentModel;
19 using Tizen.NUI.Binding;
21 namespace Tizen.NUI.Components
24 /// PageAppearingEventArgs is a class to record <see cref="Page.Appearing"/> event arguments which will be sent to user.
26 /// <since_tizen> 9 </since_tizen>
27 public class PageAppearingEventArgs : EventArgs
32 /// PageDisappearingEventArgs is a class to record <see cref="Page.Disappearing"/> event arguments which will be sent to user.
34 /// <since_tizen> 9 </since_tizen>
35 public class PageDisappearingEventArgs : EventArgs
40 /// PageAppearedEventArgs is a class to record <see cref="Page.Appeared"/> event arguments which will be sent to user.
42 /// <since_tizen> 9 </since_tizen>
43 public class PageAppearedEventArgs : EventArgs
48 /// PageDisappearedEventArgs is a class to record <see cref="Page.Disappeared"/> event arguments which will be sent to user.
50 /// <since_tizen> 9 </since_tizen>
51 public class PageDisappearedEventArgs : EventArgs
56 /// The Page class is a class which is an element of navigation.
58 /// <since_tizen> 9 </since_tizen>
59 public abstract class Page : Control
62 /// AppearingTransitionProperty
64 [EditorBrowsable(EditorBrowsableState.Never)]
65 public static readonly BindableProperty AppearingTransitionProperty = BindableProperty.Create(nameof(AppearingTransition), typeof(TransitionBase), typeof(Page), null, propertyChanged: (bindable, oldValue, newValue) =>
67 var instance = (Page)bindable;
70 instance.InternalAppearingTransition = newValue as TransitionBase;
73 defaultValueCreator: (bindable) =>
75 var instance = (Page)bindable;
76 return instance.InternalAppearingTransition;
80 /// DisappearingTransitionProperty
82 [EditorBrowsable(EditorBrowsableState.Never)]
83 public static readonly BindableProperty DisappearingTransitionProperty = BindableProperty.Create(nameof(DisappearingTransition), typeof(TransitionBase), typeof(Page), null, propertyChanged: (bindable, oldValue, newValue) =>
85 var instance = (Page)bindable;
88 instance.InternalDisappearingTransition = newValue as TransitionBase;
91 defaultValueCreator: (bindable) =>
93 var instance = (Page)bindable;
94 return instance.InternalDisappearingTransition;
98 /// EnableBackNavigationProperty
100 [EditorBrowsable(EditorBrowsableState.Never)]
101 public static readonly BindableProperty EnableBackNavigationProperty = BindableProperty.Create(nameof(EnableBackNavigation), typeof(bool), typeof(Page), default(bool), propertyChanged: (bindable, oldValue, newValue) =>
103 var instance = (Page)bindable;
104 if (newValue != null)
106 instance.InternalEnableBackNavigation = (bool)newValue;
109 defaultValueCreator: (bindable) =>
111 var instance = (Page)bindable;
112 return instance.InternalEnableBackNavigation;
116 [EditorBrowsable(EditorBrowsableState.Never)]
117 protected internal BaseComponents.View LastFocusedView = null;
119 private Navigator navigator = null;
121 // Default transition is Fade.
122 private TransitionBase appearingTransition = null;
124 private TransitionBase disappearingTransition = null;
126 private bool enableBackNavigation = true;
129 /// Creates a new instance of a Page.
131 /// <since_tizen> 9 </since_tizen>
132 public Page() : base()
137 /// Creates a new instance of a Page with style.
139 /// <param name="style">A style applied to the newly created Page.</param>
140 [EditorBrowsable(EditorBrowsableState.Never)]
141 public Page(ControlStyle style) : base(style)
146 /// Navigator which has pushed the Page into its stack.
147 /// If this Page has not been pushed into any Navigator, then Navigator is null.
149 /// <since_tizen> 9 </since_tizen>
150 public Navigator Navigator
158 if (navigator == value)
168 /// Transition properties for the transition of Views in this page during this page is pushed to Navigator.
170 [EditorBrowsable(EditorBrowsableState.Never)]
171 public TransitionBase AppearingTransition
175 return GetValue(AppearingTransitionProperty) as TransitionBase;
179 SetValue(AppearingTransitionProperty, value);
180 NotifyPropertyChanged();
183 private TransitionBase InternalAppearingTransition
187 appearingTransition = value;
191 return appearingTransition;
196 /// Transition properties for the transition of Views in this page during this page is popped from Navigator.
198 [EditorBrowsable(EditorBrowsableState.Never)]
199 public TransitionBase DisappearingTransition
203 return GetValue(DisappearingTransitionProperty) as TransitionBase;
207 SetValue(DisappearingTransitionProperty, value);
208 NotifyPropertyChanged();
211 private TransitionBase InternalDisappearingTransition
215 disappearingTransition = value;
219 return disappearingTransition;
224 /// Appearing event is invoked right before the page appears.
226 /// <since_tizen> 9 </since_tizen>
227 public event EventHandler<PageAppearingEventArgs> Appearing;
230 /// Disappearing event is invoked right before the page disappears.
232 /// <since_tizen> 9 </since_tizen>
233 public event EventHandler<PageDisappearingEventArgs> Disappearing;
236 /// Appeared event is invoked right after the page appears.
238 /// <since_tizen> 9 </since_tizen>
239 public event EventHandler<PageAppearedEventArgs> Appeared;
242 /// Disappeared event is invoked right after the page disappears.
244 /// <since_tizen> 9 </since_tizen>
245 public event EventHandler<PageDisappearedEventArgs> Disappeared;
248 /// Gets or sets if this page is popped when back button or back key is pressed and released.
250 [EditorBrowsable(EditorBrowsableState.Never)]
251 public bool EnableBackNavigation
255 return (bool)GetValue(EnableBackNavigationProperty);
259 SetValue(EnableBackNavigationProperty, value);
260 NotifyPropertyChanged();
264 private bool InternalEnableBackNavigation
268 enableBackNavigation = value;
272 return enableBackNavigation;
276 internal void InvokeAppearing()
278 Appearing?.Invoke(this, new PageAppearingEventArgs());
281 internal void InvokeDisappearing()
283 Disappearing?.Invoke(this, new PageDisappearingEventArgs());
286 internal void InvokeAppeared()
288 Appeared?.Invoke(this, new PageAppearedEventArgs());
291 internal void InvokeDisappeared()
293 Disappeared?.Invoke(this, new PageDisappearedEventArgs());
297 /// works only when DefaultAlgorithm is enabled.
298 /// to save the currently focused View when disappeared.
300 [EditorBrowsable(EditorBrowsableState.Never)]
301 protected internal virtual void SaveKeyFocus()
303 if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
305 if (this is DialogPage)
307 FocusManager.Instance.ResetFocusFinderRootView();
310 var currentFocusedView = FocusManager.Instance.GetCurrentFocusView();
311 if (currentFocusedView)
313 var findChild = FindDescendantByID(currentFocusedView.ID);
316 LastFocusedView = findChild;
320 LastFocusedView = null;
325 /// works only when DefaultAlgorithm is enabled.
326 /// to set key focused View when showing.
328 [EditorBrowsable(EditorBrowsableState.Never)]
329 protected internal virtual void RestoreKeyFocus()
331 if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
335 FocusManager.Instance.SetCurrentFocusView(LastFocusedView);
339 var temp = new Tizen.NUI.BaseComponents.View()
341 Size = new Size(0.1f, 0.1f, 0.0f),
342 Position = new Position(0, 0, 0),
346 temp.LowerToBottom();
347 FocusManager.Instance.SetCurrentFocusView(temp);
348 var focused = FocusManager.Instance.GetNearestFocusableActor(this, temp, Tizen.NUI.BaseComponents.View.FocusDirection.Down);
351 FocusManager.Instance.SetCurrentFocusView(focused);
355 FocusManager.Instance.ClearFocus();
361 if (this is DialogPage)
363 FocusManager.Instance.SetFocusFinderRootView(this);
369 /// Called when the back navigation is started.
371 /// <param name="eventArgs">The back navigation information.</param>
372 [EditorBrowsable(EditorBrowsableState.Never)]
373 protected virtual void OnBackNavigation(PageBackNavigationEventArgs eventArgs)
379 /// Called when the back navigation is required outside Navigator.
381 internal void NavigateBack()
383 OnBackNavigation(new PageBackNavigationEventArgs());
388 /// PageBackNavigationEventArgs is a class to record back navigation event arguments which will sent to user.
390 [EditorBrowsable(EditorBrowsableState.Never)]
391 public class PageBackNavigationEventArgs : EventArgs