CouponBarcodeView.swift
10.3 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
//
// CouponBarcodeView.swift
// WarplySDKFrameworkIOS
//
// Created by Manos Chorianopoulos on 21/4/22.
//
#if canImport(SwiftUI)
import SwiftUI
import Combine
import Foundation
import UIKit
extension CouponBarcodeView {
struct headerView: View {
var goBack: () -> ()
var uiscreen = UIScreen.main.bounds
var body: some View {
HStack(alignment: .center) {
Button {
// Button Action
goBack()
} label: {
Image("ic_back", bundle: Bundle(for: MyEmptyClass.self))
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: self.uiscreen.height * 0.025, height: self.uiscreen.height * 0.02)
}
Text("Εκπτωτικό κουπόνι")
.fontWeight(.medium)
.font(.system(size: 16))
.foregroundColor(Color(red: 0.20784313725490197, green: 0.3176470588235294, blue: 0.40784313725490196))
.multilineTextAlignment(.center)
.frame(maxWidth: .infinity)
.padding(.horizontal)
}
.frame(maxWidth: .infinity)
.padding(.horizontal)
.padding(.vertical, 10)
}
}
struct couponContainer: View {
@State var coupon: Dictionary<String, Any>
// @State var couponset:CouponSetItemModel
var uiscreen = UIScreen.main.bounds
static func convertDateFormat(inputDate: String) -> String {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd hh:mm"
if let date = dateFormatter.date(from: inputDate) {
dateFormatter.dateFormat = "dd/MM/yyyy"
let resultString = dateFormatter.string(from: date)
return resultString
} else {
return ""
}
}
var body: some View {
GeometryReader { geometry in
ScrollView(showsIndicators: false) {
VStack(alignment: .leading) {
ImageView(withURL: coupon["img_preview"] as? String ?? "")
Text(coupon["name"] as? String ?? "")
.fontWeight(.bold)
.font(.system(size: 16))
.foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
.multilineTextAlignment(.leading)
.padding(.horizontal)
.padding(.top, self.uiscreen.height * 0.04)
Text(coupon["short_description"] as? String ?? "")
.fontWeight(.regular)
.font(.system(size: 14))
.foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
.multilineTextAlignment(.leading)
.padding(.horizontal)
.padding(.top, self.uiscreen.height * 0.02)
VStack(alignment: .center) {
VStack {}
.frame(height: 1)
.frame(width: self.uiscreen.width * 0.9)
.background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255))
}
.frame(maxWidth: .infinity)
VStack(alignment: .center) {
VStack {}
.frame(height: 1)
.frame(width: self.uiscreen.width * 0.9)
.background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255))
}
.frame(maxWidth: .infinity)
Text("Το κουπόνι ισχύει έως " + CouponBarcodeView.couponContainer.convertDateFormat(inputDate: coupon["img_preview"] as? String ?? ""))
.fontWeight(.medium)
.font(.system(size: 14))
.foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
.multilineTextAlignment(.center)
.padding(.top, self.uiscreen.height * 0.03)
.padding(.horizontal)
.frame(maxWidth: .infinity)
Spacer()
VStack(alignment: .center) {
Button {
// Button Action
print("Send Gift Button tapped!")
} label: {
HStack {
Text("Κάντο δώρο!")
.fontWeight(.medium)
.font(.system(size: 16))
.foregroundColor(Color(red: 0.3137254901960784, green: 0.6196078431372549, blue: 0.1843137254901961))
.multilineTextAlignment(.center)
.padding(.all)
}
}
.frame(width: self.uiscreen.width * 0.8)
.background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255))
.cornerRadius(7)
}
.frame(maxWidth: .infinity)
.padding(.top, self.uiscreen.height * 0.1)
VStack(alignment: .center) {
Button {
// Button Action
print("Shops Map Button tapped!")
} label: {
HStack {
Text("Χάρτης Καταστημάτων")
.fontWeight(.medium)
.font(.system(size: 16))
.foregroundColor(Color.white)
.multilineTextAlignment(.center)
.padding(.all)
}
}
.frame(width: self.uiscreen.width * 0.8)
.background(Color(red: 0.4745098039215686, green: 0.7490196078431373, blue: 0.0784313725490196))
.cornerRadius(7)
}
.frame(maxWidth: .infinity)
.padding(.top, self.uiscreen.height * 0.02)
Button {
// Button Action
print("Terms Button tapped!")
} label: {
Text("Όροι χρήσης")
.fontWeight(.medium)
.font(.system(size: 14))
.foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
.underline()
.multilineTextAlignment(.center)
.padding(.vertical, self.uiscreen.height * 0.03)
.padding(.horizontal)
.frame(maxWidth: .infinity)
}
.frame(maxWidth: .infinity)
}
.frame(width:self.uiscreen.width)
.frame(minHeight: geometry.size.height)
.padding(.bottom, self.uiscreen.height * 0.03)
}
.frame(width:self.uiscreen.width)
.frame(maxHeight: .infinity)
}
.frame(width:self.uiscreen.width)
.frame(maxHeight: .infinity)
}
}
struct ImageView: View {
@ObservedObject var imageLoader:UrlImageModel
var uiscreen = UIScreen.main.bounds
init(withURL url:String) {
imageLoader = UrlImageModel(urlString:url)
}
var body: some View {
Image(uiImage: imageLoader.image ?? UIImage())
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: self.uiscreen.width, height: self.uiscreen.height * 0.25)
}
}
}
@available(iOS 13.0.0, *)
struct CouponBarcodeView: View {
var parentView: UIView
var coupon: Dictionary<String, Any>
@State var couponset: CouponSetItemModel?
var uiscreen = UIScreen.main.bounds
func goBack() {
for subview in parentView.subviews {
if(subview.tag == 7) {
subview.removeFromSuperview()
}
}
}
var body: some View {
VStack {
headerView(goBack: goBack)
VStack {
couponContainer(coupon: coupon)
}
.background(Color.white)
.cornerRadius(30, corners: [.topLeft])
.frame(width:self.uiscreen.width)
.frame(maxHeight: .infinity)
}
.edgesIgnoringSafeArea([.bottom])
.frame(width:self.uiscreen.width)
.frame(maxHeight: .infinity)
// .onAppear {
// // If you want to setup data with model
// couponset = CouponSetItemModel(dictionary: coupon)
//
// }
}
}
#endif
//struct CouponBarcodeView_Previews: PreviewProvider {
// static var previews: some View {
// CouponBarcodeView()
// }
//}