KEMBAR78
[Windows] Fixed Unstable order of Flyout Items with conditional visibility by SubhikshaSf4851 · Pull Request #29197 · dotnet/maui · GitHub
Skip to content

Conversation

@SubhikshaSf4851
Copy link
Contributor

Root Cause:

When the visibility of a Flyout item is changed, the UpdateMenuItemSource method simply adds the item to the end, resulting in the original order of the Flyout items being mismatched.

Description of change:

Instead of adding the item, I have retrieved its original position and inserted it back into the Flyout items accordingly, which results the original order being maintained.

Tested the behavior in the following platforms:

  • Windows
  • Android
  • iOS
  • Mac

Issue Fixed:

Fixes #23834

Before Issue Fix After Issue Fix
Issue23834_BeforeFix.mp4
Issue23834_AfterFix.mp4

@dotnet-policy-service dotnet-policy-service bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Apr 25, 2025
if (flyoutItemIndex == -1)
{
FlyoutItems.Add(item);
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.

var item = newItems[index];
var flyoutItemIndex = FlyoutItems.IndexOf(item);

if (flyoutItemIndex == -1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not big performance differences, but can simplify this using Contains:

if (!FlyoutItems.Contains(item))
    {
        // Use Insert when within bounds, otherwise Add
        if (index < count)
        {
            FlyoutItems.Insert(index, item);
        }
        else
        {
            FlyoutItems.Add(item);
        }
    }

NOTE: count is a variable with the FlyoutItems.Count value.

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.

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

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

@SubhikshaSf4851 SubhikshaSf4851 marked this pull request as ready for review April 28, 2025 11:15
@SubhikshaSf4851 SubhikshaSf4851 requested a review from a team as a code owner April 28, 2025 11:15
@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@bronteq
Copy link

bronteq commented May 22, 2025

@jsuarezruiz friendly ping, is it possible to merge in the next inflight round this pr? It seems ready.
My company is hitting the bug solved by this pr, then I saw that pr #28977 about Shell Flyout was merged.

@bronteq
Copy link

bronteq commented Jun 3, 2025

@jsuarezruiz friendly ping, is it possible to merge this pr in the next inflight round?

var itemsCount = FlyoutItems.Count;

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

{
_flyoutGrouping = newGrouping;
var newItems = IterateItems(newGrouping).ToList();
var itemsCount = 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.

This count becomes stale after Insert operations.

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 FlyoutItems Count directly.

{
var item = newItems[index];

if (!FlyoutItems.Contains(item))
Copy link
Contributor

Choose a reason for hiding this comment

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

The performance degrades quadratically with collection size, for example, 100 items = 100,000 operations instead of 100.

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've addressed the performance concern by using HashSet. Kindly let me know if you have any suggestions

@bronteq
Copy link

bronteq commented Jul 15, 2025

@jsuarezruiz friendly ping

@bronteq
Copy link

bronteq commented Aug 5, 2025

@jsuarezruiz @PureWeen friendly ping

@bronteq
Copy link

bronteq commented Aug 25, 2025

@PureWeen @jfversluis friendly ping, this should be ready to merge

@jfversluis
Copy link
Member

/rebase

@jfversluis
Copy link
Member

@bronteq did you download the artifacts and verified this fixes your issue?

@Copilot Copilot AI review requested due to automatic review settings August 25, 2025 13:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@jfversluis
Copy link
Member

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@bronteq
Copy link

bronteq commented Aug 26, 2025

@bronteq did you download the artifacts and verified this fixes your issue?

@jfversluis i followed this https://github.com/dotnet/maui/wiki/Testing-PR-Builds but i do not find nuget folder in the artifacts, probably because MAUI-public was not executed

I also tried this https://github.com/dotnet/maui/wiki/Nightly-Builds but i think that nightlies do not contain not merged PRs, this has the wrong behavior

@jfversluis
Copy link
Member

/azp run MAUI-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jfversluis
Copy link
Member

@bronteq you're totally right, my bad! Triggered that one now, please let me know :)

@bronteq
Copy link

bronteq commented Aug 27, 2025

@jfversluis thank you so much, i can confirm that this PR solves the issue

@jfversluis jfversluis changed the base branch from main to inflight/current August 27, 2025 13:44
@jfversluis jfversluis added this to the .NET 9 SR11 milestone Aug 27, 2025
@jfversluis jfversluis merged commit a489638 into dotnet:inflight/current Aug 27, 2025
94 checks passed
PureWeen pushed a commit that referenced this pull request Sep 8, 2025
Updated concerns

Updated review concern

Added snapshots and requested changes

Modified the sample used HashSet

Used FlyoutItems Count directly
@github-actions github-actions bot locked and limited conversation to collaborators Sep 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-flyout Flyout community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unstable order of FlyoutItems with conditional visibility

4 participants