When I navigate, the next page opens and closes quickly. Why ?
I tried this on an empty project and didn't run into this issue. Why in my project does the navigation come back after going forward? I want to create a nested navigation structure.
MY PROJECT CODES:
App:
@main
struct FileApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.onAppear {
UserDefaults.standard.set(false, forKey: "_UIConstraintBasedLayoutLogUnsatisfiable")
}
}
}
}
ContentView:
struct ContentView: View {
@StateObject var safeFileVM: SafeFileViewModel = SafeFileViewModel()
var body: some View {
NavigationView {
AView(safeFileVM: safeFileVM)
}
}
}
AView:
struct AView: View {
@ObservedObject var safeFileVM: SafeFileViewModel
@State var currentLocation = ""
@State var currentFolder: String = "Safe File"
var body: some View {
List(safeFileVM.arrayOfFiles, id: \.id) { folderItem in
BView(safeFileVM: safeFileVM, currentFile: folderItem, currentLocation: currentLocation)
}
.navigationTitle(Text(currentFolder))
.onAppear {
safeFileVM.additionPath = currentLocation
safeFileVM.takeArrayOfItems()
}
}
}
BView:
struct BView: View {
@ObservedObject var safeFileVM: SafeFileViewModel
@State var currentFile: MyFile
@State var currentLocation: String
var body: some View {
VStack {
if currentFile.typeOfFile == "folder" {
NavigationLink(currentFile.fileName) {
AView(safeFileVM: safeFileVM, currentLocation: currentLocation + "/" + currentFile.fileName, currentFolder: currentFile.fileName)
}
.isDetailLink(false)
} else {
Text(currentFile.fileName)
}
}
}
}
EMPTY PROJECT CODES:
ContentView:
struct ContentView: View {
var body: some View {
NavigationView {
AView()
.navigationBarTitleDisplayMode(.inline)
}
}
}
AView:
struct AView: View {
var body: some View {
List(0..<5) { item in
BView(title: item)
}
}
}
BView:
struct BView: View {
var title: Int = 0
var body: some View {
NavigationLink("test \(title)") {
AView()
}
}
}