A sheet which you can use anywhere (eg, on another modal .sheet) with a few customisation options.
In Xcode:
- File ⭢ Swift Packages ⭢ Add Package Dependency...
- Use the URL https://github.com/franklynw/HalfASheet
NB: All examples require
import HalfASheet
at the top of the source file
It can be used directly as a view, which offers the full range of customisation options -
var body: some View {
HalfASheet(isPresented: $isPresented, title: "Half a sheet") {
// your view here
}
.backgroundColor(backgroundColor)
.closeButtonColor(UIColor.gray.faded(0.4))
.disableDragToDismiss
}
or as a modifier, which presents the default half-sheet, which is about 5/6 the height of the containing view -
var body: some View {
MyView {
}
.halfASheet(isPresented: $isPresented, title: "Half a sheet") {
// your view here
}
}
Set the height of the sheet as either a fixed height or as a proportion of the containing view's height
HalfASheet(isPresented: $isPresented, title: "Half a sheet") {
// your view here
}
.height(.fixed(400))
or
HalfASheet(isPresented: $isPresented, title: "Half a sheet") {
// your view here
}
.height(.proportional(0.6))
HalfASheet(isPresented: $isPresented, title: "Half a sheet") {
// your view here
}
.contentInsets(EdgeInsets(top: 5, leading: 10, bottom: 5, trailing: 10))
HalfASheet(isPresented: $isPresented, title: "Half a sheet") {
// your view here
}
.backgroundColor(.red)
HalfASheet(isPresented: $isPresented, title: "Half a sheet") {
// your view here
}
.closeButtonColor(.green)
Normally, you can dismiss the sheet by dragging it downwards - this will disable that
HalfASheet(isPresented: $isPresented, title: "Half a sheet") {
// your view here
}
.disableDragToDismiss
Possibly not an issue, but the dimming background which is behind the HalfASheet only covers the containing view, rather than the whole screen. I aim to provide an option in the future which allows it to be full-screen
HalfASheet
is available under the MIT license