1

I use TabView & NavigationStack. TabView covered NavigationStack & inner View also covered NavigationStack. I want an inner navigation Push but it's always the root Navigation Push (in TabViewTest). Can I push the inner NavigationStack View (in PresentView)?

struct TabViewTest: View {
    var body: some View {
        NavigationStack {
            TabView {
                PresentView()
                    .tabItem {
                        Image(systemName: "2.square.fill")
                    }
                Text("Another Tab")
                    .tabItem {
                        Image(systemName: "2.square.fill")
                    }
            }
        }
    }
}


struct PresentView: View {
    @State var stack = NavigationPath()
    @State var presentingModal = false
    
    var body: some View {
        NavigationStack(path: $stack) {
            ZStack {
                Color.purple
                VStack {
                    NavigationLink(value: "hi") {
                        Image(systemName: "person")
                    }
                    .navigationDestination(for: String.self) { value in
                        PushedView(stack: $stack)
                    }
                    
                }
            }
        }
    }
}

struct PushedView: View {
    @Binding var stack: NavigationPath
    
    var body: some View {
        ZStack {
            Color.red
        
            VStack {
                NavigationLink(value: Color.red) {
                    Image(systemName: "person")
                }
                .navigationDestination(for: Color.self) { value in
                    Text("Hello")
                }
                
                
                Button {
                    stack.removeLast()
                } label: {
                    Text("pop")
                }

                
            }

        }
    }
}
Sujith Kumar
  • 872
  • 6
  • 19
이기완
  • 11
  • 2
  • There shouldn’t be a NavigationStack above the TabView it is against the human interface guidelines and causes many navigation bugs. Eac tab has to have its own – lorem ipsum Mar 29 '23 at 07:38
  • @loremipsum thanks swiftui can't do that? tabBarController?.navigationController?.pushViewController() uikit is simple – 이기완 Mar 30 '23 at 02:32
  • What you are doing right now is “navigationController.tabControlller.navigationController.pushViewController” that isn’t allowed. Remove the outer one so you can resemble what you are describing. – lorem ipsum Mar 30 '23 at 09:40

0 Answers0