-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathOSIABWebViewWrapperView.swift
More file actions
81 lines (71 loc) · 2.7 KB
/
OSIABWebViewWrapperView.swift
File metadata and controls
81 lines (71 loc) · 2.7 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
import SwiftUI
/// View that manages which view to present, depending if the page load was successful or not or is being loaded.
@available(iOS 14.0, *)
struct OSIABWebViewWrapperView: View {
/// View Model containing all the customisable elements.
@StateObject private var model: OSIABWebViewModel
/// Constructor method.
/// - Parameter model: View Model containing all the customisable elements.
init(_ model: OSIABWebViewModel) {
self._model = StateObject(wrappedValue: model)
}
var body: some View {
ZStack {
OSIABWebView(model)
.ignoresSafeArea(edges: model.toolbarPosition == .bottom ? [] : .bottom)
if model.isLoading {
ProgressView()
}
}
}
}
// MARK: - OSIABViewModel's constructor accelerator.
private extension OSIABWebViewModel {
convenience init(toolbarPosition: OSIABToolbarPosition = .defaultValue) {
let configurationModel = OSIABWebViewConfigurationModel()
self.init(
url: .init(string: "https://outsystems.com")!,
webViewConfiguration: configurationModel.toWebViewConfiguration(),
uiModel: .init(toolbarPosition: toolbarPosition),
callbackHandler: .init(
onDelegateURL: { _ in },
onDelegateAlertController: { _ in },
onBrowserPageLoad: {},
onBrowserClosed: { _ in },
onBrowserPageNavigationCompleted: { _ in }
)
)
}
convenience init(url: String) {
let configurationModel = OSIABWebViewConfigurationModel()
self.init(
url: .init(string: url)!,
webViewConfiguration: configurationModel.toWebViewConfiguration(),
uiModel: .init(),
callbackHandler: .init(
onDelegateURL: { _ in },
onDelegateAlertController: { _ in },
onBrowserPageLoad: {},
onBrowserClosed: { _ in },
onBrowserPageNavigationCompleted: { _ in }
)
)
}
}
@available(iOS 14.0, *)
struct OSIABWebViewWrapperView_Previews: PreviewProvider {
static var previews: some View {
// Default - Light Mode
OSIABWebViewWrapperView(.init())
// Default - Dark Mode
OSIABWebViewWrapperView(.init())
.preferredColorScheme(.dark)
// Bottom Toolbar Defined
OSIABWebViewWrapperView(.init(toolbarPosition: .bottom))
// Error View - Light mode
OSIABWebViewWrapperView(.init(url: "https://outsystems/"))
// Error View - Dark mode
OSIABWebViewWrapperView(.init(url: "https://outsystems/"))
.preferredColorScheme(.dark)
}
}