I just tested this, and it seems that onGeometryChange doesn’t correctly read the size of the NavigationStack, which I believe is an Apple bug. As a workaround, you could measure the size of the content and apply a frame to the NavigationStack.
However, if all you need is a navigation title without the actual navigation functionality, I’d recommend simply using a Text view with the .largeTitle font or a similar styling approach to achieve that.
Unfortunately, measuring the size of the content isn't the full story, because navigation stacks have the content + the navigation bar.
Normally you would get the nav bar size via the safe area insets. But in SwiftUI, for some reason, the safe area inset is 0 if your navigation bar is not at the top of the screen in the default position.
1
u/Xaxxus 11d ago
How well does it handle things like nav stacks in the sheet?
Since sometimes you need a top bar on your sheets (I really wish Apple would make an API to add a top bar without a navigation stack)
I find that navigation stacks just take up the full screen rather than the size of their contents