diff --git a/Shared/Article Rendering/ArticleRenderer.swift b/Shared/Article Rendering/ArticleRenderer.swift index 327bbec76..be8f5daef 100644 --- a/Shared/Article Rendering/ArticleRenderer.swift +++ b/Shared/Article Rendering/ArticleRenderer.swift @@ -14,15 +14,14 @@ import Account struct ArticleRenderer { typealias Rendering = (style: String, html: String) - typealias Page = (html: String, baseURL: URL) + typealias Page = (url: URL, baseURL: URL) static var imageIconScheme = "nnwImageIcon" static var page: Page = { - let pageURL = Bundle.main.url(forResource: "page", withExtension: "html")! - let html = try! String(contentsOf: pageURL) - let baseURL = pageURL.deletingLastPathComponent() - return Page(html: html, baseURL: baseURL) + let url = Bundle.main.url(forResource: "page", withExtension: "html")! + let baseURL = url.deletingLastPathComponent() + return Page(url: url, baseURL: baseURL) }() private let article: Article? diff --git a/iOS/Article/WebViewController.swift b/iOS/Article/WebViewController.swift index 208d75f66..40038d000 100644 --- a/iOS/Article/WebViewController.swift +++ b/iOS/Article/WebViewController.swift @@ -30,7 +30,6 @@ class WebViewController: UIViewController { private var topShowBarsViewConstraint: NSLayoutConstraint! private var bottomShowBarsViewConstraint: NSLayoutConstraint! - private var renderingTracker = 0 private var webView: WKWebView! private lazy var contextMenuInteraction = UIContextMenuInteraction(delegate: self) private var isFullScreenAvailable: Bool { @@ -44,7 +43,7 @@ class WebViewController: UIViewController { private var isShowingExtractedArticle = false { didSet { if isShowingExtractedArticle != oldValue { - renderPage() + reloadHTML() } } } @@ -66,7 +65,7 @@ class WebViewController: UIViewController { } if article != oldValue { restoreWindowScrollY = 0 - renderPage() + reloadHTML() } } } @@ -267,7 +266,7 @@ extension WebViewController: ArticleExtractorDelegate { func articleExtractionDidFail(with: Error) { stopArticleExtractor() articleExtractorButtonState = .error - renderPage() + reloadHTML() } func articleExtractionDidComplete(extractedArticle: ExtractedArticle) { @@ -351,7 +350,7 @@ extension WebViewController: WKNavigationDelegate { } func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { - self.renderPage() + renderPage() } } @@ -451,24 +450,12 @@ private struct ImageClickMessage: Codable { private extension WebViewController { func reloadHTML() { - let url = Bundle.main.url(forResource: "page", withExtension: "html")! - webView.loadFileURL(url, allowingReadAccessTo: url.deletingLastPathComponent()) - renderingTracker = 0 + webView?.loadFileURL(ArticleRenderer.page.url, allowingReadAccessTo: ArticleRenderer.page.baseURL) } func renderPage() { guard let webView = webView else { return } - // It looks like we need to clean up the webview every once in a while by reloading it from scratch - // Otherwise it will stop responding or cause rendering artifacts. This typically only comes into - // play on the iPad where we aren't constantly pushing and popping this controller. - if (renderingTracker > 10) { - reloadHTML() - return - } - - renderingTracker += 1 - let style = ArticleStylesManager.shared.currentStyle let rendering: ArticleRenderer.Rendering diff --git a/iOS/Article/WebViewProvider.swift b/iOS/Article/WebViewProvider.swift index 2c90e4505..49068b5e3 100644 --- a/iOS/Article/WebViewProvider.swift +++ b/iOS/Article/WebViewProvider.swift @@ -40,7 +40,7 @@ class WebViewProvider: NSObject, WKNavigationDelegate { webView.navigationDelegate = self queue.insert(webView, at: 0) - webView.loadHTMLString(ArticleRenderer.page.html, baseURL: ArticleRenderer.page.baseURL) + webView.loadFileURL(ArticleRenderer.page.url, allowingReadAccessTo: ArticleRenderer.page.baseURL) }