diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellItemRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellItemRenderer.cs index 217b3ca87bdd..16676bc973b0 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellItemRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellItemRenderer.cs @@ -5,6 +5,7 @@ using System.ComponentModel; using System.Linq; using Foundation; +using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific; using Microsoft.Maui.Graphics; using ObjCRuntime; using UIKit; @@ -399,6 +400,7 @@ void OnDisplayedPageChanged(Page page) { _displayedPage.PropertyChanged += OnDisplayedPagePropertyChanged; UpdateTabBarHidden(); + UpdateLargeTitles(); } } @@ -408,6 +410,31 @@ void OnDisplayedPagePropertyChanged(object sender, PropertyChangedEventArgs e) UpdateTabBarHidden(); } + + void UpdateLargeTitles() + { + var page = _displayedPage; + if (page is null || !OperatingSystem.IsIOSVersionAtLeast(11)) + return; + + var largeTitleDisplayMode = page.OnThisPlatform().LargeTitleDisplay(); + + if (SelectedViewController is UINavigationController navigationController) + { + navigationController.NavigationBar.PrefersLargeTitles = largeTitleDisplayMode == LargeTitleDisplayMode.Always; + var top = navigationController.TopViewController; + if (top is not null) + { + top.NavigationItem.LargeTitleDisplayMode = largeTitleDisplayMode switch + { + LargeTitleDisplayMode.Always => UINavigationItemLargeTitleDisplayMode.Always, + LargeTitleDisplayMode.Automatic => UINavigationItemLargeTitleDisplayMode.Automatic, + _ => UINavigationItemLargeTitleDisplayMode.Never + }; + } + } + } + void RemoveRenderer(IShellSectionRenderer renderer) { if (_sectionRenderers.Remove(renderer.ViewController)) @@ -441,6 +468,7 @@ IShellSectionRenderer RendererForViewController(UIViewController viewController) public override void ViewWillLayoutSubviews() { UpdateTabBarHidden(); + UpdateLargeTitles(); base.ViewWillLayoutSubviews(); } diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue12156.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue12156.xaml new file mode 100644 index 000000000000..2fc30cb4e560 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue12156.xaml @@ -0,0 +1,17 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue12156.xaml.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue12156.xaml.cs new file mode 100644 index 000000000000..44868857cd28 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue12156.xaml.cs @@ -0,0 +1,10 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 12156, "iOS Page.LargeTitleDisplay does not work on iOS", PlatformAffected.iOS)] +public partial class Issue12156 : Shell +{ + public Issue12156() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/LargeTitleDisplayWorks.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/LargeTitleDisplayWorks.png new file mode 100644 index 000000000000..f41ba82aab49 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/LargeTitleDisplayWorks.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue12156.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue12156.cs new file mode 100644 index 000000000000..169695ba4bec --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue12156.cs @@ -0,0 +1,24 @@ +#if TEST_FAILS_ON_ANDROID && TEST_FAILS_ON_ANDROID && TEST_FAILS_ON_WINDOWS +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue12156 : _IssuesUITest +{ + public Issue12156(TestDevice testDevice) : base(testDevice) + { + } + + public override string Issue => "iOS Page.LargeTitleDisplay does not work on iOS"; + + [Test] + [Category(UITestCategories.TitleView)] + public void LargeTitleDisplayWorks() + { + App.WaitForElement("Label"); + VerifyScreenshot(); + } +} +#endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/LargeTitleDisplayWorks.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/LargeTitleDisplayWorks.png new file mode 100644 index 000000000000..615003281faa Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/LargeTitleDisplayWorks.png differ