John Harrington
John Harrington

Reputation: 1697

SwiftUI NavigationView content only visible in iPad sidebar

My app is working as expected across all iPhone models, but when running on iPad I notice that the my application content, which is wrapped within a NavigationView, only displays in the iPad's sidebar, and only after tapping the 'Back` toolbar button.

var body: some View {
        NavigationView{
            ZStack{

        ...

        }
         .navigationBarTitleDisplayMode(.inline)
         .toolbar {
                ToolbarItem(placement: .principal) {
                    VStack {
                        Text("Add Light to Your Journey")
                            .font(Font.custom("EduTASBeginner-Regular", size: 24))
                        ...
    }
}

I found a similar question on SO that suggested adding the attribute .navigationViewStyle(.stack), but this did not change the way the app is displayed on iPad:

iPad

Note the solution on this similar post also did not resolve the issue.

Upvotes: 9

Views: 2589

Answers (2)

nir barzilay
nir barzilay

Reputation: 91

You can just use NavigationStack instead of NavigationView, and it will resolve the issue.

var body: some View {
    NavigationStack{
        ZStack{

    ...

    }
     .navigationBarTitleDisplayMode(.inline)
     .toolbar {
            ToolbarItem(placement: .principal) {
                VStack {
                    Text("Add Light to Your Journey")
                        .font(Font.custom("EduTASBeginner-Regular", size: 24))
                    ...
}

}

Upvotes: 3

John Harrington
John Harrington

Reputation: 1697

As noted in the comments on the linked post, the .navigationViewStyle(StackNavigationViewStyle()) must be applied directly to the NavigationView, and not a view contained therein as with .navigationTitle

Upvotes: 18

Related Questions