[Android] Fix blank gap when HasNavigationBar=false with SafeAreaEdges=None#36072
Draft
praveenkumarkarunanithi wants to merge 1 commit into
Draft
[Android] Fix blank gap when HasNavigationBar=false with SafeAreaEdges=None#36072praveenkumarkarunanithi wants to merge 1 commit into
praveenkumarkarunanithi wants to merge 1 commit into
Conversation
Contributor
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 36072Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 36072" |
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.HasNavigationBaris set tofalse,ToolbarExtensions.UpdateIsVisiblecollapses the toolbar height to0. However, theAppBarLayoutparent retains stale top padding from a previous inset dispatch — for example,159pxfrom the status bar/cutout.Even with toolbar height
0,AppBarLayout.MeasuredHeightremains at159pxbecause it is driven by padding alone.MauiWindowInsetListenerchecksMeasuredHeight > 0to determine whether the AppBar has content. Since it sees159 > 0, it treats the AppBar as having content, consumes the top system inset, and the inset never reachesSafeAreaExtensionsdownstream.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) andShell(when the navigation bar is hidden at runtime).Description of Change
A single line is added to
ToolbarExtensions.UpdateIsVisiblein the!showNavBarbranch to callSetPadding(0, 0, 0, 0)on theAppBarLayout.This clears the stale padding so
MeasuredHeightcollapses to0. The inset listener then correctly identifies the AppBar as having no content, passes the top inset downstream, andSafeAreaEdges=Noneis fully respected with no blank gap.The re-show path is safe —
RequestApplyInsetsis called in both branches ofUpdateIsVisible, 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 inShellToolbarTracker.cs.Two new device tests pin the fix for both affected paths:
PushingToPageWithoutNavigationBarClearsAppBarInsetPaddingfor theNavigationPagescenarioHiddenShellNavigationBarClearsAppBarInsetPaddingfor theShellscenarioThese tests were adopted from open contributor PR Fix Android Shell top inset when nav bar is hidden #35555 .
Issues Fixed
Fixes #35103
Fixes #34472
Tested the behaviour in the following platforms
Screenshots
WithoutFix.mov
WithFix.mov