Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 8, 2025

Summary

This PR changes the ContentPage SafeAreaEdges default to return None on Android when the user hasn't explicitly set a value, ensuring consistent edge-to-edge behavior across iOS, Android, and Mac Catalyst platforms.

Problem

Previously, ContentPage had different default safe area behaviors across platforms:

  • ContentPage on iOS: Defaulted to None via legacy IgnoreSafeArea (edge-to-edge) ✅
  • ContentPage on Mac Catalyst: Defaulted to None via legacy IgnoreSafeArea (edge-to-edge) ✅
  • ContentPage on Android: Defaulted to Container (safe area padding) ❌

This inconsistency made it difficult for developers to predict layout behavior across platforms and led to unexpected UI rendering.

Solution

Updated ContentPage to default to None (edge-to-edge) on Android when the user hasn't specified safe area behavior:

Changes Made

  1. ContentPage (src/Controls/src/Core/ContentPage/ContentPage.cs)

    • Changed Android default from Container to None in the #else block
    • iOS/Mac Catalyst behavior preserved (uses legacy IgnoreSafeArea property which defaults to trueNone)
  2. SafeAreaExtensions (src/Core/src/Platform/Android/SafeAreaExtensions.cs)

    • Improved margin handling to ensure margins and safe area insets are additive
    • Enhanced view dimension checks to use actual Width/Height when available
    • Better calculation of safe area insets relative to parent position
  3. Test Updates (Multiple test files in TestCases.HostApp)

    • Explicitly set SafeAreaEdges = new SafeAreaEdges(SafeAreaRegions.Container) on ContentPages in existing tests
    • This maintains the previous behavior for existing tests to ensure they continue to pass
    • Updated Android and iOS screenshot baselines to reflect the new consistent behavior

Platform-Specific API Support

The legacy iOS/Mac Catalyst platform-specific UseSafeArea API continues to work as before:

// Explicitly enable safe area
page.On<iOS>().SetUseSafeArea(true);

// Explicitly disable safe area  
page.On<iOS>().SetUseSafeArea(false);

// Not set (defaults to None via IgnoreSafeArea=true)
var page = new ContentPage(); // Edge-to-edge by default

iOS Screenshot Changes Explained

Important Note: All iOS screenshot changes in this PR are due to test files being updated to explicitly set SafeAreaEdges = Container on ContentPages.

Why are iOS screenshots changing?

  • Before this PR: iOS defaulted to None (edge-to-edge), Android defaulted to Container (safe area padding)
  • After this PR: Both iOS and Android default to None (edge-to-edge)
  • Test Updates: To maintain existing test behavior, we explicitly set SafeAreaEdges = Container on test ContentPages
  • Result: iOS screenshots now show safe area padding (Container behavior) instead of edge-to-edge (None behavior)

This is the intended behavior - the tests are now explicitly specifying Container to maintain their previous appearance, whereas before they were implicitly getting different defaults on different platforms.

Breaking Changes ⚠️

This is an intentional breaking change to ensure platform consistency:

Impact:

  • Android ContentPage will now layout edge-to-edge by default
  • Apps that relied on default safe area padding on Android will need explicit configuration

Migration:
Apps that need safe area padding can use either:

// Option 1: SafeAreaEdges property (recommended)
var page = new ContentPage { SafeAreaEdges = SafeAreaEdges.All };
// or for Container behavior (avoids notch/bars but not keyboard):
var page = new ContentPage { SafeAreaEdges = new SafeAreaEdges(SafeAreaRegions.Container) };

// Option 2: Platform-specific API (pages only, iOS/Mac Catalyst)
page.On<iOS>().SetUseSafeArea(true);

Testing

  • 45/45 SafeAreaTests pass
  • 5,419/5,419 Core.UnitTests pass
  • ✅ Updated Android screenshot baselines (3 files)
  • ✅ Updated iOS screenshot baselines (29 files)
  • ✅ Updated 60+ test files to explicitly set SafeAreaEdges for consistency

Fixes

Fixes #31925

Original prompt

This section details on the original issue you should resolve

<issue_title>[NET10.0] Change all defaults of SafeAreaEdges so that they will return "None" as the default if the user hasn't set the value</issue_title>
<issue_description>### Description

