Skip to content

[net11.0] Expose safe area contract for custom views - #38039

Merged
kubaflo merged 1 commit into
net11.0from
kubaflo-safe-area-custom-views-net11
Aug 31, 2026
Merged

kubaflo merged 1 commit into
net11.0from
kubaflo-safe-area-custom-views-net11

Conversation

@kubaflo

@kubaflo kubaflo commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

Expose a focused public safe-area contract for third-party and custom views:

  • make ISafeAreaElement public with its per-edge SafeAreaEdges configuration
  • add GetEffectiveSafeAreaEdges() so native hosts can read the same compatibility-resolved values used by MAUI handlers
  • keep MAUI control-specific default-value creation internal
  • route iOS, Mac Catalyst, and Android safe-area handling through the public contract while retaining the existing ISafeAreaView2 path for built-in controls
  • invalidate the iOS native subtree when SafeAreaEdges changes at runtime
  • treat custom ISafeAreaElement layouts as explicitly opted in when Android evaluates nested recycler/scroll-view listeners

This lets a custom view define its own bindable SafeAreaEdges property and participate in Container, None, All, and SoftInput behavior without implementing MAUI-internal interfaces. Existing built-in defaults and legacy IgnoreSafeArea behavior remain unchanged.

This PR supersedes and replaces #37750. That PR grew to 58 files and its current CI fails during compilation because stale StatusBarTheme entries are duplicated in PublicAPI.Unshipped.txt, preventing its platform tests from running. This replacement was developed independently from the current net11.0 source, then compared afterward; it retains the necessary native-host resolution and runtime invalidation while avoiding the unrelated API baseline churn and broad safe-area refactor.

Public API

public interface ISafeAreaElement
{
    SafeAreaEdges SafeAreaEdges { get; }
}

public static SafeAreaEdges GetEffectiveSafeAreaEdges(this ISafeAreaElement safeAreaElement);

Validation

Unit and API validation

  • dotnet build Microsoft.Maui.BuildTasks.slnf --no-restore -p:PublicApiType=Validate --nologo --verbosity:minimal
    • succeeded, including Core and Controls for iOS, Mac Catalyst, Android, .NET, and .NET Standard
  • dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --no-restore -p:PublicApiType=Validate --filter FullyQualifiedName~SafeAreaTests --logger "console;verbosity=minimal"
    • 61 passed, 0 failed

iOS

  • dotnet build src/Core/src/Core.csproj -f net11.0-ios26.5 -p:IncludeIosTargetFrameworks=true -p:PublicApiType=Validate --no-restore --nologo --verbosity:minimal
    • Build succeeded, 0 errors
  • pwsh .github/scripts/BuildAndRunSandbox.ps1 -Platform ios -Configuration Debug -DeviceUdid 20F5E8A1-901C-4C42-B8AA-E41A0641E2C5
    • iPhone 17 Pro simulator, iOS 26.5
    • custom TemplatedView : ISafeAreaElement toggled None -> Container -> None
    • observed top/bottom inset changes of 62 / 34 points, then exact restoration
safe-area-custom-view-ios.mp4

Android

  • dotnet build src/Core/src/Core.csproj -f net11.0-android37.0 -p:IncludeAndroidTargetFrameworks=true -p:PublicApiType=Validate --no-restore --nologo --verbosity:minimal
    • Build succeeded, 0 errors
  • ANDROID_SERIAL=emulator-5554 pwsh .github/scripts/BuildAndRunSandbox.ps1 -Platform android -Configuration Release -DeviceUdid emulator-5554
    • Copilot_API_35 emulator, Android API 35
    • custom TemplatedView : ISafeAreaElement toggled None -> Container -> None
    • observed top/bottom inset changes of 128 / 63 pixels, then exact restoration
safe-area-custom-view-android.mp4

The proof-only Sandbox scenario was removed after recording; production tests remain in the change.

Issues Fixed

Fixes #37384

Allow custom views and native hosts to use MAUI's per-edge safe area model while preserving built-in compatibility behavior across iOS and Android.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings August 31, 2026 15:58
@kubaflo
kubaflo temporarily deployed to copilot-pat-pool August 31, 2026 15:58 — with GitHub Actions Inactive
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 38039

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 38039"

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

