Skip to content

Commit 231c587

Browse files
committed
POC of ProductDetailRouter
1 parent 5d7bfde commit 231c587

File tree

3 files changed

+21
-53
lines changed

3 files changed

+21
-53
lines changed

WooCommerce/Classes/Routing/ProductDetailRouter.swift

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,10 @@ import Yosemite
44
final class ProductDetailRouter {
55
enum PresentationStyle {
66
case undefined
7-
case push
8-
case modal
97
case contained(containerViewController: () -> UIViewController?)
108

119
var asProductFormPresentationStyle: ProductFormPresentationStyle {
1210
switch self {
13-
case .push:
14-
.navigationStack
15-
case .modal:
16-
.navigationStack
1711
case .contained(let containerViewController):
1812
.contained(containerViewController: containerViewController)
1913
case .undefined:
@@ -30,42 +24,24 @@ final class ProductDetailRouter {
3024
self.productURLProvider = productURLProvider
3125
}
3226

33-
func open(product: Product,
34-
presenter: UIViewController,
35-
presentationStyle: PresentationStyle,
36-
onDismiss: (() -> Void)? = nil) {
37-
if product.productType == .booking {
38-
let coordinator = WebViewProductDetailCoordinator(product: product,
39-
productURLProvider: productURLProvider)
40-
coordinator.start(presenter: presenter, onDismiss: onDismiss)
41-
} else {
42-
let coordinator = NativeProductDetailCoordinator(product: product)
43-
coordinator.start(presenter: presenter,
44-
presentationStyle: presentationStyle,
45-
onDismiss: onDismiss)
46-
}
47-
}
48-
4927
func viewController(product: Product,
5028
presentationStyle: PresentationStyle = .undefined,
5129
forceReadOnly: Bool,
5230
onDeleteCompletion: (() -> Void)? = nil) -> UIViewController {
31+
32+
let viewController: UIViewController
5333
if product.productType == .booking {
5434
let coordinator = WebViewProductDetailCoordinator(product: product,
5535
productURLProvider: productURLProvider)
56-
return coordinator.viewController()
36+
viewController = coordinator.viewController()
5737

5838
} else {
5939
let coordinator = NativeProductDetailCoordinator(product: product)
60-
return coordinator.viewController(presentationStyle: presentationStyle,
40+
viewController = coordinator.viewController(presentationStyle: presentationStyle,
6141
forceReadOnly: forceReadOnly)
6242
}
63-
}
64-
}
6543

66-
final class ProductURLProvider {
67-
func adminURL(for product: Product) -> URL? {
68-
return URL(string: "https://wordpress.com")
44+
return viewController
6945
}
7046
}
7147

@@ -91,18 +67,6 @@ final class WebViewProductDetailCoordinator: NSObject {
9167
return webViewController
9268
}
9369

94-
func start(presenter: UIViewController,
95-
onDismiss: (() -> Void)? = nil) {
96-
let webViewController = viewController()
97-
webViewController.navigationItem.leftBarButtonItem = UIBarButtonItem(
98-
barButtonSystemItem: .done,
99-
target: self,
100-
action: #selector(dismissWebView)
101-
)
102-
103-
presenter.navigationController?.present(webViewController, animated: true)
104-
}
105-
10670
@objc
10771
private func dismissWebView() {
10872
let completion = onDismiss
@@ -118,12 +82,6 @@ final class NativeProductDetailCoordinator {
11882
self.product = product
11983
}
12084

121-
func start(presenter: UIViewController,
122-
presentationStyle: ProductDetailRouter.PresentationStyle,
123-
onDismiss: (() -> Void)? = nil) {
124-
125-
}
126-
12785
func viewController(
12886
presentationStyle: ProductDetailRouter.PresentationStyle,
12987
forceReadOnly: Bool,
@@ -134,3 +92,9 @@ final class NativeProductDetailCoordinator {
13492
onDeleteCompletion: onDeleteCompletion ?? {})
13593
}
13694
}
95+
96+
final class ProductURLProvider {
97+
func adminURL(for product: Product) -> URL? {
98+
return URL(string: "https://wordpress.com")
99+
}
100+
}

WooCommerce/Classes/ViewRelated/Products/ProductDetailsFactory.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ struct ProductDetailsFactory {
2727
onCompletion(vc)
2828
}
2929

30+
/// Creates a product details view controller asynchronously based on the app settings.
31+
/// - Parameters:
32+
/// - product: product model.
33+
/// - presentationStyle: how the product details are presented.
34+
/// - currencySettings: site currency settings.
35+
/// - forceReadOnly: force the product detail to be presented in read only mode
36+
/// - onDeleteCompletion: called when the product deletion completes in the product form.
3037
static func productDetails(product: Product,
3138
presentationStyle: ProductFormPresentationStyle,
3239
currencySettings: CurrencySettings = ServiceLocator.currencySettings,

WooCommerce/Classes/ViewRelated/Products/ProductsViewController.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,12 +1214,9 @@ extension ProductsViewController: UITableViewDelegate {
12141214
private extension ProductsViewController {
12151215
func didSelectProduct(product: Product) {
12161216
guard isSplitViewEnabled else {
1217-
// TODO: Replace with ProductDetailRouter
1218-
ProductDetailsFactory.productDetails(product: product,
1219-
presentationStyle: .navigationStack,
1220-
forceReadOnly: false) { [weak self] viewController in
1221-
self?.navigationController?.pushViewController(viewController, animated: true)
1222-
}
1217+
let viewController = ProductDetailRouter.shared.viewController(product: product,
1218+
forceReadOnly: false)
1219+
navigationController?.pushViewController(viewController, animated: true)
12231220
return
12241221
}
12251222
navigateToContent(.productForm(product: product))

0 commit comments

Comments
 (0)