using System; using System.Collections.Generic; using System.ComponentModel; using System.Text; using System.Threading.Tasks; namespace AntDesign { public class DrawerRef : FeedbackRefBase { [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("Please replace it with Config")] public DrawerOptions Options => Config; public DrawerOptions Config { get; private set; } public Drawer Drawer { get; set; } public Func OnClosing { get; set; } protected readonly DrawerService _service; internal DrawerRef(DrawerOptions options, DrawerService service) { Config = options; _service = service; } /// /// close Confirm dialog /// /// public override async Task CloseAsync() { var e = new ModalClosingEventArgs(); await (OnClosing?.Invoke(e) ?? Task.CompletedTask); if (!e.Cancel) { await _service.CloseAsync(this); if (OnClose != null)//before close await OnClose.Invoke(); } } /// /// Open Confirm dialog /// /// public override async Task OpenAsync() { await _service.OpenAsync(this); if (OnOpen != null) await OnOpen.Invoke(); } /// /// update Confirm dialog config which Visible=true /// /// public override async Task UpdateConfigAsync() { await (_service?.UpdateAsync(this) ?? Task.CompletedTask); } /// /// update Confirm dialog config with a new ConfirmOptions /// /// /// public async Task UpdateConfigAsync(DrawerOptions config) { Config = config; await UpdateConfigAsync(); } } public class DrawerRef : DrawerRef { internal TaskCompletionSource TaskCompletionSource { get; set; } public Func OnClosed { get; set; } internal DrawerRef(DrawerOptions options, DrawerService service) :base(options,service) { } /// /// 关闭抽屉 /// /// public async Task CloseAsync(TResult result) { var closeEventArgs = new ModalClosingEventArgs(); if (OnClosing != null)//before close await OnClosing.Invoke(closeEventArgs); if (closeEventArgs.Cancel) return; await _service.CloseAsync(this); if (OnClosed != null)//after close await OnClosed.Invoke(result); TaskCompletionSource?.SetResult(result); } } }