KEMBAR78
[iOS] Shell/navigation page title view - respect the margin property by kubaflo · Pull Request #31701 · dotnet/maui · GitHub
Skip to content

Conversation

@kubaflo
Copy link
Contributor

@kubaflo kubaflo commented Sep 19, 2025

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 of Change

On iOS, the NavigationPage TitleView is currently overflowing, causing its content to be cut off.
This appears to be related to #20959, which removed the default margin.

While the extra margin was not ideal and the change was meant to improve alignment, it introduced new layout issues (as discussed in #31688.

This PR refines that behavior:

  • It replaces the custom CalculateUIEdgeInsets method with an override of AlignmentRectInsets that uses the IView.Margin property.
  • By default, the native iOS gap is preserved to prevent layout regressions.
  • Developers who want the TitleView aligned flush with the screen edges can now achieve this by applying a negative margin.
  • This approach maintains compatibility with existing apps while providing more flexibility for developers who need precise control over TitleView alignment.
Code View
Screenshot 2025-09-20 at 01 59 42 Screenshot 2025-09-20 at 02 00 36
Screenshot 2025-09-20 at 02 01 28 Screenshot 2025-09-20 at 02 02 22

Issues Fixed

Fixes #31688
Fixes #31681 (comment)

@Copilot Copilot AI review requested due to automatic review settings September 19, 2025 23:46
@kubaflo kubaflo changed the base branch from main to inflight/candidate September 19, 2025 23:46
@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Sep 19, 2025
@kubaflo kubaflo changed the title I os] shell/navigation page title view [iOS] Shell/navigation page title view - respect the margin property Sep 19, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@PureWeen
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen
Copy link
Member

/rebase

@PureWeen PureWeen added this to the .NET 9 SR12 milestone Sep 20, 2025
@PureWeen PureWeen moved this from Todo to Ready To Review in MAUI SDK Ongoing Sep 20, 2025
@PureWeen PureWeen added the p/0 Work that we can't release without label Sep 20, 2025
@PureWeen
Copy link
Member

@sheiksyedm can you test this pr please

@EmilienDup
Copy link

I did a quick test of this PR using the sample project from dotnet/maui#31688

With this PR, the navigation bar title view now includes some default margin, resulting in a layout consistent with earlier MAUI versions.

Fine-tuning the positioning of the title view by applying negative left and positive right margins, works well.

👍

@sheiksyedm
Copy link
Contributor

@kubaflo Please resave the latest iOS and Mac image from the CI run.
image

@sheiksyedm
Copy link
Contributor

@sheiksyedm can you test this pr please

Yes, I tested this fix, and it resolves the failures. LGTM.

@PureWeen
Copy link
Member

/rebase

@github-actions github-actions bot force-pushed the iOS]-Shell/NavigationPage-TitleView branch from 37d4363 to 091d0e8 Compare September 22, 2025 21:33
@PureWeen
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@Felix-Dev
Copy link

@kubaflo Where is that -20 Margin coming from to align the TitleView with the edges of the screen? Ideally, I as developer don't want to guess/experiment what the correct negative offset here would be to correctly align the the view to the edges.

If that -20 value is a value based on official data, could something like a resource be added to MAUI which developers could then reference to properly remove the default margin entirely?

@kubaflo
Copy link
Contributor Author

kubaflo commented Sep 22, 2025

@kubaflo Where is that -20 Margin coming from to align the TitleView with the edges of the screen? Ideally, I as developer don't want to guess/experiment what the correct negative offset here would be to correctly align the the view to the edges.

If that -20 value is a value based on official data, could something like a resource be added to MAUI which developers could then reference to properly remove the default margin entirely?

Yeah, that’s the tricky part - iOS doesn’t expose any public API (at least none that I know of) to reliably remove or control that default margin. To make it more complicated, the margin itself isn’t consistent: it can vary depending on screen size, device orientation, and even whether the “Back” text is shown in the navigation bar.

Because of that, if MAUI were to just hard-code the margin to 0, it would actually cause more layout issues than it solves. Without an official value from Apple or a stable API to query, the safest option for now is to preserve the native behavior and let developers apply their own negative margin when they want to override it.

kubaflo and others added 2 commits September 23, 2025 00:54
Replaces the custom CalculateUIEdgeInsets method with an override of AlignmentRectInsets that leverages the IView.Margin property. This ensures the alignment insets reflect the view’s actual margins, allowing developers to align the TitleView directly with the screen edges.
Replaces the custom CalculateUIEdgeInsets method with an override of AlignmentRectInsets that leverages the IView.Margin property. This ensures the alignment insets reflect the view’s actual margins, allowing developers to align the TitleView directly with the screen edges.
@kubaflo kubaflo force-pushed the iOS]-Shell/NavigationPage-TitleView branch from 091d0e8 to 7ceac33 Compare September 22, 2025 22:55
@PureWeen
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@github-project-automation github-project-automation bot moved this from Ready To Review to Approved in MAUI SDK Ongoing Sep 23, 2025
@PureWeen PureWeen merged commit 1e4c148 into dotnet:inflight/candidate Sep 23, 2025
126 of 129 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing Sep 23, 2025
github-actions bot pushed a commit that referenced this pull request Sep 23, 2025
…31701)

* [iOS] Shell/NavigationPage TitleView

Replaces the custom CalculateUIEdgeInsets method with an override of AlignmentRectInsets that leverages the IView.Margin property. This ensures the alignment insets reflect the view’s actual margins, allowing developers to align the TitleView directly with the screen edges.

* [iOS] Shell/NavigationPage TitleView

Replaces the custom CalculateUIEdgeInsets method with an override of AlignmentRectInsets that leverages the IView.Margin property. This ensures the alignment insets reflect the view’s actual margins, allowing developers to align the TitleView directly with the screen edges.
github-actions bot pushed a commit that referenced this pull request Sep 23, 2025
…31701)

* [iOS] Shell/NavigationPage TitleView

Replaces the custom CalculateUIEdgeInsets method with an override of AlignmentRectInsets that leverages the IView.Margin property. This ensures the alignment insets reflect the view’s actual margins, allowing developers to align the TitleView directly with the screen edges.

* [iOS] Shell/NavigationPage TitleView

Replaces the custom CalculateUIEdgeInsets method with an override of AlignmentRectInsets that leverages the IView.Margin property. This ensures the alignment insets reflect the view’s actual margins, allowing developers to align the TitleView directly with the screen edges.
@github-actions github-actions bot locked and limited conversation to collaborators Oct 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-titleview TitleView community ✨ Community Contribution p/0 Work that we can't release without platform/ios

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants