Change to always reload the page when rendering an article. Issue #1713

This commit is contained in:
Maurice Parker 2020-01-26 20:29:58 -07:00
parent 4a63b28c73
commit 97d6c69431
3 changed files with 10 additions and 24 deletions

View File

@ -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?

View File

@ -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

View File

@ -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)
}