From a5b2c759ecb1552d526c89c50f39a18059a7c992 Mon Sep 17 00:00:00 2001 From: Jim Correia Date: Sat, 31 Aug 2019 12:30:01 -0700 Subject: [PATCH] Create the WKWebView instance at runtime. Specify a container view in the storyboard and create+install the web view at viewDidLoad time. This lets us experiment with solutions for providing a web view that avoids the flash-to-white problem. --- iOS/Base.lproj/Main.storyboard | 23 ++++++------------ iOS/Detail/DetailViewController.swift | 34 +++++++++++++++++++-------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/iOS/Base.lproj/Main.storyboard b/iOS/Base.lproj/Main.storyboard index 4c40e5500..63ea87669 100644 --- a/iOS/Base.lproj/Main.storyboard +++ b/iOS/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -15,22 +15,13 @@ - + - - - - - - + + + - - - - - - @@ -112,7 +103,7 @@ - + diff --git a/iOS/Detail/DetailViewController.swift b/iOS/Detail/DetailViewController.swift index 8755137d2..632a5134f 100644 --- a/iOS/Detail/DetailViewController.swift +++ b/iOS/Detail/DetailViewController.swift @@ -14,22 +14,36 @@ import SafariServices class DetailViewController: UIViewController { - @IBOutlet weak var nextUnreadBarButtonItem: UIBarButtonItem! - @IBOutlet weak var prevArticleBarButtonItem: UIBarButtonItem! - @IBOutlet weak var nextArticleBarButtonItem: UIBarButtonItem! - @IBOutlet weak var readBarButtonItem: UIBarButtonItem! - @IBOutlet weak var starBarButtonItem: UIBarButtonItem! - @IBOutlet weak var actionBarButtonItem: UIBarButtonItem! - @IBOutlet weak var browserBarButtonItem: UIBarButtonItem! - @IBOutlet weak var webView: WKWebView! - + @IBOutlet private weak var nextUnreadBarButtonItem: UIBarButtonItem! + @IBOutlet private weak var prevArticleBarButtonItem: UIBarButtonItem! + @IBOutlet private weak var nextArticleBarButtonItem: UIBarButtonItem! + @IBOutlet private weak var readBarButtonItem: UIBarButtonItem! + @IBOutlet private weak var starBarButtonItem: UIBarButtonItem! + @IBOutlet private weak var actionBarButtonItem: UIBarButtonItem! + @IBOutlet private weak var browserBarButtonItem: UIBarButtonItem! + @IBOutlet private weak var webViewContainer: UIView! + private var webView: WKWebView! + weak var coordinator: AppCoordinator! override func viewDidLoad() { - super.viewDidLoad() + + webView = WKWebView(frame: webViewContainer.bounds) + webView.translatesAutoresizingMaskIntoConstraints = false webView.navigationDelegate = self + webViewContainer.addSubview(webView) + + let constraints: [NSLayoutConstraint] = [ + webView.leadingAnchor.constraint(equalTo: webViewContainer.safeAreaLayoutGuide.leadingAnchor), + webView.trailingAnchor.constraint(equalTo: webViewContainer.safeAreaLayoutGuide.trailingAnchor), + webView.topAnchor.constraint(equalTo: webViewContainer.safeAreaLayoutGuide.topAnchor), + webView.bottomAnchor.constraint(equalTo: webViewContainer.safeAreaLayoutGuide.bottomAnchor), + ] + + NSLayoutConstraint.activate(constraints) + markAsRead() updateUI() reloadHTML()