Imagine a SwiftUI View having an @ObservedObject var someObject
that can update anytime in the background (for example via network connection) and showing a NavigationLink based on some condition of it:
if someObject.someCondition {
NavigationLink(destination: { DetailView() }, label: { ... })
}
If you now tapped the NavigationLink, DetailView
will be pushed on the current NavigationView. Now if afterwards someCondition
would change to false, DetailView
would be popped off again, since the Link to the View would not exist anymore: This was always the behaviour of NavigationViews with .navigationViewStyle(.stack)
set since I use them.
navigationViewStyle
is deprecated now, but by using NavigationStack I don't get this behaviour anymore. The DetailView would stay on the Stack, even if the NavigationLink would not exist anymore at all.
Is there a way to reproduce this "old behavior" again?