Skip to content

Fix TitleView not showing in iOS 26 - #32793

Closed
StephaneDelcroix wants to merge 1 commit into
mainfrom
fix/issue-32777-titleview-ios26
Closed

StephaneDelcroix wants to merge 1 commit into
mainfrom
fix/issue-32777-titleview-ios26

Conversation

@StephaneDelcroix

Copy link
Copy Markdown
Contributor

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 from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description

Fixes #32777 - TitleView not showing in iOS 26

This PR addresses the issue where custom TitleViews in Shell navigation were not displaying correctly in iOS 26 and MacCatalyst 26 due to changes in how UINavigationItem.TitleView handles autolayout constraints.

Changes Made

Core Fix

  • Modified TitleViewContainer constructor to detect iOS 26+ and MacCatalyst 26+ and use autoresizing masks instead of autolayout constraints
  • Added new constructor TitleViewContainer(View view, CGRect navigationBarFrame) that accepts the navigation bar frame for proper sizing on iOS 26+
  • Updated UpdateTitleView method to use the new constructor for iOS 26+ platforms

Test Coverage

  • Created Issue32777.xaml - Reproduction test case with TitleView containing a grid, label, and button
  • Created Issue32777.xaml.cs - Code-behind with proper Issue attribute
  • Created Issue32777.cs - Comprehensive UI test that verifies the fix works correctly

Technical Details

In iOS 26+, Apple changed how UINavigationItem.TitleView handles autolayout constraints. The fix switches to using autoresizing masks for iOS 26+, which resolves the display issues while maintaining backward compatibility.

Testing

✅ UI Test: Issue32777.TitleViewShouldBeVisibleAndNotCoverContent - PASSED

  • Tested on iPhone 17 Pro simulator (iOS 26+)
  • Verifies that TitleView displays correctly without covering content

Platforms Affected

  • iOS 26+
  • MacCatalyst 26+

Backward Compatibility

Maintains full backward compatibility with iOS versions prior to 26.

Related Issues

Fixes #32777

Copilot AI review requested due to automatic review settings November 21, 2025 10:20
- Modified TitleViewContainer to use autoresizing masks for iOS 26+ and MacCatalyst 26+
- Added constructor to set frame from navigation bar dimensions
- Updated UpdateTitleView to use new constructor for iOS 26+
- Added test case Issue32777 with UI test to verify the fix

This addresses the issue where custom TitleViews were not displaying correctly
in iOS 26 due to changes in how UINavigationItem.TitleView handles autolayout
constraints. The fix switches to using autoresizing masks for iOS 26+, which
resolves the display issues while maintaining backward compatibility.

Fixes #32777

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR aims to fix an issue where custom TitleViews in Shell navigation were not displaying correctly in iOS 26 and MacCatalyst 26. However, the PR contains several critical issues and unrelated changes that need to be addressed.

Key Changes

  • Modified TitleViewContainer to use autoresizing masks instead of autolayout constraints for iOS 26+
  • Added new test case (Issue32777) with XAML, code-behind, and UI tests
  • Fixed a bug in source generator where TargetNullValue binding property flag was incorrectly checked
  • Enhanced source generator test infrastructure with compilation error checking
  • Added verbatim string literals (@"") for file paths in source generators
  • Added new XAML unit testing guidelines documentation

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs Core fix switching to autoresizing masks for iOS 26+ (but version number is incorrect)
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32777.cs UI test implementation (missing TitleView visibility verification)
src/Controls/tests/TestCases.HostApp/Issues/Issue32777.xaml Test page XAML with TitleView and content
src/Controls/tests/TestCases.HostApp/Issues/Issue32777.xaml.cs Test page code-behind (incorrect PlatformAffected value)
src/Controls/tests/SourceGen.UnitTests/SourceGeneratorDriver.cs Enhanced test infrastructure with compilation validation
src/Controls/tests/SourceGen.UnitTests/InitializeComponent/*.cs Updated tests to use new compilation checking parameter
src/Controls/src/SourceGen/CompiledBindingMarkup.cs Fixed TargetNullValue flag bug (unrelated to TitleView, not documented)
src/Controls/src/SourceGen/*.cs Added verbatim string literals for file paths
.github/instructions/xaml-unittests.instructions.md New XAML unit testing guidelines (unrelated, not documented)

{
var view = new TitleViewContainer(titleView, frame);
NavigationItem.TitleView = view;
}

Copilot AI Nov 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing null check and potential crash

If ViewController?.NavigationController?.NavigationBar.Frame is null (returns null for CGRect?), the code inside this if block won't execute, and NavigationItem.TitleView won't be set at all. This could leave the TitleView in an inconsistent state.

Consider adding an else clause or logging when the frame is not available:

if (OperatingSystem.IsIOSVersionAtLeast(26) || OperatingSystem.IsMacCatalystVersionAtLeast(26))
{
    if (ViewController?.NavigationController?.NavigationBar.Frame is CGRect frame)
    {
        var view = new TitleViewContainer(titleView, frame);
        NavigationItem.TitleView = view;
    }
    else
    {
        // Fallback to default constructor if frame is not available
        var view = new TitleViewContainer(titleView);
        NavigationItem.TitleView = view;
    }
}
Suggested change
}
}
else
{
// Fallback to default constructor if frame is not available
var view = new TitleViewContainer(titleView);
NavigationItem.TitleView = view;
}

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,10 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 32777, "TitleView not showing in iOS 26", PlatformAffected.iOS)]

Copilot AI Nov 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue attribute uses incorrect PlatformAffected value

The PlatformAffected parameter should be PlatformAffected.iOS | PlatformAffected.MacCatalyst (or PlatformAffected.All) since the PR description states this affects both iOS 26+ and MacCatalyst 26+.

Using only PlatformAffected.iOS is inconsistent with the actual platforms affected by this issue.

Suggested change
[Issue(IssueTracker.Github, 32777, "TitleView not showing in iOS 26", PlatformAffected.iOS)]
[Issue(IssueTracker.Github, 32777, "TitleView not showing in iOS 26", PlatformAffected.iOS | PlatformAffected.MacCatalyst)]

Copilot uses AI. Check for mistakes.
@PureWeen

Copy link
Copy Markdown
Member

#32341

@PureWeen PureWeen closed this Nov 21, 2025
@StephaneDelcroix
StephaneDelcroix deleted the fix/issue-32777-titleview-ios26 branch November 21, 2025 13:13
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TitleView not showing in iOS 26 - .NET10

3 participants