Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SafeArea adjustments #27043

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Fix SafeArea adjustments #27043

wants to merge 1 commit into from

Conversation

PureWeen
Copy link
Member

@PureWeen PureWeen commented Jan 9, 2025

Description of Change

We initially had to revert this PR because of a conflict with ScrollView that was uncovered #24600

We recently vastly simplified the ScrollView control on iOS #26763 which looks to have fixed the issue we were running up against.

This PR relates to some issues found here #22476 when trying to layout a Button when it's inside a layout that is partly inside the safearea.

The problem we found is that the MauiView returns a size from SizeThatFits that doesn't include the SafeAreaInsets. The arrange pass insets its Bounds and passes this value to CrossPlatformArrange but the Bounds being used is the size of the children not including the SafeAreaInsets which means the bounds used for arranging is wrong.

You can see from the screenshots below that the VSL surrounding the the entry gets arranged incorrectly

Comparison

Given the following XAML

<ContentPage
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="Maui.Controls.Sample.MainPage"
    xmlns:local="clr-namespace:Maui.Controls.Sample"
    xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls"
    ios:Page.UseSafeArea="false"
    >
    <VerticalStackLayout x:Name="layout" Background="Purple" IgnoreSafeArea="False" VerticalOptions="Start" IsClippedToBounds="True" >
        <Entry x:Name="label" Background="Green" Text="Hello there"></Entry>
    </VerticalStackLayout>
</ContentPage>

Before

image

After

image

Issues Fixed

Fixes #24246

@Copilot Copilot bot review requested due to automatic review settings January 9, 2025 21:24
@PureWeen PureWeen requested a review from a team as a code owner January 9, 2025 21:24
@PureWeen PureWeen added this to the .NET 9 SR4 milestone Jan 9, 2025

Choose a reason for hiding this comment

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

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

Files not reviewed (1)
  • src/Controls/tests/TestCases.HostApp/Issues/Issue24246.xaml: Language not supported
Comments suppressed due to low confidence (2)

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24246.cs:15

  • The test case should verify that the layout adjusts correctly for the safe area insets. Add a test to check the visual layout to confirm that the safe area insets are applied correctly.
[Test]

src/Core/src/Platform/iOS/MauiView.cs:123

  • Ensure that the new behavior for adjusting safe area insets in SizeThatFits is covered by tests.
if (RespondsToSafeArea() && widthConstraint >= 0 && heightConstraint >= 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready To Review
Development

Successfully merging this pull request may close these issues.

[iOS] SafeArea arrange insets are currently insetting based on an incorrect Bounds
1 participant