0

I come across a strange navigation bug, this is my code:

import SwiftUI


struct TestNavView: View {
    
    @State var isPresented = false
    
    var body: some View {
        NavigationStack{
            VStack{
                VStack{
                    Button {
                        isPresented = true
                    } label: {
                        Text("navigate by isPresented")
                    }
                }
                .navigationDestination(isPresented: $isPresented) {
                    Text("pushed in by isPresented")
                    NavigationLink(value: "stringvalue") {
                        Text("show color view by NavigationLink" )
                    }
                }
                .navigationDestination(for: String.self) { item in
                    Color.blue
                }
                  
            }
            
        }
    }
}

struct TestNavView_Previews: PreviewProvider {
    static var previews: some View {
        TestNavView()
    }
}

When I press [show color view by NavigationLink], the [Color View] is pushed into the navigationStack , but the [pushed in by isPresented] view is brought to the top of the NavigationStack . The result is wrong . Why ? I wonder if it is right to use navigationDestination(isPresented: ) and .navigationDestination(for: data) together. Thanks a lot !

Rufus
  • 640
  • 1
  • 7
  • 14

0 Answers0