Search code examples
swiftuixcode12

SwiftUI in Xcode 12 Beta 3 - Picker is disabled when presenting a view as a Sheet


The following code presents the same view PatientView in 2 ways:

  1. As a Sheet
  2. NavigationLink
    var body: some View {
        NavigationView {
                List {
                    ForEach(patients, id: \.self) { patient in
                        NavigationLink(destination:
                                        PatientView(selectedPatient: patient, isDependant: false, mainID: "")) {
                            PatientRowView(patient: patient)
                        }
                    }
                    .onDelete { indexSet in
                        for index in indexSet {
                            self.moc.delete(self.patients[index])
                        }
                    }
                }
                .navigationBarItems(trailing: Button(action: {
                    self.showingAddScreen.toggle()
                }) {
                    Image(systemName: "plus")
                })
                .sheet(isPresented: $showingAddScreen) {
                    PatientView(selectedPatient: nil, isDependant: false, mainID: "").environment(\.managedObjectContext, self.moc)
                }
                .navigationBarTitle("Patients")
                .background(NavigationConfigurator { nc in
                    nc.navigationBar.barTintColor = .launchpadBackgroundGray
                    nc.navigationBar.titleTextAttributes = [.foregroundColor : UIColor.black]
                })
        }
    }

When presented as a Sheet the Pickers on the PatientView are disabled:

PatientView Presented as a Sheet

But when presented through the Navigationlink the pickers work as expected:

enter image description here

Does anyone know why this is happening? Any solutions to make the pickers were properly when presented as a Sheet would be greatly appreciated.

Thank You


Solution

  • Form picker requires NavigationView so provide it for sheet workflow explicitly

    .sheet(isPresented: $showingAddScreen) {
      NavigationView {
        PatientView(selectedPatient: nil, isDependant: false, 
            mainID: "").environment(\.managedObjectContext, self.moc)
      }
    }