Do a full reload of the article when rearranging the UI to accommodate for split screen color changes.
This commit is contained in:
parent
7c947b935d
commit
56d43f8f2d
|
@ -221,7 +221,7 @@ private extension DetailWebViewController {
|
|||
var render = "error();"
|
||||
if let data = try? encoder.encode(templateData) {
|
||||
let json = String(data: data, encoding: .utf8)!
|
||||
render = "render(\(json));"
|
||||
render = "render(\(json), 0);"
|
||||
}
|
||||
|
||||
webView.evaluateJavaScript(render)
|
||||
|
|
|
@ -30,11 +30,11 @@ function error() {
|
|||
document.body.innerHTML = "error";
|
||||
}
|
||||
|
||||
function render(data) {
|
||||
function render(data, scrollY) {
|
||||
document.getElementsByTagName("style")[0].innerHTML = data.style;
|
||||
document.body.innerHTML = data.body;
|
||||
|
||||
window.scrollTo(0, 0);
|
||||
window.scrollTo(0, scrollY);
|
||||
|
||||
wrapFrames()
|
||||
stripStyles()
|
||||
|
|
|
@ -59,6 +59,8 @@ class ArticleViewController: UIViewController {
|
|||
}
|
||||
}
|
||||
|
||||
var restoreOffset = 0
|
||||
|
||||
var currentArticle: Article? {
|
||||
switch state {
|
||||
case .article(let article):
|
||||
|
@ -190,9 +192,11 @@ class ArticleViewController: UIViewController {
|
|||
var render = "error();"
|
||||
if let data = try? encoder.encode(templateData) {
|
||||
let json = String(data: data, encoding: .utf8)!
|
||||
render = "render(\(json));"
|
||||
render = "render(\(json), \(restoreOffset));"
|
||||
}
|
||||
|
||||
restoreOffset = 0
|
||||
|
||||
ArticleViewControllerWebViewProvider.shared.articleIconSchemeHandler.currentArticle = currentArticle
|
||||
webView?.scrollView.setZoomScale(1.0, animated: false)
|
||||
webView?.evaluateJavaScript(render)
|
||||
|
@ -319,6 +323,13 @@ class ArticleViewController: UIViewController {
|
|||
webView?.evaluateJavaScript("showClickedImage();")
|
||||
}
|
||||
|
||||
func fullReload() {
|
||||
if let offset = webView?.scrollView.contentOffset.y {
|
||||
restoreOffset = Int(offset)
|
||||
webView?.reload()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: WKNavigationDelegate
|
||||
|
|
|
@ -1572,6 +1572,10 @@ private extension SceneCoordinator {
|
|||
rootSplitViewController.showDetailViewController(controller, sender: self)
|
||||
}
|
||||
|
||||
// We have to do a full reload when installing an article controller. We may have changed color contexts
|
||||
// and need to update the article colors. An example is in dark mode. Split screen doesn't use true black
|
||||
// like darkmode usually does.
|
||||
articleController.fullReload()
|
||||
return articleController
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue