Skip to content

[Android] Fix blank gap when HasNavigationBar=false with SafeAreaEdges=None#36072

Draft
praveenkumarkarunanithi wants to merge 1 commit into
dotnet:mainfrom
praveenkumarkarunanithi:fix-35103
Draft

[Android] Fix blank gap when HasNavigationBar=false with SafeAreaEdges=None#36072
praveenkumarkarunanithi wants to merge 1 commit into
dotnet:mainfrom
praveenkumarkarunanithi:fix-35103

Conversation

@praveenkumarkarunanithi

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!

Root Cause

When NavigationPage.HasNavigationBar is set to false, ToolbarExtensions.UpdateIsVisible collapses the toolbar height to 0. However, the AppBarLayout parent retains stale top padding from a previous inset dispatch — for example, 159px from the status bar/cutout.

Even with toolbar height 0, AppBarLayout.MeasuredHeight remains at 159px because it is driven by padding alone. MauiWindowInsetListener checks MeasuredHeight > 0 to determine whether the AppBar has content. Since it sees 159 > 0, it treats the AppBar as having content, consumes the top system inset, and the inset never reaches SafeAreaExtensions downstream.

The result is a blank gap at the top of the screen equal to the status bar height — visible on both NavigationPage (when a page is pushed with the nav bar hidden) and Shell (when the navigation bar is hidden at runtime).

Description of Change

A single line is added to ToolbarExtensions.UpdateIsVisible in the !showNavBar branch to call SetPadding(0, 0, 0, 0) on the AppBarLayout.

This clears the stale padding so MeasuredHeight collapses to 0. The inset listener then correctly identifies the AppBar as having no content, passes the top inset downstream, and SafeAreaEdges=None is fully respected with no blank gap.

The re-show path is safe — RequestApplyInsets is called in both branches of UpdateIsVisible, so the next inset dispatch naturally restores the correct padding when the nav bar is shown again.

Parent traversal uses nativeToolbar.Parent?.GetParentOfType<AppBarLayout>() — the established MAUI pattern used in ShellToolbarTracker.cs.

Two new device tests pin the fix for both affected paths:

Issues Fixed

Fixes #35103
Fixes #34472

Tested the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Screenshots

Before Issue Fix After Issue Fix
WithoutFix.mov
WithFix.mov

@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 -- 36072

Or

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

@dotnet-policy-service dotnet-policy-service Bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Jun 23, 2026
@praveenkumarkarunanithi praveenkumarkarunanithi added platform/android area-safearea Issues/PRs that have to do with the SafeArea functionality and removed partner/syncfusion Issues / PR's with Syncfusion collaboration labels Jun 23, 2026
@NirmalKumarYuvaraj NirmalKumarYuvaraj added the community ✨ Community Contribution label Jun 23, 2026
@vishnumenon2684

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-safearea Issues/PRs that have to do with the SafeArea functionality community ✨ Community Contribution platform/android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wrong statusbar height when Android device has a notch [Android] Top SafeAreEdge isn't respected when the page is pushed to a NavigationPage

3 participants