0
votes

I have a View with a list with navigationLinks, and show a list of items to DetailView, and DetailView can go to another View and so on. Therefore it will have a full navigation stack in here.

However, in our app, we have two ways to show this view, first, a presenting View to show this view. Second, by other navigationLink under another NavigationView to push to this view. In the first case, it is fine. however in second case, it will show nested navigation bar, which I don't really like it.

Is there any possible way to show the following view without any nested navigationBar, in the pushing and presenting(UIKit wording) way

    var body: some View {
        NavigationView {
            List(items) { item in
                NavigationLink(destination: DetailView(item)) {
                   ItemRow(item)
                }
            }
            .navigationBarTitle("Item list")
        }
    }

thanks a lot!

1
Just separate this view on two: one with list only and second navigation view containing that first one.Asperi
@Asperi let's say this view is separated in another pod, the caller doesn't know too much about the view. in my view , how to detect if its parent view push it or present it? or another word , how to know the parent view has NavigationView already?justicepenny
In "DetailView" do you have a NavigationView? If yes, then, remove it because that could be the issue. There must only be one NavigationView per stack.Abdulelah Hajjar

1 Answers

0
votes

As Asperi says, you must separate the View into two Views. You have double NavigationBar because in the case where you already enter with the previous NavigationView at the top level of the View hierarchy, having another NavigatioView makes it double the NavigationBar.

You must do something like this in the View before this one:


var body: some View {

    VSTack {
      Text("Hello Word")

      Button(action: {
        if isShowWithPresent { // Some Bool
           NavigationView {
             SomeView()
           }
        } else {
          AnotherView() // Some View without the NavigationView in the code
        }
      }) {
         Text("Hit Me!")
      }
    }
 }