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 7cf73c19e0
commit 4e37034fba
3 changed files with 24 additions and 4 deletions

View file

@ -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
}
}
}
}

View file

@ -48,9 +48,10 @@ final class ComposerCreateActionListCoordinator: NSObject, Coordinator, Presenta
view = ComposerCreateActionList(viewModel: viewModel.context)
let hostingVC = VectorHostingController(rootView: view)
hostingVC.bottomSheetPreferences = VectorHostingBottomSheetPreferences(
detents: [.medium],
detents: [.custom(height: 470)],
prefersGrabberVisible: true,
cornerRadius: 20
cornerRadius: 20,
prefersScrollingExpandsWhenScrolledToEdge: false
)
hostingController = hostingVC
super.init()

View file

@ -78,9 +78,10 @@ struct ComposerCreateActionList: View {
}
}
.padding(.top, 8)
Spacer()
}.background(theme.colors.background.ignoresSafeArea())
}
.padding(.top, 23)
.background(theme.colors.background.ignoresSafeArea())
}
}