I've got some code, where I've nested 2 Buttons in an HStack in a Form. When I click either Button, both actions fire, printing "US to Canadian" and" Canadian to US" -- like the HStack itself was receiving the tap.
If I change the Form to a VStack, each Button works separately, as expected.
That's not supposed to happen is it? Is there something about Forms that I'm missing? Or is this a bug?
struct Currency {
var canadian:String {
get { "\(canadianDollar)"}
set { americanDollar = Double(newValue) ?? 0.00}
}
var american:String {
get { "\(americanDollar)"}
set { americanDollar = Double(newValue) ?? 0.00}
}
var canadianDollar:Double
var americanDollar:Double
}
struct ContentView : View {
@State private var currency = Currency(canadianDollar: 0.00, americanDollar: 0.00)
var body: some View {
NavigationView {
Form {
HStack {
Text("CAD: ")
TextField($currency.canadian).textFieldStyle(.roundedBorder)
}
HStack {
Text("USD: ")
TextField($currency.american).textFieldStyle(.roundedBorder)
}
HStack {
Button(action: { print("Canadian to US") }){
Text("CAD -> USD")
}.background(Color.green)
Spacer()
Button(action: { print("US to Canadian") }){
Text("USD -> CAD")
}.background(Color.yellow)
}
}.navigationBarTitle(Text("Currency Converter"))
}
}
}