-
Notifications
You must be signed in to change notification settings - Fork 0
/
SheetDetent.swift
71 lines (59 loc) · 1.6 KB
/
SheetDetent.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// iOS 16 and SwiftUI introduced presentationDetent modifier to showcase full sheet, half bottom sheet and also you can use fractioned and height to showcase
// a sheet according your convenience
import SwiftUI
enum SheetType: CaseIterable {
case half
case full
case heighted
case fractioned
var name: String {
switch self {
case .half:
return "Half"
case .full:
return "Full"
case .heighted:
return "Height - 100"
case .fractioned:
return "Fraction - 3/4th"
}
}
}
struct ContentView: View {
@State private var showSheet = false
@State private var sheetType: SheetType = .half
var body: some View {
Form {
Picker("Sheet Styles", selection: $sheetType) {
ForEach(SheetType.allCases, id: \.self) {
Text($0.name)
}
}
Button("Show Sheet") {
showSheet.toggle()
}
.sheet(isPresented: $showSheet) {
SheetView()
.presentationDetents([sheetDetent(type: sheetType)])
}
}
}
func sheetDetent(type: SheetType) -> PresentationDetent {
switch type {
case .half:
return .medium
case .full:
return .large
case .heighted:
return .height(100)
case .fractioned:
return .fraction(0.75)
}
}
}
struct SheetView: View {
var body: some View {
VStack {
}
}
}