Skip to content

Commit 878b4e4

Browse files
authored
Merge pull request #5823 from woocommerce/feat/5742-update-placeholder-separately
Remove placeholder content for store stats / top performers sections for each time range tab ASAP
2 parents 2013271 + bf3cc3b commit 878b4e4

File tree

3 files changed

+42
-24
lines changed

3 files changed

+42
-24
lines changed

WooCommerce/Classes/ViewRelated/Dashboard/Stats v4/StoreStatsAndTopPerformersPeriodViewController.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,15 @@ extension StoreStatsAndTopPerformersPeriodViewController {
189189
topPerformersPeriodViewController.displayGhostContent()
190190
}
191191

192-
/// Unlocks the and removes the Placeholder Content
192+
/// Removes the placeholder content for store stats.
193193
///
194-
func removeGhostContent() {
194+
func removeStoreStatsGhostContent() {
195195
storeStatsPeriodViewController.removeGhostContent()
196+
}
197+
198+
/// Removes the placeholder content for top performers.
199+
///
200+
func removeTopPerformersGhostContent() {
196201
topPerformersPeriodViewController.removeGhostContent()
197202
}
198203

WooCommerce/Classes/ViewRelated/Dashboard/Stats v4/StoreStatsAndTopPerformersViewController.swift

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ private extension StoreStatsAndTopPerformersViewController {
110110
defer {
111111
group.notify(queue: .main) { [weak self] in
112112
self?.isSyncing = false
113-
self?.removeGhostContent()
114113
self?.showSpinner(shouldShowSpinner: false)
115114
if let error = syncError {
116115
DDLogError("⛔️ Error loading dashboard: \(error)")
@@ -151,8 +150,12 @@ private extension StoreStatsAndTopPerformersViewController {
151150
// For tasks dispatched for each time period.
152151
let periodGroup = DispatchGroup()
153152

153+
// For tasks dispatched for store stats (order and visitor stats) for each time period.
154+
let periodStoreStatsGroup = DispatchGroup()
155+
154156
group.enter()
155157
periodGroup.enter()
158+
periodStoreStatsGroup.enter()
156159
self.syncStats(for: siteID,
157160
siteTimezone: timezoneForSync,
158161
timeRange: vc.timeRange,
@@ -166,10 +169,12 @@ private extension StoreStatsAndTopPerformersViewController {
166169
}
167170
group.leave()
168171
periodGroup.leave()
172+
periodStoreStatsGroup.leave()
169173
}
170174

171175
group.enter()
172176
periodGroup.enter()
177+
periodStoreStatsGroup.enter()
173178
self.syncSiteVisitStats(for: siteID,
174179
siteTimezone: timezoneForSync,
175180
timeRange: vc.timeRange,
@@ -180,6 +185,7 @@ private extension StoreStatsAndTopPerformersViewController {
180185
}
181186
group.leave()
182187
periodGroup.leave()
188+
periodStoreStatsGroup.leave()
183189
}
184190

185191
group.enter()
@@ -194,6 +200,8 @@ private extension StoreStatsAndTopPerformersViewController {
194200
}
195201
group.leave()
196202
periodGroup.leave()
203+
204+
vc.removeTopPerformersGhostContent()
197205
}
198206

199207
periodGroup.notify(queue: .main) {
@@ -204,6 +212,10 @@ private extension StoreStatsAndTopPerformersViewController {
204212
syncError = periodSyncError
205213
}
206214
}
215+
216+
periodStoreStatsGroup.notify(queue: .main) {
217+
vc.removeStoreStatsGhostContent()
218+
}
207219
}
208220
}
209221

@@ -225,27 +237,12 @@ private extension StoreStatsAndTopPerformersViewController {
225237
/// Displays the Ghost Placeholder whenever there is no visible data.
226238
///
227239
func ensureGhostContentIsDisplayed() {
228-
guard visibleChildViewController.shouldDisplayStoreStatsGhostContent else {
229-
return
240+
periodVCs.forEach { periodVC in
241+
guard periodVC.shouldDisplayStoreStatsGhostContent else {
242+
return
243+
}
244+
periodVC.displayGhostContent()
230245
}
231-
232-
displayGhostContent()
233-
}
234-
235-
/// Locks UI Interaction and displays Ghost Placeholder animations.
236-
///
237-
func displayGhostContent() {
238-
view.isUserInteractionEnabled = false
239-
buttonBarView.startGhostAnimation(style: .wooDefaultGhostStyle)
240-
visibleChildViewController.displayGhostContent()
241-
}
242-
243-
/// Unlocks the and removes the Placeholder Content
244-
///
245-
func removeGhostContent() {
246-
view.isUserInteractionEnabled = true
247-
buttonBarView.stopGhostAnimation()
248-
visibleChildViewController.removeGhostContent()
249246
}
250247

251248
/// If the Ghost Content was previously onscreen, this method will restart the animations.

WooCommerce/Classes/ViewRelated/Dashboard/Stats v4/StoreStatsV4PeriodViewController.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Charts
22
import Combine
33
import UIKit
4+
import struct WordPressUI.GhostStyle
45
import Yosemite
56

67
/// Different display modes of site visit stats
@@ -160,6 +161,13 @@ final class StoreStatsV4PeriodViewController: UIViewController {
160161
observeReloadChartAnimated()
161162
}
162163

164+
override func viewWillAppear(_ animated: Bool) {
165+
super.viewWillAppear(animated)
166+
167+
// After returning to the My Store tab, `restartGhostAnimation` is required to resume ghost animation.
168+
restartGhostAnimationIfNeeded()
169+
}
170+
163171
override func viewDidAppear(_ animated: Bool) {
164172
super.viewDidAppear(animated)
165173
reloadAllFields()
@@ -243,7 +251,7 @@ extension StoreStatsV4PeriodViewController {
243251
///
244252
func displayGhostContent() {
245253
ensurePlaceholderIsVisible()
246-
placeholderChartsView.startGhostAnimation(style: .wooDefaultGhostStyle)
254+
placeholderChartsView.startGhostAnimation(style: Constants.ghostStyle)
247255
}
248256

249257
/// Removes the Placeholder Content.
@@ -267,6 +275,12 @@ extension StoreStatsV4PeriodViewController {
267275
view.pinSubviewToAllEdges(placeholderChartsView)
268276
}
269277

278+
private func restartGhostAnimationIfNeeded() {
279+
guard placeholderChartsView.superview != nil else {
280+
return
281+
}
282+
placeholderChartsView.restartGhostAnimation(style: Constants.ghostStyle)
283+
}
270284
}
271285

272286
// MARK: - Configuration
@@ -748,5 +762,7 @@ private extension StoreStatsV4PeriodViewController {
748762

749763
static let containerBackgroundColor: UIColor = .systemBackground
750764
static let headerComponentBackgroundColor: UIColor = .clear
765+
766+
static let ghostStyle: GhostStyle = .wooDefaultGhostStyle
751767
}
752768
}

0 commit comments

Comments
 (0)