-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathRootView.swift
67 lines (59 loc) · 1.76 KB
/
RootView.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
import SwiftUI
import SherlockHUD
@MainActor
struct RootView: View
{
/// - Note:
/// Attaching `.enableSherlockHUD(true)` to topmost view will allow using `showHUD`.
/// See `SherlockHUD` module for more information.
@Environment(\.showHUD)
private var showHUD: @MainActor (HUDMessage) -> Void
var body: some View
{
VStack(spacing: 16) {
Button("Top") {
showHUD(randomHUDMessage(alignment: .top))
}
Button("Center") {
showHUD(randomHUDMessage(alignment: .center))
}
Button("Bottom") {
showHUD(randomHUDMessage(alignment: .bottom))
}
Button("Dismiss All") {
showHUD(.dismiss(alignment: .top))
showHUD(.dismiss(alignment: .center))
showHUD(.dismiss(alignment: .bottom))
}
}
.font(.largeTitle)
}
func randomHUDMessage(alignment: HUDAlignment) -> HUDMessage
{
let duration: TimeInterval = .random(in: 1 ... 3)
let content: AnyView? = {
switch (0 ... 2).randomElement()! {
case 0: return AnyView(Text("Complete!"))
case 1: return AnyView(Text(Constant.loremIpsum))
case 2: return nil // Use `.loading`
default: fatalError()
}
}()
if let content = content {
return .init(duration: duration, alignment: alignment, content: {
content
})
}
else {
return .loading(message: "Loading", duration: duration, alignment: alignment)
}
}
}
// MARK: - Previews
struct RootView_Previews: PreviewProvider
{
static var previews: some View
{
RootView()
}
}