Reputation: 31
Apple deprecated NavigationView and requires to use NavigationStack instead. However, I found a problem when using NavigationStack with List and NavigationLink. Here is an example of the code:
NavigationStack {
List {
ForEach(0..<15) { _ in
NavigationLink(destination: SomeView()) {
RowItem()
}
}
}
}
When the navigationTitle is large and you tap any element in the List, it takes you to SomeView(). And when you scroll down a little (when the navTitle gets small) and do the same thing, all elements jump down as SwiftUI trying to create a space that large title requires. And when you go back from SomeView(), everything seems fine like nothing jumped. And you can only see that when the transition is performed. NavigationView does not have that strange jumping behaviour.
And what I find strange, if you embed NavigationLink in any stack (VStack, HStack etc), animation gets performed as it meant to be. What is the trick, and what is it that breaks NavigationLink? Is embedding it into any stack a bad practise?
VStack {
NavigationLink(destination: SomeView()) {
RowItem()
}
}
Upvotes: 0
Views: 176
Reputation: 46
With NavigationStack you need to use the form NavigationLink(value: ) as that other one is deprecated in this context so like this..
NavigationStack {
List {
ForEach(0..<15) { _ in
NavigationLink(value: "Row") {
RowItem()
}
}
}
.navigationTitle("Title One")
.navigationDestination(for: String.self) { value in
SomeView()
}
}
Upvotes: 0