Skip to content

Commit 066ceca

Browse files
authored
[iOS] Added support for large titles in Shell (#32081)
<!-- 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. !!!!!!! --> ### Description of Change 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. ### 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 #12156 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
2 parents ce589f6 + 4461913 commit 066ceca

6 files changed

Lines changed: 79 additions & 0 deletions

File tree

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.Always;
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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<Shell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls"
5+
x:Class="Maui.Controls.Sample.Issues.Issue12156">
6+
7+
<ShellContent Title="Home">
8+
<ContentPage ios:Page.LargeTitleDisplay="Always">
9+
<Label
10+
Text="Issue 12156"
11+
AutomationId="Label"
12+
VerticalOptions="Center"
13+
HorizontalOptions="Center"/>
14+
</ContentPage>
15+
</ShellContent>
16+
17+
</Shell>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Maui.Controls.Sample.Issues;
2+
3+
[Issue(IssueTracker.Github, 12156, "iOS Page.LargeTitleDisplay does not work on iOS", PlatformAffected.iOS)]
4+
public partial class Issue12156 : Shell
5+
{
6+
public Issue12156()
7+
{
8+
InitializeComponent();
9+
}
10+
}
4.95 KB
Loading
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#if TEST_FAILS_ON_ANDROID && TEST_FAILS_ON_ANDROID && TEST_FAILS_ON_WINDOWS
2+
using NUnit.Framework;
3+
using UITest.Appium;
4+
using UITest.Core;
5+
6+
namespace Microsoft.Maui.TestCases.Tests.Issues;
7+
8+
public class Issue12156 : _IssuesUITest
9+
{
10+
public Issue12156(TestDevice testDevice) : base(testDevice)
11+
{
12+
}
13+
14+
public override string Issue => "iOS Page.LargeTitleDisplay does not work on iOS";
15+
16+
[Test]
17+
[Category(UITestCategories.TitleView)]
18+
public void LargeTitleDisplayWorks()
19+
{
20+
App.WaitForElement("Label");
21+
VerifyScreenshot();
22+
}
23+
}
24+
#endif
13.4 KB
Loading

0 commit comments

Comments
 (0)