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;
97 protected internal BaseComponents.View LastFocusedView = null;
99 private Navigator navigator = null;
101 // Default transition is Fade.
102 private TransitionBase appearingTransition = null;
104 private TransitionBase disappearingTransition = null;
107 /// Creates a new instance of a Page.
109 /// <since_tizen> 9 </since_tizen>
110 public Page() : base()
115 /// Navigator which has pushed the Page into its stack.
116 /// If this Page has not been pushed into any Navigator, then Navigator is null.
118 /// <since_tizen> 9 </since_tizen>
119 public Navigator Navigator
127 if (navigator == value)
137 /// Transition properties for the transition of Views in this page during this page is pushed to Navigator.
139 [EditorBrowsable(EditorBrowsableState.Never)]
140 public TransitionBase AppearingTransition
144 return GetValue(AppearingTransitionProperty) as TransitionBase;
148 SetValue(AppearingTransitionProperty, value);
149 NotifyPropertyChanged();
152 private TransitionBase InternalAppearingTransition
156 appearingTransition = value;
160 return appearingTransition;
165 /// Transition properties for the transition of Views in this page during this page is popped from Navigator.
167 [EditorBrowsable(EditorBrowsableState.Never)]
168 public TransitionBase DisappearingTransition
172 return GetValue(DisappearingTransitionProperty) as TransitionBase;
176 SetValue(DisappearingTransitionProperty, value);
177 NotifyPropertyChanged();
180 private TransitionBase InternalDisappearingTransition
184 disappearingTransition = value;
188 return disappearingTransition;
193 /// Appearing event is invoked right before the page appears.
195 /// <since_tizen> 9 </since_tizen>
196 public event EventHandler<PageAppearingEventArgs> Appearing;
199 /// Disappearing event is invoked right before the page disappears.
201 /// <since_tizen> 9 </since_tizen>
202 public event EventHandler<PageDisappearingEventArgs> Disappearing;
205 /// Appeared event is invoked right after the page appears.
207 /// <since_tizen> 9 </since_tizen>
208 public event EventHandler<PageAppearedEventArgs> Appeared;
211 /// Disappeared event is invoked right after the page disappears.
213 /// <since_tizen> 9 </since_tizen>
214 public event EventHandler<PageDisappearedEventArgs> Disappeared;
216 internal void InvokeAppearing()
218 Appearing?.Invoke(this, new PageAppearingEventArgs());
221 internal void InvokeDisappearing()
223 Disappearing?.Invoke(this, new PageDisappearingEventArgs());
226 internal void InvokeAppeared()
228 Appeared?.Invoke(this, new PageAppearedEventArgs());
231 internal void InvokeDisappeared()
233 Disappeared?.Invoke(this, new PageDisappearedEventArgs());
237 /// works only when DefaultAlgorithm is enabled.
238 /// to save the currentl focused View when disappeared.
240 [EditorBrowsable(EditorBrowsableState.Never)]
241 protected internal virtual void SaveKeyFocus()
243 if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
245 var currentFocusedView = FocusManager.Instance.GetCurrentFocusView();
246 if (currentFocusedView)
248 var findChild = this.FindDescendantByID(currentFocusedView.ID);
251 this.LastFocusedView = findChild;
255 this.LastFocusedView = null;
260 /// works only when DefaultAlgorithm is enabled.
261 /// to set key focused View when showing.
263 [EditorBrowsable(EditorBrowsableState.Never)]
264 protected internal virtual void RestoreKeyFocus()
266 if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
268 if (this.LastFocusedView)
270 FocusManager.Instance.SetCurrentFocusView(this.LastFocusedView);
274 var temp = new Tizen.NUI.BaseComponents.View()
276 Size = new Size(0.1f, 0.1f, 0.0f),
277 Position = new Position(0, 0, 0),
281 temp.LowerToBottom();
282 FocusManager.Instance.SetCurrentFocusView(temp);
283 var focused = FocusManager.Instance.GetNearestFocusableActor(this, temp, Tizen.NUI.BaseComponents.View.FocusDirection.Down);
286 FocusManager.Instance.SetCurrentFocusView(focused);
290 FocusManager.Instance.ClearFocus();