dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.24k stars 1.76k forks source link

Detecting Light and Darkmode does not seem to be updated resuming the app. #10729

Open RonnyRos opened 2 years ago

RonnyRos commented 2 years ago

Description

I want to detect the themechanges from the Android OS. That means when i am minimizing the app and changing Android OS theme from Light to Dark, i expect my app to pickup when its getting resumed the latest theme changes, this does not seem to work.

Steps to Reproduce

protected override void OnResume()
{
    base.OnResume();
    var platformTheme1 = App.Current.PlatformAppTheme; //Switching from Dark in Android OS settings to Light i expect this to be Light, its still Dark
    var platformTheme2 = App.Current.RequestedTheme; //Switching from Dark in Android OS settings to Light i expect this to be Light, its still Dark
 }

 When changing from Dark to Light theme both of these are still showing Dark theme selected.

Link to public reproduction project repository

see codesnippet.

Version with bug

7.0 Release Candidate 1

Last version that worked well

Unknown/Other

Affected platforms

Android, iOS

Affected platform versions

Android 12.1 and iOS 15+

Did you find any workaround?

No

Relevant log output

No response

RonnyRos commented 2 years ago

Maybe related: #10310, #10490, #7377, #9220

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ghost commented 2 years ago

Hi @RonnyRos. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

RonnyRos commented 2 years ago

Needs-repro is mentioned, but the issue mentions how to reproduce it with the codesnippet in the issue itself, so not sure why that tag is added here. Seems like this is related to caching of themes in MAUI.

Workaround: Rip the code from the MAUI repository: https://github.com/dotnet/maui/tree/4e29fd25069d641b5c3d647ec54a70b01322deee/src/Essentials/src/AppInfo without the lazycaching.

ewerspej commented 2 years ago

@RonnyRos @jsuarezruiz @rmarinho The issue is even reproducible with the MAUI template project. Just create a new MAUI project using the template that comes with VS2022, run the app, change the system theme and go back to the app - the AppThemeBinding doesn't get updated, although it should, because UserAppTheme is set to Unspecified by default.

AndreasReitberger commented 1 year ago

Facing the same issue, While using AppThemeBinding and switch the theme in the device settings, the theme is not updated once the app is resumed out of the background. New created resources after that (through navigation opening a new page) seems to use the new theme.

leapse commented 1 year ago

Any updates related to this issue? Seems that it is still happening.

homeyf commented 11 months ago

Verified this issue with Visual Studio Enterprise 17.9.0 Preview 1.0. Can repro on android platform.