0

When I include a Page View as written by Apple in a Navigation View with a hidden Navigation Bar Title, swiping the page makes the title appear.

struct ContentView: View {
  var body: some View {
    NavigationView {
      PageView(pages: [Text("Foo"), Text("Bar")])
      .navigationBarTitle("Title")
      .navigationBarHidden(true)
    }
  }
}

I tried adding a state variable that sets the navigationBarHidden Bool to true using a button, to no avail. It seems like the connection between the navigationBarHidden property and the UI breaks when the Page View flips the page.

I was able to hack something that worked by forcing the view with the navigation title to redraw by putting in both in the if navigationBarHidden and else blocks and triggering a .onAppear { isNavigationBarHidden = true } in the else block, but that stinks.

Appearing Title

AlexMath
  • 567
  • 1
  • 6
  • 16

1 Answers1

0

I landed on a the hacky solution of including the Page View in a List (which is what Apple did in its example app, which is how I found it).

struct ContentView: View {
  var body: some View {
    NavigationView {
      List {
        PageView(pages: [Text("Foo"), Text("Bar")])
      }
      .navigationBarTitle("Title")
      .navigationBarHidden(true)
    }
  }
}

I tried including the Page View in a VStack, an AnyView, its own custom View object, none of those worked. I guess it works because a List is inherently Dynamic and so it triggers a whole-view redraw? But it still looks like an Apple bug to me.

I'll still have to massage the UI quite a bit since I actually don't want a List, but it's the best I could find.

Navigation Bar stays hidden

AlexMath
  • 567
  • 1
  • 6
  • 16