import SwiftUI /// A ScrollView that is as tall as its content, up to a cap. /// /// Exists because a plain `ScrollView` inside a `VStack` has a tiny ideal /// height: given only `.frame(maxHeight:)` it collapses to nearly nothing. That /// bug shipped twice — once emptying the share list, once emptying the whole /// settings window — so the fix lives in one place now. /// File scope, not nested: a generic type cannot hold the static storage a /// PreferenceKey needs. private struct HeightKey: PreferenceKey { static let defaultValue: CGFloat = 0 static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) { value = max(value, nextValue()) } } struct MeasuredScrollView: View { var minHeight: CGFloat = 0 var maxHeight: CGFloat @ViewBuilder var content: Content @State private var measured: CGFloat = 0 var body: some View { ScrollView { content .background( GeometryReader { geometry in Color.clear.preference( key: HeightKey.self, value: geometry.size.height) } ) } .frame(height: min(max(measured, minHeight), maxHeight)) .onPreferenceChange(HeightKey.self) { measured = $0 } } }