1

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?

6
  • it isn’t a good idea to use NavigationView with visionOS, Apple deprecated it a couple of OSs ago and it is known to have a lot of bugs. Commented Feb 25, 2024 at 13:21
  • Thank you @loremipsum, wasn't aware of that. So I presume currently there's no official recommended way to get this kind of layout (single sidebar to the left and single content view)? Commented Feb 25, 2024 at 13:39
  • I don’t know what you mean by that. If you are looking for a traditional Master/Detail that is what the NavigationSplitView does by default developer.apple.com/documentation/swiftui/navigationsplitview you are depicting with this code a 3 column navigation. Commented Feb 25, 2024 at 13:43
  • Yep, the code is an example of a 3 column NavigationSplitView, but as stated in the question I'm working on a 2 column layout, which is what I get with the NavigationView. Commented Feb 25, 2024 at 14:33
  • If you look at the first set of code in the documentation you’ll see how to get a 2 column setup with NavigationSplitView Commented Feb 25, 2024 at 14:34

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you @loremipsum, this works great, my only issue now is that I was using searchable to show a searchBar in the main content (right panel). Now it seems I can only show the search in the sidePanel unless I add the content object to get 3 columns.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.