Skip to content

Commit aad72a9

Browse files
committed
DI view model to HubMenu from HubMenuViewController so that we can show review details without calling the view.
1 parent fffffe3 commit aad72a9

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

WooCommerce/Classes/ViewRelated/Hub Menu/HubMenu.swift

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ struct HubMenu: View {
2121
///
2222
private let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
2323

24-
init(siteID: Int64, navigationController: UINavigationController? = nil) {
25-
viewModel = HubMenuViewModel(siteID: siteID, navigationController: navigationController)
24+
init(viewModel: HubMenuViewModel) {
25+
self.viewModel = viewModel
2626
}
2727

2828
var body: some View {
@@ -111,10 +111,6 @@ struct HubMenu: View {
111111
}
112112
}
113113

114-
func pushReviewDetailsView(using parcel: ProductReviewFromNoteParcel) {
115-
viewModel.showReviewDetails(using: parcel)
116-
}
117-
118114
/// Reset state to make the menu items tappable
119115
private func enableMenuItemTaps() {
120116
shouldDisableItemTaps = false
@@ -213,17 +209,17 @@ struct HubMenu: View {
213209

214210
struct HubMenu_Previews: PreviewProvider {
215211
static var previews: some View {
216-
HubMenu(siteID: 123)
212+
HubMenu(viewModel: .init(siteID: 123))
217213
.environment(\.colorScheme, .light)
218214

219-
HubMenu(siteID: 123)
215+
HubMenu(viewModel: .init(siteID: 123))
220216
.environment(\.colorScheme, .dark)
221217

222-
HubMenu(siteID: 123)
218+
HubMenu(viewModel: .init(siteID: 123))
223219
.previewLayout(.fixed(width: 312, height: 528))
224220
.environment(\.sizeCategory, .accessibilityExtraExtraExtraLarge)
225221

226-
HubMenu(siteID: 123)
222+
HubMenu(viewModel: .init(siteID: 123))
227223
.previewLayout(.fixed(width: 1024, height: 768))
228224
}
229225
}

WooCommerce/Classes/ViewRelated/Hub Menu/HubMenuViewController.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import Yosemite
44

55
/// Displays a grid view of all available menu in the "Menu" tab (eg. View Store, Reviews, Coupons, etc...)
66
final class HubMenuViewController: UIHostingController<HubMenu> {
7+
private let viewModel: HubMenuViewModel
78

89
init(siteID: Int64, navigationController: UINavigationController?) {
9-
super.init(rootView: HubMenu(siteID: siteID, navigationController: navigationController))
10+
self.viewModel = HubMenuViewModel(siteID: siteID, navigationController: navigationController)
11+
super.init(rootView: HubMenu(viewModel: viewModel))
1012
configureTabBarItem()
1113
}
1214

@@ -17,7 +19,7 @@ final class HubMenuViewController: UIHostingController<HubMenu> {
1719
/// Present the specific Review Details View from a push notification
1820
///
1921
func pushReviewDetailsViewController(using parcel: ProductReviewFromNoteParcel) {
20-
rootView.pushReviewDetailsView(using: parcel)
22+
viewModel.showReviewDetails(using: parcel)
2123
}
2224
}
2325

0 commit comments

Comments
 (0)