SwiftUI - Navigation View opening with Back button and half grey screen / weird behavior

1.4k Views Asked by At

I am trying to add navigation view to my app, but it is causing issues. My main UI is an infinitely swipe-able carousel of pages. It originally looks like this: swipable pages without navigation view

Then when I wrap it in a navigation view, it opens like this, with a back button and nothing else: enter image description here

When I hit the back button, it looks like this:enter image description here

The left side is swipe-able like the original UI, but when I touch the right, grey side, it takes me back to the empty page with the back button.

Any idea what may be causing this? I implemented the infinite carousel by putting each page in a ZStack, and using offsets/relativeLocation. I referred to this tutorial: https://www.youtube.com/watch?v=fB5MzDD1PZI

Can I not use a NavigationView? Is there an alternative route I can take in which I create my own top NavBar and navigate to separate views without NavigationBar/NavigationLink?

Any help is appreciated and please feel free to ask questions, etc. Thanks!

1

There are 1 best solutions below

0
aheze On BEST ANSWER

You want to apply StackNavigationViewStyle to your NavigationView.

NavigationView {

...

}.navigationViewStyle(StackNavigationViewStyle())

You're experiencing an unwanted split view, and you can find more info here.

For larger devices like an iPad or iPhone Pro Max in landscape, it defaults to DoubleColumnNavigationViewStyle.