I am utilizing a customized modifier referred to as AutoSheetDetentModifier to robotically measurement a sheet primarily based on its content material. (in SwiftUI)
On iOS 26, it really works as anticipated: the content material peak is measured and the sheet shrinks to match that peak.
Nonetheless, on iOS 16, 17 and 18, the identical code doesn’t work.
The content material peak continues to be measured, however the sheet doesn’t cut back its peak. As an alternative, the sheet stays bigger and the content material seems vertically centered.
public struct AutoSheetDetentModifier: ViewModifier {
@State non-public var peak: CGFloat = 380 // default worth to keep away from bouncing
public func physique(content material: Content material) -> some View {
content material
.modifier(MeasureHeightViewModifier(peak: $peak))
.presentationDetents([.height(height)])
}
}
public struct MeasureHeightViewModifier: ViewModifier {
@Binding var peak: CGFloat
public func physique(content material: Content material) -> some View {
content material
.fixedSize(horizontal: false, vertical: true)
.background(
GeometryReader { geo -> Colour in
DispatchQueue.foremost.async {
peak = geo.measurement.peak
}
return Colour.clear
}
)
}
}
extension View {
public func applyAutoSheetDetent() -> some View {
self
.modifier(AutoSheetDetentModifier())
}
}
public var physique: some View {
VStack {
header()
content material()
footer()
}
.background(Colour.customGray)
.applyAutoSheetDetent()
}
Screenshot from iOS 26 (working as anticipated):
Screenshot from iOS 18 (not working):
How can I make .presentationDetents(.peak) shrink the sheet appropriately on iOS 16–18, the identical manner it does on iOS 26?


