0

I am navigating from one screen to another on previous screen i am hiding navigation bar but on second screen I want to show navigation bar but in mu case its hiding on second screen also.

navigation bar hidden on first screen as

.navigationBarHidden(true)

How can i show navigation bar on second screen? (I am NOT using navigation view on either screen)

My First parent screen has

            NavigationView {
//design
}
.navigationBarTitle("ABCScreen", displayMode: .inline)
                .navigationViewStyle(StackNavigationViewStyle())

Thank you for help.

Rahul
  • 537
  • 1
  • 7
  • 19

2 Answers2

0

The possible approach to hide navigation bar in root view and show in child subviews.

struct FirstNavigationView: View {
    @State private var hideBar = true // <<  hide state
    var body: some View {
        NavigationView {
            VStack {
                Text("FirstView")
                Divider()
                NavigationLink("Goto Child", destination: NextChildView(index: 1))
                 .simultaneousGesture(TapGesture().onEnded {
                    self.hideBar = false     // << show
                 })
            }
            .navigationBarHidden(hideBar)
        //    .navigationBarTitle("Back to Root") // << choice 
            .onAppear {
                self.hideBar = true  // << hide on back
            }
        }
    }
}

The only needed modifications is in root view.

Sumit_VE
  • 429
  • 2
  • 12
  • I personal used same in past. And I took reference from https://stackoverflow.com/a/60996978/16083654 – Sumit_VE Sep 20 '21 at 11:03
0

For your first screen you can add .navigationBarHidden(true) inside your NavigationView to hide it and false on second screen to unhide.

FIRST SCREEN:

NavigationView{
        Button(action: {}, label: {
            Text("Button")
        })
        .navigationBarHidden(true) //This flag will hide your navigationBar
    }

SECOND SCREEN:

NavigationView{
        Button(action: {}, label: {
            Text("Button")
        })
        .navigationBarHidden(false) //This flag will unhide your navigationBar
    }
Umair Khan
  • 993
  • 8
  • 14