@@ -10,13 +10,19 @@ final class AnalyticsHubHostingViewController: UIHostingController<AnalyticsHubV
1010 ///
1111 private let systemNoticePresenter : NoticePresenter
1212
13+ /// Defines a notice that should be presented after `self` is dismissed.
14+ /// Defaults to `nil`.
15+ ///
16+ var notice : Notice ?
17+
1318 init ( siteID: Int64 , timeRange: StatsTimeRangeV4 , systemNoticePresenter: NoticePresenter = ServiceLocator . noticePresenter) {
1419 let viewModel = AnalyticsHubViewModel ( siteID: siteID, statsTimeRange: timeRange)
1520 self . systemNoticePresenter = systemNoticePresenter
1621 super. init ( rootView: AnalyticsHubView ( viewModel: viewModel) )
1722
1823 // Needed to pop the hosting controller from within the SwiftUI view
19- rootView. dismiss = { [ weak self] in
24+ rootView. dismissWithNotice = { [ weak self] notice in
25+ self ? . notice = notice
2026 self ? . navigationController? . popViewController ( animated: true )
2127 }
2228 }
@@ -29,8 +35,8 @@ final class AnalyticsHubHostingViewController: UIHostingController<AnalyticsHubV
2935 override func viewWillDisappear( _ animated: Bool ) {
3036 super. viewWillDisappear ( animated)
3137
32- // Show any notice that should have been presented before the underlying disappears.
33- enqueuePendingNotice ( rootView . viewModel . notice, using: systemNoticePresenter)
38+ // Show any notice that should be presented after the underlying disappears.
39+ enqueuePendingNotice ( notice, using: systemNoticePresenter)
3440 }
3541}
3642
@@ -41,9 +47,10 @@ struct AnalyticsHubView: View {
4147 /// Environment safe areas
4248 @Environment ( \. safeAreaInsets) var safeAreaInsets : EdgeInsets
4349
44- /// Set this closure with UIKit code to pop the view controller. Needed because we need access to the UIHostingController `popViewController` method.
50+ /// Set this closure with UIKit code to pop the view controller and display the provided notice.
51+ /// Needed because we need access to the UIHostingController `popViewController` method.
4552 ///
46- var dismiss : ( ( ) -> Void ) = { }
53+ var dismissWithNotice : ( ( Notice ) -> Void ) = { _ in }
4754
4855 @StateObject var viewModel : AnalyticsHubViewModel
4956
@@ -103,7 +110,7 @@ struct AnalyticsHubView: View {
103110 . task {
104111 await viewModel. updateData ( )
105112 if viewModel. errorSelectingTimeRange {
106- dismiss ( )
113+ dismissWithNotice ( notice )
107114 }
108115 }
109116 }
0 commit comments