Native partial customizable SwiftUI sheets from iOS 15.0
NativePartialSheet
Main feature of this library – native support of custom SwiftUI’s presentationDetents from iOS 15.0 ?
Simple example
extension Detent {
static let customCompact: Detent = .custom(constant: 100)
}
struct MyView: View {
@State var isPresented = false
var body: some View {
Text("Open sheet")
.onTapGesture {
isPresented = true
}
.sheet(isPresented: $isPresented) {
NativePartialSheet() {
Text("Hello world")
.interactiveDismissDisabled()
}
}
}
}
Advanced example
import NativePartialSheet
import SwiftUI
extension Detent { // complile time static detents
static let customCompact: Detent = .custom(constant: 100)
}
struct MyView: View {
@State var isPresented = false
@State var selectedDetent: Detent? = .customCompact
@State var detents: [Detent] = [.large, .customCompact]
var body: some View {
Text("Open sheet")
.onTapGesture {
isPresented = true
}
.sheet(isPresented: $isPresented) {
NativePartialSheet( // all params not required
detents: detents,
preferredCornerRadius: 32,
prefersGrabberVisible: false,
prefersEdgeAttachedInCompactHeight: false,
prefersScrollingExpandsWhenScrolledToEdge: true,
widthFollowsPreferredContentSizeWhenEdgeAttached: false,
largestUndimmedDetent: .medium,
selectedDetent: $selectedDetent
) {
Text("Hello world")
.interactiveDismissDisabled()
}
.onAppear {
// runtime calculated detent
let newDetent: Detent = .custom(constant: .init(400))
detents.append(newDetent)
selectedDetent = newDetent // animated by default
}
}
}
}