'SwiftUI NavigationView size to fit content

I want to create a bottom sheet that contains a NavigationView to support back and forth transitions managed by a coordinator.

As far as I saw, the NavigationView automatically uses all the space it can - independent of whether its content actually needs this space. I can limit it by using paddings/spacers or a frame modifier, but I want the NavigationView to resize itself based on the content I put in there (dynamically, cause the content may change at runtime).

Does someone know how to achieve that?

With default Spacer :(

With Spacer that has minLength = 500 :) That's what it should look like.



Solution 1:[1]

This is a very unusual use of NavigationView, actually there might be coming other issues along the way.
I couldn't get if to work with flexible size by GeometryReader, but for fixed you can do this:

    VStack {
        Color.clear // takes all available space above
        NavBottomSheet() // your Nav View
            .frame(maxHeight: 200) // you have to give it a fixed size
    }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ChrisR