When a parent view is selected for the detail pane of a NavigationSplitView subviews appear as expected but not with the dimensions set by .frame on the subview.
Toggling the flag works as expected, appearing the subview with the idealWidth. I persist the flag in a SwiftData @Model class so that on restart and first appearance of the parent view the Right View subview presence is as it was left. The problem is that the .frame size is ignored, apparently. No manner of programatic view refresh seems to trigger a resize to the preferred values, only toggling the flag.
Is there a better way to handle a collapsing subview in an HSplitView? Why is the .frame not respected?
In this example I've added the else clause so HSplitView always has two views with .frame settings but the result is the same without it.
VStack {
HSplitView {
VStack {
Text("left view")
}
.frame(
minWidth: 100,
idealWidth: .infinity,
maxWidth: .infinity,
maxHeight: .infinity
)
if documentSettings.nwIsPieChartShowing {
VStack {
Text("right view")
}
.frame(
minWidth: 100,
idealWidth: 200,
maxWidth: .infinity,
maxHeight: .infinity
)
}
else {
Text("")
.frame(
minWidth: 0,
idealWidth: 0,
maxWidth: 0,
maxHeight: .infinity
)
}
}
HStack {
Button("Right View",
systemImage: { documentSettings.nwIsPieChartShowing ? "chart.pie.fill" : "chart.pie"}(),
action: { documentSettings.nwIsPieChartShowing.toggle() }
)
}
}
}
}
MacOS Sequoia 15.3.1, Xcode 16.2