Улучшен layout и contextualbar
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
@using MudBlazor.Services
|
||||
@using PlaylistShared.Pwa.Components.Global
|
||||
@inherits LayoutComponentBase
|
||||
@inject PwaUpdateService PwaUpdateService
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject ContextualActionBarService ContextualActionBarService
|
||||
@inject IBrowserViewportService BrowserViewportService
|
||||
@implements IBrowserViewportObserver
|
||||
|
||||
<MudThemeProvider Theme="@_theme" IsDarkMode="_isDarkMode" />
|
||||
<MudPopoverProvider />
|
||||
@@ -38,7 +41,14 @@
|
||||
|
||||
@code {
|
||||
private RenderFragment? _actionBarContent;
|
||||
private bool _actionBarBottom = false;
|
||||
private bool _actionBarBottom => _contextualPosition switch
|
||||
{
|
||||
ContextualActionBarPosition.Bottom => true,
|
||||
ContextualActionBarPosition.Top => false,
|
||||
_ => _isMobile,
|
||||
};
|
||||
private bool _isMobile = false;
|
||||
private ContextualActionBarPosition _contextualPosition = ContextualActionBarPosition.Default;
|
||||
|
||||
private bool _drawerOpen = true;
|
||||
private bool _isDarkMode = true;
|
||||
@@ -66,13 +76,14 @@
|
||||
{
|
||||
_dotNetRef = DotNetObjectReference.Create(PwaUpdateService);
|
||||
await JSRuntime.InvokeVoidAsync("registerSWMessageHandler", _dotNetRef);
|
||||
await BrowserViewportService.SubscribeAsync(this, fireImmediately: true);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnContextualChangedHandler()
|
||||
{
|
||||
_actionBarContent = ContextualActionBarService.Content;
|
||||
_actionBarBottom = ContextualActionBarService.Bottom ?? false;
|
||||
_contextualPosition = ContextualActionBarService.Position;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
@@ -130,4 +141,21 @@
|
||||
true => Icons.Material.Rounded.AutoMode,
|
||||
false => Icons.Material.Outlined.DarkMode,
|
||||
};
|
||||
|
||||
|
||||
|
||||
Guid IBrowserViewportObserver.Id { get; } = Guid.NewGuid();
|
||||
|
||||
ResizeOptions IBrowserViewportObserver.ResizeOptions { get; } = new()
|
||||
{
|
||||
ReportRate = 250,
|
||||
NotifyOnBreakpointOnly = true
|
||||
};
|
||||
|
||||
Task IBrowserViewportObserver.NotifyBrowserViewportChangeAsync(BrowserViewportEventArgs browserViewportEventArgs)
|
||||
{
|
||||
_isMobile = browserViewportEventArgs.Breakpoint <= Breakpoint.Sm;
|
||||
|
||||
return InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user