Fix: [BUG] StatusBarBehavior is causing Android layouts to go behind status bar and navigation bar buttons on launch #2351#3189
Conversation
|
@evgenyvalavin |
|
Thanks @Pastajello! I'm sure you already know this (and it's probably why the PR is still in Draft), but I'll need you to remove |
There was a problem hiding this comment.
Pull request overview
This PR aims to fix an Android launch-time layout issue where applying StatusBarBehavior can cause content to render under the status bar / navigation bar, by adjusting how window flags and insets handling are applied on Android. It also adds a new MauiApp1 sample project intended to reproduce the issue and visually validate the fix, and wires that sample into the samples solution.
Changes:
- Adjusts Android status bar window flag/insets behavior in
StatusBar.android.cs. - Adds a new
samples/MauiApp1repro app (resources, platform stubs, pages) for validating the bug/fix. - Updates
samples/CommunityToolkit.Maui.Sample.slnxto include the new sample project.
Reviewed changes
Copilot reviewed 34 out of 40 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/CommunityToolkit.Maui.Core/Platform/StatusBar/StatusBar.android.cs | Updates Android window flag / insets handling for status bar behavior. |
| samples/MauiApp1/Resources/Styles/Styles.xaml | Adds sample styling resources for the repro app. |
| samples/MauiApp1/Resources/Styles/Colors.xaml | Adds sample color resources for the repro app. |
| samples/MauiApp1/Resources/Splash/splash.svg | Adds splash asset for the repro app. |
| samples/MauiApp1/Resources/Raw/AboutAssets.txt | Adds template raw asset for the repro app. |
| samples/MauiApp1/Resources/Images/dotnet_bot.png | Adds an image asset used by the repro UI. |
| samples/MauiApp1/Resources/AppIcon/appiconfg.svg | Adds app icon foreground asset for the repro app. |
| samples/MauiApp1/Resources/AppIcon/appicon.svg | Adds app icon background asset for the repro app. |
| samples/MauiApp1/Properties/launchSettings.json | Adds Windows launch settings for the repro app. |
| samples/MauiApp1/Platforms/Windows/Package.appxmanifest | Adds Windows packaging manifest for the repro app. |
| samples/MauiApp1/Platforms/Windows/App.xaml.cs | Adds WinUI app bootstrap for the repro app. |
| samples/MauiApp1/Platforms/Windows/App.xaml | Adds WinUI app XAML entry for the repro app. |
| samples/MauiApp1/Platforms/Windows/app.manifest | Adds Windows app manifest for the repro app. |
| samples/MauiApp1/Platforms/Tizen/tizen-manifest.xml | Adds Tizen manifest stub for the repro app. |
| samples/MauiApp1/Platforms/Tizen/Main.cs | Adds Tizen entry point stub for the repro app. |
| samples/MauiApp1/Platforms/MacCatalyst/Program.cs | Adds MacCatalyst entry point stub for the repro app. |
| samples/MauiApp1/Platforms/MacCatalyst/Info.plist | Adds MacCatalyst Info.plist for the repro app. |
| samples/MauiApp1/Platforms/MacCatalyst/Entitlements.plist | Adds MacCatalyst entitlements for the repro app. |
| samples/MauiApp1/Platforms/MacCatalyst/AppDelegate.cs | Adds MacCatalyst app delegate for the repro app. |
| samples/MauiApp1/Platforms/iOS/Resources/PrivacyInfo.xcprivacy | Adds iOS privacy manifest for the repro app. |
| samples/MauiApp1/Platforms/iOS/Program.cs | Adds iOS entry point for the repro app. |
| samples/MauiApp1/Platforms/iOS/Info.plist | Adds iOS Info.plist for the repro app. |
| samples/MauiApp1/Platforms/iOS/AppDelegate.cs | Adds iOS app delegate for the repro app. |
| samples/MauiApp1/Platforms/Android/Resources/values/colors.xml | Adds Android color resources for the repro app. |
| samples/MauiApp1/Platforms/Android/MainApplication.cs | Adds Android Application class for the repro app. |
| samples/MauiApp1/Platforms/Android/MainActivity.cs | Adds Android MainActivity for the repro app. |
| samples/MauiApp1/Platforms/Android/AndroidManifest.xml | Adds Android manifest for the repro app. |
| samples/MauiApp1/MauiProgram.cs | Adds app builder initialization for the repro app. |
| samples/MauiApp1/MauiApp1.csproj | Adds the repro project file and references. |
| samples/MauiApp1/MainPage.xaml.cs | Adds sample main page code-behind for repro UI. |
| samples/MauiApp1/MainPage.xaml | Adds sample main page UI to demonstrate insets/layout. |
| samples/MauiApp1/InitialPage.xaml.cs | Adds initial page code-behind for repro navigation. |
| samples/MauiApp1/InitialPage.xaml | Adds initial page UI for repro navigation. |
| samples/MauiApp1/AppShell.xaml.cs | Adds Shell code-behind and initial navigation logic. |
| samples/MauiApp1/AppShell.xaml | Adds Shell structure and attaches StatusBarBehavior for repro. |
| samples/MauiApp1/App.xaml.cs | Adds Application bootstrap for the repro app. |
| samples/MauiApp1/App.xaml | Adds Application resources for the repro app. |
| samples/CommunityToolkit.Maui.Sample.slnx | Adds MauiApp1 to the samples solution. |
|
I have removed the sample project, created a bit better sample butttt.... if we add this fix it breaks the BehaviorGalleryPage in the same way it is broken on API 35+ (or 31+, didnt check) as described here:
Yet... if we do this in BehaviorsGalleryPage ctor: Which should be a default value for ContentPage it behaves correctly for all 29/35 (which I use for testing) Should this be merged or wait for #34886 so it can be safely merged? |
TheCodeTraveler
left a comment
There was a problem hiding this comment.
Thanks again @Pastajello! I have some formatting / refactoring comments in the Sample to add to CoPilot's review of the code updates.
Co-authored-by: Brandon Minnick <13558917+TheCodeTraveler@users.noreply.github.com>
|
Thanks @Pastajello! I'm not too concerned about dotnet/maui#34886 as that is specific to .NET MAUI, not our toolkit. I'm cool with adding Could you take a moment to respond to CoPilot's suggestions and either implement them if you deem it appropriate, or respond + resolve the comment if it's not. I've also added some comments asking for formatting fixes. |
| static void ApplyWindowFlags(Window window) | ||
| { | ||
| bool isTransparent = platformColor == PlatformColor.Transparent; | ||
|
|
||
| if (isTransparent) | ||
| if (OperatingSystem.IsAndroidVersionAtLeast(30)) | ||
| { | ||
| window.ClearFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); | ||
| window.SetFlags(WindowManagerFlags.LayoutNoLimits, WindowManagerFlags.LayoutNoLimits); | ||
| ApplyAndroidApi30(window); |
There was a problem hiding this comment.
ApplyWindowFlags now always ends up calling SetDecorFitsSystemWindows(window, false) (via ApplyAndroidApi30/ApplyAndroidApiLessThan30). Previously opaque StatusBarColor values would set DecorFitsSystemWindows=true, and elsewhere in the repo dialogs still use a transparency check (e.g., DialogFragmentService.android.cs:140-145). This is a behavioral change for non-transparent colors and can make content lay out under system bars when it previously would not. Consider restoring a transparency-based decision for DecorFitsSystemWindows (or documenting an intentional breaking change).
There was a problem hiding this comment.
What are your thoughts on this comment from CoPilot, @Pastajello?
There was a problem hiding this comment.
Hello. Yea so. DialogFragmentService.android.cs( and connected) from what I gather is an old(Net 9) fix for StatusBarBeahvior on ModalPages? Technically could be deprecated?
Recently #3123 was added and it re-introduced the fix for NET 10.
Removal of window.SetFlags(WindowManagerFlags.LayoutNoLimits, WindowManagerFlags.LayoutNoLimits);
is main fix in the PR basically - I've not seen an instance where it is needed - perhaps with all EdgeToEdge work in .NET 10.
Setting SetDecorFitsSystemWindows(window, !isTransparent) breaks transparency setting on normal/modal pages.
I've found that PR also partially fixes the #3009 if we remove broken line from Snackbar.android.cs : SetLayoutParametersForView
!TryGetPageActiveModalPage(out _) ||
which skips setting layout parameters for snack.
(and snacks on modal pages are generally broken..)
I'm starting to lose context with all the different paths I've changed and tested(and english is not my main language) so sorry for chaotic message.
Generally with .NET 10 beahvior of app changed heavily and I have no idea of inner MAUI working.
…Behavior/OverflowingTitleViewPage.xaml.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…Behavior/BrokenTitleViewShell.xaml.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
….com/Pastajello/CommunityToolkit.Maui into bugfix/2351-content-behind-statusbar
…Behavior/BrokenTitleViewShell.xaml ok Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
….com/Pastajello/CommunityToolkit.Maui into bugfix/2351-content-behind-statusbar

Description of Change
Hello!
In the course of investigating the issue I found that flag swapping that was done before is, apparently, no longer needed. Now, the changes are... quite small but impactful and I havent tested every scenario possible:
so.... Its something to do still. When I have time I can go on and test.
Linked Issues
PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information