My goal is the selection of different Modal Views over Menu. But on my code, always the first Modal View is selected.
Here is my code:
import SwiftUI
struct ContentView: View {
@State var showingModal = false
var body: some View {
NavigationView {
VStack {
Text("Content View")
}
.navigationBarItems( trailing: actionM )
}
}
var actionM: some View {
Menu {
Button("Buy something") { self.showingModal = true }.sheet(isPresented: $showingModal) { ModalBuyView(showModal: self.$showingModal) }
Button("Sell something"){ self.showingModal = true }.sheet(isPresented: $showingModal) { ModalSellView(showModal: self.$showingModal) }
} label: {
Image(systemName: "gift.circle")
.font(.largeTitle)
}
}
}
struct ModalBuyView: View {
@Binding var showModal: Bool
var body: some View {
Button("dismiss for BUY ModalView") {
self.showModal = false
}
}
}
struct ModalSellView: View {
@Binding var showModal: Bool
var body: some View {
Button("dismiss for SELL ModalView") {
self.showModal = false
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Here is my code:
import SwiftUI
struct ContentView: View {
@State var showingModal = false
var body: some View {
NavigationView {
VStack {
Text("Content View")
}
.navigationBarItems( trailing: actionM )
}
}
var actionM: some View {
Menu {
Button("Buy something") { self.showingModal = true }.sheet(isPresented: $showingModal) { ModalBuyView(showModal: self.$showingModal) }
Button("Sell something"){ self.showingModal = true }.sheet(isPresented: $showingModal) { ModalSellView(showModal: self.$showingModal) }
} label: {
Image(systemName: "gift.circle")
.font(.largeTitle)
}
}
}
struct ModalBuyView: View {
@Binding var showModal: Bool
var body: some View {
Button("dismiss for BUY ModalView") {
self.showModal = false
}
}
}
struct ModalSellView: View {
@Binding var showModal: Bool
var body: some View {
Button("dismiss for SELL ModalView") {
self.showModal = false
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}