I have passed a constant value to Toggle since I want to perform certain acctions on value change of toggle and it needs to be done on Tap Gesture as internally I might need to change the value of toggle as well. But hus code is not working
@State private var toggle = false
var body: some View {
VStack {
Toggle(isOn: .constant(toggle)) {
Text("Hello World")
}
.padding()
.onTapGesture {
print("Tapped")
self.toggle.toggle()
}
}
}
}
Toggle(isOn: Binding(
get:{isToggled},
set:{v in
isToggled = v
customAction()
})) {
Text("Status")
}
Custom action code does not get triggered if the state is modified. But will be triggered on UI interaction
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With