Add Support for StatusBarBehavior in Android Modal Page#3123
Add Support for StatusBarBehavior in Android Modal Page#3123TheCodeTraveler merged 17 commits intomainfrom
StatusBarBehavior in Android Modal Page#3123Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to make StatusBarBehavior work correctly on Android modal pages by resolving and targeting the active modal Window (DialogFragment window) instead of always using the hosting Activity’s window. It also simplifies a shared property-changed helper and refreshes the sample UI layout for StatusBar/NavigationBar pages.
Changes:
- Update Android
StatusBarimplementation to resolve the “current window” (including modal DialogFragment windows) before applying color/style. - Replace multiple
IsOneOfoverloads with a single variadic helper inPropertyChangedEventArgsExtensions. - Update sample view model defaults and tweak sample XAML layout for StatusBar/NavigationBar selection UI.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/CommunityToolkit.Maui/Extensions/PropertyChangedEventArgsExtensions.shared.cs |
Consolidates property-name helper methods into a single IsOneOf API. |
src/CommunityToolkit.Maui.Core/Platform/StatusBar/StatusBar.android.cs |
Applies status bar changes to the appropriate Android Window, including modals. |
samples/.../StatusBarBehaviorViewModel.cs |
Adjusts sample defaults for initial UI state. |
samples/.../NavigationBarPage.xaml |
Refactors sample layout for NavigationBar style selection. |
samples/.../StatusBarBehaviorPage.xaml |
Refactors sample layout/formatting for style selection and modal button. |
src/CommunityToolkit.Maui.Core/Platform/StatusBar/StatusBar.android.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui/Extensions/PropertyChangedEventArgsExtensions.shared.cs
Show resolved
Hide resolved
…droid.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
src/CommunityToolkit.Maui/Extensions/PropertyChangedEventArgsExtensions.shared.cs
Show resolved
Hide resolved
src/CommunityToolkit.Maui.Core/Platform/StatusBar/StatusBar.android.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.Core/Platform/StatusBar/StatusBar.android.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.Core/Platform/StatusBar/StatusBar.android.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.Core/Platform/StatusBar/StatusBar.android.cs
Outdated
Show resolved
Hide resolved
samples/CommunityToolkit.Maui.Sample/ViewModels/Behaviors/StatusBarBehaviorViewModel.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.Core/Extensions/WindowExtensions.android.cs
Outdated
Show resolved
Hide resolved
samples/CommunityToolkit.Maui.Sample/ViewModels/Behaviors/StatusBarBehaviorViewModel.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui/Extensions/PropertyChangedEventArgsExtensions.shared.cs
Show resolved
Hide resolved
…roid.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…' of https://github.com/CommunityToolkit/Maui into Add-Support-For-Android-StatusBarBehavior-in-Modal-Page
| window.SetFlags(WindowManagerFlags.DrawsSystemBarBackgrounds, WindowManagerFlags.DrawsSystemBarBackgrounds); | ||
| } | ||
|
|
||
| WindowCompat.SetDecorFitsSystemWindows(window, !isColorTransparent); |
There was a problem hiding this comment.
This method is deprecated on Android API 36. It is highly recommended that we add a check and only use it on an OS using a lower API.
| bool isColorTransparent = platformColor == PlatformColor.Transparent; | ||
| if (isColorTransparent) | ||
| { | ||
| window.ClearFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); |
There was a problem hiding this comment.
I don't know any other way to deal with issue of status bar transparency but settings and clearing flags can and will interfere with developers attempts to set or use full screen and in a test app I had to remove all the settings and clearing of flags to have my app do what I wanted. I removed it throughout the toolkit where I found it in statusbar.
I am not sure what we should do here. This is more a comment about the current state of the behavior of hiding/showing status bar is a complicated mess atm and depending on API level settings these options will have completely different behavior on each API.
I do not advocate ripping out the flags I am simply stating all of my use cases do require it. It would have significant impact on all API below 36 so I am not suggesting we do that. Just maybe add checks and block the changes for android 36?
There was a problem hiding this comment.
It might be a good idea to add full-screen mode to CommunityToolkit.Maui so it doesn't interfere with the color change. We could also use an IsVisible boolean on the status bar and navigation bar.
There was a problem hiding this comment.
@IgrisModz sure! What specifically do we need to add?
Do you have any links to documentation you could share?
ne0rrmatrix
left a comment
There was a problem hiding this comment.
The issue I was having was unrelated to flags and I am happy to now approve this pr. I found out the issue was with my app and has nothing to do with @TheCodeTraveler code. It was all me. Anyways these changes do fix the issues they raised and I will be very happy to see the fixes live.
|
Hi @TheCodeTraveler , |
Description of Change
This PR updates
StatusBar.android.csto get the current window, checking to see if a Modal Page is being displayed.Because MAUI uses a
Dialogwith its ownWindow, not the Activity'sWindowfor modal pages,Platform.CurrentActivity?.Windowgives the wrong window when a modal is displayed. This PR updates the extension methodGetCurrentWindow()to check for aDialogFragment(aka a .NET MAUI Modal Page on Android) and returns theDialogFragment'sWindow.Linked Issues
PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information
This PR also removes duplicate methods from
PropertyChangedEventArgsExtensionsand updates the Sample App UI forStatusBarPageandNavigationBarPage