1

When I add .navigationBarItems modifier list is clipping and doesn't take all space like thisenter image description here

It should be like on this photo (without .navigationBarItems): enter image description here

Code

struct PatientsListView: View {
    @ObservedObject var listData = PatientsListViewModel()
    var body: some View {
        NavigationView{
            Group {
                if listData.patientsList.count > 0{
                    List{
                        ForEach(Array(listData.patientsList)) {  patient in
                            NavigationLink(destination: PatientsDetailView(patient: patient),
                                           label: {
                                            PatientsListRow(patient: patient)
                                           })
                        }
                    }
                }
                else if listData.patientsList.count == 0 {
                    Text("Самое время добавить пациентов!").foregroundColor(.gray)
                    
                }
                else if listData.isLoading {
                    ProgressView()
                }
            }
            .navigationTitle("Пациенты")
            .navigationBarTitleDisplayMode(.large)
            .navigationBarItems(trailing: NavigationLink(destination: PatientCreateView(), label: {
                Image(systemName: "plus").foregroundColor(.white)
            }))
            
            
            
        }
        .onAppear(perform: {
            listData.fetchPatients()
        })
    }
}

1 Answers1

2

This is default behavior. If you like you can set List style explicitly, like

List{
    ForEach(Array(listData.patientsList)) {  patient in
        NavigationLink(destination: PatientsDetailView(patient: patient),
                       label: {
                        PatientsListRow(patient: patient)
                       })
    }
}
.listStyle(PlainListStyle())        // << here !!
Asperi
  • 228,894
  • 20
  • 464
  • 690