From 84389e2cf4e37b69bb89b8ccf72b8c547fb80a3f Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Thu, 16 Jul 2020 13:56:07 -0500 Subject: [PATCH] Move from using views for the queue to using an array and remove unneeded flush of queue --- iOS/Article/ArticleViewController.swift | 11 +----- iOS/Article/WebViewProvider.swift | 47 ++++++------------------- iOS/SceneCoordinator.swift | 2 +- 3 files changed, 12 insertions(+), 48 deletions(-) diff --git a/iOS/Article/ArticleViewController.swift b/iOS/Article/ArticleViewController.swift index 21aab45d8..0a254c401 100644 --- a/iOS/Article/ArticleViewController.swift +++ b/iOS/Article/ArticleViewController.swift @@ -225,7 +225,7 @@ class ArticleViewController: UIViewController { } @objc func contentSizeCategoryDidChange(_ note: Notification) { - resetWebViewController() + currentWebViewController?.fullReload() } @objc func willEnterForeground(_ note: Notification) { @@ -470,13 +470,4 @@ private extension ArticleViewController { return controller } - func resetWebViewController() { - coordinator.webViewProvider.flushQueue() - coordinator.webViewProvider.replenishQueueIfNeeded() - if let controller = currentWebViewController { - controller.fullReload() - self.pageViewController.setViewControllers([controller], direction: .forward, animated: false, completion: nil) - } - } - } diff --git a/iOS/Article/WebViewProvider.swift b/iOS/Article/WebViewProvider.swift index 2d820c181..4ea1474ee 100644 --- a/iOS/Article/WebViewProvider.swift +++ b/iOS/Article/WebViewProvider.swift @@ -16,18 +16,13 @@ class WebViewProvider: NSObject { private let articleIconSchemeHandler: ArticleIconSchemeHandler private let operationQueue = MainThreadOperationQueue() - private var queue = UIView() + private var queue = NSMutableArray() - init(coordinator: SceneCoordinator, viewController: UIViewController) { + init(coordinator: SceneCoordinator) { articleIconSchemeHandler = ArticleIconSchemeHandler(coordinator: coordinator) super.init() - viewController.view.insertSubview(queue, at: 0) replenishQueueIfNeeded() } - - func flushQueue() { - operationQueue.add(WebViewProviderFlushQueueOperation(queue: queue)) - } func replenishQueueIfNeeded() { operationQueue.add(WebViewProviderReplenishQueueOperation(queue: queue, articleIconSchemeHandler: articleIconSchemeHandler)) @@ -40,28 +35,6 @@ class WebViewProvider: NSObject { } -class WebViewProviderFlushQueueOperation: MainThreadOperation { - - // MainThreadOperation - public var isCanceled = false - public var id: Int? - public weak var operationDelegate: MainThreadOperationDelegate? - public var name: String? = "WebViewProviderFlushQueueOperation" - public var completionBlock: MainThreadOperation.MainThreadOperationCompletionBlock? - - private var queue: UIView - - init(queue: UIView) { - self.queue = queue - } - - func run() { - queue.subviews.forEach { $0.removeFromSuperview() } - self.operationDelegate?.operationDidComplete(self) - } - -} - class WebViewProviderReplenishQueueOperation: MainThreadOperation { // MainThreadOperation @@ -73,18 +46,18 @@ class WebViewProviderReplenishQueueOperation: MainThreadOperation { private let minimumQueueDepth = 3 - private var queue: UIView + private var queue: NSMutableArray private var articleIconSchemeHandler: ArticleIconSchemeHandler - init(queue: UIView, articleIconSchemeHandler: ArticleIconSchemeHandler) { + init(queue: NSMutableArray, articleIconSchemeHandler: ArticleIconSchemeHandler) { self.queue = queue self.articleIconSchemeHandler = articleIconSchemeHandler } func run() { - while queue.subviews.count < minimumQueueDepth { + while queue.count < minimumQueueDepth { let webView = PreloadedWebView(articleIconSchemeHandler: articleIconSchemeHandler) - queue.insertSubview(webView, at: 0) + queue.insert(webView, at: 0) webView.preload() } self.operationDelegate?.operationDidComplete(self) @@ -101,21 +74,21 @@ class WebViewProviderDequeueOperation: MainThreadOperation { public var name: String? = "WebViewProviderFlushQueueOperation" public var completionBlock: MainThreadOperation.MainThreadOperationCompletionBlock? - private var queue: UIView + private var queue: NSMutableArray private var articleIconSchemeHandler: ArticleIconSchemeHandler private var completion: (PreloadedWebView) -> () - init(queue: UIView, articleIconSchemeHandler: ArticleIconSchemeHandler, completion: @escaping (PreloadedWebView) -> ()) { + init(queue: NSMutableArray, articleIconSchemeHandler: ArticleIconSchemeHandler, completion: @escaping (PreloadedWebView) -> ()) { self.queue = queue self.articleIconSchemeHandler = articleIconSchemeHandler self.completion = completion } func run() { - if let webView = queue.subviews.last as? PreloadedWebView { + if let webView = queue.lastObject as? PreloadedWebView { webView.ready { preloadedWebView in - preloadedWebView.removeFromSuperview() self.completion(preloadedWebView) + self.queue.remove(webView) } self.operationDelegate?.operationDidComplete(self) return diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 0f6ddbb69..2183cb4f5 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -37,7 +37,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { return rootSplitViewController.undoManager } - lazy var webViewProvider = WebViewProvider(coordinator: self, viewController: rootSplitViewController) + lazy var webViewProvider = WebViewProvider(coordinator: self) private var panelMode: PanelMode = .unset