I am attempting to including a dynamic list of navigation links within each row of a List in a NavigationView. Whenever I tap one of the links though, the navigation jumps back and forth several times.
What is causing the back and forth navigation? And is it possible to express this pattern in some other way with SwiftUI to avoid this issue?
import SwiftUI
struct MonthData: Hashable, Codable, Identifiable {
var id: Int
var name: String
var tasks: [TaskData]
}
struct TaskData: Hashable, Codable, Identifiable {
var id: Int
var name: String
}
let months: [MonthData] = [
MonthData(id: 1, name: "January", tasks: []),
MonthData(id: 2, name: "February", tasks: [
TaskData(id: 21, name: "Do something"),
TaskData(id: 22, name: "Do something else")
])
]
struct FooView: View {
var body: some View {
NavigationView {
List(months) { month in
VStack {
ForEach(month.tasks) { task in
NavigationLink(
destination: Text(task.name)
) {
Text(task.name)
}
}
}
}
.navigationBarTitle(Text("Months"))
}
}
}
struct FooView_Previews: PreviewProvider {
static var previews: some View {
FooView()
}
}