I have noticed that TabView has another behavior than UITabBarController, the view stack is cleared each time the user moves from one tab to another.
I have created a small sample to illustrate my case:
struct ContentView: View {
@State private var selection = 0
var body: some View {
TabView(selection: $selection) {
NavView(id: "A").tabItem { Text("Alpha") }.tag(0)
NavView(id: "B").tabItem { Text("Beta") }.tag(1)
}
}
}
struct NavView: View {
var id: String
var body: some View {
NavigationView {
List {
NavigationLink(destination: Text("Detail \(id)")) { Text(id) }
}
}
}
}
The detail view is gone since the NavView
is recreated after a visit to the other tab.
Question: Is there a way to recreate the old behavior, that a presented detail view is still present after a visit on another tab?