Pull request overview

This PR introduces a public, per-edge safe-area contract (ISafeAreaElement) for custom/third-party views and updates MAUI’s iOS/MacCatalyst/Android platform logic to honor that contract while keeping existing built-in/legacy behaviors intact.

Changes:

  • Adds public Microsoft.Maui.ISafeAreaElement and SafeAreaElementExtensions.GetEffectiveSafeAreaEdges() and updates all Core PublicAPI baselines accordingly.
  • Routes iOS/MacCatalyst and Android safe-area resolution through the public contract (while preserving ISafeAreaView2 and legacy ISafeAreaView behavior).
  • Adds/updates unit tests to validate the public contract and effective-edge behavior.
File summaries
File Description
src/Core/src/Core/ISafeAreaElement.cs Makes ISafeAreaElement public and adds GetEffectiveSafeAreaEdges() plus internal helper extensions used by platform code.
src/Core/src/Handlers/View/ViewHandler.cs Enables safe-area edge mapping on MacCatalyst as well as iOS/Android.
src/Core/src/Handlers/View/ViewHandler.iOS.cs Invalidates the native safe-area subtree when SafeAreaEdges changes at runtime.
src/Core/src/Platform/iOS/MauiView.cs Switches per-edge safe-area evaluation to the shared public/internal contract and adds subtree invalidation helper.
src/Core/src/Platform/iOS/MauiScrollView.cs Uses shared edge-resolution logic for scroll-view safe-area decisions.
src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs Aligns keyboard auto-scroll suppression with the updated safe-area edges handling.
src/Core/src/Platform/Android/SafeAreaExtensions.cs Adds support for reading safe-area edges from ISafeAreaElement (including via handler.VirtualView).
src/Core/src/Platform/Android/MauiWindowInsetListener.cs Treats ISafeAreaElement as an explicit safe-area opt-in for inset tracking decisions.
src/Controls/src/Core/SafeAreaElement.cs Keeps default-value creation internal via an internal controller interface while preserving safe defaults.
src/Controls/src/Core/Layout/Layout.cs Updates built-in controls to participate via the internal controller interface for default-value creation.
src/Controls/src/Core/ContentView/ContentView.cs Same: shifts to the controller interface to keep default creation internal while enabling public reading.
src/Controls/src/Core/ContentPage/ContentPage.cs Same: aligns built-in page with controller-based defaults and public contract.
src/Controls/src/Core/Border/Border.cs Same: aligns built-in border with controller-based defaults and public contract.
src/Controls/src/Core/ScrollView/ScrollView.cs Same: aligns built-in scroll view with controller-based defaults and public contract.
src/Controls/tests/Core.UnitTests/SafeAreaTests.cs Adds tests covering custom ISafeAreaElement behavior and effective-edge semantics.
src/Core/src/PublicAPI/net/PublicAPI.Unshipped.txt Records new public API surface for .NET TFMs.
src/Core/src/PublicAPI/netstandard/PublicAPI.Unshipped.txt Records new public API surface for netstandard TFMs.
src/Core/src/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt Records new public API surface for netstandard2.0 TFMs.
src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt Records new public API surface for Android TFM.
src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt Records new public API surface for iOS TFM.
src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt Records new public API surface for MacCatalyst TFM.
src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt Records new public API surface for Windows TFM.
src/Core/src/PublicAPI/net-tizen/PublicAPI.Unshipped.txt Records new public API surface for Tizen TFM.
Review details
  • Files reviewed: 23/23 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment on lines 616 to +618
/// <summary>
    /// Called when the scroll orientation has changed to trigger proper RTL layout recalculation.
    /// </summary>
    /// Called when the scroll orientation has changed to trigger proper RTL layout recalculation.
    /// </summary>
@kubaflo
kubaflo merged commit 92f4887 into net11.0 Aug 31, 2026
37 of 40 checks passed
@kubaflo
kubaflo deleted the kubaflo-safe-area-custom-views-net11 branch August 31, 2026 21:32
@github-actions github-actions Bot added this to the .NET 11.0-preview7 milestone Aug 31, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 9, 2026

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — a2dac642 Deployed Aug 31, 2026 by kubaflo via conclusion #1649
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants