Remove flash when changing out the web view upon returning to the foreground

This commit is contained in:
Maurice Parker 2020-05-06 17:35:38 -05:00
parent 8fc915f5dc
commit 211e44fff5
1 changed files with 9 additions and 4 deletions

View File

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