diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index a9519699302d..e782766f07c4 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -3,6 +3,7 @@ * [*] Blogging Reminders: Disabled prompt for self-hosted sites not connected to Jetpack. [#20970] * [**] [internal] Do not save synced blogs if the app has signed out. [#20959] * [**] [internal] Make sure synced posts are saved before calling completion block. [#20960] +* [**] [internal] Fix observing Quick Start notifications. [#20997] * [**] [internal] Fixed an issue that was causing a memory leak in the domain selection flow. [#20813] diff --git a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/BlogDashboardViewController.swift b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/BlogDashboardViewController.swift index 464d5abb8f2f..e6b2a62a5aea 100644 --- a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/BlogDashboardViewController.swift +++ b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/BlogDashboardViewController.swift @@ -159,30 +159,27 @@ final class BlogDashboardViewController: UIViewController { } private func addQuickStartObserver() { - NotificationCenter.default.addObserver(forName: .QuickStartTourElementChangedNotification, object: nil, queue: nil) { [weak self] notification in - - guard let self = self else { - return - } - - if let info = notification.userInfo, - let element = info[QuickStartTourGuide.notificationElementKey] as? QuickStartTourElement { - - switch element { - case .setupQuickStart: - self.loadCardsFromCache() - self.displayQuickStart() - case .updateQuickStart: - self.loadCardsFromCache() - case .stats, .mediaScreen: - if self.embeddedInScrollView { - self.mySiteScrollView?.scrollToTop(animated: true) - } else { - self.collectionView.scrollToTop(animated: true) - } - default: - break + NotificationCenter.default.addObserver(self, selector: #selector(handleQuickStartTourElementChangedNotification(_:)), name: .QuickStartTourElementChangedNotification, object: nil) + } + + @objc private func handleQuickStartTourElementChangedNotification(_ notification: Foundation.Notification) { + if let info = notification.userInfo, + let element = info[QuickStartTourGuide.notificationElementKey] as? QuickStartTourElement { + + switch element { + case .setupQuickStart: + self.loadCardsFromCache() + self.displayQuickStart() + case .updateQuickStart: + self.loadCardsFromCache() + case .stats, .mediaScreen: + if self.embeddedInScrollView { + self.mySiteScrollView?.scrollToTop(animated: true) + } else { + self.collectionView.scrollToTop(animated: true) } + default: + break } } } diff --git a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Quick Actions/DashboardQuickActionsCardCell.swift b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Quick Actions/DashboardQuickActionsCardCell.swift index 1657074621ec..6fef2411bba3 100644 --- a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Quick Actions/DashboardQuickActionsCardCell.swift +++ b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Quick Actions/DashboardQuickActionsCardCell.swift @@ -57,10 +57,6 @@ final class DashboardQuickActionsCardCell: UICollectionViewCell, Reusable { required init?(coder: NSCoder) { fatalError("Not implemented") } - - deinit { - stopObservingQuickStart() - } } // MARK: - Button Actions @@ -142,35 +138,34 @@ extension DashboardQuickActionsCardCell { } private func startObservingQuickStart() { - NotificationCenter.default.addObserver(forName: .QuickStartTourElementChangedNotification, object: nil, queue: nil) { [weak self] notification in - - if let info = notification.userInfo, - let element = info[QuickStartTourGuide.notificationElementKey] as? QuickStartTourElement { - - switch element { - case .stats: - guard QuickStartTourGuide.shared.entryPointForCurrentTour == .blogDashboard else { - return - } - - self?.autoScrollToStatsButton() - case .mediaScreen: - guard QuickStartTourGuide.shared.entryPointForCurrentTour == .blogDashboard else { - return - } - - self?.autoScrollToMediaButton() - default: - break - } - self?.statsButton.shouldShowSpotlight = element == .stats - self?.mediaButton.shouldShowSpotlight = element == .mediaScreen - } - } + NotificationCenter.default.addObserver(self, selector: #selector(handleQuickStartTourElementChangedNotification(_:)), name: .QuickStartTourElementChangedNotification, object: nil) } - private func stopObservingQuickStart() { - NotificationCenter.default.removeObserver(self) + @objc private func handleQuickStartTourElementChangedNotification(_ notification: Foundation.Notification) { + guard let info = notification.userInfo, + let element = info[QuickStartTourGuide.notificationElementKey] as? QuickStartTourElement + else { + return + } + + switch element { + case .stats: + guard QuickStartTourGuide.shared.entryPointForCurrentTour == .blogDashboard else { + return + } + + autoScrollToStatsButton() + case .mediaScreen: + guard QuickStartTourGuide.shared.entryPointForCurrentTour == .blogDashboard else { + return + } + + autoScrollToMediaButton() + default: + break + } + statsButton.shouldShowSpotlight = element == .stats + mediaButton.shouldShowSpotlight = element == .mediaScreen } private func autoScrollToStatsButton() { diff --git a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Quick Start/NewQuickStartChecklistView.swift b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Quick Start/NewQuickStartChecklistView.swift index 0a340b22366b..d39586676348 100644 --- a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Quick Start/NewQuickStartChecklistView.swift +++ b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Quick Start/NewQuickStartChecklistView.swift @@ -112,10 +112,6 @@ final class NewQuickStartChecklistView: UIView, QuickStartChecklistConfigurable fatalError("Not implemented") } - deinit { - stopObservingQuickStart() - } - // MARK: - Trait Collection override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { @@ -197,20 +193,18 @@ extension NewQuickStartChecklistView { } private func startObservingQuickStart() { - NotificationCenter.default.addObserver(forName: .QuickStartTourElementChangedNotification, object: nil, queue: nil) { [weak self] notification in - - guard let userInfo = notification.userInfo, - let element = userInfo[QuickStartTourGuide.notificationElementKey] as? QuickStartTourElement, - element == .tourCompleted else { - return - } + NotificationCenter.default.addObserver(self, selector: #selector(handleQuickStartTourElementChangedNotification(_:)), name: .QuickStartTourElementChangedNotification, object: nil) + } - self?.updateViews() + @objc private func handleQuickStartTourElementChangedNotification(_ notification: Foundation.Notification) { + guard let userInfo = notification.userInfo, + let element = userInfo[QuickStartTourGuide.notificationElementKey] as? QuickStartTourElement, + element == .tourCompleted + else { + return } - } - private func stopObservingQuickStart() { - NotificationCenter.default.removeObserver(self) + updateViews() } @objc private func didTap() { diff --git a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Quick Start/QuickStartChecklistView.swift b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Quick Start/QuickStartChecklistView.swift index 300c7477e2ec..4f8002793e44 100644 --- a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Quick Start/QuickStartChecklistView.swift +++ b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Quick Start/QuickStartChecklistView.swift @@ -80,10 +80,6 @@ final class QuickStartChecklistView: UIView, QuickStartChecklistConfigurable { fatalError("Not implemented") } - deinit { - stopObservingQuickStart() - } - func configure(collection: QuickStartToursCollection, blog: Blog) { self.tours = collection.tours self.blog = blog @@ -134,20 +130,18 @@ extension QuickStartChecklistView { } private func startObservingQuickStart() { - NotificationCenter.default.addObserver(forName: .QuickStartTourElementChangedNotification, object: nil, queue: nil) { [weak self] notification in - - guard let userInfo = notification.userInfo, - let element = userInfo[QuickStartTourGuide.notificationElementKey] as? QuickStartTourElement, - element == .tourCompleted else { - return - } + NotificationCenter.default.addObserver(self, selector: #selector(handleQuickStartTourElementChangedNotification(_:)), name: .QuickStartTourElementChangedNotification, object: nil) + } - self?.updateViews() + @objc private func handleQuickStartTourElementChangedNotification(_ notification: Foundation.Notification) { + guard let userInfo = notification.userInfo, + let element = userInfo[QuickStartTourGuide.notificationElementKey] as? QuickStartTourElement, + element == .tourCompleted + else { + return } - } - private func stopObservingQuickStart() { - NotificationCenter.default.removeObserver(self) + updateViews() } @objc private func didTap() { diff --git a/WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController+QuickStart.swift b/WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController+QuickStart.swift index be911fbddf9c..d07ae63326a2 100644 --- a/WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController+QuickStart.swift +++ b/WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController+QuickStart.swift @@ -3,28 +3,31 @@ import UIKit extension MySiteViewController { func startObservingQuickStart() { - NotificationCenter.default.addObserver(forName: .QuickStartTourElementChangedNotification, object: nil, queue: nil) { [weak self] (notification) in + NotificationCenter.default.addObserver(self, selector: #selector(handleQuickStartTourElementChangedNotification(_:)), name: .QuickStartTourElementChangedNotification, object: nil) + } - if let info = notification.userInfo, - let element = info[QuickStartTourGuide.notificationElementKey] as? QuickStartTourElement { + @objc private func handleQuickStartTourElementChangedNotification(_ notification: Foundation.Notification) { + guard let info = notification.userInfo, + let element = info[QuickStartTourGuide.notificationElementKey] as? QuickStartTourElement + else { + return + } - self?.siteMenuSpotlightIsShown = element == .siteMenu + siteMenuSpotlightIsShown = element == .siteMenu - switch element { - case .noSuchElement, .newpost: - self?.additionalSafeAreaInsets = .zero + switch element { + case .noSuchElement, .newpost: + additionalSafeAreaInsets = .zero - case .siteIcon, .siteTitle, .viewSite: - self?.scrollView.scrollToTop(animated: true) - fallthrough + case .siteIcon, .siteTitle, .viewSite: + scrollView.scrollToTop(animated: true) + fallthrough - case .siteMenu, .pages, .sharing, .stats, .readerTab, .notifications, .mediaScreen: - self?.additionalSafeAreaInsets = Constants.quickStartNoticeInsets + case .siteMenu, .pages, .sharing, .stats, .readerTab, .notifications, .mediaScreen: + additionalSafeAreaInsets = Constants.quickStartNoticeInsets - default: - break - } - } + default: + break } } diff --git a/WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController+QuickStart.swift b/WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController+QuickStart.swift index 528b4d52a487..b828d41e7085 100644 --- a/WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController+QuickStart.swift +++ b/WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController+QuickStart.swift @@ -10,19 +10,17 @@ extension SitePickerViewController { } func startObservingQuickStart() { - NotificationCenter.default.addObserver(forName: .QuickStartTourElementChangedNotification, object: nil, queue: nil) { [weak self] (notification) in - guard self?.blog.managedObjectContext != nil else { - return - } - - self?.blogDetailHeaderView.toggleSpotlightOnSiteTitle() - self?.blogDetailHeaderView.toggleSpotlightOnSiteUrl() - self?.blogDetailHeaderView.refreshIconImage() - } + NotificationCenter.default.addObserver(self, selector: #selector(handleQuickStartTourElementChangedNotification(_:)), name: .QuickStartTourElementChangedNotification, object: nil) } - func stopObservingQuickStart() { - NotificationCenter.default.removeObserver(self) + @objc private func handleQuickStartTourElementChangedNotification(_ notification: Foundation.Notification) { + guard blog.managedObjectContext != nil else { + return + } + + blogDetailHeaderView.toggleSpotlightOnSiteTitle() + blogDetailHeaderView.toggleSpotlightOnSiteUrl() + blogDetailHeaderView.refreshIconImage() } func startAlertTimer() { diff --git a/WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController.swift b/WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController.swift index bc41dc10ac05..381d5cbc695c 100644 --- a/WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController.swift +++ b/WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController.swift @@ -49,10 +49,6 @@ final class SitePickerViewController: UIViewController { startObservingTitleChanges() } - deinit { - stopObservingQuickStart() - } - private func setupHeaderView() { blogDetailHeaderView.blog = blog blogDetailHeaderView.delegate = self diff --git a/WordPress/Classes/ViewRelated/Reader/Tab Navigation/ReaderTabViewController.swift b/WordPress/Classes/ViewRelated/Reader/Tab Navigation/ReaderTabViewController.swift index 5a2ef070bc2c..92b63fbc272b 100644 --- a/WordPress/Classes/ViewRelated/Reader/Tab Navigation/ReaderTabViewController.swift +++ b/WordPress/Classes/ViewRelated/Reader/Tab Navigation/ReaderTabViewController.swift @@ -140,11 +140,13 @@ extension ReaderTabViewController { // MARK: Observing Quick Start extension ReaderTabViewController { private func startObservingQuickStart() { - NotificationCenter.default.addObserver(forName: .QuickStartTourElementChangedNotification, object: nil, queue: nil) { [weak self] notification in - if let info = notification.userInfo, - let element = info[QuickStartTourGuide.notificationElementKey] as? QuickStartTourElement { - self?.settingsButton.shouldShowSpotlight = element == .readerDiscoverSettings - } + NotificationCenter.default.addObserver(self, selector: #selector(handleQuickStartTourElementChangedNotification(_:)), name: .QuickStartTourElementChangedNotification, object: nil) + } + + @objc private func handleQuickStartTourElementChangedNotification(_ notification: Foundation.Notification) { + if let info = notification.userInfo, + let element = info[QuickStartTourGuide.notificationElementKey] as? QuickStartTourElement { + settingsButton.shouldShowSpotlight = element == .readerDiscoverSettings } } }