Skip to content

Commit

Permalink
fix(ShellView): Fixed an issue in ShellView where items added via c…
Browse files Browse the repository at this point in the history
…ode would be duplicated (#13326)

Co-authored-by: Mike Corsaro <mikecorsaro@microsoft.com>
  • Loading branch information
Foda and Mike Corsaro authored Feb 15, 2023
1 parent 5cbb27e commit 0ea3ee2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Controls/src/Core/Handlers/Shell/Windows/ShellView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,25 @@ IEnumerable<object> IterateItems(List<List<Element>> groups)

foreach (var item in group)
{
bool foundExistingVM = false;

// Check to see if this element already has a VM counter part
foreach (var navItem in FlyoutItems)
{
if (navItem is NavigationViewItemViewModel viewModel && viewModel.Data == item)
{
foundExistingVM = true;
yield return viewModel;
}
}

yield return new NavigationViewItemViewModel()
if (!foundExistingVM)
{
Data = item
};
yield return new NavigationViewItemViewModel()
{
Data = item
};
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Maui.Controls;
Expand Down Expand Up @@ -240,6 +241,35 @@ await CreateHandlerAndAddToWindow<ShellHandler>(shell, (handler) =>
});
}

[Fact(DisplayName = "Shell Has Correct Item Count")]
public async Task ShellContentHasCorrectItemCount()
{
SetupBuilder();

var content1 = new ShellContent();
content1.Title = "Hello";
content1.Route = $"...";

var content2 = new ShellContent();
content2.Title = "World";
content2.Route = $"...";

var shell = await CreateShellAsync((shell) =>
{
shell.Items.Add(content1);
shell.Items.Add(content2);
});

await CreateHandlerAndAddToWindow<ShellHandler>(shell, (handler) =>
{
shell.FlyoutBehavior = FlyoutBehavior.Flyout;
handler.PlatformView.UpdateMenuItemSource();
var items = handler.PlatformView.MenuItemsSource as ObservableCollection<object>;
Assert.True(items.Count == 2);
});
}

[Fact(DisplayName = "Single Shell Section with Multiple Children")]
public async Task SingleShellSectionWithMultipleChildren()
{
Expand Down

0 comments on commit 0ea3ee2

Please sign in to comment.