-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItemCard.swift
More file actions
151 lines (100 loc) · 5.53 KB
/
Copy pathItemCard.swift
File metadata and controls
151 lines (100 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import SwiftUI
struct ItemCard: View {
@EnvironmentObject var viewRouter: ViewRouter
@State var color: Color
@State var image: Image
@State var title: String
@State var time: String
@State var price: Double
@State var item: Item
@State var cardBg = Color(.white)
@State var textColor = Color(.black)
@State var timeColor = Color(#colorLiteral(red: 0.6117647059, green: 0.6117647059, blue: 0.6117647059, alpha: 1))
init(color: Color, item: Item) {
self._color = State(initialValue: color)
self._image = State(initialValue: item.image)
self._title = State(initialValue: item.name)
self._time = State(initialValue: item.time)
self._price = State(initialValue: item.price)
self._item = State(initialValue: item)
}
var body: some View {
ZStack {
RoundedRectangle(cornerRadius: 20) // Background
.fill(cardBg)
.frame(width: 180, height: 220)
.shadow(color: Color(#colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.1026428811)), radius: 8, x: 0, y: 1)
VStack { // Content
Spacer(minLength: 20)
ZStack { // Image
RoundedRectangle(cornerRadius: 13) // Color background
.fill(color)
.opacity(0.1)
.frame(width: 85, height: 85)
image.resizable()
.aspectRatio(contentMode: .fit)
.frame(height: 65, alignment: .center)
}
Spacer(minLength: 20)
VStack { // Product Info
HStack { // Title
Text(title)
.font(.custom("OpenSans-Semibold", size: 15))
.foregroundColor(textColor)
.padding(.leading, 10)
.padding(.bottom, -10)
Spacer()
}
HStack { // Time
Image("Clock_white").resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 12)
.colorMultiply(timeColor)
.padding(.leading, 10)
Text(time)
.font(.custom("OpenSans-Semibold", size: 12))
.padding(.leading, -5)
.foregroundColor(timeColor)
Spacer()
}
Spacer()
HStack { // Price and add button
Text("$\(String(format: "%.2f", price))")
.font(.custom("OpenSans-Semibold", size: 20))
.padding(.leading, 10)
.foregroundColor(textColor)
Spacer()
QuantitySelector(item: self.item) {
if cart.count(itemName: item.name) >= 1 {
self.cardBg = Color(#colorLiteral(red: 0.3490196078, green: 0.3137254902, blue: 0.6509803922, alpha: 1))
self.textColor = Color(.white)
self.timeColor = Color(#colorLiteral(red: 0.8823529412, green: 0.8823529412, blue: 0.8823529412, alpha: 1))
} else {
self.cardBg = Color(.white)
self.textColor = Color(.black)
self.timeColor = Color(#colorLiteral(red: 0.6117647059, green: 0.6117647059, blue: 0.6117647059, alpha: 1))
}
}.padding(.trailing, 10)
}
Spacer()
}
}
}.frame(width: 180, height: 220).onAppear {
if cart.count(itemName: item.name) == 0 {
self.cardBg = Color(.white)
self.textColor = Color(.black)
self.timeColor = Color(#colorLiteral(red: 0.6117647059, green: 0.6117647059, blue: 0.6117647059, alpha: 1))
} else {
self.cardBg = Color(#colorLiteral(red: 0.3490196078, green: 0.3137254902, blue: 0.6509803922, alpha: 1))
self.textColor = Color(.white)
self.timeColor = Color(#colorLiteral(red: 0.8823529412, green: 0.8823529412, blue: 0.8823529412, alpha: 1))
}
}
}
}
struct ItemCard_Previews: PreviewProvider {
@State static var quantity = 0
static var previews: some View {
ItemCard(color: Color(#colorLiteral(red: 0.9372549057, green: 0.3490196168, blue: 0.1921568662, alpha: 1)), item: Items.blouse).previewLayout(.sizeThatFits)
}
}