Skip to content

Commit 28fdfd2

Browse files
committed
Insights Management: Better handling of dismiss gesture
1 parent fe65222 commit 28fdfd2

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

WordPress/Classes/ViewRelated/Stats/Insights/Insights Management/AddInsightTableViewController.swift

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class AddInsightTableViewController: UITableViewController {
2828
private var selectedStat: StatSection?
2929

3030
private lazy var saveButton = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(saveTapped))
31-
private var dismissedViaButton = false
3231

3332
private lazy var tableHandler: ImmuTableViewHandler = {
3433
return ImmuTableViewHandler(takeOver: self)
@@ -73,21 +72,11 @@ class AddInsightTableViewController: UITableViewController {
7372
navigationItem.leftBarButtonItem = UIBarButtonItem(image: .gridicon(.cross), style: .plain, target: self, action: #selector(doneTapped))
7473
}
7574

76-
override func viewWillDisappear(_ animated: Bool) {
77-
super.viewWillDisappear(animated)
78-
79-
// Catches user swiping down to dismiss
80-
if FeatureFlag.statsNewAppearance.enabled {
81-
if !dismissedViaButton {
82-
if hasChanges {
83-
promptToSave(from: presentingViewController)
84-
} else {
85-
WPAnalytics.trackEvent(.statsInsightsManagementDismissed)
86-
insightsDelegate?.addInsightDismissed?()
87-
}
88-
}
89-
} else if selectedStat == nil {
90-
insightsDelegate?.addInsightDismissed?()
75+
func handleDismissViaGesture(from presenter: UIViewController) {
76+
if FeatureFlag.statsNewAppearance.enabled && hasChanges {
77+
promptToSave(from: presenter)
78+
} else {
79+
trackDismiss()
9180
}
9281
}
9382

@@ -160,8 +149,6 @@ class AddInsightTableViewController: UITableViewController {
160149
}
161150

162151
@objc private func doneTapped() {
163-
dismissedViaButton = true
164-
165152
if FeatureFlag.statsNewAppearance.enabled && hasChanges {
166153
promptToSave(from: self)
167154
} else {
@@ -170,20 +157,22 @@ class AddInsightTableViewController: UITableViewController {
170157
}
171158

172159
@objc func saveTapped() {
173-
dismissedViaButton = true
174-
175160
saveChanges()
176161

177162
dismiss(animated: true, completion: nil)
178163
}
179164

180165
private func dismiss() {
181-
WPAnalytics.trackEvent(.statsInsightsManagementDismissed)
182-
insightsDelegate?.addInsightDismissed?()
166+
trackDismiss()
183167

184168
dismiss(animated: true, completion: nil)
185169
}
186170

171+
private func trackDismiss() {
172+
WPAnalytics.trackEvent(.statsInsightsManagementDismissed)
173+
insightsDelegate?.addInsightDismissed?()
174+
}
175+
187176
private func saveChanges() {
188177
insightsManagementDelegate?.userUpdatedActiveInsights(insightsShown)
189178

WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsInsightsTableViewController.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class SiteStatsInsightsTableViewController: UIViewController, StoryboardLoadable
106106
let controller = AddInsightTableViewController(insightsDelegate: self,
107107
insightsManagementDelegate: self, insightsShown: insightsToShow.compactMap { $0.statSection })
108108
let navigationController = UINavigationController(rootViewController: controller)
109+
navigationController.presentationController?.delegate = self
109110
present(navigationController, animated: true, completion: nil)
110111
}
111112

@@ -651,6 +652,19 @@ extension SiteStatsInsightsTableViewController: StatsInsightsManagementDelegate
651652
}
652653
}
653654

655+
// MARK: - Presentation delegate
656+
657+
extension SiteStatsInsightsTableViewController: UIAdaptivePresentationControllerDelegate {
658+
func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
659+
guard let navigationController = presentationController.presentedViewController as? UINavigationController,
660+
let controller = navigationController.topViewController as? AddInsightTableViewController else {
661+
return
662+
}
663+
664+
controller.handleDismissViaGesture(from: self)
665+
}
666+
}
667+
654668
// MARK: - SharingViewControllerDelegate
655669

656670
extension SiteStatsInsightsTableViewController: SharingViewControllerDelegate {

0 commit comments

Comments
 (0)