SwiftUI-Drawer
A bottom-up drawer view.
Contents
Installation
For Swift Packages
Add a dependency in your your Package.swift
file
.package(name: "Drawer", url: "https://github.com/bwide/SwiftUI-Drawer", from: "1.1.1")
Examples
Simple Drawer with no handle
ZStack {
Color.black
GeometryReader {
Drawer {
EmptyView()
}
.background(color: .blue)
.rest(in: [135, $0.size.height])
}
}.edgesIgnoringSafeArea(.vertical)
Drawer with the default handle
ZStack {
Color.black
GeometryReader {
Drawer({
EmptyView()
}, handle: {
DrawerHandles.defaultHandle
})
.background(color: .blue)
.handle(height: 6, padding: 10)
.rest(in: [135, $0.size.height])
}
}.edgesIgnoringSafeArea(.vertical)
Drawer with no rounded edges when reaching the top of the screen and a custom handle offset
GeometryReader { geometry in
Drawer({
EmptyView()
}, handle: {
DrawerHandles.defaultHandle
})
.cornerRadius(radius)
.onRest({ position in
radius = position == geometry.size.height
? 0
: 16
})
.onDrag({ _ in
radius = 16
})
.background(color: .blue)
.rest(in: [136, geometry.size.height])
.handle(height: 6, padding: 10)
}
Drawer with scrollable content
ZStack {
Color.black
GeometryReader {
Drawer({
ZStack {
Color.blue
VStack {
ForEach(0..<100) {
Text("item \($0)")
}
}
}
}, handle: {
DrawerHandles.defaultHandle
})
.scrollableContent()
.background(color: .blue)
.handle(height: 6, padding: 10)
.rest(in: [135, $0.size.height])
.interactive(in: [$0.size.height])
}
}.edgesIgnoringSafeArea(.vertical)