forked from Christmas-Blues/FullScreenOverlay
/
Previews.swift
63 lines (54 loc) · 1.79 KB
/
Previews.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
import SwiftUI
import FullScreenOverlay
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
private struct RootView: View {
@State private var isPresentingBottomSheet: Bool = false
var body: some View {
List {
Button(
"Present Bottom Sheet",
action: { isPresentingBottomSheet = true }
)
.fullScreenOverlay(presentationSpace: .named("RootView")) {
if isPresentingBottomSheet {
BottomSheet(onDismiss: { isPresentingBottomSheet = false })
}
}
}
}
}
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
private struct BottomSheet: View {
var onDismiss: () -> Void
@State private var isAppearing: Bool = false
var body: some View {
Color.black.opacity(0.2)
.edgesIgnoringSafeArea(.all)
.zIndex(-1)
.onTapGesture(perform: onDismiss)
.transition(.opacity.animation(.default))
VStack {
Text("Bottom Sheet")
.font(.title.weight(.semibold))
.padding(.vertical, 128)
Button("Dismiss", action: { isAppearing = false; onDismiss() })
}
.padding(.vertical, 32)
.frame(maxWidth: .infinity)
.background(
Color.white
.shadow(radius: 1)
.edgesIgnoringSafeArea(.all)
)
.frame(maxHeight: .infinity, alignment: .bottom)
.transition(.move(edge: .bottom))
.animation(.spring())
}
}
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
internal struct SwiftUIView_Previews: PreviewProvider {
static var previews: some View {
RootView()
.fullScreenOverlayPresentationSpace(name: "RootView")
}
}