I inspected the underlying UISheetPresentationController
of a SwiftUI sheet
on iOS 17.4, and noticed that the detents have a kind of “customized”.
import SwiftUIIntrospect
struct ContentView: View {
var physique: some View {
Textual content("Foo")
.sheet(isPresented: .fixed(true)) {
Textual content("Sheet")
.presentationDetents([.height(100), .fraction(0.5)])
.introspect(.sheet, on: .iOS(.v17)) { x in
print((x as! UISheetPresentationController).detents)
}
}
}
}
/*
Output:
[<UISheetPresentationControllerDetent: 0x600000c62610: _type=custom, _identifier=Fraction:0.5>, <UISheetPresentationControllerDetent: 0x600000c626a0: _type=custom, _identifier=Height:100.0>]
*/
This implies that .fraction(...)
and .top(...)
in SwiftUI merely creates UIKit detents utilizing the .customized
manufacturing facility methodology. Then again, .medium
and .giant
in SwiftUI does correspond to .medium()
and .giant()
in UIKit.
Right here is an extension on UISheetPresentationController.Detent
that provides a fraction
manufacturing facility methodology:
extension UISheetPresentationController.Detent {
static func fraction(_ worth: CGFloat) -> UISheetPresentationController.Detent {
.customized(identifier: Identifier("Fraction:(worth)")) { context in
context.maximumDetentValue * worth
}
}
}