ant-design-blazor/components/modal/modalDialog/ModalContainer.razor.cs
zxyao 31aac9f914 refactor: unified use of FeedbackComponent for modal comfirm and drawer (#1263)
* refactor: support to use the same template for confirm and modal

* refactor: support to use the same template for drawer

* refactor: separate interface IOkCancelRef

* chore: modify EventUtil class summary

Co-authored-by: James Yeung <shunjiey@hotmail.com>
2021-04-04 15:40:54 +08:00

60 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
namespace AntDesign
{
public partial class ModalContainer
{
[Inject]
private ModalService ModalService { get; set; }
private readonly List<ModalRef> _modalRefs = new List<ModalRef>();
protected override void OnInitialized()
{
ModalService.OnModalOpenEvent += ModalService_OnModalOpenEvent;
ModalService.OnModalCloseEvent += ModalService_OnModalCloseEvent;
ModalService.OnModalUpdateEvent += ModalService_OnModalUpdateEvent;
}
private async Task ModalService_OnModalOpenEvent(ModalRef modalRef)
{
if (!_modalRefs.Contains(modalRef))
{
_modalRefs.Add(modalRef);
}
await InvokeAsync(StateHasChanged);
}
private async Task ModalService_OnModalCloseEvent(ModalRef modalRef)
{
modalRef.Config.Visible = false;
await InvokeAsync(StateHasChanged);
await Task.Delay(250);
if (modalRef.Config.DestroyOnClose && _modalRefs.Contains(modalRef))
{
_modalRefs.Remove(modalRef);
}
}
private async Task ModalService_OnModalUpdateEvent(ModalRef arg)
{
await InvokeStateHasChangedAsync();
}
protected override void Dispose(bool disposing)
{
ModalService.OnModalOpenEvent -= ModalService_OnModalOpenEvent;
ModalService.OnModalCloseEvent -= ModalService_OnModalCloseEvent;
ModalService.OnModalUpdateEvent -= ModalService_OnModalUpdateEvent;
base.Dispose(disposing);
}
}
}