I'm working with a vertical ScrollView in SwiftUI, and I want to have dynamic resizing for two components inside it. Specifically, I want one component to have a constrained maxWidth and maxHeight (up to a certain limit), while the other component should have a flexible width and height that takes up the remaining space.
However, due to the nature of ScrollView—where its maxHeight is effectively .infinity—it seems challenging to constrain one component dynamically.
Without the ScrollView, resizing works as expected, but with ScrollView, I have to set fixed width and height, which removes the dynamic behavior.
Without ScrollView, letting SwiftUI resize:
VStack(spacing: .zero) {
ViewWithMaxSize()
.frame(maxWidth: UIScreen.main.bounds.width * 0.5, maxHeight: UIScreen.main.bounds.height * 0.3)
PriorityView()
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
With ScrollView, forced to set a fixed width / height, no longer dynamic:
VStack(spacing: .zero) {
ScrollView {
ViewWithMaxSize()
.frame(width: UIScreen.main.bounds.width * 0.5, height: UIScreen.main.bounds.height * 0.3)
PriorityView()
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
Is there a way to maintain dynamic resizing behavior for both components inside a ScrollView, where one has limited size and the other expands?
I've tried wrapping the ScrollView in a GeometryReader to constrain the frame of the ScrollView to the space available on the screen. ViewWithMaxSize becomes too small (almost no height).
ScrollViewin the first place? Do you just want the scroll bounce behaviour?ScrollViewisn’t “scrollable”. The view looks great without aScrollViewbut when trying to adopt Dynamic Type it inevitably overflows. I would prefer theViewWithMaxSizeto shrink based on the size of thePriorityViewbut I guess this is the tradeoff that we have to live with then?