-
Notifications
You must be signed in to change notification settings - Fork 9
/
LoadingOverlayView.swift
51 lines (46 loc) · 1.11 KB
/
LoadingOverlayView.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
extension View {
public func presentsLoadingViewOverlay() -> some View {
overlayPreferenceValue(LoadingContextKey.self, alignment: .center) { context in
if case let .global(text) = context {
LoadingOverlayView(text)
}
}
}
}
// MARK: - LoadingOverlayView
private struct LoadingOverlayView: View {
private let text: String?
public init(_ text: String?) {
self.text = text
}
public var body: some View {
ZStack {
VStack(spacing: .medium2) {
LoadingView().frame(width: 100, height: 100)
if let text {
Text(text)
.lineLimit(nil)
.textStyle(.body1Regular)
.foregroundColor(.app.white)
.multilineTextAlignment(.center)
}
}
.padding(.medium2)
}
.frame(minWidth: 180)
.background(Color.app.gray2.cornerRadius(.small1))
.frame(maxWidth: 240)
}
}
#if DEBUG
// MARK: - ConnectUsingPassword_Preview
struct LoadingOverlayView_Preview: PreviewProvider {
static var previews: some View {
VStack {
LoadingOverlayView("Loading...")
LoadingOverlayView("Preparing transaction...")
LoadingOverlayView("Doing something very long to describe...")
}
}
}
#endif