diff --git a/WooCommerce/Classes/ViewRelated/Dashboard/DashboardViewController.swift b/WooCommerce/Classes/ViewRelated/Dashboard/DashboardViewController.swift index df85fe82959..a3cfd4e4c4d 100644 --- a/WooCommerce/Classes/ViewRelated/Dashboard/DashboardViewController.swift +++ b/WooCommerce/Classes/ViewRelated/Dashboard/DashboardViewController.swift @@ -42,8 +42,8 @@ class DashboardViewController: UIViewController { configureView() } - override func viewDidAppear(_ animated: Bool) { - super.viewDidAppear(animated) + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) reloadData() } diff --git a/WooCommerce/Classes/ViewRelated/Dashboard/MyStore/PeriodDataViewController.swift b/WooCommerce/Classes/ViewRelated/Dashboard/MyStore/PeriodDataViewController.swift index a4fb3895a12..f03c9762336 100644 --- a/WooCommerce/Classes/ViewRelated/Dashboard/MyStore/PeriodDataViewController.swift +++ b/WooCommerce/Classes/ViewRelated/Dashboard/MyStore/PeriodDataViewController.swift @@ -145,6 +145,12 @@ extension PeriodDataViewController { extension PeriodDataViewController { + /// Indicates if the receiver has Remote Stats, or not. + /// + var shouldDisplayGhostContent: Bool { + return orderStats == nil + } + /// Displays the Placeholder Period Graph + Starts the Animation. /// Why is this public? Because the actual Sync OP is handled by StoreStatsViewController. We coordinate multiple /// placeholder animations from that spot! diff --git a/WooCommerce/Classes/ViewRelated/Dashboard/MyStore/StoreStatsViewController.swift b/WooCommerce/Classes/ViewRelated/Dashboard/MyStore/StoreStatsViewController.swift index 828fd5de7c7..930eb4edda8 100644 --- a/WooCommerce/Classes/ViewRelated/Dashboard/MyStore/StoreStatsViewController.swift +++ b/WooCommerce/Classes/ViewRelated/Dashboard/MyStore/StoreStatsViewController.swift @@ -69,7 +69,7 @@ extension StoreStatsViewController { func syncAllStats(onCompletion: (() -> Void)? = nil) { let group = DispatchGroup() - displayGhostContent() + ensureGhostContentIsDisplayed() periodVCs.forEach { (vc) in group.enter() @@ -97,6 +97,16 @@ extension StoreStatsViewController { // private extension StoreStatsViewController { + /// Displays the Ghost Placeholder whenever there is no visible data. + /// + func ensureGhostContentIsDisplayed() { + guard visibleChildViewController.shouldDisplayGhostContent else { + return + } + + displayGhostContent() + } + /// Locks UI Interaction and displays Ghost Placeholder animations. /// func displayGhostContent() { diff --git a/WooCommerce/Classes/ViewRelated/Dashboard/MyStore/TopPerformerDataViewController.swift b/WooCommerce/Classes/ViewRelated/Dashboard/MyStore/TopPerformerDataViewController.swift index 3a5e20152a6..4eac7ced636 100644 --- a/WooCommerce/Classes/ViewRelated/Dashboard/MyStore/TopPerformerDataViewController.swift +++ b/WooCommerce/Classes/ViewRelated/Dashboard/MyStore/TopPerformerDataViewController.swift @@ -10,7 +10,11 @@ class TopPerformerDataViewController: UIViewController, IndicatorInfoProvider { // MARK: - Properties - public let granularity: StatGranularity + let granularity: StatGranularity + + var hasTopEarnerStatsItems: Bool { + return (topEarnerStats?.items?.count ?? 0) > 0 + } @IBOutlet private weak var tableView: IntrinsicTableView! @@ -33,10 +37,6 @@ class TopPerformerDataViewController: UIViewController, IndicatorInfoProvider { return resultsController.fetchedObjects.first } - private var hasTopEarnerStatsItems: Bool { - return (topEarnerStats?.items?.count ?? 0) > 0 - } - private var tabDescription: String { switch granularity { case .day: diff --git a/WooCommerce/Classes/ViewRelated/Dashboard/MyStore/TopPerformersViewController.swift b/WooCommerce/Classes/ViewRelated/Dashboard/MyStore/TopPerformersViewController.swift index 96b7201cd8e..5441113d266 100644 --- a/WooCommerce/Classes/ViewRelated/Dashboard/MyStore/TopPerformersViewController.swift +++ b/WooCommerce/Classes/ViewRelated/Dashboard/MyStore/TopPerformersViewController.swift @@ -62,7 +62,7 @@ extension TopPerformersViewController { func syncTopPerformers(onCompletion: (() -> Void)? = nil) { let group = DispatchGroup() - displayGhostContent() + ensureGhostContentIsDisplayed() dataVCs.forEach { vc in group.enter() @@ -83,6 +83,16 @@ extension TopPerformersViewController { // private extension TopPerformersViewController { + /// Displays the Ghost Placeholder whenever there is no visible data. + /// + func ensureGhostContentIsDisplayed() { + guard visibleChildViewController.hasTopEarnerStatsItems == false else { + return + } + + displayGhostContent() + } + /// Locks UI Interaction and displays Ghost Placeholder animations. /// func displayGhostContent() {