How should TextField be properly disabled when using Toogle in swiftUI? The following simple example causes warnings in the console if we disable a TextField that has some value entered in it, deleting it doesn't fix the situation either.
struct ContentView: View {
@State var isToogleOn = false
@State var textFieldValue = ""
var body: some View {
HStack {
TextField("Placeholder", text: $textFieldValue)
.disabled(!isToogleOn)
Toggle("Activate textField", isOn: $isToogleOn)
}
}
}
Warnings when textfield is switched off:
=== AttributeGraph: cycle detected through attribute 160396 === 2022-01-08 15:27:46.182588+0100 CrochetIo[15460:1558507] [SwiftUI] Modifying state during view update, this will cause undefined behavior