Skip to content

Commit e1dfe8a

Browse files
committed
Adds UI for paymethd methods
1 parent 99a7061 commit e1dfe8a

File tree

1 file changed

+106
-1
lines changed

1 file changed

+106
-1
lines changed

WooCommerce/Classes/ViewRelated/Orders/Simple Payments/Method/SimplePaymentsMethod.swift

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,112 @@ import SwiftUI
55
///
66
struct SimplePaymentsMethod: View {
77

8+
/// Navigation bar title.
9+
///
10+
let title: String
11+
12+
var body: some View {
13+
VStack(alignment: .leading, spacing: Layout.noSpacing) {
14+
15+
Text(Localization.header)
16+
.subheadlineStyle()
17+
.padding()
18+
19+
Divider()
20+
21+
Group {
22+
MethodRow(icon: .priceImage, title: Localization.cash) {
23+
print("Tapped Cash")
24+
}
25+
26+
Divider()
27+
28+
MethodRow(icon: .creditCardImage, title: Localization.card) {
29+
print("Tapped Card")
30+
}
31+
}
32+
.padding(.leading)
33+
.background(Color(.listForeground))
34+
35+
Divider()
36+
37+
Spacer()
38+
}
39+
.background(Color(.listBackground).ignoresSafeArea())
40+
.navigationTitle(title)
41+
}
42+
}
43+
44+
/// Represents a Payment method row
45+
///
46+
private struct MethodRow: View {
47+
/// Icon of the row
48+
///
49+
let icon: UIImage
50+
51+
/// Title of the row
52+
///
53+
let title: String
54+
55+
/// Action when the row is selected
56+
///
57+
let action: () -> ()
58+
59+
/// Keeps track of the current screen scale.
60+
///
61+
@ScaledMetric private var scale = 1
62+
863
var body: some View {
9-
Text("Payment method")
64+
HStack(spacing: SimplePaymentsMethod.Layout.noSpacing) {
65+
Image(uiImage: icon)
66+
.resizable()
67+
.frame(width: SimplePaymentsMethod.Layout.iconWidthHeight(scale: scale),
68+
height: SimplePaymentsMethod.Layout.iconWidthHeight(scale: scale))
69+
.foregroundColor(Color(.systemGray))
70+
71+
TitleAndValueRow(title: title, value: .content(""), selectable: true, action: action)
72+
}
73+
}
74+
}
75+
76+
// MARK: Constants
77+
private extension SimplePaymentsMethod {
78+
enum Localization {
79+
static let header = NSLocalizedString("Choose your payment method", comment: "Heading text on the select payment method screen for simple payments")
80+
static let cash = NSLocalizedString("Cash", comment: "Cash method title on the select payment method screen for simple payments")
81+
static let card = NSLocalizedString("Card", comment: "Card method title on the select payment method screen for simple payments")
82+
}
83+
84+
enum Layout {
85+
static let noSpacing: CGFloat = 0
86+
static func iconWidthHeight(scale: CGFloat) -> CGFloat {
87+
24 * scale
88+
}
89+
}
90+
}
91+
92+
// MARK: Previews
93+
struct SimplePaymentsMethod_Preview: PreviewProvider {
94+
static var previews: some View {
95+
NavigationView {
96+
SimplePaymentsMethod(title: "Take payment ($15.99)")
97+
.environment(\.colorScheme, .light)
98+
.previewDisplayName("Light")
99+
.navigationBarTitleDisplayMode(.inline)
100+
}
101+
102+
NavigationView {
103+
SimplePaymentsMethod(title: "Take payment ($15.99)")
104+
.environment(\.colorScheme, .dark)
105+
.previewDisplayName("Dark")
106+
.navigationBarTitleDisplayMode(.inline)
107+
}
108+
109+
NavigationView {
110+
SimplePaymentsMethod(title: "Take payment ($15.99)")
111+
.environment(\.sizeCategory, .accessibilityExtraExtraLarge)
112+
.previewDisplayName("Accessibility")
113+
.navigationBarTitleDisplayMode(.inline)
114+
}
10115
}
11116
}

0 commit comments

Comments
 (0)