We want to make sure that ios and android behave consistently and ensure the least amount of surprise and difficulty on users trying to influence SafeAreas.

This will be a breaking change because now by default Android will layout edge to edge but this is acceptable because we want to make sure ios/android act the same.

We need to go through the code everywhere where we are returning a default for the GetSafeAreaEdges and make sure that the default returned is NONE

  1. if there is an existing API in place that API should win. For example, on Page if the user has set with the platform specific or on Layout if they've set IgnoreSafeArea to true then that will be used as the default
  2. if the user hasn't specified any values that influence the safe area the default should always be none. This applies to Layouts, Borders, ContentViews, ScrollView, ContentPage.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #31925

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Update SafeAreaEdges defaults to None for consistency [NET10.0] Change SafeAreaEdges defaults to None for consistent edge-to-edge behavior Oct 8, 2025
Copilot finished work on behalf of PureWeen October 8, 2025 20:23
@Copilot Copilot AI requested a review from PureWeen October 8, 2025 20:23

// Default to None (edge-to-edge) when user hasn't set any value
// This ensures consistent behavior across iOS, Android, and Mac Catalyst
return SafeAreaRegions.None;
Copy link
Member

Choose a reason for hiding this comment

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

@copilot I think this is the only change that we need in this file.

we just need to change the default to None for platforms other than ios/catalyst

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated ContentPage.cs with the minimal change - only changed the Android default from Container to None in the #else block. The iOS/Mac Catalyst behavior with legacy IgnoreSafeArea is preserved. (commit 1f8e702)

Copy link
Member

Choose a reason for hiding this comment

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

@copilot I think we can revert these changes.

The default for IgnoreSafeArea is going to true which will default to None

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted the Page.cs changes. The default for IgnoreSafeArea is true which correctly defaults to None. (commit 1f8e702)

@github-project-automation github-project-automation bot moved this from Todo to Changes Requested in MAUI SDK Ongoing Oct 8, 2025
@Copilot Copilot AI requested a review from PureWeen October 8, 2025 21:02
Copilot finished work on behalf of PureWeen October 8, 2025 21:02
Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

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

@copilot remove the changes to Layout and SCrollView from this PR

Just keep the changes that were made to ContentPage and the test fixes required for those changes

Copy link
Contributor Author

Copilot AI commented Oct 8, 2025

@copilot remove the changes to Layout and SCrollView from this PR

Just keep the changes that were made to ContentPage and the test fixes required for those changes

Removed changes to Layout and ScrollView. The PR now only contains the ContentPage change (Android default from Container to None) and the updated test. All 45 SafeAreaTests and 5,419 Core.UnitTests pass. (commit f0b6d04)

@Copilot Copilot AI changed the title [NET10.0] Change SafeAreaEdges defaults to None for consistent edge-to-edge behavior [NET10.0] Change ContentPage SafeAreaEdges default to None for consistent edge-to-edge behavior Oct 8, 2025
@Copilot Copilot AI requested a review from PureWeen October 8, 2025 22:07
Copilot finished work on behalf of PureWeen October 8, 2025 22:07
@PureWeen
Copy link
Member

PureWeen commented Oct 8, 2025

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen
Copy link
Member

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@PureWeen
Copy link
Member

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@PureWeen
Copy link
Member

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@PureWeen
Copy link
Member

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@PureWeen
Copy link
Member

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@PureWeen
Copy link
Member

@copilot can you update the description on this PR based on all the changes made?

Can you make a note how all the iOS screen shot changes are because we are now setting the SafeAreaEdges on the "ContentPages" to "Container"

This is going to cause the images on the iOS screenshots to change because before we were basically doing "none" for iOS and "Container" for Android since these values weren't configurable.

@PureWeen
Copy link
Member

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor Author

Copilot AI commented Oct 13, 2025

@copilot can you update the description on this PR based on all the changes made?

Can you make a note how all the iOS screen shot changes are because we are now setting the SafeAreaEdges on the "C...

Updated the PR description to reflect all changes made, including the explicit SafeAreaEdges settings in test files and the explanation of iOS screenshot changes.

Copilot finished work on behalf of PureWeen October 13, 2025 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Changes Requested

Development

Successfully merging this pull request may close these issues.

2 participants