maui
maui copied to clipboard
Implement iOS/macOS secondary ToolbarItems
Description of Change
Uses a more modern pattern for iOS to show secondary toolbar items. This PR detects toolbar items that have the Order property set to Secondary and displays them in a popover menu. The icon is the system icon from iOS, we might consider letting the people customize that, although I'm not 100% sure how.
The secondary menu is always shown on the far right (or left when RTL is on) and takes into account Priority to order the items.
This PR:
- Implements the secondary toolbar item functionality for iOS
- Adds a Toolbar section to the sample app
- Fixes the Menubar description in the sample app
- Moves API documentation from external XML files to inline
- Deletes the (now) unused API docs XML files
- Removes a (now) unused extension method
- Adds a new extension method
- Minor code improvements overall
Note that this uses APIs that are only available on iOS 13+, I think that is the minimum supported version for .NET MAUI on .NET 10 anyway?
Be aware that when enabled changes for one of the secondary items, the menu will be closed. The menu items in there are immutable, so when that happens, the whole menu is rebuilt which causes the menu to close when its opened.
Issues Fixed
Fixes #815
Preview
iOS
https://github.com/user-attachments/assets/8161b602-7960-4243-b73d-5e853afcbbf7
macOS
/rebase
Failing test unrelated
@jfversluis
Hi, I've had look at this PR because I need secondary ToolbarItems in .NET 9.
As I wrote a solution based on your PR I observed that ToolbarItem.Command is executed twice.
Imho here only IMenuItemController.Activate should be called
https://github.com/dotnet/maui/blob/725fec19e6e1b54b1bc3abe20239416c0c584e08/src/Controls/src/Core/Compatibility/iOS/Extensions/ToolbarItemExtensions.cs#L27-L28
@lucacivale I've also interested in this PR feature but on .NET 9. Can you share your solution or is it private?