|
@@ -1,45 +1,16 @@
|
|
|
import UIKit
|
|
|
import WebKit
|
|
|
|
|
|
-class HelpViewController: UIViewController, WKNavigationDelegate {
|
|
|
+class HelpViewController: WebViewViewController {
|
|
|
|
|
|
- private lazy var webView: WKWebView = {
|
|
|
- let view = WKWebView()
|
|
|
- view.navigationDelegate = self
|
|
|
- return view
|
|
|
- }()
|
|
|
-
|
|
|
- init() {
|
|
|
- super.init(nibName: nil, bundle: nil)
|
|
|
- hidesBottomBarWhenPushed = true
|
|
|
- }
|
|
|
-
|
|
|
- required init?(coder: NSCoder) {
|
|
|
- fatalError("init(coder:) has not been implemented")
|
|
|
- }
|
|
|
-
|
|
|
- func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
|
|
|
- if navigationAction.navigationType == .linkActivated {
|
|
|
- if let url = navigationAction.request.url,
|
|
|
- url.host != nil,
|
|
|
- UIApplication.shared.canOpenURL(url) {
|
|
|
- UIApplication.shared.open(url)
|
|
|
- decisionHandler(.cancel)
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
- decisionHandler(.allow)
|
|
|
- }
|
|
|
-
|
|
|
- // MARK: - lifecycle
|
|
|
override func viewDidLoad() {
|
|
|
super.viewDidLoad()
|
|
|
- view.backgroundColor = .white //DcColors.defaultBackgroundColor
|
|
|
+ view.backgroundColor = .white
|
|
|
self.title = String.localized("menu_help")
|
|
|
- setupSubviews()
|
|
|
}
|
|
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
|
+ super.viewWillAppear(animated)
|
|
|
loadHtmlContent { [weak self] url in
|
|
|
// return to main thread
|
|
|
DispatchQueue.main.async {
|
|
@@ -48,27 +19,6 @@ class HelpViewController: UIViewController, WKNavigationDelegate {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // MARK: - setup + configuration
|
|
|
- private func setupSubviews() {
|
|
|
- view.addSubview(webView)
|
|
|
- webView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
- webView.topAnchor.constraint(equalTo: view.topAnchor, constant: 0).isActive = true
|
|
|
-
|
|
|
- if #available(iOS 11, *) {
|
|
|
- webView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 0).isActive = true
|
|
|
- webView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: 0).isActive = true
|
|
|
-
|
|
|
- //webView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 0).isActive = true
|
|
|
- } else {
|
|
|
- webView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 0).isActive = true
|
|
|
- webView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0).isActive = true
|
|
|
-
|
|
|
- // webView.topAnchor.constraint(equalTo: view.topAnchor, constant: 0).isActive = true
|
|
|
- }
|
|
|
- webView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0).isActive = true
|
|
|
- webView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0).isActive = true
|
|
|
- }
|
|
|
-
|
|
|
private func loadHtmlContent(completionHandler: ((URL) -> Void)?) {
|
|
|
// execute in background thread because file loading would blockui for a few milliseconds
|
|
|
DispatchQueue.global(qos: .background).async {
|