scrollable bottom sheet, with custom size on iOS 16

This commit is contained in:
Mauro Romito
2022-11-16 17:23:32 +01:00
parent bf18ba4f86
commit 96c5337204
3 changed files with 24 additions and 4 deletions
@@ -25,11 +25,23 @@ class VectorHostingBottomSheetPreferences {
case medium
case large
/// only available on iOS16, medium behaviour will be used instead
case custom(height: CGFloat, identifier: String = "custom")
@available(iOS 15, *)
fileprivate func uiSheetDetent() -> UISheetPresentationController.Detent {
switch self {
case .medium: return .medium()
case .large: return .large()
case let .custom(height, identifier):
if #available(iOS 16, *) {
let identifier = UISheetPresentationController.Detent.Identifier(identifier)
return .custom(identifier: identifier) { context in
return min(height, context.maximumDetentValue)
}
} else {
return .medium()
}
}
}
@@ -38,6 +50,12 @@ class VectorHostingBottomSheetPreferences {
switch self {
case .medium: return .medium
case .large: return .large
case let .custom(_, identifier):
if #available(iOS 16, *) {
return UISheetPresentationController.Detent.Identifier(identifier)
} else {
return .medium
}
}
}
}