Skip to content

[net10.0] Fix SafeArea management on iOS #30629

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

Open
wants to merge 5 commits into
base: net10.0
Choose a base branch
from

Conversation

PureWeen
Copy link
Member

Description of Change

Regarding the MauiScrollView one, the fix simply checks whether the MauiScrollView lives inside another UIScrollView.
In such case we can give for granted that the ancestor one is properly accounting for safe area.

Regarding safe area, the main problem is that MAUI was measuring the content without accounting for the safe area.

This PR makes the SizeThatFits smarter by accounting for safe area adjustments:

  1. Cache safe area thickness
  2. Reduce constraints by safe area thickness
  3. Measure
  4. Add safe area thickness back to measured size

Then when arranging we can simply adjust for safe area using the cached thickness.

We only need to pay attention when the SafeAreaInsets change and trigger an invalidation of the ancestors.

Issues Fixed

Fixes #27715
Fixes #24246

PureWeen and others added 2 commits July 15, 2025 10:02
* Fixed the SafeArea test case issues and 22417(mac) main issue

* Removed the Fails condition on Mac
@Copilot Copilot AI review requested due to automatic review settings July 15, 2025 15:09
@PureWeen PureWeen requested a review from a team as a code owner July 15, 2025 15:09
@PureWeen PureWeen added this to the .NET 10.0-preview7 milestone Jul 15, 2025
@PureWeen PureWeen added the p/0 Work that we can't release without label Jul 15, 2025
Copy link
Contributor

@Copilot 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.

Pull Request Overview

Fix SafeArea management on iOS by introducing caching and smart adjustments during measure and layout, and ensure nested UIScrollView scenarios are handled correctly.

  • Introduce SafeAreaPadding struct and extensions to compute and apply safe area insets.
  • Update MauiView and MauiScrollView to cache safe area, adjust constraints in SizeThatFits, CrossPlatformMeasure, and CrossPlatformArrange, and trigger extra layout passes when insets change.
  • Add new public API overrides (AdjustedContentInsetDidChange, SafeAreaInsetsDidChange), rename ISafeAreaView2 to ISafeAreaPage, and include UI tests and HostApp pages for issues 27715 and 24246.

Reviewed Changes

Copilot reviewed 16 out of 28 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/TestUtils/src/UITest.Appium/Actions/AppiumLifecycleActions.cs Add Thread.Sleep(100) after app activation to wait for animations
src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt Add overrides for AdjustedContentInsetDidChange and SafeAreaInsetsDidChange
src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt Add overrides for AdjustedContentInsetDidChange and SafeAreaInsetsDidChange
src/Core/src/Platform/iOS/SafeAreaPadding.cs New SafeAreaPadding record struct and ToSafeAreaInsets extension
src/Core/src/Platform/iOS/MauiView.cs Integrate safe area caching, measurement, and arrangement adjustments
src/Core/src/Platform/iOS/MauiScrollView.cs Detect nested scroll views, cache safe area, adjust measure/layout logic
src/Core/src/Core/ISafeAreaPage.cs Rename ISafeAreaView2 to ISafeAreaPage
src/Controls/src/Core/Page/Page.cs Update Page to implement ISafeAreaPage and adjust explicit interface implementation
src/Controls/src/Core/Handlers/Items/CarouselViewHandler.iOS.cs Clamp desired size on Mac Catalyst to constraints
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27715.cs Add UI test for ScrollView adjusted insets issue
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24246.cs Add UI test for SafeArea arrange insets issue
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22417.cs Update conditional compilation directive for a failing test
src/Controls/tests/TestCases.HostApp/Issues/Issue27715.xaml.cs Add HostApp code-behind page for issue 27715
src/Controls/tests/TestCases.HostApp/Issues/Issue27715.xaml Add XAML page for ScrollView insets test
src/Controls/tests/TestCases.HostApp/Issues/Issue24246.xaml.cs Add HostApp code-behind page for issue 24246
src/Controls/tests/TestCases.HostApp/Issues/Issue24246.xaml Add XAML page for SafeArea arrange test

@PureWeen
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen moved this from Todo to Ready To Review in MAUI SDK Ongoing Jul 15, 2025
@PureWeen
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

return;
}

if (!ValidateSafeArea())
Copy link
Member

Choose a reason for hiding this comment

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

I wonder this check will have some performance impact.. Will look up the tree and all.. can we cache this in some way?

@@ -148,6 +193,34 @@ public override void LayoutSubviews()
CrossPlatformArrange(bounds);
}

bool ValidateSafeArea()
Copy link
Member

Choose a reason for hiding this comment

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

Can this be shared with MauiScrollView?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p/0 Work that we can't release without
Projects
Status: Ready To Review
Development

Successfully merging this pull request may close these issues.

3 participants