Post

Replies

Boosts

Views

Activity

iOS15 NavigationView lost the state after putting app in background and bring it back
In the app, if I follow the navigations from MainView->Tab1->Link1->Sub Link1, put the app to background, then bring it back, then it shows back to Tab1 again, does anyone know why NavigationView cannot keep the last view? it works fine in iOS 14.7 struct LocalNotificationDemoView: View { @StateObject var localNotification = LocalNotification() @ObservedObject var notificationCenter: NotificationCenter var body: some View { NavigationView { VStack { MainView() } } .navigationViewStyle(.stack) } } struct MainView: View { var body: some View { TabView { Tab1() .tabItem { Text("Tab1") } Tab2() .tabItem { Text("Tab2") } } } } struct Tab1: View { @State var selection: Int? = nil var body: some View { NavigationLink(destination: View1(), tag: 1, selection: $selection) { Text("Link 1") } } } struct Tab2: View { @State var selection: Int? = nil var body: some View { NavigationLink(destination: Text("Link 2").navigationTitle("").navigationBarHidden(true), tag: 1, selection: $selection) { Text("Link 2") .onAppear { print("Link2 shows") Thread.callStackSymbols.forEach{print($0)} } } } } struct View1: View { @State var selection: Int? = nil var body: some View { NavigationLink(destination: Text("Sub Link 1"), tag: 1, selection: $selection) { Text("Sub Link 1") } } }
4
0
629
Nov ’21