[ABANDONED] Mastodon iOS client.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.8 KiB

//
// WebViewController.swift
// elpha-ios
//
// Created by Dwayne Harris on 9/17/18.
// Copyright © 2018 Elpha. All rights reserved.
//
import Foundation
import UIKit
import WebKit
class WebViewController: UIViewController, WKNavigationDelegate {
@IBOutlet var mainWebView: WKWebView!
@IBOutlet var mainProgressView: UIProgressView!
var url: URL? = nil
override func viewDidLoad() {
super.viewDidLoad()
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
mainWebView.navigationDelegate = self
mainWebView.addObserver(self, forKeyPath: #keyPath(WKWebView.title), options: .new, context: nil)
mainWebView.addObserver(self, forKeyPath: #keyPath(WKWebView.estimatedProgress), options: .new, context: nil)
if let url = url {
mainWebView.load(URLRequest(url: url))
}
}
@objc func done() {
dismiss(animated: true, completion: nil)
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == #keyPath(WKWebView.title) {
if let title = mainWebView.title {
navigationItem.title = title
}
}
if keyPath == #keyPath(WKWebView.estimatedProgress) {
mainProgressView.progress = Float(mainWebView.estimatedProgress)
}
}
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
mainProgressView.alpha = 1.0
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
mainProgressView.alpha = 0.0
}
}