Type 'DefaultNavigationViewStyle' has no member 'automatic'

I am trying to show a StackNavigationView for my app's menu if the user is on iPad and the default Navigation view elsewhere. The reason is because on iPad the default view only shows the back button and nothing else, and the user has to click the back button to access the menu in portrait mode, which is not user friendly at all. Here is a simplified version of my code


    @State var selectedView:Int?;

    @Environment(\.colorScheme) var colorScheme;

    var body: some View {

        ZStack{

        NavigationView{

                List{
                    NavigationLink(destination: textChangeView(){

                        Text("mOcK tExT")

                    }

                NavigationLink(destination: textChangeView()) {

                        Text("S P A C E D")
                    }

                NavigationLink(destination: textChangeView() {

                        Text("Windy text")
                    }
                    }

                }.navigationTitle("Options")
// PROBLEM IS HERE 
        }.navigationViewStyle(UIDevice.current.model == "iPad" ? StackNavigationViewStyle() : DefaultNavigationViewStyle.automatic)
        }

        }

The official SwiftUI documentation tells us to use automatic which is an attribute of DefaultNavigationStyle. Yet, I get the error Type 'DefaultNavigationViewStyle' has no member 'automatic'

How can I set up my navigationViewStyle to be StackNavigationStyle and the default elsewhere ?

How can I set up my navigationViewStyle to be StackNavigationStyle and the default elsewhere ?

The modifier navigationViewStyle requires a value of one concrete type conforming to NavigationViewStyle. So, even when DefaultNavigationViewStyle.automatic is valid there, you cannot use the ternary operator which may return two different types -- StackNavigationViewStyle or DefaultNavigationViewStyle.


One possible solution would be using a custom modifier:

struct ContentView: View {
    //...
    
    var body: some View {
        ZStack {
            NavigationView {
                List {
                    //...
                }
                
            }.navigationTitle("Options")
        }
        .modifier(MyNavigationViewStyle())
    }
    
}

struct MyNavigationViewStyle: ViewModifier {
    func body(content: Content) -> some View {
        if UIDevice.current.model == "iPad" {
            content.navigationViewStyle(StackNavigationViewStyle())
        } else {
            content.navigationViewStyle(DefaultNavigationViewStyle())
        }
    }
}
Type 'DefaultNavigationViewStyle' has no member 'automatic'
 
 
Q