diff --git a/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs index a120b1cdee60..e7e6ad7ce2e5 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs @@ -2295,10 +2295,34 @@ public override CGRect Frame value.Width = (value.X - xSpace) + value.Width; value.X = xSpace; } + + if (_child?.VirtualView is IView view) + { + var margin = view.Margin; + + // Apply margins AFTER back button spacing calculations + // Margins push the view inward to keep it within the nav bar bounds + var newWidth = value.Width - (nfloat)(margin.Left + margin.Right); + if (newWidth < 0) + newWidth = 0; + + value = new RectangleF( + value.X + (nfloat)margin.Left, + value.Y + (nfloat)margin.Top, + newWidth, + value.Height + ); + } } - ; value.Height = ToolbarHeight; + + // Reduce height by vertical margins so the view stays within the nav bar + if (_child?.VirtualView is IView marginView) + { + var verticalMargin = (nfloat)(marginView.Margin.Top + marginView.Margin.Bottom); + value.Height = (nfloat)Math.Max(0, value.Height - verticalMargin); + } } base.Frame = value; diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/NavigationPageTitleViewShouldRespectMargins.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/NavigationPageTitleViewShouldRespectMargins.png new file mode 100644 index 000000000000..25153196ecbc Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/NavigationPageTitleViewShouldRespectMargins.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue32200.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue32200.xaml new file mode 100644 index 000000000000..1d19d535b74a --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue32200.xaml @@ -0,0 +1,18 @@ + + + + + + + \ No newline at end of file diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue32200.xaml.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue32200.xaml.cs new file mode 100644 index 000000000000..3ca1badf773b --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue32200.xaml.cs @@ -0,0 +1,15 @@ +namespace Maui.Controls.Sample.Issues; + +[XamlCompilation(XamlCompilationOptions.Compile)] +[Issue(IssueTracker.Github, 32200, "NavigationPage TitleView iOS 26", PlatformAffected.iOS)] +public class Issue32200NavigationPage : NavigationPage +{ + public Issue32200NavigationPage() : base(new Issue32200()) { } +} +public partial class Issue32200 : ContentPage +{ + public Issue32200() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/NavigationPageTitleViewShouldRespectMargins.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/NavigationPageTitleViewShouldRespectMargins.png new file mode 100644 index 000000000000..61930b320b73 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/NavigationPageTitleViewShouldRespectMargins.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32200.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32200.cs new file mode 100644 index 000000000000..cbb124a7cb9f --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32200.cs @@ -0,0 +1,19 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue32200 : _IssuesUITest +{ + public override string Issue => "NavigationPage TitleView iOS 26"; + public Issue32200(TestDevice device) : base(device) { } + + [Test] + [Category(UITestCategories.Navigation)] + public void NavigationPageTitleViewShouldRespectMargins() + { + App.WaitForElement("Label"); + VerifyScreenshot(); + } +} diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/NavigationPageTitleViewShouldRespectMargins.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/NavigationPageTitleViewShouldRespectMargins.png new file mode 100644 index 000000000000..b12c45a48a9c Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/NavigationPageTitleViewShouldRespectMargins.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios-26/NavigationPageTitleViewShouldRespectMargins.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios-26/NavigationPageTitleViewShouldRespectMargins.png new file mode 100644 index 000000000000..edcccefc3dad Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios-26/NavigationPageTitleViewShouldRespectMargins.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/NavigationPageTitleViewShouldRespectMargins.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/NavigationPageTitleViewShouldRespectMargins.png new file mode 100644 index 000000000000..edcccefc3dad Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/NavigationPageTitleViewShouldRespectMargins.png differ