0

A simple NavigationLink to a List view gives me the following strange behavior. After the navigation successfully occurs, the list abruptly shifts to where the title and back button are no longer on the screen:

Screen capture of strange behavior

Here is the code (Xcode 11.5). Any idea what's going on?

struct ContentView: View {
    var body: some View {
        NavigationView {
            NavigationLink(destination: ListView()) {
                Text("Go to List View ›")
            }.navigationBarTitle("").navigationBarHidden(true)
        }
    }
}

struct ListView: View {
    var body: some View {
        List {
            ForEach(0 ..< 3) { person in
                HStack {
                    Image(systemName: "person.crop.circle.fill")
                        .resizable().frame(width: 80, height: 80)
                    Text("User \(person+1)")
                }
            }
        }.listStyle(GroupedListStyle())
            .navigationBarTitle("List")
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
Anton
  • 2,512
  • 2
  • 20
  • 36

1 Answers1

1

The issue occurs because you try to hide/show the NavigationBar in a way which is not currently supported in SwiftUI (it may be fixed in the next releases).

This bug in SwiftUI occurs when you try to make the NavigationBar hidden in the root view and shown in the detail view:

EDIT

It seems like this bug was fixed in Xcode 12 beta.

pawello2222
  • 46,897
  • 22
  • 145
  • 209
  • Thank you, @pawello2222! I searched for awhile but didn't turn these up because I didn't realize the issue was the title-hiding carrying over. Commenting out .navigationBarHidden(true) solves the problem but leaves an annoying unusable space at the top of the ContentView. I'll hope for a fix soon! – Anton Jun 07 '20 at 22:57