From fc6093a3b6b5b9e0e529c304ee5636841e333321 Mon Sep 17 00:00:00 2001 From: eriklimakc Date: Wed, 12 Jun 2024 18:54:31 +0100 Subject: [PATCH 1/2] fix: Include FooterMenuItems NavigationMenuItems --- .../Navigators/NavigationViewNavigator.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Uno.Extensions.Navigation.UI/Navigators/NavigationViewNavigator.cs b/src/Uno.Extensions.Navigation.UI/Navigators/NavigationViewNavigator.cs index c4646adb8c..1bd522a8f1 100644 --- a/src/Uno.Extensions.Navigation.UI/Navigators/NavigationViewNavigator.cs +++ b/src/Uno.Extensions.Navigation.UI/Navigators/NavigationViewNavigator.cs @@ -71,13 +71,24 @@ private object[] NavigationMenuItems return Array.Empty(); } - - if (Control.MenuItemsSource is IEnumerable items) + if (Control.MenuItemsSource is IEnumerable || + Control.FooterMenuItemsSource is IEnumerable) { - return items.OfType().ToArray(); + var menuItemsSource = Control.MenuItemsSource is IEnumerable itemsSource ? + itemsSource.ToArray() : Array.Empty(); + var footerMenuItemsSource = Control.FooterMenuItemsSource is IEnumerable footerItemsSource ? + footerItemsSource.ToArray() : Array.Empty(); + + var allitems = menuItemsSource.Concat(footerMenuItemsSource).ToArray(); + + return allitems; } - return Control.MenuItems.ToArray(); + var menuItems = Control.MenuItems.OfType(); + var footerMenuItems = Control.FooterMenuItems.OfType(); + var navigationViewItems = menuItems.Concat(footerMenuItems).ToArray(); + + return navigationViewItems; } } From d0410297b9d837d3c6350eb0a4a689465955c90f Mon Sep 17 00:00:00 2001 From: Nick Randolph Date: Thu, 20 Jun 2024 01:41:09 +1000 Subject: [PATCH 2/2] chore: Tidying up concat of menu and footer items and adjusting sample --- .../Navigators/NavigationViewNavigator.cs | 27 +++++++------------ .../NavigationViewDataBoundPage.xaml | 2 +- .../NavigationViewDataBoundPage.xaml.cs | 2 +- .../NavigationViewDataBoundViewModel.cs | 4 ++- .../NavigationViewHomePage.xaml | 5 +++- .../Navigation/TabBar/TabBarHomeViewModel.cs | 1 + 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/Uno.Extensions.Navigation.UI/Navigators/NavigationViewNavigator.cs b/src/Uno.Extensions.Navigation.UI/Navigators/NavigationViewNavigator.cs index 1bd522a8f1..f8cded7b52 100644 --- a/src/Uno.Extensions.Navigation.UI/Navigators/NavigationViewNavigator.cs +++ b/src/Uno.Extensions.Navigation.UI/Navigators/NavigationViewNavigator.cs @@ -19,7 +19,7 @@ public override void ControlInitialize() // Make sure selectionchanged event handlers are wired up base.ControlInitialize(); - if(Control?.SelectedItem is not null) + if (Control?.SelectedItem is not null) { _ = SelectionChanged(Control, MenuItemToFrameworkElement(Control.SelectedItem)); } @@ -71,24 +71,17 @@ private object[] NavigationMenuItems return Array.Empty(); } - if (Control.MenuItemsSource is IEnumerable || - Control.FooterMenuItemsSource is IEnumerable) - { - var menuItemsSource = Control.MenuItemsSource is IEnumerable itemsSource ? - itemsSource.ToArray() : Array.Empty(); - var footerMenuItemsSource = Control.FooterMenuItemsSource is IEnumerable footerItemsSource ? - footerItemsSource.ToArray() : Array.Empty(); - - var allitems = menuItemsSource.Concat(footerMenuItemsSource).ToArray(); - - return allitems; - } + static IEnumerable GetItems(object source, IEnumerable items) => + (source as IEnumerable)?.OfType() ?? + items?.OfType() ?? + Array.Empty(); - var menuItems = Control.MenuItems.OfType(); - var footerMenuItems = Control.FooterMenuItems.OfType(); - var navigationViewItems = menuItems.Concat(footerMenuItems).ToArray(); + var allitems = Enumerable.Concat( + GetItems(Control.MenuItemsSource, Control.MenuItems), + GetItems(Control.FooterMenuItemsSource, Control.FooterMenuItems) + ).ToArray(); - return navigationViewItems; + return allitems; } } diff --git a/testing/TestHarness/TestHarness.Shared/Ext/Navigation/NavigationView/NavigationViewDataBoundPage.xaml b/testing/TestHarness/TestHarness.Shared/Ext/Navigation/NavigationView/NavigationViewDataBoundPage.xaml index 73a29b0ab7..55a5a55183 100644 --- a/testing/TestHarness/TestHarness.Shared/Ext/Navigation/NavigationView/NavigationViewDataBoundPage.xaml +++ b/testing/TestHarness/TestHarness.Shared/Ext/Navigation/NavigationView/NavigationViewDataBoundPage.xaml @@ -10,7 +10,6 @@ xmlns:utu="using:Uno.Toolkit.UI" xmlns:muxc="using:Microsoft.UI.Xaml.Controls" Background="LightBlue"> - @@ -38,6 +37,7 @@ SelectedItem="{Binding SelectedNavigationItem, Mode=TwoWay}" ItemInvoked="NavigationItemInvoked" MenuItemsSource="{Binding NavigationItems}" + FooterMenuItemsSource="{Binding FooterItems}" IsSettingsVisible="True"> diff --git a/testing/TestHarness/TestHarness.Shared/Ext/Navigation/NavigationView/NavigationViewDataBoundPage.xaml.cs b/testing/TestHarness/TestHarness.Shared/Ext/Navigation/NavigationView/NavigationViewDataBoundPage.xaml.cs index 070a948671..2083fbc63f 100644 --- a/testing/TestHarness/TestHarness.Shared/Ext/Navigation/NavigationView/NavigationViewDataBoundPage.xaml.cs +++ b/testing/TestHarness/TestHarness.Shared/Ext/Navigation/NavigationView/NavigationViewDataBoundPage.xaml.cs @@ -11,7 +11,7 @@ public NavigationViewDataBoundPage() public void NavigationItemInvoked(Microsoft.UI.Xaml.Controls.NavigationView sender, Microsoft.UI.Xaml.Controls.NavigationViewItemInvokedEventArgs e) { - if(e.InvokedItemContainer == sender.SettingsItem as Microsoft.UI.Xaml.Controls.NavigationViewItem) + if (e.InvokedItemContainer == sender.SettingsItem as Microsoft.UI.Xaml.Controls.NavigationViewItem) { this.Navigator()!.NavigateViewModelAsync(this); } diff --git a/testing/TestHarness/TestHarness.Shared/Ext/Navigation/NavigationView/NavigationViewDataBoundViewModel.cs b/testing/TestHarness/TestHarness.Shared/Ext/Navigation/NavigationView/NavigationViewDataBoundViewModel.cs index bea288844d..24b609529b 100644 --- a/testing/TestHarness/TestHarness.Shared/Ext/Navigation/NavigationView/NavigationViewDataBoundViewModel.cs +++ b/testing/TestHarness/TestHarness.Shared/Ext/Navigation/NavigationView/NavigationViewDataBoundViewModel.cs @@ -1,11 +1,13 @@ namespace TestHarness.Ext.Navigation.NavigationView; +[ReactiveBindable(false)] public partial class NavigationViewDataBoundViewModel : ObservableObject { [ObservableProperty] private string selectedNavigationItem = "Deals"; - public string[] NavigationItems { get; } = new string[] { "Products", "Deals", "Profile" }; + public string[] NavigationItems { get; } = ["Products", "Deals"]; + public string[] FooterItems { get; } = ["Profile"]; public void SelectProfile() { diff --git a/testing/TestHarness/TestHarness.Shared/Ext/Navigation/NavigationView/NavigationViewHomePage.xaml b/testing/TestHarness/TestHarness.Shared/Ext/Navigation/NavigationView/NavigationViewHomePage.xaml index 17cb970cc5..0c9e36dfdc 100644 --- a/testing/TestHarness/TestHarness.Shared/Ext/Navigation/NavigationView/NavigationViewHomePage.xaml +++ b/testing/TestHarness/TestHarness.Shared/Ext/Navigation/NavigationView/NavigationViewHomePage.xaml @@ -35,10 +35,13 @@ + + + - +