-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathHotwireWebViewController.swift
More file actions
70 lines (55 loc) · 2.1 KB
/
Copy pathHotwireWebViewController.swift
File metadata and controls
70 lines (55 loc) · 2.1 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
import UIKit
import WebKit
/// A base controller to use or subclass that handles bridge lifecycle callbacks.
/// Use `Hotwire.registerBridgeComponents(_:)` to register bridge components.
open class HotwireWebViewController: VisitableViewController, BridgeDestination {
public lazy var bridgeDelegate = BridgeDelegate(
location: initialVisitableURL.absoluteString,
destination: self,
componentTypes: Hotwire.bridgeComponentTypes
)
// MARK: View lifecycle
override open func viewDidLoad() {
super.viewDidLoad()
navigationItem.backButtonDisplayMode = Hotwire.config.backButtonDisplayMode
view.backgroundColor = .systemBackground
if Hotwire.config.showDoneButtonOnModals {
addDoneButtonToModals()
}
bridgeDelegate.onViewDidLoad()
}
override open func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
bridgeDelegate.onViewWillAppear()
}
override open func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
bridgeDelegate.onViewDidAppear()
}
override open func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
bridgeDelegate.onViewWillDisappear()
}
override open func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
bridgeDelegate.onViewDidDisappear()
}
// MARK: Visitable
override open func visitableDidActivateWebView(_ webView: WKWebView) {
super.visitableDidActivateWebView(webView)
bridgeDelegate.webViewDidBecomeActive(webView)
}
override open func visitableDidDeactivateWebView() {
super.visitableDidDeactivateWebView()
bridgeDelegate.webViewDidBecomeDeactivated()
}
// MARK: Private
private func addDoneButtonToModals() {
if presentingViewController != nil {
let action = UIAction { [unowned self] _ in
dismiss(animated: true)
}
navigationItem.rightBarButtonItem = UIBarButtonItem(systemItem: .done, primaryAction: action)
}
}
}