Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Fix Shell FlyoutBackground property #13132

Merged
merged 6 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Handlers;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Platform;
using Microsoft.UI.Xaml;
using Xunit;
Expand All @@ -23,6 +24,53 @@ protected Task CheckFlyoutState(ShellHandler handler, bool desiredState)
return Task.CompletedTask;
}

[Theory(DisplayName = "Shell FlyoutBackground Initializes Correctly")]
[InlineData("#FF0000")]
[InlineData("#00FF00")]
[InlineData("#0000FF")]
[InlineData("#000000")]
public async Task ShellFlyoutBackgroundInitializesCorrectly(string colorHex)
{
SetupBuilder();

var expectedColor = Color.FromArgb(colorHex);

var shell = await CreateShellAsync((shell) =>
{
shell.FlyoutBehavior = FlyoutBehavior.Locked;
shell.FlyoutBackground = new SolidColorBrush(expectedColor);

var shellItem = new FlyoutItem();
shellItem.Items.Add(new ContentPage());
shell.Items.Add(shellItem);
});

await InvokeOnMainThreadAsync(async () =>
{
await CreateHandlerAndAddToWindow<ShellHandler>(shell, (handler) =>
{
var rootNavView = handler.PlatformView;
var shellItemView = shell.CurrentItem.Handler.PlatformView as MauiNavigationView;
var expectedRoot = UI.Xaml.Controls.NavigationViewPaneDisplayMode.Left;
var expectedShellItems = UI.Xaml.Controls.NavigationViewPaneDisplayMode.LeftMinimal;

Assert.Equal(expectedRoot, rootNavView.PaneDisplayMode);
Assert.NotNull(shellItemView);
Assert.Equal(expectedShellItems, shellItemView.PaneDisplayMode);

return Task.CompletedTask;
});

await AssertionExtensions.Wait(() =>
{
var platformView = shell.Handler.PlatformView as FrameworkElement;
return platformView is not null && (platformView.Height > 0 || platformView.Width > 0);
});
});

await ValidateHasColor(shell, expectedColor, typeof(ShellHandler));
}

[Fact(DisplayName = "Back Button Enabled/Disabled")]
public async Task BackButtonEnabledAndDisabled()
{
Expand Down Expand Up @@ -631,4 +679,4 @@ async Task TapToSelect(ContentPage page)
await OnNavigatedToAsync(page);
}
}
}
}
34 changes: 18 additions & 16 deletions src/Core/src/Platform/Windows/NavigationViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public static void UpdateTopNavigationViewItemTextColor(this MauiNavigationView
navigationView.TopNavArea.Resources["TopNavigationViewItemForegroundPressed"] = brush;
navigationView.TopNavArea.Resources["TopNavigationViewItemForegroundDisabled"] = brush;
}

navigationView.TopNavArea.RefreshThemeResources();
}

if (navigationView.MenuItemsSource is IList<NavigationViewItemViewModel> items)
Expand Down Expand Up @@ -70,6 +72,8 @@ public static void UpdateTopNavigationViewItemBackgroundUnselectedColor(this Mau
navigationView.TopNavArea.Resources["TopNavigationViewItemBackgroundPointerOver"] = brush;
navigationView.TopNavArea.Resources["TopNavigationViewItemBackgroundPressed"] = brush;
}

navigationView.TopNavArea.RefreshThemeResources();
}

if (navigationView.MenuItemsSource is IList<NavigationViewItemViewModel> items)
Expand Down Expand Up @@ -98,6 +102,8 @@ public static void UpdateTopNavigationViewItemBackgroundSelectedColor(this MauiN
navigationView.TopNavArea.Resources["TopNavigationViewItemBackgroundSelectedPointerOver"] = brush;
navigationView.TopNavArea.Resources["TopNavigationViewItemBackgroundSelectedPressed"] = brush;
}

navigationView.TopNavArea.RefreshThemeResources();
}

if (navigationView.MenuItemsSource is IList<NavigationViewItemViewModel> items)
Expand All @@ -111,32 +117,28 @@ public static void UpdateTopNavigationViewItemBackgroundSelectedColor(this MauiN

public static void UpdatePaneBackground(this MauiNavigationView navigationView, Paint? paint)
{
var rootSplitView = navigationView.RootSplitView;
var paneContentGrid = navigationView.PaneContentGrid;

if (paneContentGrid is null)
return;

var brush = paint?.ToPlatform();

if (brush == null)
if (brush is null)
{
object? color = null;
object? color;
if (navigationView.IsPaneOpen)
color = navigationView.Resources["NavigationViewExpandedPaneBackground"];
else
color = navigationView.Resources["NavigationViewDefaultPaneBackground"];

if (rootSplitView != null)
{
if (color is WBrush colorBrush)
rootSplitView.PaneBackground = colorBrush;
else if (color is global::Windows.UI.Color uiColor)
rootSplitView.PaneBackground = new WSolidColorBrush(uiColor);
}
if (color is WBrush colorBrush)
paneContentGrid.Background = colorBrush;
else if (color is global::Windows.UI.Color uiColor)
paneContentGrid.Background = new WSolidColorBrush(uiColor);
}
else
{
if (rootSplitView != null)
{
rootSplitView.PaneBackground = brush;
}
}
paneContentGrid.Background = brush;
}

public static void UpdateFlyoutVerticalScrollMode(this MauiNavigationView navigationView, ScrollMode scrollMode)
Expand Down