aurora/aurora-sharp-desktop/Aurora/UserInterface/Views/BaseViewModel.cs
2021-04-11 20:54:59 -04:00

64 lines
1.8 KiB
C#

using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Aurora.Models.Media;
using Xamarin.Forms;
using Aurora.Design.Views.Main;
namespace Aurora.Design.Views
{
public class BaseViewModel : INotifyPropertyChanged
{
public BaseViewModel()
{
}
public ShowModalDelegate ShowModal { get; set; }
public HideModalDelegate HideModal { get; set; }
public SetViewDelegate SetView { get; set; }
#region Lifecycle Callbacks
/// <summary>
/// Called by main screen on view appearing
/// </summary>
/// <typeparam name="object"></typeparam>
/// <returns></returns>
public virtual Task OnActive() { return Task.FromResult<object>(null); }
/// <summary>
/// Called by main screen on view disappearing
/// </summary>
/// <typeparam name="object"></typeparam>
/// <returns></returns>
public virtual Task OnInactive() { return Task.FromResult<object>(null); }
#endregion Lifecycle Callbacks
#region INotifyPropertyChanged Implementation
public bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
{
if (Object.Equals(storage, value))
return false;
storage = value;
OnPropertyChanged(propertyName);
return true;
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
if (PropertyChanged == null)
return;
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
}