From b14025fc73417fc6b72446545bf35af4c08d446c Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+TheCodeTraveler@users.noreply.github.com> Date: Fri, 27 Feb 2026 12:02:31 -0800 Subject: [PATCH 01/11] Apply StatusBarColor and StatusBarAppearence to Correct Window --- .../Platform/StatusBar/StatusBar.android.cs | 95 ++++++++++--------- 1 file changed, 51 insertions(+), 44 deletions(-) diff --git a/src/CommunityToolkit.Maui.Core/Platform/StatusBar/StatusBar.android.cs b/src/CommunityToolkit.Maui.Core/Platform/StatusBar/StatusBar.android.cs index 50d7fbc709..639fac2395 100644 --- a/src/CommunityToolkit.Maui.Core/Platform/StatusBar/StatusBar.android.cs +++ b/src/CommunityToolkit.Maui.Core/Platform/StatusBar/StatusBar.android.cs @@ -35,57 +35,57 @@ static void PlatformSetColor(Color color) return; } - if (Activity.Window is not null) + if (GetCurrentWindow() is not Window { DecorView.RootView: not null } window) { - var platformColor = color.ToPlatform(); + return; + } - if (OperatingSystem.IsAndroidVersionAtLeast(35)) - { - const string statusBarOverlayTag = "StatusBarOverlay"; + var platformColor = color.ToPlatform(); - var window = Activity.GetCurrentWindow(); + if (OperatingSystem.IsAndroidVersionAtLeast(35)) + { + const string statusBarOverlayTag = "StatusBarOverlay"; - var decorGroup = (ViewGroup)window.DecorView; - var statusBarOverlay = decorGroup.FindViewWithTag(statusBarOverlayTag); + var decorGroup = (ViewGroup)window.DecorView.RootView; + var statusBarOverlay = decorGroup.FindViewWithTag(statusBarOverlayTag); - if (statusBarOverlay is null) - { - var statusBarHeight = Activity.Resources?.GetIdentifier("status_bar_height", "dimen", "android") ?? 0; - var statusBarPixelSize = statusBarHeight > 0 ? Activity.Resources?.GetDimensionPixelSize(statusBarHeight) ?? 0 : 0; + if (statusBarOverlay is null) + { + var statusBarHeight = Activity.Resources?.GetIdentifier("status_bar_height", "dimen", "android") ?? 0; + var statusBarPixelSize = statusBarHeight > 0 ? Activity.Resources?.GetDimensionPixelSize(statusBarHeight) ?? 0 : 0; - statusBarOverlay = new(Activity) + statusBarOverlay = new(Activity) + { + LayoutParameters = new FrameLayout.LayoutParams(Android.Views.ViewGroup.LayoutParams.MatchParent, statusBarPixelSize + 3) { - LayoutParameters = new FrameLayout.LayoutParams(Android.Views.ViewGroup.LayoutParams.MatchParent, statusBarPixelSize + 3) - { - Gravity = GravityFlags.Top - } - }; - - decorGroup.AddView(statusBarOverlay); - statusBarOverlay.SetZ(0); - } + Gravity = GravityFlags.Top + } + }; - statusBarOverlay.SetBackgroundColor(platformColor); - } - else - { - Activity.Window.SetStatusBarColor(platformColor); + decorGroup.AddView(statusBarOverlay); + statusBarOverlay.SetZ(0); } - bool isColorTransparent = platformColor == PlatformColor.Transparent; - if (isColorTransparent) - { - Activity.Window.ClearFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); - Activity.Window.SetFlags(WindowManagerFlags.LayoutNoLimits, WindowManagerFlags.LayoutNoLimits); - } - else - { - Activity.Window.ClearFlags(WindowManagerFlags.LayoutNoLimits); - Activity.Window.SetFlags(WindowManagerFlags.DrawsSystemBarBackgrounds, WindowManagerFlags.DrawsSystemBarBackgrounds); - } + statusBarOverlay.SetBackgroundColor(platformColor); + } + else + { + window.SetStatusBarColor(platformColor); + } - WindowCompat.SetDecorFitsSystemWindows(Activity.Window, !isColorTransparent); + bool isColorTransparent = platformColor == PlatformColor.Transparent; + if (isColorTransparent) + { + window.ClearFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); + window.SetFlags(WindowManagerFlags.LayoutNoLimits, WindowManagerFlags.LayoutNoLimits); } + else + { + window.ClearFlags(WindowManagerFlags.LayoutNoLimits); + window.SetFlags(WindowManagerFlags.DrawsSystemBarBackgrounds, WindowManagerFlags.DrawsSystemBarBackgrounds); + } + + WindowCompat.SetDecorFitsSystemWindows(window, !isColorTransparent); } static void PlatformSetStyle(StatusBarStyle style) @@ -98,12 +98,12 @@ static void PlatformSetStyle(StatusBarStyle style) switch (style) { case StatusBarStyle.DarkContent: - SetStatusBarAppearance(Activity, true); + SetStatusBarAppearance(true); break; case StatusBarStyle.Default: case StatusBarStyle.LightContent: - SetStatusBarAppearance(Activity, false); + SetStatusBarAppearance(false); break; default: @@ -111,12 +111,19 @@ static void PlatformSetStyle(StatusBarStyle style) } } - static void SetStatusBarAppearance(Activity activity, bool isLightStatusBars) + static void SetStatusBarAppearance(bool isLightStatusBars) { - var window = activity.GetCurrentWindow(); - if (WindowCompat.GetInsetsController(window, window.DecorView) is WindowInsetsControllerCompat windowController) + if(GetCurrentWindow() is Window window + && WindowCompat.GetInsetsController(window, window.DecorView) is WindowInsetsControllerCompat windowController) { windowController.AppearanceLightStatusBars = isLightStatusBars; } } + + // Check if a modal DialogFragment is active and use its window + static Window? GetCurrentWindow() + { + var dialogFragment = Activity.GetFragmentManager()?.Fragments.OfType().LastOrDefault(); + return dialogFragment?.Dialog?.Window ?? Activity.Window; // Fall back to the Activity window for non-modal pages + } } \ No newline at end of file From 286b267901996174f30be3ab0471fd84c52c2b2f Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+TheCodeTraveler@users.noreply.github.com> Date: Fri, 27 Feb 2026 12:02:42 -0800 Subject: [PATCH 02/11] Update formatting --- .../Behaviors/StatusBarBehaviorViewModel.cs | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/samples/CommunityToolkit.Maui.Sample/ViewModels/Behaviors/StatusBarBehaviorViewModel.cs b/samples/CommunityToolkit.Maui.Sample/ViewModels/Behaviors/StatusBarBehaviorViewModel.cs index 8b5a7f560a..eee918ab74 100644 --- a/samples/CommunityToolkit.Maui.Sample/ViewModels/Behaviors/StatusBarBehaviorViewModel.cs +++ b/samples/CommunityToolkit.Maui.Sample/ViewModels/Behaviors/StatusBarBehaviorViewModel.cs @@ -5,34 +5,6 @@ namespace CommunityToolkit.Maui.Sample.ViewModels.Behaviors; public partial class StatusBarBehaviorViewModel : BaseViewModel { - [ObservableProperty] - [NotifyPropertyChangedFor(nameof(StatusBarColor))] - public partial double RedSliderValue { get; set; } - - [ObservableProperty] - [NotifyPropertyChangedFor(nameof(StatusBarColor))] - public partial double GreenSliderValue { get; set; } - - [ObservableProperty] - [NotifyPropertyChangedFor(nameof(StatusBarColor))] - public partial double BlueSliderValue { get; set; } - - [ObservableProperty] - [NotifyPropertyChangedFor(nameof(StatusBarColor))] - public partial double AlphaSliderValue { get; set; } = 1; - - [ObservableProperty] - [NotifyPropertyChangedFor(nameof(StatusBarStyle))] - public partial bool IsLightContentChecked { get; set; } = true; - - [ObservableProperty] - [NotifyPropertyChangedFor(nameof(StatusBarStyle))] - public partial bool IsDarkContentChecked { get; set; } = true; - - [ObservableProperty] - [NotifyPropertyChangedFor(nameof(StatusBarStyle))] - public partial bool IsDefaultChecked { get; set; } = true; - public Color StatusBarColor => Color.FromRgba(RedSliderValue, GreenSliderValue, BlueSliderValue, AlphaSliderValue); public StatusBarStyle StatusBarStyle @@ -55,4 +27,32 @@ public StatusBarStyle StatusBarStyle throw new NotSupportedException($"{nameof(StatusBarStyle)} {StatusBarStyle} is not supported."); } } + + [ObservableProperty] + [NotifyPropertyChangedFor(nameof(StatusBarColor))] + public partial double RedSliderValue { get; set; } = 0.5; + + [ObservableProperty] + [NotifyPropertyChangedFor(nameof(StatusBarColor))] + public partial double GreenSliderValue { get; set; } = 0.5; + + [ObservableProperty] + [NotifyPropertyChangedFor(nameof(StatusBarColor))] + public partial double BlueSliderValue { get; set; } = 0.5; + + [ObservableProperty] + [NotifyPropertyChangedFor(nameof(StatusBarColor))] + public partial double AlphaSliderValue { get; set; } = 1; + + [ObservableProperty] + [NotifyPropertyChangedFor(nameof(StatusBarStyle))] + public partial bool IsLightContentChecked { get; set; } + + [ObservableProperty] + [NotifyPropertyChangedFor(nameof(StatusBarStyle))] + public partial bool IsDarkContentChecked { get; set; } + + [ObservableProperty] + [NotifyPropertyChangedFor(nameof(StatusBarStyle))] + public partial bool IsDefaultChecked { get; set; } = true; } \ No newline at end of file From c3c730615e140e4cb213b85bf6489f36a8a65a43 Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+TheCodeTraveler@users.noreply.github.com> Date: Fri, 27 Feb 2026 12:03:00 -0800 Subject: [PATCH 03/11] Reduce duplicate extension methods --- ...opertyChangedEventArgsExtensions.shared.cs | 36 ++----------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/src/CommunityToolkit.Maui/Extensions/PropertyChangedEventArgsExtensions.shared.cs b/src/CommunityToolkit.Maui/Extensions/PropertyChangedEventArgsExtensions.shared.cs index 4d4929512b..7156502fb8 100644 --- a/src/CommunityToolkit.Maui/Extensions/PropertyChangedEventArgsExtensions.shared.cs +++ b/src/CommunityToolkit.Maui/Extensions/PropertyChangedEventArgsExtensions.shared.cs @@ -7,40 +7,8 @@ namespace CommunityToolkit.Maui.Extensions; static class PropertyChangedEventArgsExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Is(this string propertyName, BindableProperty property) => - propertyName == property.PropertyName; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool IsOneOf(this string propertyName, BindableProperty p0, BindableProperty p1) - { - return propertyName == p0.PropertyName - || propertyName == p1.PropertyName; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool IsOneOf(this string propertyName, BindableProperty p0, BindableProperty p1, BindableProperty p2) - { - return propertyName == p0.PropertyName - || propertyName == p1.PropertyName - || propertyName == p2.PropertyName; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool IsOneOf(this string propertyName, BindableProperty p0, BindableProperty p1, BindableProperty p2, BindableProperty p3) - { - return propertyName == p0.PropertyName - || propertyName == p1.PropertyName - || propertyName == p2.PropertyName - || propertyName == p3.PropertyName; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool IsOneOf(this string propertyName, BindableProperty p0, BindableProperty p1, BindableProperty p2, BindableProperty p3, BindableProperty p4) + public static bool IsOneOf(this string propertyName, params IReadOnlyList bindableProperties) { - return propertyName == p0.PropertyName - || propertyName == p1.PropertyName - || propertyName == p2.PropertyName - || propertyName == p3.PropertyName - || propertyName == p4.PropertyName; + return bindableProperties.Any(bindableProperty => bindableProperty.PropertyName == propertyName); } } \ No newline at end of file From ac477deb0f9f7d2768a79af8cd954be0599adad7 Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+TheCodeTraveler@users.noreply.github.com> Date: Fri, 27 Feb 2026 12:18:57 -0800 Subject: [PATCH 04/11] Update Sample App --- .../Behaviors/StatusBarBehaviorPage.xaml | 48 ++++++++++++------- .../PlatformSpecific/NavigationBarPage.xaml | 10 ++-- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/samples/CommunityToolkit.Maui.Sample/Pages/Behaviors/StatusBarBehaviorPage.xaml b/samples/CommunityToolkit.Maui.Sample/Pages/Behaviors/StatusBarBehaviorPage.xaml index 7698437c54..f60382815e 100644 --- a/samples/CommunityToolkit.Maui.Sample/Pages/Behaviors/StatusBarBehaviorPage.xaml +++ b/samples/CommunityToolkit.Maui.Sample/Pages/Behaviors/StatusBarBehaviorPage.xaml @@ -1,4 +1,5 @@  + - +