CommunityToolkit / Maui

The .NET MAUI Community Toolkit is a community-created library that contains .NET MAUI Extensions, Advanced UI/UX Controls, and Behaviors to help make your life as a .NET MAUI developer easier
https://learn.microsoft.com/dotnet/communitytoolkit/maui
MIT License
2.14k stars 350 forks source link

[BUG] Setting Android using NavigationBar.Color in xaml or code permanently changes the navigationBar color everywhere rather than just that ContentPage #1987

Open UnreachableCode opened 1 week ago

UnreachableCode commented 1 week ago

Is there an existing issue for this?

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

Setting the NavigationBar.Color in xaml or code sets it app wide. This is easy to do using Android styles.xml and colors.xml anyway.

Expected Behavior

I would expect the color to only be changed for the specifc ContentPage I was on, so that in my own applications I can set specific colours for specific screens for a specific look and feel.

Steps To Reproduce

Run the sample app on Android and navigate to Platform Specific -> NavigationBar.

Use the slider to set the NavigationBar color like so:

Screenshot 2024-06-26 at 16 14 20

And then navigate away from this screen:

Screenshot 2024-06-26 at 16 14 32

Link to public reproduction project repository

https://github.com/CommunityToolkit/Maui/tree/main/samples/CommunityToolkit.Maui.Sample/Pages/PlatformSpecific

Environment

- .NET MAUI CommunityToolkit:9.0.1
- OS: Android
- .NET MAUI: 8.0.300 (I think)

Anything else?

Thanks!

bijington commented 1 week ago

I believe the desired behavior is to allow you to control it on a per page basis but you would need to clear it when navigating away from the page yourself. Or set it on the next page.

That being said I understand your expectation. The difficult thing would be to change this if we decided it was a bug as it could break developers. If we wanted to introduce a fix we could add a property to determine whether this is unset on navigating away.

UnreachableCode commented 1 week ago

It could work like that where I change it on entry and exit, but it's a lot of overhead. And that's on the presumption that the default light grey is fine for every other screen (that doesn't have the same entry/exit behavior).

I hear what you're saying about breaking changes. I'm not sure how people are currently using this and what their expectation is. But I would have thought that the point is that it can set in one ContentPage at a time, especially given you can do it in xaml.

Is there a way to access the default navbar color for when I revert it?