One of the requirements for an app I'm working on is for the user to be able to choose from a handful of "themes" for their experience. A "theme" in this context is pretty simple:
I know how to apply these styles appropriately to all the app elements involved. Where I'm having trouble is: When the user goes into settings (within the app) and chooses a new theme, how can I get the new theme to propagate to all existing NavigationViews (including the main "root" navigation, which is "beneath" the settings modal)?
I thought maybe I could use a preference key to bubble the theme choice all the way up to the root view, set the theme, then propagate it back down with an environment key, but I've either got something wrong with the relevant incantation, or that just isn't going to play nice with the appearance() methods necessary to set the NavigationBar background.
Has anyone accomplished something like this in a SwiftUI app?
An accentColor
A background color (for lists, scroll views, etc)
I know how to apply these styles appropriately to all the app elements involved. Where I'm having trouble is: When the user goes into settings (within the app) and chooses a new theme, how can I get the new theme to propagate to all existing NavigationViews (including the main "root" navigation, which is "beneath" the settings modal)?
I thought maybe I could use a preference key to bubble the theme choice all the way up to the root view, set the theme, then propagate it back down with an environment key, but I've either got something wrong with the relevant incantation, or that just isn't going to play nice with the appearance() methods necessary to set the NavigationBar background.
Has anyone accomplished something like this in a SwiftUI app?