SwiftUI NavigationStack bug – tapping on NavigationLink leads to freeze when destination view contains AppStorage
struct NavStack: View { @AppStorage(“userid”) var userid: Int = 0 @State var memes = [MemeModel]() @State var path = NavigationPath() var body: some View { NavigationStack(path: $path){ ScrollView(.vertical, showsIndicators: false){ LazyVStack(spacing: 100){ ForEach($memes, id: .memeid){ meme in MemeView(memes: self.$memes, memeid: meme.memeid) } } } .onAppear{ memes.append(MemeModel(memeid: 1, title: “meme1”, pic: “bla.jpg”)) memes.append(MemeModel(memeid: 2, title: “meme2”, […]
SwiftUI NavigationStack – tapping on NavigationLink leads to freeze when destination view contains AppStorage
struct NavStack: View { @AppStorage(“userid”) var userid: Int = 0 @State var memes = [MemeModel]() @State var path = NavigationPath() var body: some View { NavigationStack(path: $path){ ScrollView(.vertical, showsIndicators: false){ LazyVStack(spacing: 100){ ForEach($memes, id: .memeid){ meme in MemeView(memes: self.$memes, memeid: meme.memeid) } } } .onAppear{ memes.append(MemeModel(memeid: 1, title: “meme1”, pic: “bla.jpg”)) memes.append(MemeModel(memeid: 2, title: “meme2”, […]
SwiftUI NavigationStack – pass binding to view
struct NavStack: View { @State private var memes = [MemeModel]() @State private var path = NavigationPath() var body: some View { NavigationStack(path: $path){ VStack{ Text(“Pass search result”) .onTapGesture { path.append(DataForSearch(searchTerm: “funny cats”, memes: memes)) } LazyVStack(spacing: 0){ ForEach(memes, id: .memeid){ meme in Text(meme.title) } } } .navigationDestination(for: DataForSearch.self){ selection in SearchResults(searchTerm: selection.searchTerm, memes: selection.$memes) } […]
SwiftUI NavigationStack – Open new view and close the current one
So far I’m using this solution:
SwiftUI NavigationStack – check which views are opened and close specific one
.navigationDestination(for: String.self){ selection in if(selection == “login”){ Login(path: $path) }else if(selection == “register”){ CreateAccount(path: $path) } } .onChange(of: path) { _ in if(path[count(path) – 1] == “login” && path[count(path) – 2] == “register”){ // if current view is login and the last one register, close rebister path.remove(count(path) – 2) } if(path[count(path) – 1] == “register” […]
NavigationStack – NavigationLink doesn’t work
In the MainView, I have this below NaviationStack:
SwiftUI NavigationStack – NavigationLink doesn’t work
In the MainView, I have this below NaviationStack: