@Tact,
There wasn't much provided except for a few pieces of code, so it is hard to determine the exact flow of your application, so I took some liberty in piecing together what you might have. I have also never tried to implement this style of application, so I decided to try my best to solve it; learned some new things! Below is what I got working:
class Store: ObservableObject {
@Published var backgroundColor: Color
init() {
self.backgroundColor = .green
}
}
struct ChangeBackgroundColor: View {
@Binding var backgroundColor: Color
var body: some View {
ZStack {
VStack {
Button(action: { self.backgroundColor = .black }, label: { Text("Black") })
Button(action: { self.backgroundColor = .green }, label: { Text("Green") })
}
}
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
.background(backgroundColor).edgesIgnoringSafeArea(.all)
}
}
struct ContentView: View {
@ObservedObject var store: Store = Store()
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: ChangeBackgroundColor(backgroundColor: $store.backgroundColor)) {
Text("Pick Background Color")
}
}
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
.background(store.backgroundColor).edgesIgnoringSafeArea(.all)
}
}
}
I ran into the issue that others have encountered when trying to set the background color that involves the NavigationView. It appears that the the underline View either doesn't have/use the dimensions of the screen, so either using GeometryReader or .infinity should get a desired effect of turning the whole background color via just SwiftUI. Hopefully this will get you going and understand the relationship on how to pass values around different views.
If you don't plan on using NavigationView or some of the other views that have issues with .background, you can easily use Color() example you provided.