-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathOSIABErrorView.swift
More file actions
57 lines (52 loc) · 1.86 KB
/
OSIABErrorView.swift
File metadata and controls
57 lines (52 loc) · 1.86 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
import SwiftUI
/// View to use in case there was an error loading a URL on `OSIABWebView`.
/// It allows a reload operation to be performed.
struct OSIABErrorView: View {
/// The error thrown.
private let error: Error
/// The reload operation to perform.
private let reload: () -> Void
/// Indicates if the how the reload view should be displayed in terms of layout.
private let reloadViewLayoutDirection: OSIABLayoutDirectionEnum
/// Constructor method.
/// - Parameters:
/// - error: The error thrown.
/// - reload: The reload operation to perform.
/// - reloadViewLayoutDirection: Indicates if the how the reload view should be displayed in terms of layout.
init(
_ error: Error,
reload: @escaping () -> Void,
reloadViewLayoutDirection: OSIABLayoutDirectionEnum
) {
self.error = error
self.reload = reload
self.reloadViewLayoutDirection = reloadViewLayoutDirection
}
var body: some View {
VStack(spacing: 16) {
Text("Couldn't load the page content.")
.foregroundColor(.gray)
HStack {
Button(action: reload, label: {
HStack {
Image(systemName: "arrow.clockwise")
Text("Reload page").fontWeight(.semibold)
}
.layoutDirection(reloadViewLayoutDirection)
})
.buttonStyle(.plain)
}
Spacer()
}
.padding(.top, 120)
}
}
struct OSIABErrorView_Previews: PreviewProvider {
static var previews: some View {
OSIABErrorView(
NSError(domain: "Preview", code: NSURLErrorBadURL),
reload: { print("Clicked reload") },
reloadViewLayoutDirection: .fixed(value: .leftToRight)
)
}
}