@using SteUp.Shared.Core.Messages.System
@inject BackButtonService BackButton
@implements IDisposable
@*
Bottom sheet (STILE_UI ยง6.14): sale dal basso, maniglia di trascinamento,
testata con titolo e chiusura, un'unica linea di struttura, corpo scorrevole.
Sostituisce i menu flottanti: stessa funzione, bersagli molto piu' grandi.
*@
@if (Open)
{
@Title
@if (!string.IsNullOrWhiteSpace(Subtitle))
{
@Subtitle
}
@ChildContent
}
@code {
[Parameter] public bool Open { get; set; }
[Parameter] public EventCallback OpenChanged { get; set; }
[Parameter] public string? Title { get; set; }
[Parameter] public string? Subtitle { get; set; }
/// Sheet di compilazione (~92% dello schermo) invece che di consultazione.
[Parameter] public bool Tall { get; set; }
[Parameter] public RenderFragment? ChildContent { get; set; }
// Il tasto indietro del dispositivo chiude lo sheet invece di uscire dalla
// schermata sotto: e' il gesto che l'utente si aspetta, ed e' anche la
// ragione per cui i gestori sono impilati (vedi BackButtonService).
private IDisposable? _backRegistration;
protected override void OnParametersSet()
{
if (Open && _backRegistration is null)
{
_backRegistration = BackButton.Register(() => InvokeAsync(Close));
}
else if (!Open)
{
Unregister();
}
}
private async Task Close()
{
Unregister();
Open = false;
await OpenChanged.InvokeAsync(false);
}
private void Unregister()
{
_backRegistration?.Dispose();
_backRegistration = null;
}
public void Dispose() => Unregister();
}