ios – shut sheet view with buttons

0
1


I am at present operating into an issue with a sheet not closing when the shut button is pushed or the save button has accomplished transferring the info from the shape to the listing in homeview. Under is the code for a customized tab bar that when “New Survey” is pushed it’s going to open the formView. The formView has two buttons closed and save. I would love it that when both of these buttons are chosen that it closes the formView.

struct FormView: View {
    @Binding var surveys: [Survey]
    @State var customerName = ""
    @State var metropolis = ""
    @State var state = ""
    @State var lineName = ""
    @State var date = Date()
    @Binding var isPresented: Bool
    @State var showingFormView = false
    var physique: some View {
        VStack{
            ZStack {
                NavigationView {
                    VStack {
                        ZStack {
                            Kind {
                                Part(header: Textual content("Survey Information").font(.customized("Roboto-Gentle", measurement: 24)).foregroundColor(Coloration(crimson: 0.00, inexperienced: 0.188, blue: 0.42)).offset(x: -20)) {      TextField("Buyer Title", textual content: $customerName)
                                        .padding(.vertical, 10.0)
                                        .font(.customized("Roboto-Gentle", measurement: 18))
                                    TextField("Buyer Metropolis", textual content: $metropolis)
                                        .padding(.vertical, 10.0)
                                        .font(.customized("Roboto-Gentle", measurement: 18))
                                    TextField("State", textual content: $state)
                                        .padding(.vertical, 10.0)
                                        .font(.customized("Roboto-Gentle", measurement: 18))
                                    TextField("Line Title", textual content: $lineName)
                                        .padding(.vertical, 10.0)
                                        .font(.customized("Roboto-Gentle", measurement: 18))
                                    DatePicker("Date", choice: $date, displayedComponents: .date)
                                        .padding(.vertical, 10.0)
                                        .font(.customized("Roboto-Gentle", measurement: 18))
                                }
                            }
                            VStack (alignment: .middle){
                                Spacer()
                                
                                HStack {
                                    **Button(motion: {
                                        self.showingFormView = false
                                        self.isPresented = false
                                    }, label:  {
                                        Textual content("Shut")
                                            .font(.customized("Roboto-Gentle", measurement: 23))
                                            .foregroundColor(Coloration.white)
                                            .body(width: 150.0, peak: 50.0, alignment: .middle)
                                            .background(Coloration(hue: 0.001, saturation: 0.768, brightness: 0.975))
                                            .cornerRadius(3)
                                    })
                                    
                                    Button(motion: {
                                        // Save survey knowledge to UserDefaults or every other means
                                        let survey = Survey(customerName: customerName, metropolis: metropolis, state: state, lineName: lineName, date: date)
                                        self.surveys.append(survey)
                                        // Clear textual content fields
                                        self.customerName = ""
                                        self.metropolis = ""
                                        self.state = ""
                                        self.lineName = ""
                                        self.date = Date()
                                        // Shut FormView
                                        self.showingFormView = false
                                        self.isPresented = false
                                    }, label:  {
                                        Textual content("Save")
                                            .font(.customized("Roboto-Gentle", measurement: 23))
                                            .foregroundColor(Coloration.white)
                                            .body(width: 150.0, peak: 50.0, alignment: .middle)
                                            .background(Coloration(crimson: 0.451, inexperienced: 0.729, blue: 0.251))

                                            .cornerRadius(3)
                                    })**
                                    
                                }
                            }
                        }
                    }
                    .navigationBarHidden(true)
                    
                    }
                }
            }
        }
    }

Customized Tab Bar

struct CustomTabBar: View {
    @Binding var surveys: [Survey]
    @Binding var isPresented : Bool
    @State var showingFormView = false
       var physique: some View {
           NavigationView{
               VStack {
                   Spacer()
                   
                   HStack (alignment: .backside) {
                       Button {
                           
                       } label: {
                           GeometryReader { geo in
                               VStack (alignment: .middle, spacing: 4) {
                                   Picture(systemName: "magnifyingglass")
                                       .resizable()
                                       .scaledToFit()
                                       .body(width: 32, peak: 32)
                                   Textual content("Search")
                                       .font(.customized("Roboto-Gentle", measurement: 14))
                               }
                               .body(width: geo.measurement.width,peak: geo.measurement.peak)
                           }
                       }
                       .tint(Coloration(crimson: 0.0, inexperienced: 0.188, blue: 0.42))
                       
                       **Button(motion: {
                           showingFormView = true
                       }) {
                           GeometryReader { geo in
                               VStack(alignment: .middle, spacing: 4) {
                                   Picture("PSIcon")
                                       .resizable()
                                       .scaledToFit()
                                       .body(width: 38, peak: 38)
                                   Textual content("New Survey")
                                       .font(.customized("Roboto-Gentle", measurement: 14))
                                       .tint(Coloration(crimson: 0.0, inexperienced: 0.188, blue: 0.42))
                               }
                               .body(width: geo.measurement.width, peak: geo.measurement.peak)
                           }
                       }
                       .sheet(isPresented: $showingFormView) {
                           FormView(surveys: $surveys, isPresented: $isPresented)           }
                       
                       //code permits you to name up a particular view as long as a var is indicated
                   **    
                       
                       Button {
                           
                       } label: {
                           GeometryReader { geo in
                               VStack (alignment: .middle, spacing: 4) {
                                   Picture(systemName: "arrow.up.arrow.down")
                                       .resizable()
                                       .scaledToFit()
                                       .body(width: 35, peak: 35)
                                   Textual content("Kind")
                                       .font(.customized("Roboto-Gentle", measurement: 14))
                               }
                               .body(width: geo.measurement.width,peak: geo.measurement.peak)
                           }
                       }
                       .tint(Coloration(crimson: 0.0, inexperienced: 0.188, blue: 0.42))
                   }
                   .body(peak: 50.0)
               }
                      
           }
       }
   }

The save button saves and creates a brand new merchandise within the dynamic listing however it doesn’t shut the formView. The one approach for me to shut the view is by swiping down on the display screen.

LEAVE A REPLY

Please enter your comment!
Please enter your name here