Skip to content

Commit c086862

Browse files
CopilotPureWeen
andauthored
[NET10.0] Change ContentPage SafeAreaEdges default to None for consistent edge-to-edge behavior (#31926)
* Initial plan * Change SafeAreaEdges defaults to None for consistent edge-to-edge behavior Co-authored-by: PureWeen <5375137+PureWeen@users.noreply.github.com> * Add test for platform-specific UseSafeArea API and fix Layout default Co-authored-by: PureWeen <5375137+PureWeen@users.noreply.github.com> * Simplify changes per feedback - only change Android default to None Co-authored-by: PureWeen <5375137+PureWeen@users.noreply.github.com> * Remove Layout and ScrollView changes per feedback - keep only ContentPage changes Co-authored-by: PureWeen <5375137+PureWeen@users.noreply.github.com> * Adjust safe area insets calculation to account for view margins, ensuring additive offsets * Refactor SafeAreaExtensions to improve margin handling and simplify view dimension checks * - fix tests * - additional fixes * - set default contentpage to container for android consistency * - fix * - fix iOS screen shot offset for consistency * - set to container * - updates tests and screen shots for consistency * - fix screenshots * - fix images --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: PureWeen <5375137+PureWeen@users.noreply.github.com> Co-authored-by: Shane Neuville <shneuvil@microsoft.com>
1 parent dc649e7 commit c086862

File tree

101 files changed

+155
-81
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+155
-81
lines changed

src/Controls/src/Core/ContentPage/ContentPage.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ SafeAreaRegions ISafeAreaView2.GetSafeAreaRegionsForEdge(int edge)
181181
}
182182

183183

184-
#if IOS || MACCATALYST
184+
#if IOS || MACCATALYST
185185

186186
// Developer hasn't set SafeAreaEdges, fall back to legacy IgnoreSafeArea behavior
187187
var ignoreSafeArea = ((ISafeAreaView)this).IgnoreSafeArea;
@@ -194,12 +194,12 @@ SafeAreaRegions ISafeAreaView2.GetSafeAreaRegionsForEdge(int edge)
194194
return SafeAreaRegions.Container; // If legacy says "don't ignore", return Container
195195
}
196196

197-
#else
198-
199-
// By default on android it was never edge to edge so we set this to container by default
200-
return SafeAreaRegions.Container;
197+
#else
201198

202-
#endif
199+
// Default to None (edge-to-edge) for consistent behavior across all platforms
200+
return SafeAreaRegions.None;
201+
202+
#endif
203203
}
204204

205205
SafeAreaEdges ISafeAreaElement.SafeAreaEdgesDefaultValueCreator()

src/Controls/tests/Core.UnitTests/SafeAreaTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,16 @@ public void ContentView_GetSafeAreaRegionsForEdge_DefaultsToNoneWhenNoPropertySe
272272
[Fact]
273273
public void Page_GetSafeAreaRegionsForEdge_DefaultsToNoneForContentPage()
274274
{
275-
var page = new ContentPage(); // ContentPage defaults to SafeAreaRegions.None on iOS (IgnoreSafeArea = true)
275+
var page = new ContentPage(); // ContentPage defaults to SafeAreaRegions.None (edge-to-edge)
276276

277-
// ContentPage has special logic - defaults to SafeAreaRegions.None (edge-to-edge) on iOS
277+
// ContentPage default is now None (edge-to-edge) for consistency across platforms
278278
var safeAreaView2 = (ISafeAreaView2)page;
279279

280-
// only iOS defaults to "None" for ContentPage so we are just validating that the default is container
281-
Assert.Equal(SafeAreaRegions.Container, safeAreaView2.GetSafeAreaRegionsForEdge(0));
282-
Assert.Equal(SafeAreaRegions.Container, safeAreaView2.GetSafeAreaRegionsForEdge(1));
283-
Assert.Equal(SafeAreaRegions.Container, safeAreaView2.GetSafeAreaRegionsForEdge(2));
284-
Assert.Equal(SafeAreaRegions.Container, safeAreaView2.GetSafeAreaRegionsForEdge(3));
280+
// Default is now "None" for all edges when user hasn't set anything
281+
Assert.Equal(SafeAreaRegions.None, safeAreaView2.GetSafeAreaRegionsForEdge(0));
282+
Assert.Equal(SafeAreaRegions.None, safeAreaView2.GetSafeAreaRegionsForEdge(1));
283+
Assert.Equal(SafeAreaRegions.None, safeAreaView2.GetSafeAreaRegionsForEdge(2));
284+
Assert.Equal(SafeAreaRegions.None, safeAreaView2.GetSafeAreaRegionsForEdge(3));
285285
}
286286

287287
// Tests based on existing iOS safe area usage patterns
35 Bytes
Loading
-799 Bytes
Loading
11 Bytes
Loading

src/Controls/tests/TestCases.HostApp/FeatureMatrix/Border/BorderControlsPage.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
xmlns:local="clr-namespace:Maui.Controls.Sample"
55
x:DataType="local:BorderViewModel"
66
x:Class="Maui.Controls.Sample.BorderControlMainPage"
7-
Title="ControlsPage">
7+
Title="ControlsPage"
8+
SafeAreaEdges="Container">
89
<ContentPage.ToolbarItems>
910
<ToolbarItem Text="Options"
1011
Clicked="NavigateToOptionsPage_Clicked"

src/Controls/tests/TestCases.HostApp/FeatureMatrix/CarouselView/CarouselViewControlPage.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
22
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
33
xmlns:local="clr-namespace:Maui.Controls.Sample"
4+
SafeAreaEdges="Container"
45
x:Class="Maui.Controls.Sample.CarouselViewControlPage"
56
Title="CarouselViewControlPage">
67

src/Controls/tests/TestCases.HostApp/FeatureMatrix/CollectionView/HeaderFooter/CollectionViewHeaderPage.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
44
xmlns:local="clr-namespace:Maui.Controls.Sample"
55
x:Class="Maui.Controls.Sample.CollectionViewHeaderPage"
6+
SafeAreaEdges="Container"
67
Title="CollectionViewFeature">
78
<ContentPage.ToolbarItems>
89
<ToolbarItem Text="Options"

src/Controls/tests/TestCases.HostApp/FeatureMatrix/ContentPage/ContentPageControlpage.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public partial class ContentPageControlMainPage : ContentPage
1818
public ContentPageControlMainPage(ContentPageViewModel viewModel)
1919
{
2020
InitializeComponent();
21+
SafeAreaEdges = new SafeAreaEdges(SafeAreaRegions.Container);
2122
_viewModel = viewModel;
2223
BindingContext = _viewModel;
2324
}

src/Controls/tests/TestCases.HostApp/FeatureMatrix/EntryControl/EntryControlPage.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
33
xmlns:local="clr-namespace:Maui.Controls.Sample"
44
x:DataType="local:EntryViewModel"
5+
SafeAreaEdges="Container"
56
x:Class="Maui.Controls.Sample.EntryControlMainPage">
67
<VerticalStackLayout Padding="20"
78
Spacing="8">

0 commit comments

Comments
 (0)