From da4715c6d199cdb7fac13a6a7a3711c9459d5ced Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Fri, 27 Sep 2019 17:23:38 -0500 Subject: [PATCH] Fix disappearing reader view button --- iOS/Article/ArticleViewController.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/iOS/Article/ArticleViewController.swift b/iOS/Article/ArticleViewController.swift index da7632ed5..2a2119d71 100644 --- a/iOS/Article/ArticleViewController.swift +++ b/iOS/Article/ArticleViewController.swift @@ -88,6 +88,7 @@ class ArticleViewController: UIViewController { NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(progressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange(_:)), name: UIContentSizeCategory.didChangeNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(willEnterForeground(_:)), name: UIApplication.willEnterForegroundNotification, object: nil) articleExtractorButton.addTarget(self, action: #selector(toggleArticleExtractor(_:)), for: .touchUpInside) navigationItem.titleView = articleExtractorButton @@ -197,6 +198,20 @@ class ArticleViewController: UIViewController { reloadHTML() } + // Don't delete this even though it looks like it isn't doing anything. This is to work + // around a bug (don't know if it is an Apple one or ours) that happens when the root + // split view controller is not collapsed. When the app goes to the background and then + // comes back to the foreground the article extractor button will disappear. The + // navigationItem will still have a reference to the articleExtractorButton, but if you + // check in the view debugger, the button isn't in the view hierarchy anymore. + // Setting the titleView to nil and then back to the articleExtractorButton hides that + // this happened. If we move the articleExtractorButton to someplace other than the + // titleView, then this code can be safely deleted. + @objc func willEnterForeground(_ note: Notification) { + navigationItem.titleView = nil + navigationItem.titleView = articleExtractorButton + } + // MARK: Actions @IBAction func toggleArticleExtractor(_ sender: Any) {