-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[iOS] Shell doesn’t expose an easy way to enable large titles + translucent navbar #32917
Copy link
Copy link
Closed as duplicate of#12156
Closed as duplicate of#12156
Copy link
Labels
Description
Description
Currently this is only possible with ios: for NavigationPages but not Shell Apps which require a custom solution. I thought my solution could be upstreamed and made available as little helper for shell apps.
public class CustomAppShell : ShellRenderer
{
protected override IShellNavBarAppearanceTracker CreateNavBarAppearanceTracker()
{
return new LargeTitleNavBarAppearanceTracker();
}
}public class LargeTitleNavBarAppearanceTracker : IShellNavBarAppearanceTracker
{
public void Dispose() { }
public void ResetAppearance(UINavigationController controller) { }
public void SetAppearance(UINavigationController controller, ShellAppearance appearance)
{
var navBar = controller.NavigationBar;
// Big titles
navBar.PrefersLargeTitles = true;
// Translucent / no separator line
var navBarAppearance = new UINavigationBarAppearance();
navBarAppearance.ConfigureWithTransparentBackground();
navBarAppearance.BackgroundColor = UIColor.Clear;
navBarAppearance.ShadowColor = UIColor.Clear; // remove bottom hairline
navBarAppearance.BackgroundEffect = null;
// Respect Shell colors if used
if (appearance?.ForegroundColor is not null)
{
var fg = appearance.ForegroundColor;
var uiFg = UIColor.FromRGBA((nfloat)fg.Red, (nfloat)fg.Green, (nfloat)fg.Blue, (nfloat)fg.Alpha);
navBarAppearance.TitleTextAttributes = new UIStringAttributes { ForegroundColor = uiFg };
navBarAppearance.LargeTitleTextAttributes = new UIStringAttributes { ForegroundColor = uiFg };
}
navBar.StandardAppearance = navBarAppearance;
navBar.ScrollEdgeAppearance = navBarAppearance;
// Force large titles on the current VC without touching ContentPages
if (controller.TopViewController is { } vc)
vc.NavigationItem.LargeTitleDisplayMode = UINavigationItemLargeTitleDisplayMode.Always;
}
public void UpdateLayout(UINavigationController controller) { }
public void SetHasShadow(UINavigationController controller, bool hasShadow)
{
// we already removed shadow via ShadowColor = Clear
// so ignore
}
}I will try to create a PR for this but feedback on how to best integrate this are very Wellcome.
Public API Changes
<Shell
xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls"
ios:Shell.PrefersLargeTitles="true"
ios:Shell.IsNavigationBarTranslucent="true">Intended Use-Case
To create more native looking apps for iOS 26. Apple now uses this still in many of their current apps like the Sports app.
Reactions are currently unavailable