Skip to content

Commit

Permalink
Hide/show titlebar on modal pages w/ Windows (#26111)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Nov 26, 2024
1 parent 1bf3a4c commit 1d14364
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,18 @@ void SetCurrent(
newPage.Toolbar ??= new Toolbar(newPage);
_ = newPage.Toolbar.ToPlatform(modalContext);

var windowManager = modalContext.GetNavigationRootManager();

if (windowManager.RootView is WindowRootView wrv)
// Hide titlebar on previous page
var previousContext = previousPage.FindMauiContext();
if (previousContext is not null)
{
wrv.SetTitleBarBackgroundToTransparent(false);
var navRoot = previousContext.GetNavigationRootManager();
if (navRoot.RootView is WindowRootView wrv && wrv.AppTitleBarContainer is not null)
{
wrv.SetTitleBarVisibility(UI.Xaml.Visibility.Collapsed);
}
}

var windowManager = modalContext.GetNavigationRootManager();
var platform = newPage.ToPlatform(modalContext);
_waitingForIncomingPage = platform.OnLoaded(() => completedCallback?.Invoke());
windowManager.Connect(platform);
Expand All @@ -119,9 +124,17 @@ void SetCurrent(
// popping modal
else
{
var windowManager = newPage.FindMauiContext()?.GetNavigationRootManager() ??
var context = newPage.FindMauiContext();
var windowManager = context?.GetNavigationRootManager() ??
throw new InvalidOperationException("Previous Page Has Lost its MauiContext");

// Toggle the titlebar visibility on the new page
var navRoot = context.GetNavigationRootManager();
if (navRoot.RootView is WindowRootView wrv && wrv.AppTitleBarContainer is not null)
{
wrv.SetTitleBarVisibility(UI.Xaml.Visibility.Visible);
}

var platform = newPage.ToPlatform();
_waitingForIncomingPage = platform.OnLoaded(() => completedCallback?.Invoke());
Container.AddPage(windowManager.RootView);
Expand Down
41 changes: 16 additions & 25 deletions src/Core/src/Platform/Windows/WindowRootView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ internal FrameworkElement? AppTitleBar
_appTitleBar = cp;
}

UpdateAppTitleBarTransparency();

return _appTitleBar;
}
}
Expand Down Expand Up @@ -477,6 +475,22 @@ internal void SetTitleBar(ITitleBar? titlebar, IMauiContext? mauiContext)
}
}

internal void SetTitleBarVisibility(UI.Xaml.Visibility visibility)
{
// Set default and custom titlebar container visibility
if (AppTitleBarContainer is not null)
{
AppTitleBarContainer.Visibility = visibility;
}

// Set the back/flyout button container visibility
if (NavigationViewControl is not null &&
NavigationViewControl.ButtonHolderGrid is not null)
{
NavigationViewControl.ButtonHolderGrid.Visibility = visibility;
}
}

private void TitlebarPropChanged_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (_titleBar is not null && _titleBar.Handler?.MauiContext is not null)
Expand Down Expand Up @@ -553,29 +567,6 @@ internal String? WindowTitle
set => SetValue(TitleProperty, value);
}

// Once we switch the TitleBar over to using replaceable IViews we won't need this
// but for the sake of first just getting us converted over to the new TitleBar
// APIs
bool _setTitleBarBackgroundToTransparent = true;
internal void SetTitleBarBackgroundToTransparent(bool value)
{
_setTitleBarBackgroundToTransparent = value;
if (value)
{
UpdateAppTitleBarTransparency();
}
else
{
_appTitleBar?.RefreshThemeResources();
}
}

void UpdateAppTitleBarTransparency()
{
if (_setTitleBarBackgroundToTransparent && _appTitleBar is Border border)
border.Background = null;
}

internal static readonly DependencyProperty WindowTitleBarContentProperty =
DependencyProperty.Register(
nameof(WindowTitleBarContent),
Expand Down

0 comments on commit 1d14364

Please sign in to comment.