Search code examples
uno-platform

How to get an event from the application when the system theme changes?


Because the Theme Qualifier for iOS assets is not yet supported on Uno, I have to resort to a helper service in my project, to provide alternate paths to image which are created for dark mode. This however causes the assets URL to be evaluated once, and not when the system theme is changed while the app is running. Is there a way to get an event or method being called from the application when the system theme changes?


Solution

  • Just for completeness, you can also use the UISettings.ColorValuesChanged event to observe theme changes. Furthermore, Microsoft Community Toolkit provides a very nice wrapper around it - ThemeListener, which can also be used in Uno Platform apps.

    Ideally, we would also like to support the theme qualifier for asset disambiguation - similarly to -scale-150, etc. it allows you to use a suffix to let the system choose light or dark assets. You can upvote this GitHub issue to help us prioritize that.