forked from turbolinks/turbolinks-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisitableViewController.swift
50 lines (38 loc) · 1.47 KB
/
VisitableViewController.swift
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
import UIKit
open class VisitableViewController: UIViewController, Visitable {
open weak var visitableDelegate: VisitableDelegate?
open var visitableURL: URL!
public convenience init(url: URL) {
self.init()
self.visitableURL = url
}
// MARK: Visitable View
open lazy var visitableView: VisitableView! = {
let view = VisitableView(frame: CGRect.zero)
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
fileprivate func installVisitableView() {
view.addSubview(visitableView)
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[view]|", options: [], metrics: nil, views: [ "view": visitableView ]))
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[view]|", options: [], metrics: nil, views: [ "view": visitableView ]))
}
// MARK: Visitable
open func visitableDidRender() {
self.title = visitableView.webView?.title
}
// MARK: View Lifecycle
open override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.white
installVisitableView()
}
open override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
visitableDelegate?.visitableViewWillAppear(self)
}
open override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
visitableDelegate?.visitableViewDidAppear(self)
}
}