i created a list with colors and i want when the user click red so all the screen was background red, if user click green so full background is green...
i don't know why but the var not change..
var body: some View {
NavigationView {
List {
Section {
ScreenColorButtons(text: "Red", color: .red)
ScreenColorButtons(text: "Green", color: .green)
ScreenColorButtons(text: "Blue", color: .blue)
}
}
}
}
}
struct ScreenColorButtons: View {
@State static var screenSelected: Color = Color.red
var text: String
var color: Color
var body: some View{
Button(action: {
ScreenColorButtons.screenSelected = color
print(ScreenColorButtons.screenSelected)
}, label: {
NavigationLink(text){}
})
}
}
the ScreenColorView:
struct ScreenColorView: View {
@Environment(\.presentationMode) var presentationMode
var body: some View {
Color.ScreenColorButtons.screenSelected
}
}
why the var not change and error to background??? thank for answer