iOS 15 SwiftUI Conditionals on a view with Navigation View makes NavigationBar config to be ignore if navigationViewStyle stack

been searching for this everywhere and can't find anything around this, I believe is a bug, maybe is not.

I need NavigationView with .navigationViewStyle(.stack) to have it stacked on the iPad and make it look the same as the iphone, now suppose you have this view:

import SwiftUI

struct ContentView: View {
    @State var isShowingProfile = false
    @State var isNavigationViewShowing = true

    var body: some View {
        if isNavigationViewShowing {
            NavigationView {
                VStack {
                    Button("Simple view") {
                        isNavigationViewShowing = false
                    }
                    .padding()
                    Button("Profile navigation") {
                        isShowingProfile = true

                    }
                    .padding()
                    NavigationLink(
                        destination: ProfileView(),
                        isActive: $isShowingProfile
                    ) {
                        EmptyView()
                    }
                }
                .frame(
                    minWidth: 0,
                    maxWidth: .infinity,
                    minHeight: 0,
                    maxHeight: .infinity
                )
                .background(Color.gray)
                .navigationBarHidden(true)
            }
            .navigationViewStyle(.stack)
        } else {
            VStack {
                Button("Show NavigationView"){
                    isNavigationViewShowing = true

                }
                .padding()
            }
            .frame(
                minWidth: 0,
                maxWidth: .infinity,
                minHeight: 0,
                maxHeight: .infinity
            ).background(Color.yellow)
        }
    }
}

struct ProfileView: View {
    var body: some View {
        Text("This is a profile")
    }
}


struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Well this just show this 3 simple views:

  • The navigationView when you start

  • The Profile view if you tap on "Profile navigation"

  • Finally the Simple view with is trigger by the conditional state pressing "Simple view"

Up to here is all fine and good. The problem is when on the "Simple view" tap "Show NavigationView", then the app opens the first view, but the NavigationView ignores the .navigationBarHidden(true) and just show a big empty space on the top. In fact, it would ignore things like .navigationBarTitleDisplayMode(.inline) and just show the large version of the navigationBar

This is working correctly in all iOS 14.x, but on iOS 15.0 seems broken. The behaviour continues to be the same on iOS 15.1 beta.

Any idea whats going on? I'm not really interested in changing the conditionals on the view, because real life app is more complex.

Also, I tried ViewBuilder without any success. And if I take out .navigationViewStyle(.stack) it works all fine on iOS 15, but then the view on the iPad is with the side menu.

Thanks a lot for any tip or help, you should be able to reproduce in simulator and real device.

Video with the current behaviour on iOS 15 https://streamable.com/rgqkef

I am also having this issue on iOS15.

@r3pps if it works for you I solved like this https://stackoverflow.com/questions/69337796/ios-15-swiftui-conditionals-on-a-view-with-navigation-view-makes-navigationbar-c/69338719#69338719 not sure yet why this gets screwed on iOS 15, but well, changing my approach works

Thanks for sharing. We're having exactly the same issue. On iOS 14 it worked fine but it broke on iOS 15.

iOS 15 SwiftUI Conditionals on a view with Navigation View makes NavigationBar config to be ignore if navigationViewStyle stack
 
 
Q