Parent view with lazyVSTack in navigation View
NavigationView {
Form{
ScrollView{
LazyVStack(alignment: .leading, spacing: 0){
///Showing all the available list after filtering
ForEach(filteredList){ checkList in
NavigationLink(
destination: ItemList(checkList: checkList).environmentObject(modelData),
tag: checkList.id,
selection: $modelData.listSelector
){
ListRow(checkList: checkList)
.addButtonActions(leadingButtons: pinUnpinButton(checkList: checkList),
trailingButtons: [.info, .delete],
onClick: { button in
sendSwipeButtonClick(Button: button, checkList: checkList)
})
.sheet(isPresented: $editSheet) {
ListInfo(showInfo: $editSheet, draftList: $draftList)
.environmentObject(modelData)
}
}
}
}
}
}
Child view. when i change anything in the modelData and if there are more than one list in the parent view it returns to parent view and not stay in child view. And when the navigation link selector is modified to remain in the child view it goes to parent view then comes back to child view and then goes back again to parent view even after using DispatchQuene.main.asyncAfter(deadline: .now() + 0.20)
List(){
ForEach(filteredItems) { item in
HStack{
/// Completed button
ToggleCompleted(item: item, indexList: indexList)
.environmentObject(modelData)
/// Item name
ItemName(item: item)
Spacer()
/// quantity
if modelData.checkLists[indexList].showQuantity {
Text("\(item.itemQuantity)")
.foregroundColor(.gray)
.font(.subheadline)
.padding()
}
/// info button
Button{
showInfo.toggle()
draftItem = item
} label: {
Image(systemName: "info.circle")
.resizable()
.frame(width: 25, height: 25, alignment: .center)
.foregroundColor(modelData.checkLists[indexList].color)
}
.sheet(isPresented: $showInfo) {
ItemInfo(showInfo: $showInfo, draftItem: $draftItem, checkList: checkList)
.environmentObject(modelData)
}
}
}
///Drag to delete
.onDelete(perform: { indexSet in
///removing notification
for i in indexSet {
AppNotification().remove(ID: modelData.checkLists[indexList].items[i].id)
}
modelData.checkLists[indexList].items.remove(atOffsets: indexSet)
})
}
I am fairly new to SwiftUI and ios app development.