I am facing an issue in refreshing a list based on a state change.
So I have a state variable which is using to show/hide a sheet , and while showing the sheet some data will be updated and the updated data needs to be shown on the list .This is my expectation , but the issue is that the list is not updating based on state change.As per my understanding , the entire View will be re-rendered when any state variable update happens, if so could anyone please check the below code and let me know why the list is not updating after the self.showSheet.toggle() inside the ProcessDocument closure:
struct DetailView: View {
@Binding var document: Doc
@State private var showSheet: Bool = false
var body: some View {
List {
Section(header: smallHeaderText("DETAILS")) {
DocTypesPicker(fleetId: fleet?.fleetId ?? "", docTypeId: $document.doc_type)
}
Section(header: smallHeaderText("IMAGES")) {
NavigationLink(destination: DetailImagesPage(document: document) ) {
HStack {
let docImage = self. document.documentData?.first?.img ?? UIImage().jpegData(compressionQuality: 1.0)
Image(uiImage: UIImage(data: docImage!) ?? UIImage())
.resizable()
.frame(width: 60, height: 60, alignment: .center)
VStack(alignment: .leading) {
Spacer()
Text(self.pageCountFor(document: self.document))
Spacer()
}.padding(.leading, 14)
}
}.listRowBackground(Color.white)
}
Section {
HStack {
Spacer()
Button("Redo") {
self.showSheet.toggle()
}
Spacer()
}
}
}
.listStyle(GroupedListStyle())
.sheet(isPresented: $showSheet) {
ProcessDocument { docs in
guard let docs = docs, let currentDoc = document.documentData else { return }
document.removeFromDocumentData(currentDoc as NSSet)
docs.forEach { doc in
let dateCreated = document.date_created
doc.doc_id = dateCreated
document.addToDocumentData(doc)
}
self.showSheet.toggle()
}
}
}
}