Skip to content

Commit 0638abd

Browse files
SubhikshaSf4851PureWeen
authored andcommitted
[Windows] Fix for flyout order mismatch (#29197)
Updated concerns Updated review concern Added snapshots and requested changes Modified the sample used HashSet Used FlyoutItems Count directly
1 parent b094e23 commit 0638abd

File tree

7 files changed

+93
-4
lines changed

7 files changed

+93
-4
lines changed

src/Controls/src/Core/Handlers/Shell/Windows/ShellView.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,34 @@ internal void UpdateMenuItemSource()
122122
{
123123
_flyoutGrouping = newGrouping;
124124
var newItems = IterateItems(newGrouping).ToList();
125+
var newItemsSet = new HashSet<object>(newItems);
126+
var flyoutItemsSet = new HashSet<object>(FlyoutItems);
125127

126-
foreach (var item in newItems)
128+
for (int index = 0; index < newItems.Count; index++)
127129
{
128-
if (!FlyoutItems.Contains(item))
130+
var item = newItems[index];
131+
132+
if (!flyoutItemsSet.Contains(item))
129133
{
130-
FlyoutItems.Add(item);
134+
// Use Insert when within bounds, otherwise Add
135+
if (index < FlyoutItems.Count)
136+
{
137+
FlyoutItems.Insert(index, item);
138+
}
139+
else
140+
{
141+
FlyoutItems.Add(item);
142+
}
131143
}
132144
}
133145

134146
for (var i = FlyoutItems.Count - 1; i >= 0; i--)
135147
{
136148
var item = FlyoutItems[i];
137-
if (!newItems.Contains(item))
149+
if (!newItemsSet.Contains(item))
150+
{
138151
FlyoutItems.RemoveAt(i);
152+
}
139153
}
140154
}
141155

20.4 KB
Loading
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
namespace Maui.Controls.Sample.Issues;
2+
3+
[Issue(IssueTracker.Github, 23834, "Flyout Item misbehavior", PlatformAffected.UWP)]
4+
public class Issue23834 : TestShell
5+
{
6+
protected override void Init()
7+
{
8+
var shellContent = new ShellContent()
9+
{
10+
ContentTemplate = new DataTemplate(typeof(Issue23834SamplePage))
11+
};
12+
13+
this.Items.Add(new FlyoutItem()
14+
{
15+
Title = "Flyout Item 1",
16+
IsVisible = false,
17+
Items =
18+
{
19+
shellContent
20+
}
21+
});
22+
23+
this.Items.Add(new FlyoutItem()
24+
{
25+
Title = "Flyout Item 2",
26+
Items =
27+
{
28+
shellContent
29+
}
30+
});
31+
}
32+
}
33+
34+
public class Issue23834SamplePage : ContentPage
35+
{
36+
public Issue23834SamplePage()
37+
{
38+
var layout = new StackLayout();
39+
var changeButton = new Button
40+
{
41+
Text = "Change First Item's IsVisible",
42+
AutomationId = "button"
43+
};
44+
45+
changeButton.Clicked += (s, e) =>
46+
{
47+
Shell.Current.Items[0].IsVisible = true;
48+
};
49+
50+
layout.Children.Add(changeButton);
51+
52+
Content = layout;
53+
}
54+
}
11.6 KB
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues;
6+
public class Issue23834 : _IssuesUITest
7+
{
8+
public Issue23834(TestDevice device) : base(device) { }
9+
10+
public override string Issue => "Flyout Item misbehavior";
11+
12+
[Test]
13+
[Category(UITestCategories.FlyoutPage)]
14+
public void Issue23834FlyoutMisbehavior()
15+
{
16+
App.WaitForElement("button");
17+
App.Tap("button");
18+
App.ShowFlyout();
19+
VerifyScreenshot();
20+
}
21+
}
8.33 KB
Loading
12.1 KB
Loading

0 commit comments

Comments
 (0)