[net10.0] Fix SafeArea management on iOS#30629
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
SafeAreaPaddingstruct and extensions to compute and apply safe area insets. - Update
MauiViewandMauiScrollViewto cache safe area, adjust constraints inSizeThatFits,CrossPlatformMeasure, andCrossPlatformArrange, and trigger extra layout passes when insets change. - Add new public API overrides (
AdjustedContentInsetDidChange,SafeAreaInsetsDidChange), renameISafeAreaView2toISafeAreaPage, 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 |
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22417.cs
Outdated
Show resolved
Hide resolved
src/Controls/src/Core/Handlers/Items/CarouselViewHandler.iOS.cs
Outdated
Show resolved
Hide resolved
Member
Author
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Member
Author
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
rmarinho
reviewed
Jul 16, 2025
rmarinho
reviewed
Jul 16, 2025
b131862 to
570efb0
Compare
4 tasks
f43e5cc to
43b907c
Compare
Member
Author
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
091c8e2 to
c847e35
Compare
Member
Author
|
/rebase |
c847e35 to
d7a7df7
Compare
mattleibow
approved these changes
Jul 18, 2025
mattleibow
requested changes
Jul 18, 2025
mattleibow
previously approved these changes
Jul 18, 2025
4 tasks
PureWeen
commented
Jul 23, 2025
jsuarezruiz
reviewed
Jul 24, 2025
jsuarezruiz
reviewed
Jul 25, 2025
| return bounds; | ||
| } | ||
|
|
||
| return new CGRect( |
Contributor
There was a problem hiding this comment.
Here, could we include a validation to prevent negative dimensions when padding exceeds bounds? (technically possible, although it probably wouldn't happen).
| } | ||
|
|
||
| var oldSafeArea = _safeArea; | ||
| _safeArea = SafeAreaInsets.ToSafeAreaInsets(); |
Contributor
There was a problem hiding this comment.
Noticed iOS can trigger multiple times with same values, we could only process if actually changed to avoid redundant calculations.
jsuarezruiz
approved these changes
Jul 25, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Change
Regarding the
MauiScrollViewone, the fix simply checks whether theMauiScrollViewlives inside anotherUIScrollView.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
SizeThatFitssmarter by accounting for safe area adjustments:Then when arranging we can simply adjust for safe area using the cached thickness.
We only need to pay attention when the
SafeAreaInsetschange and trigger an invalidation of the ancestors.Issues Fixed
Fixes #27715
Fixes #24246