Skip to content

Commit c548e9a

Browse files
committed
[iOS] Add support for large titles in Shell
Introduces the UpdateLargeTitles method to manage large title display modes for navigation bars in ShellItemRenderer. This ensures that the large title preference is updated when the displayed page changes or when the view lays out subviews, aligning with iOS-specific platform configurations.
1 parent 8b0b8be commit c548e9a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellItemRenderer.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.ComponentModel;
66
using System.Linq;
77
using Foundation;
8+
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;
89
using Microsoft.Maui.Graphics;
910
using ObjCRuntime;
1011
using UIKit;
@@ -399,6 +400,7 @@ void OnDisplayedPageChanged(Page page)
399400
{
400401
_displayedPage.PropertyChanged += OnDisplayedPagePropertyChanged;
401402
UpdateTabBarHidden();
403+
UpdateLargeTitles();
402404
}
403405
}
404406

@@ -408,6 +410,31 @@ void OnDisplayedPagePropertyChanged(object sender, PropertyChangedEventArgs e)
408410
UpdateTabBarHidden();
409411
}
410412

413+
414+
void UpdateLargeTitles()
415+
{
416+
var page = _displayedPage;
417+
if (page is null || !OperatingSystem.IsIOSVersionAtLeast(11))
418+
return;
419+
420+
var largeTitleDisplayMode = page.OnThisPlatform().LargeTitleDisplay();
421+
422+
if (SelectedViewController is UINavigationController navigationController)
423+
{
424+
navigationController.NavigationBar.PrefersLargeTitles = largeTitleDisplayMode != LargeTitleDisplayMode.Never;
425+
var top = navigationController.TopViewController;
426+
if (top is not null)
427+
{
428+
top.NavigationItem.LargeTitleDisplayMode = largeTitleDisplayMode switch
429+
{
430+
LargeTitleDisplayMode.Always => UINavigationItemLargeTitleDisplayMode.Always,
431+
LargeTitleDisplayMode.Automatic => UINavigationItemLargeTitleDisplayMode.Automatic,
432+
_ => UINavigationItemLargeTitleDisplayMode.Never
433+
};
434+
}
435+
}
436+
}
437+
411438
void RemoveRenderer(IShellSectionRenderer renderer)
412439
{
413440
if (_sectionRenderers.Remove(renderer.ViewController))
@@ -441,6 +468,7 @@ IShellSectionRenderer RendererForViewController(UIViewController viewController)
441468
public override void ViewWillLayoutSubviews()
442469
{
443470
UpdateTabBarHidden();
471+
UpdateLargeTitles();
444472
base.ViewWillLayoutSubviews();
445473
}
446474

0 commit comments

Comments
 (0)