Coming from UIKit I find it struggling to achieve desired results in SwiftUI. I assume I am to caught in the constraint driven layout to get my head around the SwiftUI approach.
Assume the following layout:
On devices with a "regular" screen the horizontal space should be split 1:1 into a top and bottom part.
The top container hold three views with fixed height which should be positioned at the top, center and bottom of the container.
The three views have some minimum spacing, e.g. 20px. If enough space is available the spacing can be more but never below 20px.
On smaller devices the top container can shrink up to a certain level. But never so small, that the fixed width of the subviews and their spacing would be violated. In this case the ratio between the top and bottom container would not be 1:1 anymore but e.g. 2:3.
On larger devices like an iPad the top container would only grow up to some max. height. In this case the ratio between top and bottom container would also not be 1:1 any more.
The bottom container view holds only one view which should always fill the available space.
Solving this using constraints in UIKit would be no problem. I am aware that "regular", "smaller" and "bigger" devices are no actual size classes. This is just for illustration.
But how would this be solved in SwiftUI?
The basic layout is of course straight forward:
VStack(spacing: 0) {
VStack {
TopView()
Spacer()
CenterView()
Spacer()
BottomView()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.red)
VStack {
FillView()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.green)
}
But how to achieve the min- and maxHeight of the top-container? Is it possible to do this without using a GeometryReader but only with relative values?
How to avoid shrinking the top container below a given min-height when the bottom container becomes to big due to its content?
