maui: Secondary Order ToolbarItems not displayed correctly on iOS
Description
On iOS, ToolbarItems that have their Order="Secondary" are not displayed in the secondary level menu bar. Instead, they appear in line with the Primary items.
I have the following XAML setup:
<ContentPage.ToolbarItems>
<ToolbarItem Command="{Binding SetLowBrightnessCommand}">
<ToolbarItem.IconImageSource>
<FontImageSource
FontFamily="MaterialIconsOutlined-Regular"
Glyph=""
Color="LightBlue"
Size="20"/>
</ToolbarItem.IconImageSource>
</ToolbarItem>
<ToolbarItem Command="{Binding SetHighBrightnessCommand}">
<ToolbarItem.IconImageSource>
<FontImageSource
FontFamily="MaterialIconsOutlined-Regular"
Glyph=""
Color="LightPink"
Size="32"/>
</ToolbarItem.IconImageSource>
</ToolbarItem>
<ToolbarItem
Order="Secondary"
Text="Item 3" />
<ToolbarItem
Order="Secondary"
Text="Item 4" />
</ContentPage.ToolbarItems>
On iOS the secondary items (Item 3, Item 4) are incorrectly displayed in the same level as the icons, which shouldn’t be the case:
On Android it works as expected:
Steps to Reproduce
- Create new MAUI project
- On MainPage, set
<ContentPage.ToolbarItems> - Add some instances of
ToolbarItemwith default setting orOrder="Primary" - Add one or more instances of
ToolbarItemwithOrder="Secondary" - Observe the incorrect behavior on iOS
Link to public reproduction project repository
https://github.com/ewerspej/maui-samples/
Version with bug
7.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
iOS 16 (and possibly earlier versions)
Did you find any workaround?
No
Relevant log output
n/a
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 6
- Comments: 17 (4 by maintainers)
Indeed, in Xamarin.Forms it wasn’t the same on iOS and Android. However, the secondary items were displayed in a proper fashion on iOS, not like it’s now with MAUI. In either case, the secondary items shouldn’t just be added to the navigation bar like in the screenshot, because they will eventually fill up the entire navigation bar with text.
This issue is still active in .NET 8 Core RC1
That’s unlikely, because it works in Xamarin.Forms AFAIK, it just looks different on iOS than it does on Android, which is fine.
Not implemented doesn’t mean not supported. In any case, the current behavior appears broken, no matter whether it’s because of a bug or because of a lack of implementation, it cannot stay like this, because otherwise the
Orderproperty is rendered useless.I can confirm that this did work in Xamarin. And in MAUI they are actually displayed correctly when using a
FlyoutPagewithDetailset to aNavigationPage.However, then the secondary toolbar items cover up the contents of the page.
There is a request open for a long time: https://github.com/dotnet/maui/issues/815 Starting with iOS 14.1 something similar is possible: https://developer.apple.com/documentation/uikit/uinavigationcontroller/customizing_your_app_s_navigation_bar#3950610 It looks a lot better as the maui/xf secondary toolbar items: https://nemecek.be/blog/85/how-to-show-uimenu-from-uibutton-or-uibarbuttonitem
Yes, it should still be reproducible there. However, note that I’ve recently added Shane’s Workarounds NuGet package, which fixes a couple of things temporarily. The issue described here is not affected by that, though.