Skip to content
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
22 changes: 18 additions & 4 deletions src/Controls/src/Core/Handlers/Shell/Windows/ShellView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,34 @@ internal void UpdateMenuItemSource()
{
_flyoutGrouping = newGrouping;
var newItems = IterateItems(newGrouping).ToList();
var newItemsSet = new HashSet<object>(newItems);
var flyoutItemsSet = new HashSet<object>(FlyoutItems);

foreach (var item in newItems)
for (int index = 0; index < newItems.Count; index++)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually cannot expect to have a big collection here, but use the Contains with the two nested for loops have a big performance impact. Ideally we could kept it simple, but it should have the best possible behavior in all situations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use a HashSet here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsuarezruiz I have used HashSet as per your suggestion

{
if (!FlyoutItems.Contains(item))
var item = newItems[index];

if (!flyoutItemsSet.Contains(item))
{
FlyoutItems.Add(item);
// Use Insert when within bounds, otherwise Add
if (index < FlyoutItems.Count)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Store FlyoutItems.Count in a variable to minimize repeated property accesses.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the changes per your suggestion.

{
FlyoutItems.Insert(index, item);
}
else
{
FlyoutItems.Add(item);
}
}
}

for (var i = FlyoutItems.Count - 1; i >= 0; i--)
{
var item = FlyoutItems[i];
if (!newItems.Contains(item))
if (!newItemsSet.Contains(item))
{
FlyoutItems.RemoveAt(i);
}
}
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue23834.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 23834, "Flyout Item misbehavior", PlatformAffected.UWP)]
public class Issue23834 : TestShell
{
protected override void Init()
{
var shellContent = new ShellContent()
{
ContentTemplate = new DataTemplate(typeof(Issue23834SamplePage))
};

this.Items.Add(new FlyoutItem()
{
Title = "Flyout Item 1",
IsVisible = false,
Items =
{
shellContent
}
});

this.Items.Add(new FlyoutItem()
{
Title = "Flyout Item 2",
Items =
{
shellContent
}
});
}
}

public class Issue23834SamplePage : ContentPage
{
public Issue23834SamplePage()
{
var layout = new StackLayout();
var changeButton = new Button
{
Text = "Change First Item's IsVisible",
AutomationId = "button"
};

changeButton.Clicked += (s, e) =>
{
Shell.Current.Items[0].IsVisible = true;
};

layout.Children.Add(changeButton);

Content = layout;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;
public class Issue23834 : _IssuesUITest
{
public Issue23834(TestDevice device) : base(device) { }

public override string Issue => "Flyout Item misbehavior";

[Test]
[Category(UITestCategories.FlyoutPage)]
public void Issue23834FlyoutMisbehavior()
{
App.WaitForElement("button");
App.Tap("button");
App.ShowFlyout();
VerifyScreenshot();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending snapshots.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Snapshots already available in the latest build:

For example:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have committed the pending snapshots

}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading