[ad_1]
How ought to TextField be correctly disabled when utilizing Toogle in swiftUI? The next easy instance causes warnings within the console if we disable a TextField that has some worth entered in it, deleting it would not repair the state of affairs both.
struct ContentView: View {
@State var isToogleOn = false
@State var textFieldValue = ""
var physique: some View {
HStack {
TextField("Placeholder", textual content: $textFieldValue)
.disabled(!isToogleOn)
Toggle("Activate textField", isOn: $isToogleOn)
}
}
}
Warnings when textfield is switched off:
=== AttributeGraph: cycle detected by means of attribute 160396 === 2022-01-08 15:27:46.182588+0100 CrochetIo[15460:1558507] [SwiftUI] Modifying state throughout view replace, this may trigger undefined habits
[ad_2]
