From 254f61a543c7b614e0556b23b1f18393399d67a6 Mon Sep 17 00:00:00 2001 From: Tony Li Date: Fri, 30 Jun 2023 19:40:20 +1200 Subject: [PATCH 1/8] Fix discarded quick start notification observers --- .../BlogDashboardViewController.swift | 43 +++++++++---------- .../DashboardQuickActionsCardCell.swift | 9 +++- .../NewQuickStartChecklistView.swift | 9 +++- .../Quick Start/QuickStartChecklistView.swift | 9 +++- .../MySiteViewController+QuickStart.swift | 4 +- .../Blog/My Site/MySiteViewController.swift | 2 + .../SitePickerViewController+QuickStart.swift | 7 ++- .../SitePickerViewController.swift | 2 + .../ReaderTabViewController.swift | 12 +++--- 9 files changed, 60 insertions(+), 37 deletions(-) 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..c1e439313e05 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 @@ -48,6 +48,8 @@ final class DashboardQuickActionsCardCell: UICollectionViewCell, Reusable { return button }() + fileprivate var quickStartObserver: NSObjectProtocol? + override init(frame: CGRect) { super.init(frame: frame) setup() @@ -142,7 +144,7 @@ extension DashboardQuickActionsCardCell { } private func startObservingQuickStart() { - NotificationCenter.default.addObserver(forName: .QuickStartTourElementChangedNotification, object: nil, queue: nil) { [weak self] notification in + quickStartObserver = 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 { @@ -170,7 +172,10 @@ extension DashboardQuickActionsCardCell { } private func stopObservingQuickStart() { - NotificationCenter.default.removeObserver(self) + if let quickStartObserver { + NotificationCenter.default.removeObserver(quickStartObserver) + } + quickStartObserver = nil } 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..62aa1624feb8 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 @@ -99,6 +99,8 @@ final class NewQuickStartChecklistView: UIView, QuickStartChecklistConfigurable return imageView }() + fileprivate var quickStartObserver: NSObjectProtocol? + // MARK: - Init override init(frame: CGRect) { @@ -197,7 +199,7 @@ extension NewQuickStartChecklistView { } private func startObservingQuickStart() { - NotificationCenter.default.addObserver(forName: .QuickStartTourElementChangedNotification, object: nil, queue: nil) { [weak self] notification in + quickStartObserver = 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, @@ -210,7 +212,10 @@ extension NewQuickStartChecklistView { } private func stopObservingQuickStart() { - NotificationCenter.default.removeObserver(self) + if let quickStartObserver { + NotificationCenter.default.removeObserver(quickStartObserver) + } + quickStartObserver = nil } @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..70771abc0f5d 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 @@ -70,6 +70,8 @@ final class QuickStartChecklistView: UIView, QuickStartChecklistConfigurable { return view }() + fileprivate var quickStartObserver: NSObjectProtocol? + override init(frame: CGRect) { super.init(frame: frame) setupViews() @@ -134,7 +136,7 @@ extension QuickStartChecklistView { } private func startObservingQuickStart() { - NotificationCenter.default.addObserver(forName: .QuickStartTourElementChangedNotification, object: nil, queue: nil) { [weak self] notification in + quickStartObserver = 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, @@ -147,7 +149,10 @@ extension QuickStartChecklistView { } private func stopObservingQuickStart() { - NotificationCenter.default.removeObserver(self) + if let quickStartObserver { + NotificationCenter.default.removeObserver(quickStartObserver) + } + quickStartObserver = nil } @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..d29401d72d6e 100644 --- a/WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController+QuickStart.swift +++ b/WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController+QuickStart.swift @@ -1,9 +1,11 @@ import UIKit +private var observerKey = 0 + extension MySiteViewController { func startObservingQuickStart() { - NotificationCenter.default.addObserver(forName: .QuickStartTourElementChangedNotification, object: nil, queue: nil) { [weak self] (notification) in + quickStartObserver = 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 { diff --git a/WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController.swift b/WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController.swift index 4812d2cf0152..87ee52d57e8d 100644 --- a/WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController.swift +++ b/WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController.swift @@ -27,6 +27,8 @@ class MySiteViewController: UIViewController, NoResultsViewHost { } } + var quickStartObserver: NSObjectProtocol? + private var isShowingDashboard: Bool { return segmentedControl.selectedSegmentIndex == Section.dashboard.rawValue } diff --git a/WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController+QuickStart.swift b/WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController+QuickStart.swift index 528b4d52a487..35c75486e827 100644 --- a/WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController+QuickStart.swift +++ b/WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController+QuickStart.swift @@ -10,7 +10,7 @@ extension SitePickerViewController { } func startObservingQuickStart() { - NotificationCenter.default.addObserver(forName: .QuickStartTourElementChangedNotification, object: nil, queue: nil) { [weak self] (notification) in + quickStartObserver = NotificationCenter.default.addObserver(forName: .QuickStartTourElementChangedNotification, object: nil, queue: nil) { [weak self] (notification) in guard self?.blog.managedObjectContext != nil else { return } @@ -22,7 +22,10 @@ extension SitePickerViewController { } func stopObservingQuickStart() { - NotificationCenter.default.removeObserver(self) + if let quickStartObserver { + NotificationCenter.default.removeObserver(quickStartObserver) + } + quickStartObserver = nil } func startAlertTimer() { diff --git a/WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController.swift b/WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController.swift index bc41dc10ac05..a6a101a69829 100644 --- a/WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController.swift +++ b/WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController.swift @@ -21,6 +21,8 @@ final class SitePickerViewController: UIViewController { let blogService: BlogService let mediaService: MediaService + var quickStartObserver: NSObjectProtocol? + private(set) lazy var blogDetailHeaderView: BlogDetailHeaderView = { let headerView = BlogDetailHeaderView(items: []) headerView.translatesAutoresizingMaskIntoConstraints = false 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 } } } From 97bbe96fe115ec2ff91988470aed952c190b1b13 Mon Sep 17 00:00:00 2001 From: Tony Li Date: Tue, 4 Jul 2023 11:10:43 +1200 Subject: [PATCH 2/8] Add a release note --- RELEASE-NOTES.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 55182b92a312..7546c0d03e57 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] Probably register and unregister some Quick start notification observers. [#20997] 22.7 From 2ea3f3562523a59cd166715088cbeaa5e92c076c Mon Sep 17 00:00:00 2001 From: Tony Li Date: Wed, 5 Jul 2023 12:58:12 +1200 Subject: [PATCH 3/8] Change DashboardQuickActionsCardCell to use self as the quick start observer --- .../DashboardQuickActionsCardCell.swift | 60 ++++++++----------- 1 file changed, 25 insertions(+), 35 deletions(-) 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 c1e439313e05..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 @@ -48,8 +48,6 @@ final class DashboardQuickActionsCardCell: UICollectionViewCell, Reusable { return button }() - fileprivate var quickStartObserver: NSObjectProtocol? - override init(frame: CGRect) { super.init(frame: frame) setup() @@ -59,10 +57,6 @@ final class DashboardQuickActionsCardCell: UICollectionViewCell, Reusable { required init?(coder: NSCoder) { fatalError("Not implemented") } - - deinit { - stopObservingQuickStart() - } } // MARK: - Button Actions @@ -144,38 +138,34 @@ extension DashboardQuickActionsCardCell { } private func startObservingQuickStart() { - quickStartObserver = 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() { - if let quickStartObserver { - NotificationCenter.default.removeObserver(quickStartObserver) + @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 } - quickStartObserver = nil + statsButton.shouldShowSpotlight = element == .stats + mediaButton.shouldShowSpotlight = element == .mediaScreen } private func autoScrollToStatsButton() { From 61724d8dc3da53a796e0d3ac9763e74c2806a36e Mon Sep 17 00:00:00 2001 From: Tony Li Date: Wed, 5 Jul 2023 13:00:51 +1200 Subject: [PATCH 4/8] Change NewQuickStartChecklistView to use self as the quick start observer --- .../NewQuickStartChecklistView.swift | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) 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 62aa1624feb8..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 @@ -99,8 +99,6 @@ final class NewQuickStartChecklistView: UIView, QuickStartChecklistConfigurable return imageView }() - fileprivate var quickStartObserver: NSObjectProtocol? - // MARK: - Init override init(frame: CGRect) { @@ -114,10 +112,6 @@ final class NewQuickStartChecklistView: UIView, QuickStartChecklistConfigurable fatalError("Not implemented") } - deinit { - stopObservingQuickStart() - } - // MARK: - Trait Collection override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { @@ -199,23 +193,18 @@ extension NewQuickStartChecklistView { } private func startObservingQuickStart() { - quickStartObserver = 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 - } - - self?.updateViews() - } + NotificationCenter.default.addObserver(self, selector: #selector(handleQuickStartTourElementChangedNotification(_:)), name: .QuickStartTourElementChangedNotification, object: nil) } - private func stopObservingQuickStart() { - if let quickStartObserver { - NotificationCenter.default.removeObserver(quickStartObserver) + @objc private func handleQuickStartTourElementChangedNotification(_ notification: Foundation.Notification) { + guard let userInfo = notification.userInfo, + let element = userInfo[QuickStartTourGuide.notificationElementKey] as? QuickStartTourElement, + element == .tourCompleted + else { + return } - quickStartObserver = nil + + updateViews() } @objc private func didTap() { From 52fdf44e5a3fa8882547e1b7c56e73845fc088b0 Mon Sep 17 00:00:00 2001 From: Tony Li Date: Wed, 5 Jul 2023 13:04:47 +1200 Subject: [PATCH 5/8] Change QuickStartChecklistView to use self as the quick start observer --- .../Quick Start/QuickStartChecklistView.swift | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) 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 70771abc0f5d..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 @@ -70,8 +70,6 @@ final class QuickStartChecklistView: UIView, QuickStartChecklistConfigurable { return view }() - fileprivate var quickStartObserver: NSObjectProtocol? - override init(frame: CGRect) { super.init(frame: frame) setupViews() @@ -82,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 @@ -136,23 +130,18 @@ extension QuickStartChecklistView { } private func startObservingQuickStart() { - quickStartObserver = 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 - } - - self?.updateViews() - } + NotificationCenter.default.addObserver(self, selector: #selector(handleQuickStartTourElementChangedNotification(_:)), name: .QuickStartTourElementChangedNotification, object: nil) } - private func stopObservingQuickStart() { - if let quickStartObserver { - NotificationCenter.default.removeObserver(quickStartObserver) + @objc private func handleQuickStartTourElementChangedNotification(_ notification: Foundation.Notification) { + guard let userInfo = notification.userInfo, + let element = userInfo[QuickStartTourGuide.notificationElementKey] as? QuickStartTourElement, + element == .tourCompleted + else { + return } - quickStartObserver = nil + + updateViews() } @objc private func didTap() { From 4d92db82ab203770fbfd4c8af9fa0f2e3c1c1f32 Mon Sep 17 00:00:00 2001 From: Tony Li Date: Wed, 5 Jul 2023 13:08:30 +1200 Subject: [PATCH 6/8] Change MySiteViewController to use self as the quick start observer --- .../MySiteViewController+QuickStart.swift | 37 ++++++++++--------- .../Blog/My Site/MySiteViewController.swift | 2 - 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController+QuickStart.swift b/WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController+QuickStart.swift index d29401d72d6e..d07ae63326a2 100644 --- a/WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController+QuickStart.swift +++ b/WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController+QuickStart.swift @@ -1,32 +1,33 @@ import UIKit -private var observerKey = 0 - extension MySiteViewController { func startObservingQuickStart() { - quickStartObserver = 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/My Site/MySiteViewController.swift b/WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController.swift index 87ee52d57e8d..4812d2cf0152 100644 --- a/WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController.swift +++ b/WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController.swift @@ -27,8 +27,6 @@ class MySiteViewController: UIViewController, NoResultsViewHost { } } - var quickStartObserver: NSObjectProtocol? - private var isShowingDashboard: Bool { return segmentedControl.selectedSegmentIndex == Section.dashboard.rawValue } From 8fd6993060181d8e0ada1187a76b607b67005004 Mon Sep 17 00:00:00 2001 From: Tony Li Date: Wed, 5 Jul 2023 13:10:46 +1200 Subject: [PATCH 7/8] Change SitePickerViewController to use self as the quick start observer --- .../SitePickerViewController+QuickStart.swift | 21 +++++++------------ .../SitePickerViewController.swift | 6 ------ 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController+QuickStart.swift b/WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController+QuickStart.swift index 35c75486e827..b828d41e7085 100644 --- a/WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController+QuickStart.swift +++ b/WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController+QuickStart.swift @@ -10,22 +10,17 @@ extension SitePickerViewController { } func startObservingQuickStart() { - quickStartObserver = 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() { - if let quickStartObserver { - NotificationCenter.default.removeObserver(quickStartObserver) + @objc private func handleQuickStartTourElementChangedNotification(_ notification: Foundation.Notification) { + guard blog.managedObjectContext != nil else { + return } - quickStartObserver = nil + + 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 a6a101a69829..381d5cbc695c 100644 --- a/WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController.swift +++ b/WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController.swift @@ -21,8 +21,6 @@ final class SitePickerViewController: UIViewController { let blogService: BlogService let mediaService: MediaService - var quickStartObserver: NSObjectProtocol? - private(set) lazy var blogDetailHeaderView: BlogDetailHeaderView = { let headerView = BlogDetailHeaderView(items: []) headerView.translatesAutoresizingMaskIntoConstraints = false @@ -51,10 +49,6 @@ final class SitePickerViewController: UIViewController { startObservingTitleChanges() } - deinit { - stopObservingQuickStart() - } - private func setupHeaderView() { blogDetailHeaderView.blog = blog blogDetailHeaderView.delegate = self From 3ee06ad0b4b12b96150c885fa7eb0844e6e1428a Mon Sep 17 00:00:00 2001 From: Tony Li Date: Wed, 5 Jul 2023 13:14:48 +1200 Subject: [PATCH 8/8] Update release note --- RELEASE-NOTES.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 7546c0d03e57..773e1af0c4c1 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -3,7 +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] Probably register and unregister some Quick start notification observers. [#20997] +* [**] [internal] Fix observing Quick Start notifications. [#20997] 22.7