Skip to content

Commit 3b7b44e

Browse files
committed
Merge branch 'issue/2053-add-product-more-details-button' into issue/2053-add-product-details-bottom-sheet
# Conflicts: # WooCommerce/Classes/ViewRelated/BottomButtonContainer/BottomButtonContainerView.swift # WooCommerce/Classes/ViewRelated/Products/Edit Product/ProductFormViewController.swift
2 parents 6ff9432 + 2558915 commit 3b7b44e

File tree

17 files changed

+999
-72
lines changed

17 files changed

+999
-72
lines changed

Networking/Networking/Model/Product/ProductType.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ extension ProductType: RawRepresentable {
4444
case .custom(let payload): return payload
4545
}
4646
}
47+
48+
/// Returns the localized text version of the Enum
49+
///
50+
public var description: String {
51+
switch self {
52+
case .simple:
53+
return NSLocalizedString("Simple", comment: "Display label for simple product type.")
54+
case .grouped:
55+
return NSLocalizedString("Grouped", comment: "Display label for grouped product type.")
56+
case .affiliate:
57+
return NSLocalizedString("External/Affiliate", comment: "Display label for affiliate product type.")
58+
case .variable:
59+
return NSLocalizedString("Variable", comment: "Display label for variable product type.")
60+
case .custom(let payload):
61+
return payload // unable to localize at runtime.
62+
}
63+
}
4764
}
4865

4966

WooCommerce/Classes/ViewRelated/BottomButtonContainer/BottomButtonContainerView.swift

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,28 @@ import UIKit
33
/// Contains a button with insets to be displayed at the bottom of a view.
44
///
55
final class BottomButtonContainerView: UIView {
6-
struct ViewModel {
7-
/// Allows the view model to configure and style the button.
8-
let configureButton: (UIButton) -> Void
6+
/// The style of the button.
7+
enum ButtonStyle {
8+
case primary
9+
case link
10+
}
911

10-
/// Called when the button is tapped.
12+
struct ViewModel {
13+
let style: ButtonStyle
14+
let title: String
15+
let image: UIImage?
1116
let onButtonTapped: (UIButton) -> Void
17+
18+
init(style: ButtonStyle, title: String, onButtonTapped: @escaping (UIButton) -> Void) {
19+
self.init(style: style, title: title, image: nil, onButtonTapped: onButtonTapped)
20+
}
21+
22+
init(style: ButtonStyle, title: String, image: UIImage?, onButtonTapped: @escaping (UIButton) -> Void) {
23+
self.style = style
24+
self.title = title
25+
self.image = image
26+
self.onButtonTapped = onButtonTapped
27+
}
1228
}
1329

1430
private let button: UIButton = UIButton(type: .custom)
@@ -47,12 +63,26 @@ private extension BottomButtonContainerView {
4763
button.translatesAutoresizingMaskIntoConstraints = false
4864
pinSubviewToAllEdges(button, insets: Constants.buttonMarginInsets)
4965

50-
button.addTarget(self, action: #selector(buttonTapped(_:)), for: .touchUpInside)
66+
button.setTitle(viewModel.title, for: .normal)
67+
button.addTarget(self, action: #selector(buttonTapped(sender:)), for: .touchUpInside)
68+
button.titleLabel?.lineBreakMode = .byTruncatingTail
69+
70+
switch viewModel.style {
71+
case .primary:
72+
button.applyPrimaryButtonStyle()
73+
case .link:
74+
button.applyLinkButtonStyle()
75+
button.contentHorizontalAlignment = .leading
76+
button.contentEdgeInsets = .zero
77+
}
5178

52-
viewModel.configureButton(button)
79+
if let image = viewModel.image {
80+
button.setImage(image, for: .normal)
81+
button.distributeTitleAndImage(spacing: 16)
82+
}
5383
}
5484

55-
@objc func buttonTapped(_ sender: UIButton) {
85+
@objc func buttonTapped(sender: UIButton) {
5686
viewModel.onButtonTapped(sender)
5787
}
5888
}

0 commit comments

Comments
 (0)