Setting sidebar width constraints in visionOS NavigationView

106 Views Asked by At

I'm aware it's possible to manipulate sidebar width for a NavigationSplitView like this.-

NavigationSplitView {
    Text("Sidebar")
        .navigationSplitViewColumnWidth(min: 100, ideal: 200, max: 300)
} content: {
    Text("Content")
        .navigationSplitViewColumnWidth(min: 100, ideal: 200, max: 300)
} detail: {
    Text("Detail")
}

But my main view includes a simple NavigationView (just a side bar and content), and it seems there's no api for specifying width in this case. Any known way to get the same effect in this scenario?

1

There are 1 best solutions below

1
lorem ipsum On BEST ANSWER

NavigationView was deprecated a few OSs ago and should not be used in visionOS because it is known to have many bugs a limitations.

If you want to duplicate the 2 column setup you should migrate your code.

From

NavigationView { // This is deprecated.
    /* column 1 */
    /* column 2 */
}

To

NavigationSplitView {
    /* column 1 */
} detail: {
    /* column 2 */
}

Then you can use

.navigationSplitViewColumnWidth(min: 100, ideal: 200, max: 300)

https://developer.apple.com/documentation/swiftui/migrating-to-new-navigation-types