Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cooloneofficial/nativepartialsheet
🔥 Native partial customizable SwiftUI sheets from iOS 15.0
https://github.com/cooloneofficial/nativepartialsheet
modals sheet swiftui
Last synced: about 1 month ago
JSON representation
🔥 Native partial customizable SwiftUI sheets from iOS 15.0
- Host: GitHub
- URL: https://github.com/cooloneofficial/nativepartialsheet
- Owner: CoolONEOfficial
- License: mit
- Created: 2022-09-18T23:11:53.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-20T22:20:24.000Z (9 months ago)
- Last Synced: 2024-03-20T23:35:19.942Z (9 months ago)
- Topics: modals, sheet, swiftui
- Language: Swift
- Homepage:
- Size: 26.4 KB
- Stars: 118
- Watchers: 6
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NativePartialSheet
Main feature of this library - native support of ***custom*** SwiftUI's presentationDetents from ***iOS 15.0*** 🔥
## Screenshots
## Simple examples
### Classic isPresented way
```swift
import SwiftUI
import NativePartialSheetstruct ContentView: View {
@State var isPresented = falsevar body: some View {
Text("Open sheet")
.onTapGesture {
isPresented = true
}
.nativePartialSheet(isPresented: $isPresented) {
Text("Sheet content")
}
.presentationDetents([ .large, .medium ])
}
}
```### Optional detent way
```swift
import SwiftUI
import NativePartialSheetstruct ContentView: View {
@State var detent: Detent?
var body: some View {
Text("Open sheet")
.onTapGesture {
detent = .medium
}
.nativePartialSheet(selectedDetent: $detent) { detent in
switch detent {
case .medium:
Text("Medium")
case .large:
Text("Large")
default:
EmptyView()
}
}
.presentationDetents([ .large, .medium ])
}
}
```## Advanced examples
### Sheet configuration
```swift
import SwiftUI
import NativePartialSheetstruct ContentView: View {
@State var isPresented = false
@State var detent: Detent = .mediumvar body: some View {
Text("Open sheet")
.onTapGesture {
isPresented = true
}
.nativePartialSheet(isPresented: $isPresented) {
Text("Sheet content")
}
.presentationDetents([ .medium, .large ], selection: $detent)
.cornerRadius(32)
.presentationDragIndicator(.visible)
.edgeAttachedInCompactHeight(true)
.scrollingExpandsWhenScrolledToEdge(true)
.widthFollowsPreferredContentSizeWhenEdgeAttached(true)
.largestUndimmedDetent(.medium)
.interactiveDismissDisabled(true, onWillDismiss: onWillDismiss, onDidDismiss: onDidDismiss)
}
func onDidDismiss() {
debugPrint("DID")
}
func onWillDismiss() {
debugPrint("WILL")
}
}
```### Use with item
```swift
import SwiftUI
import NativePartialSheetstruct MyItem: Identifiable {
var content: String
var id: String { content }
}struct ContentView: View {
@State var item: MyItem?var body: some View {
Text("Open sheet")
.onTapGesture {
item = .init(content: "Test content")
}
.nativePartialSheet(item: $item) { item in
VStack {
Button("recreate") {
self.item = .init(content: "Recreated content")
}
Button("change") {
self.item?.content = "Changed content"
}
Text(item.content)
}
}
.presentationDetents([ .large, .medium ])
}
}
```### Custom static detents
```swift
import SwiftUI
import NativePartialSheetextension Detent {
static let customSmall: Detent = .height(100)
}struct ContentView: View {
@State var detent: Detent?
var body: some View {
Text("Open sheet")
.onTapGesture {
detent = .customSmall
}
.nativePartialSheet(selectedDetent: $detent) { detent in
switch detent {
case .medium:
Text("Medium")
case .large:
Text("Large")
case .customSmall:
Text("Custom small")
default:
EmptyView()
}
}
.presentationDetents([ .large, .medium, .customSmall ])
}
}
```### Custom dynamic detents
```swift
import SwiftUI
import NativePartialSheetstruct ContentView: View {
@State var detent: Detent?
@State var detents: Set = [ .large, .medium ]
var body: some View {
Text("Open sheet")
.onTapGesture {
let dynamic = Detent.height(123)
detents.insert(dynamic)
detent = dynamic
}
.nativePartialSheet(selectedDetent: $detent) { detent in
switch detent {
case .height(_):
Text("Dynamic")
case .medium:
Text("Medium")
case .large:
Text("Large")
}
}
.presentationDetents(detents)
}
}
```