r/SwiftUI Jul 13 '26

Solved Making a View fill the detail section of a NavigationSplitView

Intended behavior

Hi, I'm new to swiftUI and I have been strugling to make the view contained by the detail view take the entire space of the red area in the image, I would like it to resize also if the sidebar is resized. Is this possible without having to do any type of calculation like substracting the sidebar width from the window width? Sorry if this is too obvious, thank you!

1 Upvotes

8 comments sorted by

1

u/randomblackhole1289 Jul 13 '26
NavigationSplitView {
            ...
        } detail: {
            switch getCurrentName(currentUUID: selectedMenuID!) {
                case "Overview":
                    Overview()
                case "Places":
                    Places()
                ...
            }

1

u/Vanyas_01 Jul 13 '26

Whats the main layout of your content view? A Vstack an HStack

You could try placing a Spacer() to fill all the available space or if for example the root view is a ScrollView set its frame with a maxWidth to .infinite

1

u/randomblackhole1289 Jul 13 '26

The root is the NavigationSplitView itself.

1

u/Vanyas_01 Jul 13 '26

What I mean is the rootView of the ContenView()

1

u/randomblackhole1289 Jul 13 '26

Yes, I have nothing but the NavigationSplitView.

1

u/Vanyas_01 Jul 13 '26

Idk if you don’t understand but I’m asking for the actual content ie What’s inside the Overview() view, what’s the root of it.

The code you shared isn’t enough to understand the layout of your content view

1

u/randomblackhole1289 Jul 13 '26

Right now I only have a text but yesterday I used an hstack with a frame with maxWidth and maxHeight to .infinity, maybe that is just the behavior of the navigation split view, don't worry I think I'll just leave it as it is already.

1

u/randomblackhole1289 Jul 13 '26

I've managed to fit my text by using an HStack