mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-28 04:06:57 +02:00
Add intrinsic sized bottom sheet
This commit is contained in:
@@ -21,6 +21,7 @@ struct InfoSheetCoordinatorParameters {
|
||||
let title: String
|
||||
let description: String
|
||||
let action: InfoSheet.Action
|
||||
let parentSize: CGSize?
|
||||
}
|
||||
|
||||
final class InfoSheetCoordinator: Coordinator, Presentable {
|
||||
@@ -39,8 +40,8 @@ final class InfoSheetCoordinator: Coordinator, Presentable {
|
||||
let view = InfoSheet(viewModel: viewModel.context)
|
||||
infoSheetViewModel = viewModel
|
||||
let controller = VectorHostingController(rootView: view)
|
||||
controller.bottomSheetPreferences = .init(cornerRadius: 24)
|
||||
infoSheetHostingController = controller
|
||||
setupPresentation(of: controller)
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
@@ -58,3 +59,33 @@ final class InfoSheetCoordinator: Coordinator, Presentable {
|
||||
infoSheetHostingController
|
||||
}
|
||||
}
|
||||
|
||||
private extension InfoSheetCoordinator {
|
||||
// The bottom sheet should be presented with the content intrinsic height as for design requirement
|
||||
// We can do it easily just on iOS 16+
|
||||
func setupPresentation(of viewController: VectorHostingController) {
|
||||
let cornerRadius: CGFloat = 24
|
||||
|
||||
guard
|
||||
#available(iOS 16, *),
|
||||
let parentSize = parameters.parentSize,
|
||||
let presentationController = viewController.sheetPresentationController
|
||||
else {
|
||||
viewController.bottomSheetPreferences = .init(cornerRadius: cornerRadius)
|
||||
return
|
||||
}
|
||||
|
||||
let intrisincSize = viewController.view.systemLayoutSizeFitting(.init(width: parentSize.width, height: 0),
|
||||
withHorizontalFittingPriority: .defaultHigh,
|
||||
verticalFittingPriority: .defaultLow)
|
||||
|
||||
presentationController.preferredCornerRadius = cornerRadius
|
||||
presentationController.prefersGrabberVisible = true
|
||||
presentationController.detents = [
|
||||
.custom { context in
|
||||
min(context.maximumDetentValue, intrisincSize.height)
|
||||
},
|
||||
.large()
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ struct InfoSheet: View {
|
||||
.foregroundColor(theme.colors.primaryContent)
|
||||
.accessibilityIdentifier(viewModel.viewState.description)
|
||||
.padding([.leading, .trailing], padding)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
.layoutPriority(1)
|
||||
|
||||
@@ -70,7 +71,7 @@ struct InfoSheet: View {
|
||||
}
|
||||
.padding(.bottom, padding)
|
||||
.padding(.top, 32)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.frame(maxWidth: .infinity)
|
||||
.background(theme.colors.background.ignoresSafeArea(edges: .bottom))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user