@@ -15,7 +15,7 @@ final class DashboardViewController: UIViewController {
1515 private let siteID : Int64
1616
1717 private let dashboardUIFactory : DashboardUIFactory
18- private var dashboardUI : DashboardUI ?
18+ @ Published private var dashboardUI : DashboardUI ?
1919
2020 // Used to enable subtitle with store name
2121 private var shouldShowStoreNameAsSubtitle : Bool = false
@@ -110,6 +110,7 @@ final class DashboardViewController: UIViewController {
110110 configureDashboardUIContainer ( )
111111 configureBottomJetpackBenefitsBanner ( )
112112 observeSiteForUIUpdates ( )
113+ observeBottomJetpackBenefitsBannerVisibilityUpdates ( )
113114 }
114115
115116 override func viewWillAppear( _ animated: Bool ) {
@@ -323,25 +324,25 @@ private extension DashboardViewController {
323324 remove ( previousDashboardUI)
324325 }
325326
326- dashboardUI = updatedDashboardUI
327-
328327 let contentView = updatedDashboardUI. view!
329328 addChild ( updatedDashboardUI)
330329 containerView. addSubview ( contentView)
331330 updatedDashboardUI. didMove ( toParent: self )
332331 addViewBelowHeaderStackView ( contentView: contentView)
333332
333+ // Sets `dashboardUI` after its view is added to the view hierarchy so that observers can update UI based on its view.
334+ dashboardUI = updatedDashboardUI
335+
334336 updatedDashboardUI. onPullToRefresh = { [ weak self] in
335337 self ? . pullToRefresh ( )
336338 }
337339 updatedDashboardUI. displaySyncingError = { [ weak self] in
338340 self ? . showTopBannerView ( )
339341 }
342+ }
340343
341- // Bottom banner
342- // TODO: 5362 & 5368 - Display banner for JCP sites and if the banner has not been dismissed before.
343- let shouldShowJetpackBenefitsBanner = ServiceLocator . featureFlagService. isFeatureFlagEnabled ( . jetpackConnectionPackageSupport)
344- if shouldShowJetpackBenefitsBanner {
344+ func updateJetpackBenefitsBannerVisibility( isBannerVisible: Bool , contentView: UIView ) {
345+ if isBannerVisible {
345346 showJetpackBenefitsBanner ( contentView: contentView)
346347 } else {
347348 hideJetpackBenefitsBanner ( )
@@ -426,6 +427,23 @@ private extension DashboardViewController {
426427 self . reloadData ( forced: true )
427428 } . store ( in: & cancellables)
428429 }
430+
431+ func observeBottomJetpackBenefitsBannerVisibilityUpdates( ) {
432+ Publishers . CombineLatest ( ServiceLocator . stores. site, $dashboardUI. eraseToAnyPublisher ( ) )
433+ . sink { [ weak self] site, dashboardUI in
434+ guard let self = self else { return }
435+
436+ guard let contentView = dashboardUI? . view else {
437+ return
438+ }
439+
440+ // TODO: 5362 - Display banner for JCP sites only if the banner has not been dismissed before.
441+ let shouldShowJetpackBenefitsBanner = ServiceLocator . featureFlagService. isFeatureFlagEnabled ( . jetpackConnectionPackageSupport)
442+ && site? . isJetpackCPConnected == true
443+
444+ self . updateJetpackBenefitsBannerVisibility ( isBannerVisible: shouldShowJetpackBenefitsBanner, contentView: contentView)
445+ } . store ( in: & cancellables)
446+ }
429447}
430448
431449// MARK: Constants
0 commit comments