import SwiftUI
struct ListView: View {
@EnvironmentObject var listViewModel: ListViewModel
@State var isTitleEdited: Bool = false
var body: some View {
ZStack {
if listViewModel.items.isEmpty {
NoItemsView()
} else {
List {
ForEach(listViewModel.items) { item in
ListRowView(item: item)
.onTapGesture (count:2){
withAnimation(.linear) {
listViewModel.updateItem(item: item)
}
}
.onTapGesture {
NavigationLink(
destination: AddView(),
label: {
Text (item.title)
}
)
}
}
.onDelete(perform: listViewModel.deleteItem)
.onMove(perform: listViewModel.moveItem)
}
.listStyle(InsetListStyle())
}
}
.navigationTitle("Todo List and Memo")
.navigationBarTitleDisplayMode(.automatic)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
EditButton()
}
ToolbarItem(placement: .navigationBarTrailing) {
NavigationLink(destination: AddView(),
label: {
Image(systemName: "plus")
.foregroundColor(.red)
})
}
}
}
}
struct ListView_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
ListView()
}
.environmentObject(ListViewModel())
}
}
I MAKE A TODOLIST
I WANT TO MAKE CHANGE WHEN I TAP THE TODOLIST
WHEN TAP THE TODOLIST 2 TIMES MAKES TODOLIST COMPLETED
WHEN TAP THE TODOLIST 1 TIME MAKES TITLE OF TODOLIST EDITED
SO I WANT TO REUSE THE ADDVIEW(), WHEN TAP THE TODOLIST 1 TIME, WITH NAVIGATIONLINK
BUT IT DOESN`T WORK....
NavigationLinkis a view. Don't use it in an closure. My suggestion should work, but could not test it because there are to many specific things in your example. Try to use code that works out of the box, so everybody can test.