Skip to content

Commit 11a0a9d

Browse files
committed
Replace cart view header with POSPageHeaderView.
1 parent 557a28d commit 11a0a9d

File tree

1 file changed

+13
-38
lines changed

1 file changed

+13
-38
lines changed

WooCommerce/Classes/POS/Presentation/CartView.swift

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,16 @@ struct CartView: View {
1818

1919
var body: some View {
2020
VStack {
21-
DynamicHStack(spacing: Constants.cartHeaderSpacing) {
22-
HStack(spacing: Constants.cartHeaderElementSpacing) {
23-
backAddMoreButton
24-
.disabled(shouldPreventCartEditing)
25-
.shimmering(active: shouldPreventCartEditing)
26-
27-
HStack {
28-
Text(Localization.cartTitle)
29-
.font(Constants.primaryFont)
30-
.foregroundColor(.posOnSurface)
31-
.accessibilityAddTraits(.isHeader)
32-
33-
Spacer()
34-
35-
if let itemsInCartLabel = viewHelper.itemsInCartLabel(for: posModel.cart.count) {
36-
Text(itemsInCartLabel)
37-
.font(Constants.itemsFont)
38-
.foregroundColor(Color.posOnSurfaceVariantLowest)
39-
}
40-
}
41-
.accessibilityElement(children: .combine)
21+
POSPageHeaderView(title: Localization.cartTitle,
22+
backButtonConfiguration: backButtonConfiguration,
23+
trailingContent: {
24+
if let itemsInCartLabel = viewHelper.itemsInCartLabel(for: posModel.cart.count) {
25+
Text(itemsInCartLabel)
26+
.font(Constants.itemsFont)
27+
.foregroundColor(Color.posOnSurfaceVariantLowest)
4228
}
4329

4430
HStack {
45-
Spacer()
46-
.renderedIf(dynamicTypeSize.isAccessibilitySize)
47-
4831
Button {
4932
posModel.removeAllItemsFromCart()
5033
} label: {
@@ -53,10 +36,7 @@ struct CartView: View {
5336
.buttonStyle(POSOutlinedButtonStyle(size: .extraSmall))
5437
.renderedIf(shouldShowClearCartButton)
5538
}
56-
}
57-
.frame(maxWidth: .infinity, alignment: .leading)
58-
.padding(.horizontal, POSHeaderLayoutConstants.sectionHorizontalPadding)
59-
.padding(.vertical, POSHeaderLayoutConstants.sectionVerticalPadding)
39+
})
6040
.if(shouldApplyHeaderBottomShadow, transform: { $0.applyBottomShadow(backgroundColor: backgroundColor) })
6141

6242
if posModel.cart.isNotEmpty {
@@ -204,7 +184,6 @@ private extension CartView {
204184
static let scrollViewCoordinateSpaceIdentifier: String = "CartScrollView"
205185
static let emptyViewImageTextSpacing: CGFloat = 30 // This should be 40 by designs, but the overlay technique means we have to tweak it
206186
static let cartHeaderSpacing: CGFloat = 8
207-
static let backButtonSymbol: String = "chevron.backward"
208187
static let cartHeaderElementSpacing: CGFloat = 16
209188
static let cartAnimation: Animation = .spring(duration: 0.2)
210189
static let checkoutButtonVerticalPadding: CGFloat = 16
@@ -247,20 +226,16 @@ private extension CartView {
247226
.buttonStyle(POSFilledButtonStyle(size: .normal))
248227
}
249228

250-
@ViewBuilder
251-
var backAddMoreButton: some View {
229+
var backButtonConfiguration: POSPageHeaderBackButtonConfiguration? {
252230
switch posModel.orderStage {
253231
case .building:
254-
EmptyView()
232+
return nil
255233
case .finalizing:
256-
Button {
234+
let state: POSPageHeaderBackButtonConfiguration.State = shouldPreventCartEditing ? .shimmering : .enabled
235+
return .init(state: state, action: {
257236
ServiceLocator.analytics.track(.pointOfSaleBackToCartTapped)
258237
posModel.addMoreToCart()
259-
} label: {
260-
Image(systemName: Constants.backButtonSymbol)
261-
.font(.posBodyLargeBold, maximumContentSizeCategory: .accessibilityLarge)
262-
.foregroundColor(.posOnSurface)
263-
}
238+
})
264239
}
265240
}
266241

0 commit comments

Comments
 (0)