-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathOSIABWebView13WrapperView.swift
More file actions
104 lines (89 loc) · 3.61 KB
/
OSIABWebView13WrapperView.swift
File metadata and controls
104 lines (89 loc) · 3.61 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
99
100
101
102
103
104
import SwiftUI
import UIKit
/// View that manages which view to present, depending if the page load was successful or not or is being loaded.
@available(iOS, deprecated: 14.0, message: "Use OSIABWebViewWrapperView for iOS 14.0+")
struct OSIABWebView13WrapperView: View {
/// View Model containing all the customisable elements.
@ObservedObject private var model: OSIABWebViewModel
/// Constructor method.
/// - Parameter model: View Model containing all the customisable elements.
init(_ model: OSIABWebViewModel) {
self._model = ObservedObject(wrappedValue: model)
}
var body: some View {
ZStack {
OSIABWebView(model)
.edgesIgnoringSafeArea(model.toolbarPosition == .bottom ? [] : .bottom)
if model.isLoading {
OSIABActivityIndicator(isAnimating: .constant(true), style: .large)
}
}
}
}
private struct OSIABActivityIndicator: UIViewRepresentable {
@Binding private var isAnimating: Bool
private let style: UIActivityIndicatorView.Style
init(isAnimating: Binding<Bool>, style: UIActivityIndicatorView.Style) {
self._isAnimating = isAnimating
self.style = style
}
func makeUIView(context: UIViewRepresentableContext<OSIABActivityIndicator>) -> UIActivityIndicatorView {
return UIActivityIndicatorView(style: style)
}
func updateUIView(_ uiView: UIActivityIndicatorView, context: UIViewRepresentableContext<OSIABActivityIndicator>) {
if self.isAnimating {
uiView.startAnimating()
} else {
uiView.stopAnimating()
}
}
}
// 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 }
)
)
}
}
struct OSIABWebView13WrapperView_Previews: PreviewProvider {
static var previews: some View {
// Default - Light Mode
OSIABWebView13WrapperView(.init())
// Default - Dark Mode
OSIABWebView13WrapperView(.init())
.preferredColorScheme(.dark)
// Bottom Toolbar Defined
OSIABWebView13WrapperView(.init(toolbarPosition: .bottom))
// Error View - Light mode
OSIABWebView13WrapperView(.init(url: "https://outsystems/"))
// Error View - Dark mode
OSIABWebView13WrapperView(.init(url: "https://outsystems/"))
.preferredColorScheme(.dark)
}
}