Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,24 @@ public ModalFragment(IMauiContext mauiContext, Page modal)

dialog.Window.SetBackgroundDrawable(TransparentColorDrawable);

var attributes = Context?.GetActivity()?.Window?.Attributes;
var mainActivityWindow = Context?.GetActivity()?.Window;
var attributes = mainActivityWindow?.Attributes;

if (attributes is not null)
{
dialog.Window.SetSoftInputMode(attributes.SoftInputMode);
}

if (mainActivityWindow is not null)
{
var navigationBarColor = mainActivityWindow.NavigationBarColor;
var statusBarColor = mainActivityWindow.StatusBarColor;
#pragma warning disable CA1422
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we detect API level and use SetSystemBarsAppearance for API 30+?

dialog.Window.SetNavigationBarColor(new AColor(navigationBarColor));
dialog.Window.SetStatusBarColor(new AColor(statusBarColor));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been thinking, should we maybe also take into account window.SetFlags just as it's done in here CommunityToolkit/Maui#2370 (comment) ?

But there are also other options for light/dark icons on status and navigation bar, visibility options etc.

Maybe that's why this issue was resolved the way it was using Community Toolkit?

That would also explain why there is a way to create your own implementation of this workaround to copy all the values needed https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/platform-specific/dialogfragment-customization#create-you-own-service

#pragma warning restore CA1422
}

return dialog;
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue28552.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 28552, "Changing StatusBar and NavigationBar background color doesn't work with Modal pages", PlatformAffected.Android)]
public class Issue28552 : ContentPage
{
public Issue28552()
{
Content = new Button()
{
Text = "Click to Open Modal",
AutomationId = "OpenModalButton",
Command = new Command(() =>
{
#if ANDROID
Android.Views.Window window = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity.Window;
#pragma warning disable CA1422
window.SetNavigationBarColor(Android.Graphics.Color.Purple);
window.SetStatusBarColor(Android.Graphics.Color.Green);
#endif
Window!.Page!.Navigation.PushModalAsync(new ContentPage
{
Content = new Label
{
VerticalOptions = LayoutOptions.Center,
Text = "Hello from Maui!",
AutomationId = "LabelOnModalPage"
}
}, false);
})
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#if ANDROID
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;
public class Issue28552 : _IssuesUITest
{
public Issue28552(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "Changing StatusBar and NavigationBar background color doesn't work with Modal pages";

[Test]
[Category(UITestCategories.Navigation)]
public void StatusBarAndNavigationBarShouldInheritColor()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending snapshot already available in the latest build.
Could you commit it?

{
App.WaitForElement("OpenModalButton");
App.Click("OpenModalButton");
App.WaitForElement("LabelOnModalPage");
VerifyScreenshot();
}
}
#endif
Loading