Skip to content

Commit e306d65

Browse files
committed
Safe check for index to insert the empty view
1 parent 214cff4 commit e306d65

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,9 @@ private extension StoreStatsV4PeriodViewController {
309309
timeRangeBarView.backgroundColor = .systemColor(.secondarySystemGroupedBackground)
310310
visitorsStackView.backgroundColor = .systemColor(.secondarySystemGroupedBackground)
311311

312-
// Visitor empty view
313-
visitorsStackView.insertArrangedSubview(visitorsEmptyView, at: 2)
312+
// Visitor empty view - insert it at the second-to-last index
313+
let emptyViewIndex = max(0, visitorsStackView.arrangedSubviews.count - 2)
314+
visitorsStackView.insertArrangedSubview(visitorsEmptyView, at: emptyViewIndex)
314315
visitorsEmptyView.isHidden = true
315316

316317
// Time range bar bottom border view
@@ -449,10 +450,10 @@ extension StoreStatsV4PeriodViewController {
449450
func updateSiteVisitStats(mode: SiteVisitStatsMode) {
450451
// Hides site visit stats for "today"
451452
guard timeRange != .today else {
452-
visitorsStackView?.isHidden = true
453+
visitorsStackView.isHidden = true
453454
return
454455
}
455-
visitorsStackView?.isHidden = (mode == .hidden)
456+
visitorsStackView.isHidden = (mode == .hidden)
456457
}
457458
}
458459

0 commit comments

Comments
 (0)