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 Page with style.
139 /// <param name="style">Creates Page by special style defined in UX.</param>
140 [EditorBrowsable(EditorBrowsableState.Never)]
141 public Page(string style) : base(style)
146 /// Creates a new instance of a Page with style.
148 /// <param name="style">A style applied to the newly created Page.</param>
149 [EditorBrowsable(EditorBrowsableState.Never)]
150 public Page(ControlStyle style) : base(style)
155 /// Navigator which has pushed the Page into its stack.
156 /// If this Page has not been pushed into any Navigator, then Navigator is null.
158 /// <since_tizen> 9 </since_tizen>
159 public Navigator Navigator
167 if (navigator == value)
177 /// Transition properties for the transition of Views in this page during this page is pushed to Navigator.
179 [EditorBrowsable(EditorBrowsableState.Never)]
180 public TransitionBase AppearingTransition
184 return GetValue(AppearingTransitionProperty) as TransitionBase;
188 SetValue(AppearingTransitionProperty, value);
189 NotifyPropertyChanged();
192 private TransitionBase InternalAppearingTransition
196 appearingTransition = value;
200 return appearingTransition;
205 /// Transition properties for the transition of Views in this page during this page is popped from Navigator.
207 [EditorBrowsable(EditorBrowsableState.Never)]
208 public TransitionBase DisappearingTransition
212 return GetValue(DisappearingTransitionProperty) as TransitionBase;
216 SetValue(DisappearingTransitionProperty, value);
217 NotifyPropertyChanged();
220 private TransitionBase InternalDisappearingTransition
224 disappearingTransition = value;
228 return disappearingTransition;
233 /// Appearing event is invoked right before the page appears.
235 /// <since_tizen> 9 </since_tizen>
236 public event EventHandler<PageAppearingEventArgs> Appearing;
239 /// Disappearing event is invoked right before the page disappears.
241 /// <since_tizen> 9 </since_tizen>
242 public event EventHandler<PageDisappearingEventArgs> Disappearing;
245 /// Appeared event is invoked right after the page appears.
247 /// <since_tizen> 9 </since_tizen>
248 public event EventHandler<PageAppearedEventArgs> Appeared;
251 /// Disappeared event is invoked right after the page disappears.
253 /// <since_tizen> 9 </since_tizen>
254 public event EventHandler<PageDisappearedEventArgs> Disappeared;
257 /// Gets or sets if this page proceeds back navigation when back button or back key is pressed and released.
258 /// Back navigation pops the peek page if Navigator has more than one page.
259 /// If Navigator has only one page, then the current program is exited.
261 [EditorBrowsable(EditorBrowsableState.Never)]
262 public bool EnableBackNavigation
266 return (bool)GetValue(EnableBackNavigationProperty);
270 SetValue(EnableBackNavigationProperty, value);
271 NotifyPropertyChanged();
275 private bool InternalEnableBackNavigation
279 enableBackNavigation = value;
283 return enableBackNavigation;
287 internal void InvokeAppearing()
289 Appearing?.Invoke(this, new PageAppearingEventArgs());
292 internal void InvokeDisappearing()
294 Disappearing?.Invoke(this, new PageDisappearingEventArgs());
297 internal void InvokeAppeared()
299 Appeared?.Invoke(this, new PageAppearedEventArgs());
302 internal void InvokeDisappeared()
304 Disappeared?.Invoke(this, new PageDisappearedEventArgs());
308 /// works only when DefaultAlgorithm is enabled.
309 /// to save the currently focused View when disappeared.
311 [EditorBrowsable(EditorBrowsableState.Never)]
312 protected internal virtual void SaveKeyFocus()
314 if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
316 if (this is DialogPage)
318 FocusManager.Instance.ResetFocusFinderRootView();
321 var currentFocusedView = FocusManager.Instance.GetCurrentFocusView();
322 if (currentFocusedView)
324 var findChild = FindDescendantByID(currentFocusedView.ID);
327 LastFocusedView = findChild;
331 LastFocusedView = null;
336 /// works only when DefaultAlgorithm is enabled.
337 /// to set key focused View when showing.
339 [EditorBrowsable(EditorBrowsableState.Never)]
340 protected internal virtual void RestoreKeyFocus()
342 if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
346 FocusManager.Instance.SetCurrentFocusView(LastFocusedView);
350 var temp = new Tizen.NUI.BaseComponents.View()
352 Size = new Size(0.1f, 0.1f, 0.0f),
353 Position = new Position(0, 0, 0),
357 temp.LowerToBottom();
358 FocusManager.Instance.SetCurrentFocusView(temp);
359 var focused = FocusManager.Instance.GetNearestFocusableActor(this, temp, Tizen.NUI.BaseComponents.View.FocusDirection.Down);
362 FocusManager.Instance.SetCurrentFocusView(focused);
366 FocusManager.Instance.ClearFocus();
372 if (this is DialogPage)
374 FocusManager.Instance.SetFocusFinderRootView(this);
380 /// Called when the back navigation is started.
381 /// Back navigation pops the peek page if Navigator has more than one page.
382 /// If Navigator has only one page, then the current program is exited.
384 /// <param name="eventArgs">The back navigation information.</param>
385 [EditorBrowsable(EditorBrowsableState.Never)]
386 protected virtual void OnBackNavigation(PageBackNavigationEventArgs eventArgs)
388 if (Navigator.PageCount > 1)
394 NUIApplication.Current?.Exit();
399 /// Called when the back navigation is required outside Navigator.
401 internal void NavigateBack()
403 OnBackNavigation(new PageBackNavigationEventArgs());
408 /// PageBackNavigationEventArgs is a class to record back navigation event arguments which will sent to user.
410 [EditorBrowsable(EditorBrowsableState.Never)]
411 public class PageBackNavigationEventArgs : EventArgs