From 211e44fff51b022ea0da10a41e8bc614c43da537 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Wed, 6 May 2020 17:35:38 -0500 Subject: [PATCH] Remove flash when changing out the web view upon returning to the foreground --- iOS/Article/WebViewController.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/iOS/Article/WebViewController.swift b/iOS/Article/WebViewController.swift index a0757fcdf..3483c2079 100644 --- a/iOS/Article/WebViewController.swift +++ b/iOS/Article/WebViewController.swift @@ -148,8 +148,7 @@ class WebViewController: UIViewController { } func fullReload() { - view.subviews.first?.removeFromSuperview() - loadWebView() + loadWebView(replaceExistingWebView: true) } func showBars() { @@ -290,6 +289,12 @@ extension WebViewController: UIContextMenuInteractionDelegate { extension WebViewController: WKNavigationDelegate { + func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { + if view.subviews.count > 1 { + view.subviews.last?.removeFromSuperview() + } + } + func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { if navigationAction.navigationType == .linkActivated { @@ -403,10 +408,10 @@ private struct ImageClickMessage: Codable { private extension WebViewController { - func loadWebView() { + func loadWebView(replaceExistingWebView: Bool = false) { guard isViewLoaded else { return } - if let webView = webView { + if !replaceExistingWebView, let webView = webView { self.renderPage(webView) return }