I am slightly confused with how to properly updating a view button color based on the state. If I am not mistaken, self.cameraOK
is true
when the user gives the camera access, but the button color does not change. I need to tap on the button again to see the color change. Why is this behaviour happening?
Also any other recommendations for good standards are encouraged as I am fairly new to swift.
Here is the code:
@State var cameraOK: Bool = false
@State var photosOK: Bool = false
var body: some View {
VStack(alignment: .leading) {
...
Button(action: {
if permissions.giveCameraAccess() {
self.cameraOK = true
}
}) {
Text("Enable access to your camera")
.font(Font.custom("Inter", size: 16))
.foregroundColor(self.cameraOK ? Color(red: 0, green: 1, blue: 0.2) : Color(red: 1, green: 0.68, blue: 0.2) )
.fontWeight(.regular)