-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathErrorView.swift
More file actions
98 lines (91 loc) · 2.63 KB
/
ErrorView.swift
File metadata and controls
98 lines (91 loc) · 2.63 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// ErrorView.swift
// LiveViewNativeGo
//
// Created by Carson Katri on 8/8/24.
//
import SwiftUI
import LiveViewNative
import LiveViewNativeCore
struct ErrorView: View {
let error: Error
@Environment(\.reconnectLiveView) private var reconnectLiveView
var body: some View {
LiveErrorView(error: error) {
if #available(iOS 17, macOS 14, tvOS 17, watchOS 10, *) {
ContentUnavailableView {
Label("Connection Failed", systemImage: "network.slash")
} description: {
description
} actions: {
actions
}
} else {
VStack {
Label("Connection Failed", systemImage: "network.slash")
.font(.headline)
description
.foregroundStyle(.secondary)
actions
}
}
}
}
@ViewBuilder
var description: some View {
#if DEBUG
ScrollView {
Text(error.localizedDescription)
.font(.caption.monospaced())
.multilineTextAlignment(.leading)
}
#else
Text("The app will reconnect when network connection is regained.")
#endif
}
@ViewBuilder
var actions: some View {
Button {
#if os(iOS)
UIPasteboard.general.string = error.localizedDescription
#elseif os(macOS)
NSPasteboard.general.setString(error.localizedDescription, forType: .string)
#endif
} label: {
Label("Copy Error", systemImage: "doc.on.doc")
}
#if os(watchOS)
SwiftUI.Button {
Task {
await reconnectLiveView(.restart)
}
} label: {
SwiftUI.Label("Restart", systemImage: "arrow.circlepath")
}
.padding()
#else
Menu {
Button {
Task {
await reconnectLiveView(.automatic)
}
} label: {
Label("Reconnect this page", systemImage: "arrow.2.circlepath")
}
Button {
Task {
await reconnectLiveView(.restart)
}
} label: {
Label("Restart from root", systemImage: "arrow.circlepath")
}
} label: {
Label("Reconnect", systemImage: "arrow.2.circlepath")
}
.padding()
#endif
}
}
#Preview {
ErrorView(error: LiveSocketError.NoDocumentInJoinPayload)
}