Swiftui: Unwanted Split View on iPad

SwiftUI: unwanted split view on iPad

Update July 2022

Using NavigationStack instead of NavigationView should display as the main view as you would expect on iPad:

NavigationStack {
Text("Hello world!")
}

*In newer versions, the navigationViewStyle modifier has been deprecated.

Original answer:

You can apply the .navigationViewStyle(.stack) modifier to the NavigationView.

... 
NavigationView {
Text("Hello world!")
}
.navigationViewStyle(.stack)
...

Edit: Below, I am answering Alexandre's questions from his comment:

  • Why full view is not the default for iPad? That's just a choice made by Apple...

  • Why this modifier goes outside of NavigationView closure, while the Navigation Title goes inside... Maybe this gives clarification: https://stackoverflow.com/a/57400873/11432719

Disable split view using Swift UI on iPad

By setting the NavigationViewStyle

import SwiftUI

struct NavView: View {
var body: some View {
NavigationView{
List{
NavigationLink(destination: TestView(), label: {Text("TestView")})
}
}.navigationViewStyle(StackNavigationViewStyle())
}
}

struct NavView_Previews: PreviewProvider {
static var previews: some View {
NavView()
}
}

Unwanted SplitView on modal view displayed on iPad

Here is fix (it has to be constructed, ie. StackNavigationViewStyle()):

} // END of Navigation View
.navigationViewStyle(StackNavigationViewStyle()) // << here !!

NavigationView SwiftUI shows split view in iPad

Use stack navigation view style explicitly (by default it is platform-dependent)

NavigationView {
Text("Hello")
.navigationBarTitle("Home")
}
.navigationViewStyle(StackNavigationViewStyle())

How to show same view as iPhone on iPad instead of Split view?

Hard to say without any code, but I bet you need to add .navigationViewStyle(StackNavigationViewStyle()) to your NavigationView to not get it in split view mode on the iPad:

NavigationView {
View1()
}.navigationViewStyle(StackNavigationViewStyle())

How to change master view width in SwiftUI split view on iPad

To change the default width of the master view you may install SwiftUI-Introspect and add this to your NavigationView:

.introspectNavigationController { navigationController in
navigationController.splitViewController?.preferredPrimaryColumnWidthFraction = 1
navigationController.splitViewController?.maximumPrimaryColumnWidth = *preferred width*
}


Related Topics



Leave a reply



Submit