/*
* Copyright(c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using System.ComponentModel;
using Tizen.NUI.Binding;
namespace Tizen.NUI.Components
{
///
/// PageAppearingEventArgs is a class to record event arguments which will be sent to user.
///
/// 9
public class PageAppearingEventArgs : EventArgs
{
}
///
/// PageDisappearingEventArgs is a class to record event arguments which will be sent to user.
///
/// 9
public class PageDisappearingEventArgs : EventArgs
{
}
///
/// PageAppearedEventArgs is a class to record event arguments which will be sent to user.
///
/// 9
public class PageAppearedEventArgs : EventArgs
{
}
///
/// PageDisappearedEventArgs is a class to record event arguments which will be sent to user.
///
/// 9
public class PageDisappearedEventArgs : EventArgs
{
}
///
/// The Page class is a class which is an element of navigation.
///
/// 9
public abstract class Page : Control
{
///
/// AppearingTransitionProperty
///
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty AppearingTransitionProperty = BindableProperty.Create(nameof(AppearingTransition), typeof(TransitionBase), typeof(Page), null, propertyChanged: (bindable, oldValue, newValue) =>
{
var instance = (Page)bindable;
if (newValue != null)
{
instance.InternalAppearingTransition = newValue as TransitionBase;
}
},
defaultValueCreator: (bindable) =>
{
var instance = (Page)bindable;
return instance.InternalAppearingTransition;
});
///
/// DisappearingTransitionProperty
///
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty DisappearingTransitionProperty = BindableProperty.Create(nameof(DisappearingTransition), typeof(TransitionBase), typeof(Page), null, propertyChanged: (bindable, oldValue, newValue) =>
{
var instance = (Page)bindable;
if (newValue != null)
{
instance.InternalDisappearingTransition = newValue as TransitionBase;
}
},
defaultValueCreator: (bindable) =>
{
var instance = (Page)bindable;
return instance.InternalDisappearingTransition;
});
///
/// EnableBackNavigationProperty
///
[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;
});
///
[EditorBrowsable(EditorBrowsableState.Never)]
protected internal BaseComponents.View LastFocusedView = null;
private Navigator navigator = null;
// Default transition is Fade.
private TransitionBase appearingTransition = null;
private TransitionBase disappearingTransition = null;
private bool enableBackNavigation = true;
///
/// Creates a new instance of a Page.
///
/// 9
public Page() : base()
{
}
///
/// Creates a new instance of a Page with style.
///
/// A style applied to the newly created Page.
[EditorBrowsable(EditorBrowsableState.Never)]
public Page(ControlStyle style) : base(style)
{
}
///
/// Navigator which has pushed the Page into its stack.
/// If this Page has not been pushed into any Navigator, then Navigator is null.
///
/// 9
public Navigator Navigator
{
get
{
return navigator;
}
internal set
{
if (navigator == value)
{
return;
}
navigator = value;
}
}
///
/// Transition properties for the transition of Views in this page during this page is pushed to Navigator.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public TransitionBase AppearingTransition
{
get
{
return GetValue(AppearingTransitionProperty) as TransitionBase;
}
set
{
SetValue(AppearingTransitionProperty, value);
NotifyPropertyChanged();
}
}
private TransitionBase InternalAppearingTransition
{
set
{
appearingTransition = value;
}
get
{
return appearingTransition;
}
}
///
/// Transition properties for the transition of Views in this page during this page is popped from Navigator.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public TransitionBase DisappearingTransition
{
get
{
return GetValue(DisappearingTransitionProperty) as TransitionBase;
}
set
{
SetValue(DisappearingTransitionProperty, value);
NotifyPropertyChanged();
}
}
private TransitionBase InternalDisappearingTransition
{
set
{
disappearingTransition = value;
}
get
{
return disappearingTransition;
}
}
///
/// Appearing event is invoked right before the page appears.
///
/// 9
public event EventHandler Appearing;
///
/// Disappearing event is invoked right before the page disappears.
///
/// 9
public event EventHandler Disappearing;
///
/// Appeared event is invoked right after the page appears.
///
/// 9
public event EventHandler Appeared;
///
/// Disappeared event is invoked right after the page disappears.
///
/// 9
public event EventHandler Disappeared;
///
/// Gets or sets if this page is popped 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;
}
}
internal void InvokeAppearing()
{
Appearing?.Invoke(this, new PageAppearingEventArgs());
}
internal void InvokeDisappearing()
{
Disappearing?.Invoke(this, new PageDisappearingEventArgs());
}
internal void InvokeAppeared()
{
Appeared?.Invoke(this, new PageAppearedEventArgs());
}
internal void InvokeDisappeared()
{
Disappeared?.Invoke(this, new PageDisappearedEventArgs());
}
///
/// works only when DefaultAlgorithm is enabled.
/// to save the currently focused View when disappeared.
///
[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 = FindDescendantByID(currentFocusedView.ID);
if (findChild)
{
LastFocusedView = findChild;
return;
}
}
LastFocusedView = null;
}
}
///
/// works only when DefaultAlgorithm is enabled.
/// to set key focused View when showing.
///
[EditorBrowsable(EditorBrowsableState.Never)]
protected internal virtual void RestoreKeyFocus()
{
if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
{
if (LastFocusedView)
{
FocusManager.Instance.SetCurrentFocusView(LastFocusedView);
}
else
{
var temp = new Tizen.NUI.BaseComponents.View()
{
Size = new Size(0.1f, 0.1f, 0.0f),
Position = new Position(0, 0, 0),
Focusable = true,
};
this.Add(temp);
temp.LowerToBottom();
FocusManager.Instance.SetCurrentFocusView(temp);
var focused = FocusManager.Instance.GetNearestFocusableActor(this, temp, Tizen.NUI.BaseComponents.View.FocusDirection.Down);
if (focused)
{
FocusManager.Instance.SetCurrentFocusView(focused);
}
else
{
FocusManager.Instance.ClearFocus();
}
temp.Unparent();
temp.Dispose();
}
if (this is DialogPage)
{
FocusManager.Instance.SetFocusFinderRootView(this);
}
}
}
}
}