I have a screen with a button that, when pressed, displays a subview with a new set of buttons. If I click any button in the subview, it should hide the subview and take me to the next view. The strange thing is that I can remove the view with a binding variable, but it does not move to the next screen.
struct CartView: View {
@State var store : Store = Store()
@State private var pushed: Bool = false
@State var notLoggedIn = false
@State var showDeliveryView : Bool = false
@State var showScheduleView : Bool = false
@StateObject var cartVM = CartViewModel()
var body: some View{
ZStack(alignment:.center){
VStack{
VStack{
Button.init(action: {
if AppSettings.shared.getUserID() != ""{
self.pushed.toggle()
withAnimation{
self.showDeliveryView.toggle()
}
}else{
self.notLoggedIn = true
}
}
, label: {
Text("CHECKOUT")
.font(.headline)
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 40)
.foregroundColor(.white)
.background(Color.theme.appColor)
.font(.title2)
})
.cornerRadius(4)
.padding([.leading, .trailing, .bottom], 10)
}
.padding().ignoresSafeArea()
}
.navigationBarTitle("Cart")
if self.showDeliveryView {
GeometryReader{ geometry in
VStack{
Spacer()
DeliveryTypeView(store:store, pushStackClear : $showDeliveryView,isCartActive: $pushed)
.background(Color.white)
}
}.transition(.move(edge: .bottom))
.background(
Color.black.opacity(0.65)
.edgesIgnoringSafeArea(.all)
.onTapGesture{
withAnimation{
self.showDeliveryView.toggle()
}
}
)
}
}
}
}
DeliveryTypeView
struct DeliveryTypeView: View {
@State var store : Store = Store()
@State private var showinfoScreen = false
@Binding var pushStackClear : Bool
@Binding var isCartActive : Bool
var body: some View {
ZStack{
VStack(alignment: .leading){
Text("Choose Service Method")
.font(.title2)
.fontWeight(.bold)
Divider()
VStack(alignment : .leading){
NavigationLink(destination: CustomerInfoFormView( isCartActive: $isCartActive,tappedStore: store), isActive : $showinfoScreen){
}
Button.init(action: {
pushStackClear.toggle()
self.showinfoScreen.toggle()
}
, label: {
Text("CHECKOUT")
.font(.headline)
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 40)
.foregroundColor(.white)
.background(Color.theme.appColor)
.font(.title2)
})
HStack{
Image.init(systemName: "car")
.font(.title2)
Text("Deliver to Me by Shop")
.font(.title2)
.padding()
.onTapGesture {
self.showinfoScreen.toggle()
}
}
Divider()
HStack{
Image.init(systemName: "building")
.font(.title2)
Text("I will Pickup from Shop")
.font(.title2)
.padding()
}.onTapGesture {
self.showinfoScreen.toggle()
}
}
}
}.padding()
}
}
Really appreciate your help.