Skip to content

Fix SafeArea management on iOS#28283

Closed
albyrock87 wants to merge 2 commits intodotnet:mainfrom
albyrock87:safe-area-fixes-ios
Closed

Fix SafeArea management on iOS#28283
albyrock87 wants to merge 2 commits intodotnet:mainfrom
albyrock87:safe-area-fixes-ios

Conversation

@albyrock87
Copy link
Contributor

@albyrock87 albyrock87 commented Mar 10, 2025

Description of Change

This is an alternative/cumulative solution for both #27839 and #28264.

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.

Thanks to @PureWeen suggestion to set RespondsToSafeArea to false when the view is a descendant of a UIScrollView.

Issues Fixed

Fixes #27715
Fixes #24246

@albyrock87 albyrock87 requested a review from a team as a code owner March 10, 2025 15:35
@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Mar 10, 2025
<Entry AutomationId="entry" Background="Green"></Entry>
<Label AutomationId="label" Text="If you can't interact with the above entry field, the test has failed" LineBreakMode="CharacterWrap"></Label>
</VerticalStackLayout>
</ContentPage> No newline at end of file
Copy link
Contributor Author

@albyrock87 albyrock87 Mar 10, 2025

Choose a reason for hiding this comment

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

This is the goal of this UITest, the entry should be visible and the user should be able to interact with it.
image

Copy link
Member

Choose a reason for hiding this comment

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

image

I was curious what this looked like on main so if anyone else was wondering :)
edit: this is already here: #28264

@PureWeen PureWeen added this to the .NET 9 SR6 milestone Mar 10, 2025
@PureWeen PureWeen moved this from Todo to Ready To Review in MAUI SDK Ongoing Mar 10, 2025
@albyrock87 albyrock87 force-pushed the safe-area-fixes-ios branch from 8aa94cb to 8b2d34a Compare March 10, 2025 22:53
@PureWeen PureWeen added the p/0 Current heighest priority issues that we are targeting for a release. label Mar 11, 2025
@albyrock87 albyrock87 force-pushed the safe-area-fixes-ios branch 2 times, most recently from c905317 to 65a33cb Compare March 12, 2025 14:24
tj-devel709
tj-devel709 previously approved these changes Mar 14, 2025
@github-project-automation github-project-automation bot moved this from Ready To Review to Approved in MAUI SDK Ongoing Mar 14, 2025
@albyrock87 albyrock87 force-pushed the safe-area-fixes-ios branch from 65a33cb to 5125c01 Compare March 16, 2025 11:22
@dotnet dotnet deleted a comment from azure-pipelines bot Mar 17, 2025
@dotnet dotnet deleted a comment from PureWeen Mar 17, 2025
@dotnet dotnet deleted a comment from PureWeen Mar 17, 2025
@dotnet dotnet deleted a comment from azure-pipelines bot Mar 17, 2025
@dotnet dotnet deleted a comment from azure-pipelines bot Mar 17, 2025
@dotnet dotnet deleted a comment from PureWeen Mar 17, 2025
@dotnet dotnet deleted a comment from azure-pipelines bot Mar 17, 2025
@dotnet dotnet deleted a comment from PureWeen Mar 17, 2025
@dotnet dotnet deleted a comment from azure-pipelines bot Mar 17, 2025
@PureWeen PureWeen marked this pull request as draft March 18, 2025 13:53
@PureWeen PureWeen moved this from Approved to Ready To Review in MAUI SDK Ongoing Mar 18, 2025
@PureWeen PureWeen force-pushed the safe-area-fixes-ios branch from 5125c01 to c4f06b5 Compare March 20, 2025 18:54
@PureWeen PureWeen marked this pull request as ready for review March 20, 2025 18:54
@PureWeen
Copy link
Member

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@PureWeen PureWeen marked this pull request as draft March 20, 2025 20:45
@PureWeen PureWeen self-assigned this Mar 20, 2025
@PureWeen PureWeen mentioned this pull request Mar 21, 2025
@PureWeen PureWeen force-pushed the safe-area-fixes-ios branch from c4f06b5 to 20d3975 Compare March 22, 2025 14:48
@PureWeen PureWeen modified the milestones: .NET 9 SR6, .NET 9 SR7 Mar 22, 2025
@PureWeen PureWeen moved this from Ready To Review to Changes Requested in MAUI SDK Ongoing Mar 24, 2025
@jfversluis jfversluis added the area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter label Mar 25, 2025
@PureWeen
Copy link
Member

PureWeen commented May 1, 2025

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@PureWeen PureWeen modified the milestones: .NET 9 SR7, .NET 9 SR8 May 8, 2025
@PureWeen PureWeen modified the milestones: .NET 9 SR8, .NET 9 Servicing May 8, 2025
albyrock87 and others added 2 commits July 16, 2025 19:00
# Conflicts:
#	src/Controls/src/Core/Page/Page.cs
#	src/Core/src/Platform/iOS/MauiScrollView.cs
#	src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt
#	src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt
@PureWeen PureWeen force-pushed the safe-area-fixes-ios branch from f279dae to e8e981d Compare July 17, 2025 00:09
@PureWeen
Copy link
Member

PureWeen commented Jul 17, 2025

Closing this in favor of
#30629
and
#30337

@PureWeen PureWeen closed this Jul 17, 2025
@albyrock87 albyrock87 deleted the safe-area-fixes-ios branch July 17, 2025 23:35
@github-actions github-actions bot locked and limited conversation to collaborators Aug 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter community ✨ Community Contribution p/0 Current heighest priority issues that we are targeting for a release. platform/ios

Projects

None yet

6 participants