Home > AI > IOS > SwiftUI >

hide navigation bar is dependent

This example shows the setting for .navigationBarHidden is dependent, same as other view modifiers.

BackgroundView.swift

struct BackgroundView: View {
    @EnvironmentObject var home: HomeGlobal
    
    var body: some View {
        
        Text("goood")
            .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
            .background(Color.orange
                            .edgesIgnoringSafeArea(.all)
            )
            .navigationBarTitle("Back", displayMode: .inline)
            .navigationBarHidden(self.home.hiddenBar)
            .onAppear {
                self.home.hiddenBar = true
            }
    }
}

SecondView.swift

struct SecondView: View {
    var body: some View {
        NavigationLink(destination: ThirdView()) {
            Text("Second View")
                .navigationBarHidden(false)
        }
        
    }
}

ThirdView.swift

struct ThirdView: View {
    var body: some View {
        NavigationLink(destination: ForthView()) {
            Text("Third View")
                .navigationBarHidden(true)
        }
        
    }
}

ForthView.swift

struct ForthView: View {
    var body: some View {
        Text("Forth View")
            .navigationBarHidden(false)
    }
}

Leave a Reply