1

I have a NavigationLink inside my ContentView that shows a SecondView with some text. When I apply an .edgesIgnoringSafeArea modifier inside SecondView, the text goes beyond the screen and this only happens inside a NavigationLink when a NavigationBar is hidden.

Can you test this code too if happens to you too?

struct ContentView: View {
@State var hiddenBar = false

var body: some View {
    NavigationView {
        NavigationLink(destination: SecondView(hiddenBar: $hiddenBar)) {
            Text("Go to second View")
        }
        .onAppear {
            self.hiddenBar = false
        }

    .navigationBarTitle("Title", displayMode: .inline)
    .navigationBarHidden(hiddenBar)
    }
}
}

struct SecondView: View {
@Binding var hiddenBar: Bool

var body: some View {
    VStack {
        Text("Text that goes outside of the safe area plus the amount of Navigation Bar height because it's hidden...You can see just this peace of text here")
        Spacer()
    }
    .onAppear {
        self.hiddenBar = true
    }

    .edgesIgnoringSafeArea(.top)
}
}
xmetal
  • 681
  • 6
  • 16
  • why do you want to use `edgesIgnoringSafeArea(.top)`? – Harsh May 12 '20 at 17:43
  • The code above is just a simple example of my error. Basically I want to display an image inside my NavigationLink that ignores the safe area while hiding NavigationBar, since NavigationLink already provides one, but my Image goes beyond what is visible – xmetal May 12 '20 at 18:09
  • If there's another way to achieve what I'm looking for I'll be happy too...I've been trying to solve this problem for hours – xmetal May 12 '20 at 18:11
  • 1
    I actually solved it randomly...I added navigationBarTitle("") and navigationBarHidden(true) after SecondView(hiddenBar: $hiddenBar) – xmetal May 12 '20 at 22:06

0 Answers0