Swiftpack.co - franklynw/HalfASheet as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by franklynw.
franklynw/HalfASheet 1.0.2
A SwiftUI pseudo-modal partial screen sheet, with height customisation
⭐️ 58
🕓 3 years ago
iOS
.package(url: "https://github.com/franklynw/HalfASheet.git", from: "1.0.2")

HalfASheet

A sheet which you can use anywhere (eg, on another modal .sheet) with a few customisation options.

Example 1

Installation

Swift Package Manager

In Xcode:

Example

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))

Set the contentInsets of the view shown on the sheet

HalfASheet(isPresented: $isPresented, title: "Half a sheet") {
    // your view here
}
.contentInsets(EdgeInsets(top: 5, leading: 10, bottom: 5, trailing: 10))

Set the background colour of the sheet

HalfASheet(isPresented: $isPresented, title: "Half a sheet") {
    // your view here
}
.backgroundColor(.red)

Set the colour of the close button

HalfASheet(isPresented: $isPresented, title: "Half a sheet") {
    // your view here
}
.closeButtonColor(.green)

Disable the default drag-down-to-dismiss behaviour

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

Issues

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

License

HalfASheet is available under the MIT license

GitHub

link
Stars: 58
Last commit: 19 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics