Skip to content

Instantly share code, notes, and snippets.

@gexiangdong
Last active August 24, 2021 02:25
Show Gist options
  • Save gexiangdong/75ded3ef35398517f0a9793d08f85ac1 to your computer and use it in GitHub Desktop.
Save gexiangdong/75ded3ef35398517f0a9793d08f85ac1 to your computer and use it in GitHub Desktop.

.navigationBarHidden(true) will not work with this code.

iOS 14.5

two conditions in ChildView

  1. @Environment(.presentationMode) (line 20)
  2. .navigationBarItems() (line 28 ... 32)

then .navigationBarHidden(true) (line 43 in GrandChildView) will not work

import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView{
VStack{
Text("Hello, Home!")
.padding()
NavigationLink(destination: ChildView()) { Text("go to child view") }
}.navigationTitle("Home")
}
}
}
struct ChildView: View {
@Environment(\.presentationMode) var presentationMode : Binding<PresentationMode>
var body: some View {
VStack{
Text("Hello, Child!")
.padding()
NavigationLink(destination: GrandChildView()) { Text("go to grand child view") }
}.navigationTitle("Child")
.navigationBarItems(trailing: Button(action:{
print("more")
}, label: {
Image(systemName: "ellipsis.circle")
}))
}
}
struct GrandChildView: View{
var body: some View {
VStack{
Text("Hello, Grandchild!")
.padding()
}.navigationTitle("Grandchild")
.navigationBarHidden(true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment