Skip to content

Instantly share code, notes, and snippets.

@filimo
Last active February 15, 2020 18:50
Show Gist options
  • Save filimo/9f55f17f19625967de3e4ea3a43176cc to your computer and use it in GitHub Desktop.
Save filimo/9f55f17f19625967de3e4ea3a43176cc to your computer and use it in GitHub Desktop.
Hide/show parent navigation bar
import SwiftUI
struct NavigationView2Demo: View {
@State var hide = false
var body: some View {
NavigationView {
NavigationView2Demo_A
.navigationBarHidden(hide)
.onAppear { self.hide = true }
}
}
var NavigationView2Demo_A: some View {
VStack(spacing: 20) {
NavigationLink(destination: NavigationView2Demo_B) {
Text("Go to screen B")
}
.navigationBarTitle("A")
Text("Navigation bar should be hidden")
}
}
var NavigationView2Demo_B: some View {
Text("Navigation bar should not be hidden")
.navigationBarTitle("B")
.onAppear { self.hide = false }
}
}
struct NavigationView2Demo_Previews: PreviewProvider {
static var previews: some View {
NavigationView2Demo()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment