Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions AppleStoreProductKiosk/Features/ShoppingCart/CartView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// CartView.swift
// AppleStoreProductKiosk
//
// Created by 김민희 on 9/16/25.
//

import SwiftUI

struct CartView: View {
@State var item = CartItem()
var body: some View {
VStack(spacing: 0) {
CartHeaderView()

Divider()

ScrollView {
VStack(spacing: 15) {
CartItemRowView(item: $item)
}
.padding(.horizontal, 20)
.padding(.vertical, 30)
}
.scrollIndicators(.hidden)

Divider()

CartSummaryView(item: $item)
.padding(.vertical, 20)

CartActionButtonsView()
}
}
}

#Preview {
CartView()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// CartActionButtonsView.swift
// AppleStoreProductKiosk
//
// Created by 김민희 on 9/17/25.
//

import SwiftUI

struct CartActionButtonsView: View {
var body: some View {
Grid(horizontalSpacing: 12) {
GridRow {
Button {
//전체 취소
} label: {
Text("전체 취소")
.font(.system(size: 15, weight: .regular))
.foregroundStyle(.black)
.frame(maxWidth: .infinity)
.padding(10)
.overlay {
Capsule(style: .continuous)
.stroke(.black.opacity(0.2), lineWidth: 1)
}
}
.gridCellColumns(4)

Button {
//결제하기
} label: {
Text("결제하기")
.font(.system(size: 15, weight: .semibold))
.foregroundStyle(.white)
.frame(maxWidth: .infinity)
.padding(10)
.background(.blue)
.clipShape(.capsule(style: .continuous))
Comment on lines +12 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 Grid

HStack이 아닌 Grid로 하신 이유가 있으실까요 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아래 버튼 두개가 화면의 4:6 비율로 차지하고있는데
그 부분을 .gridCellColumns(4) / .gridCellColumns(6) 을 사용해서 만드려고 Grid 사용했습니다!

}
.gridCellColumns(6)
}
}
.padding(.horizontal, 20)
}
}

#Preview {
CartActionButtonsView()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// CartHeaderView.swift
// AppleStoreProductKiosk
//
// Created by 김민희 on 9/16/25.
//

import SwiftUI

struct CartHeaderView: View {
@Environment(\.dismiss) var dismiss

var body: some View {
HStack(spacing: 0) {
Text("장바구니")
.font(.system(size: 20, weight: .bold))
Spacer()

Button {
dismiss()
} label: {
Image(systemName: "xmark")
.foregroundColor(.black)
.font(.system(size: 15))
.padding(8)
.background(.gray.opacity(0.15))
.clipShape(Circle())
}
}
.padding(.horizontal, 20)
.padding(.vertical, 25)
}
}

#Preview {
CartHeaderView()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// CartItemRowView.swift
// AppleStoreProductKiosk
//
// Created by 김민희 on 9/16/25.
//

import SwiftUI

//TODO: 데이터 작업할 때 없앨예정
struct CartItem {
let name: String = "iphone17 pro"
let price: Int = 1000000
let imageName: String = "iphone17pro"
var quantity: Int = 2
}

struct CartItemRowView: View {
@Binding var item: CartItem

var body: some View {
HStack(spacing: 0) {
Image(item.imageName)
.resizable()
.scaledToFit()
.frame(width: 80, height: 80)
.cornerRadius(10)

Spacer()
.frame(width: 20)

VStack(alignment: .leading, spacing: 10) {
Text(item.name)
.font(.system(size: 17, weight: .semibold))

Text("₩\(item.price)")
.font(.system(size: 14, weight: .regular))
.foregroundStyle(.black.opacity(0.7))

Text("소계: ₩\(item.price * item.quantity)")
.font(.system(size: 12, weight: .regular))
.foregroundStyle(.blue)
}

Spacer()

HStack(spacing: 13) {
if item.quantity > 1 {
Button {
item.quantity -= 1
} label: {
Image(systemName: "minus")
.font(.system(size: 15))
.padding(12)
.foregroundStyle(.black)
.background(.white)
.clipShape(Circle())
.overlay(
Circle()
.stroke(.gray.opacity(0.3), lineWidth: 0.7)
)
}
} else {
Button {
//삭제
} label: {
Image(systemName: "trash")
.font(.system(size: 13))
.padding(8)
.foregroundStyle(.red)
.background(.white)
.clipShape(Circle())
.overlay(
Circle()
.stroke(.gray.opacity(0.3), lineWidth: 0.7)
)
}
}

Text("\(item.quantity)").frame(minWidth: 20)

Button {
item.quantity += 1
} label: {
Image(systemName: "plus")
.font(.system(size: 15))
.padding(7)
.foregroundStyle(.black)
.background(.white)
.clipShape(Circle())
.overlay(
Circle()
.stroke(.gray.opacity(0.3), lineWidth: 0.7)
)
}
}
}
.padding(.horizontal, 10)
.padding(.vertical, 20)
.background(.gray.opacity(0.05))
.clipShape(RoundedRectangle(cornerRadius: 14))
}
}

#Preview {
@State var item = CartItem(quantity: 1)
CartItemRowView(item: $item)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// CartSummaryView.swift
// AppleStoreProductKiosk
//
// Created by 김민희 on 9/17/25.
//

import SwiftUI

struct CartSummaryView: View {
@Binding var item: CartItem

var body: some View {
HStack(spacing: 0) {
VStack(alignment: .leading, spacing: 10) {
Text("상품 개수")
.font(.system(size: 14, weight: .regular))
.foregroundStyle(.black.opacity(0.7))
Text("총 결제금액")
.font(.system(size: 18, weight: .semibold))
}

Spacer()

VStack(alignment: .trailing, spacing: 10) {
Text("\(item.quantity)개")
.font(.system(size: 14, weight: .semibold))
Text("₩\(item.price * item.quantity)")
.font(.system(size: 20, weight: .bold))
.foregroundStyle(.blue)
}

}
.padding(.horizontal, 20)
}
}

#Preview {
@State var item = CartItem()
CartSummaryView(item: $item)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "iphone17pro.jpeg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading