Skip to content

Commit 6851493

Browse files
committed
ios: design cart with +- actions
1 parent 0b43489 commit 6851493

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

Fruitties/iosApp/iosApp/ui/CartView.swift

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,18 @@ struct CartView : View {
3939
/// For more details, refer to: https://skie.touchlab.co/features/flows-in-swiftui
4040
Observing(cartViewModel.cartUiState) { cartUIState in
4141
VStack {
42-
HStack {
43-
let total = cartUIState.totalItemCount
44-
Text("Cart has \(total) items").padding()
45-
Spacer()
46-
}
4742
CartDetailsView(cartViewModel: cartViewModel)
4843
Spacer()
4944
}
50-
.navigationTitle("Your Cart")
45+
.navigationTitle("Cart")
46+
.toolbar {
47+
ToolbarItem(placement: .navigationBarTrailing) {
48+
Observing(cartViewModel.cartUiState) { cartUIState in
49+
let total = cartUIState.totalItemCount
50+
Text("Cart has \(total) items")
51+
}
52+
}
53+
}
5154
}
5255
}
5356
}
@@ -63,9 +66,28 @@ struct CartDetailsView: View {
6366
ScrollView {
6467
LazyVStack {
6568
ForEach(cartUIState.cartDetails, id: \.fruittie.id) { item in
66-
Text("\(item.fruittie.name): \(item.count)")
69+
HStack {
70+
Text("\(item.count)x \(item.fruittie.name)")
71+
.frame(maxWidth: .infinity, alignment: .leading)
72+
Spacer()
73+
Button(action: {
74+
self.cartViewModel.decreaseCountClick(cartItem: item)
75+
}) {
76+
Image(systemName: "minus.circle.fill")
77+
.foregroundColor(.red)
78+
}
79+
80+
Button(action: {
81+
self.cartViewModel.increaseCountClick(cartItem: item)
82+
}) {
83+
Image(systemName: "plus.circle.fill")
84+
.foregroundColor(.green)
85+
}
86+
}
87+
.padding()
6788
}
6889
}
90+
.animation(.default, value: cartUIState.cartDetails)
6991
}
7092
}
7193
}

0 commit comments

Comments
 (0)