I have multiple buttons in an HStack in SwiftUI 2 (iOS 14). When i tap on a single button, the whole stack gets highlighted and the actions for ALL of the buttons gets executed.
struct ActionsView: View {
var truckDetails: TruckDetails
@State var selectedTag: String?
var body: some View {
HStack (alignment: .bottom) {
Button(action: {
if let url = URL(string: "tel://\(truckDetails.phone)"), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}
}, label: {
VStack {
Image(systemName: "phone")
Text("Call")
}
})
.disabled(truckDetails.phone == "")
Spacer()
Button(action: {
self.selectedTag = "menus"
}, label: {
VStack {
Image(systemName: "line.horizontal.3")
.padding(.bottom, 3)
Text("Menu")
}
})
.disabled(!truckDetails.menus)
.background(
NavigationLink(
destination: Text("Menus"),
tag: "menus",
selection: $selectedTag,
label: {
EmptyView()
})
.buttonStyle(PlainButtonStyle())
)
Spacer()
Button(action: {
selectedTag = "schedules"
}, label: {
VStack {
Image(systemName: "calendar")
Text("Schedule")
}
})
.disabled(!truckDetails.schedules)
.background(
NavigationLink(
destination: Text("Schedules"),
tag: "schedules",
selection: $selectedTag,
label: {
EmptyView()
})
.buttonStyle(PlainButtonStyle())
)
Spacer()
Button(action: {
}, label: {
VStack {
Image(systemName: "heart")
Text("Favorite")
}
})
}
.padding(.horizontal)
.font(.footnote)
}
}
So if I tap on the Call button not only does it bring up the Calling UI but it navigates to the Schedules Text (second option.)
Is this a Swift 2 bug that I should be filing a Feedback on or am I doing something wrong here?