2020-03-22 21:24:41 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
2020-06-23 15:19:44 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2020-03-22 21:24:41 +08:00
|
|
|
|
|
2020-05-29 00:33:49 +08:00
|
|
|
|
namespace AntDesign
|
2020-03-22 21:24:41 +08:00
|
|
|
|
{
|
2020-09-16 19:42:48 +08:00
|
|
|
|
public class DrawerRef<TResult> : IDrawerRef
|
2020-06-30 13:40:51 +08:00
|
|
|
|
{
|
2020-09-16 19:42:48 +08:00
|
|
|
|
public DrawerOptions Options { get; set; }
|
2020-06-30 13:40:51 +08:00
|
|
|
|
|
|
|
|
|
public Drawer Drawer { get; set; }
|
|
|
|
|
|
|
|
|
|
public Func<Task> OnOpen { get; set; }
|
|
|
|
|
|
2020-09-16 19:42:48 +08:00
|
|
|
|
public Func<DrawerClosingEventArgs, Task> OnClosing { get; set; }
|
2020-06-23 15:19:44 +08:00
|
|
|
|
|
2020-09-16 19:42:48 +08:00
|
|
|
|
public Func<TResult, Task> OnClosed { get; set; }
|
|
|
|
|
|
|
|
|
|
private DrawerService _service;
|
|
|
|
|
|
|
|
|
|
internal DrawerRef(DrawerOptions options)
|
2020-06-23 15:19:44 +08:00
|
|
|
|
{
|
2020-09-16 19:42:48 +08:00
|
|
|
|
Options = options;
|
2020-06-23 15:19:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-16 19:42:48 +08:00
|
|
|
|
internal DrawerRef(DrawerOptions options, DrawerService service)
|
2020-06-23 15:19:44 +08:00
|
|
|
|
{
|
2020-09-16 19:42:48 +08:00
|
|
|
|
Options = options;
|
2020-06-23 15:19:44 +08:00
|
|
|
|
_service = service;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-09-09 11:33:41 +08:00
|
|
|
|
/// open a drawer
|
2020-06-23 15:19:44 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2020-06-30 13:40:51 +08:00
|
|
|
|
public async Task OpenAsync()
|
2020-06-23 15:19:44 +08:00
|
|
|
|
{
|
2020-06-30 13:40:51 +08:00
|
|
|
|
await _service.OpenAsync(this);
|
|
|
|
|
if (OnOpen != null)
|
|
|
|
|
await OnOpen.Invoke();
|
2020-06-23 15:19:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-30 13:40:51 +08:00
|
|
|
|
/// <summary>
|
2020-09-09 11:33:41 +08:00
|
|
|
|
/// close the drawer without return value
|
2020-06-30 13:40:51 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task CloseAsync()
|
|
|
|
|
{
|
2020-09-16 19:42:48 +08:00
|
|
|
|
await CloseAsync(default);
|
2020-06-30 13:40:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-16 19:42:48 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 关闭抽屉
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task CloseAsync(TResult result)
|
2020-06-30 13:40:51 +08:00
|
|
|
|
{
|
2020-09-16 19:42:48 +08:00
|
|
|
|
var closeEventArgs = new DrawerClosingEventArgs();
|
|
|
|
|
|
|
|
|
|
if (OnClosing != null)//before close
|
|
|
|
|
await OnClosing.Invoke(closeEventArgs);
|
|
|
|
|
|
|
|
|
|
if (closeEventArgs.Rejected)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
await _service.CloseAsync(this);
|
|
|
|
|
|
|
|
|
|
if (OnClosed != null)//after close
|
|
|
|
|
await OnClosed.Invoke(result);
|
|
|
|
|
|
|
|
|
|
if (TaskCompletionSource != null)//dialog close
|
|
|
|
|
TaskCompletionSource.SetResult(result);
|
2020-06-30 13:40:51 +08:00
|
|
|
|
}
|
2020-09-16 19:42:48 +08:00
|
|
|
|
|
|
|
|
|
internal TaskCompletionSource<TResult> TaskCompletionSource { get; set; }
|
2020-03-22 21:24:41 +08:00
|
|
|
|
}
|
2020-06-23 15:19:44 +08:00
|
|
|
|
}
|