[BUG] Setting Android using NavigationBar.Color in xaml or code permanently changes the navigationBar color everywhere rather than just that ContentPage
UnreachableCode opened this issue · comments
Is there an existing issue for this?
- I have searched the existing issues
Did you read the "Reporting a bug" section on Contributing file?
- I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
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](https://private-user-images.githubusercontent.com/1167553/343222150-a845a63f-700a-4c00-a7a8-7b9aaf9f873f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjMzMzI4MTAsIm5iZiI6MTcyMzMzMjUxMCwicGF0aCI6Ii8xMTY3NTUzLzM0MzIyMjE1MC1hODQ1YTYzZi03MDBhLTRjMDAtYTdhOC03YjlhYWY5Zjg3M2YucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgxMCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MTBUMjMyODMwWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YWI2OTkzYjY4NDc1NWQzOWQ0MjMxZDg5MjdlODY5NDllMWEyMGM0YmNlZTY3NWMyMmE2MDFlNmM4YWY1YTE4YyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.JxRO8D524ajtUKTsvv_cRY7p1H3ZE49Man1VS8CgVNQ)
And then navigate away from this screen:
![Screenshot 2024-06-26 at 16 14 32](https://private-user-images.githubusercontent.com/1167553/343222313-c1896796-f3ca-4ee9-b666-7e3fa515dcbb.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjMzMzI4MTAsIm5iZiI6MTcyMzMzMjUxMCwicGF0aCI6Ii8xMTY3NTUzLzM0MzIyMjMxMy1jMTg5Njc5Ni1mM2NhLTRlZTktYjY2Ni03ZTNmYTUxNWRjYmIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgxMCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MTBUMjMyODMwWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NzAxZjU4NmJkNjUwYmNmYTk1ZjM4MDRmMjNlYTU0NTZkNzMxMWY2Y2IwMTVlOTRiYTUzMTg0OWQyNTNkZjdhNiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.GBynMSJYbELKGf8TNYGHE73RsSubeY8JAMiIQjNa_os)
Link to public reproduction project repository
Environment
- .NET MAUI CommunityToolkit:9.0.1
- OS: Android
- .NET MAUI: 8.0.300 (I think)
Anything else?
Thanks!
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.
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?