ant-design-blazor/components/modal/modalDialog/ModalContainer.razor.cs
zxyao ef4701b6ed refactor(module: modal): refactor the code of Modal, Confirm (#914)
* refactor(module: modal): refactor the code of Modal, Confirm and Dialog

refactor details:
- Add DialogWrapper compontent to control the logic of dialog removal from DOM
- Add the appropriate folders for Dialog, Modal, and Confirm
- Remove methods with the same logic but different names in ConfirmService
- Split Title into Title (string) and Titletemplate (renderfragment)
- Add comments to code
- Rename ConfirmDialog to Confirm
- Specification of method name in ConfirmService
- Adjust the time of throttle function for draggabe modal
- Extract the common part of ModalOptions, ConfirmOptions and DialogOptions as DialogOptionsBase

* refactor: move DefaultCloseIcon etc. static members to DialogOptionsBase

* docs(module: modal): update docs

* fix: dialog incorrect waiting

* fix: pickup missing pr/7
2020-12-26 21:39:04 +08:00

53 lines
1.5 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;
}
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);
}
}
protected override void Dispose(bool disposing)
{
ModalService.OnModalOpenEvent -= ModalService_OnModalOpenEvent;
ModalService.OnModalCloseEvent -= ModalService_OnModalCloseEvent;
base.Dispose(disposing);
}
}
}