Repository navigation
Fix Shell Flyout item ordering when CurrentItem is set in XAML - #39541
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 39541Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 39541" |
This comment has been minimized.
This comment has been minimized.
|
Hey there @@SubhikshaSf4851! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🟡 Changes recommended
The batched reorder leaves the cached flyout order unchanged in the reported two-item scenario, so the intended fix remains incomplete.
1 open issue
What changed in this PR
This PR addresses #29272 by restoring declaration order for implicit Shell items when CurrentItem is assigned during XAML loading.
Changes:
- Adds a remove-and-reinsert helper that batches collection notifications.
- Uses the helper when adding an implicit item already in the collection.
- Adds a regression test checking item order and preservation of the selected content.
| File | Description |
|---|---|
| src/Controls/tests/Core.UnitTests/ShellFlyoutItemGroupTests.cs | Tests implicit item ordering after assigning CurrentItem. |
| src/Controls/src/Core/Shell/ShellItemCollection.cs | Restores order when an implicit item is already present. |
| src/Controls/src/Core/Shell/ShellElementCollection.cs | Adds the batched reordering helper. |
Review effort: Balanced
| return; | ||
| } | ||
|
|
||
| PauseCollectionChanged(); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| return; | ||
| } | ||
|
|
||
| PauseCollectionChanged(); |
There was a problem hiding this comment.
[major] Logic and Correctness Verification - The original two-content reproduction still leaves the displayed flyout in the wrong order. Set CurrentItem to the second ShellContent before adding the first and then the second content, as in the new test: adding the first content caches the flyout as [second, first]. Pausing the visible notifications means both replayed notifications observe the final [first, second] collection. ShellFlyoutItemsManager.UpdateFlyoutGroupings compares group sizes, but its element-comparison loop uses j > topLevelNew.Count, so it never detects this same-size reorder and never synchronizes FlyoutItems. Shell.Items is corrected while the displayed flyout remains [second, first]. Correct the flyout reorder detection alongside this batching and extend the regression test to assert the actual flyout order through shell.GenerateTestFlyoutItems(), not only Shell.Items and selection.
PR Test Gate
🧪 Gate analysis — click to expand✅ Passed. The selected verification satisfied the gate's passing conditions. Unmatched, skipped, or inconclusive groups are not passing evidence. 🧪 Unit tests
Execution log excerptsWithout fix With fix PR head: 5f5e6760. Without-fix baseline: ab49b07d. |
Tests Failure Analysis
🧪 CI Analysis — click to expand📊 maui-prNo failures found. 🧪 maui-pr-devicetests
🧪 maui-pr-uitests
🧭 Follow-up — actions and refreshNext action: Inspect Android crash/retention diagnostics and MacCatalyst timeout; confirm Entry baseline runtime and restore canceled Layout coverage.
|
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> This pull request improves how the order of `ShellItem` elements is maintained in the collection, especially during XAML loading, and adds a test to ensure that setting the `CurrentItem` does not unintentionally affect the order of implicit shell contents. ### Description of Change Shell item order handling: * Added a new method `RestoreDeclarationOrder` in `ShellElementCollection.cs` to remove and re-add an item, ensuring its position reflects the original declaration order without triggering unwanted collection change events. * Updated `ShellItemCollection.cs` to use `RestoreDeclarationOrder` when setting the `CurrentItem` for implicit items during XAML loading, preserving the intended order. Testing: * Added a unit test `CurrentItemDoesNotChangeTheFlyoutOrderOfImplicitShellContents` in `ShellFlyoutItemGroupTests.cs` to verify that setting the `CurrentItem` does not change the order of implicit shell contents in the flyout. <!-- Enter description of the fix in this section --> ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #29272 - [x] Windows - [x] Android - [x] iOS - [x] Mac | Before Issue Fix | After Issue Fix | |----------|----------| | <img width="441" height="920" alt="BeforeFix29272" src="https://github.com/user-attachments/assets/aab4fc64-ab21-4826-a7bf-6543f80ec1b1" /> | <img width="443" height="923" alt="AfterFix29272" src="https://github.com/user-attachments/assets/0cc628cc-5cdd-46e3-9379-a13123e246e3" /> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->

Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
This pull request improves how the order of
ShellItemelements is maintained in the collection, especially during XAML loading, and adds a test to ensure that setting theCurrentItemdoes not unintentionally affect the order of implicit shell contents.Description of Change
Shell item order handling:
RestoreDeclarationOrderinShellElementCollection.csto remove and re-add an item, ensuring its position reflects the original declaration order without triggering unwanted collection change events.ShellItemCollection.csto useRestoreDeclarationOrderwhen setting theCurrentItemfor implicit items during XAML loading, preserving the intended order.Testing:
CurrentItemDoesNotChangeTheFlyoutOrderOfImplicitShellContentsinShellFlyoutItemGroupTests.csto verify that setting theCurrentItemdoes not change the order of implicit shell contents in the flyout.Issues Fixed
Fixes #29272