Manos Chorianopoulos

add CouponBarcodeView v2

...@@ -5,16 +5,254 @@ ...@@ -5,16 +5,254 @@
5 // Created by Manos Chorianopoulos on 21/4/22. 5 // Created by Manos Chorianopoulos on 21/4/22.
6 // 6 //
7 7
8 +#if canImport(SwiftUI)
8 import SwiftUI 9 import SwiftUI
10 +import Combine
11 +import Foundation
12 +import UIKit
13 +
14 +
15 +
16 +extension CouponBarcodeView {
17 + struct headerView: View {
18 + var goBack: () -> ()
19 +
20 + var uiscreen = UIScreen.main.bounds
21 +
22 + var body: some View {
23 + HStack(alignment: .center) {
24 + Button {
25 + // Button Action
26 + goBack()
27 + } label: {
28 + Image("ic_back", bundle: Bundle(for: MyEmptyClass.self))
29 + .resizable()
30 + .aspectRatio(contentMode: .fit)
31 + .frame(width: self.uiscreen.height * 0.025, height: self.uiscreen.height * 0.02)
32 + }
33 +
34 + Text("Εκπτωτικό κουπόνι")
35 + .fontWeight(.medium)
36 + .font(.system(size: 16))
37 + .foregroundColor(Color(red: 0.20784313725490197, green: 0.3176470588235294, blue: 0.40784313725490196))
38 + .multilineTextAlignment(.center)
39 + .frame(maxWidth: .infinity)
40 + .padding(.horizontal)
41 +
42 + }
43 + .frame(maxWidth: .infinity)
44 + .padding(.horizontal)
45 + .padding(.vertical, 10)
46 + }
47 + }
48 +
49 + struct couponContainer: View {
50 + @State var coupon: Dictionary<String, Any>
51 +// @State var couponset:CouponSetItemModel
52 +
53 + var uiscreen = UIScreen.main.bounds
54 +
55 +
56 + static func convertDateFormat(inputDate: String) -> String {
57 + let dateFormatter = DateFormatter()
58 + dateFormatter.dateFormat = "yyyy-MM-dd hh:mm"
59 + if let date = dateFormatter.date(from: inputDate) {
60 + dateFormatter.dateFormat = "dd/MM/yyyy"
61 + let resultString = dateFormatter.string(from: date)
62 + return resultString
63 + } else {
64 + return ""
65 + }
66 + }
9 67
10 -struct CouponBarcodeView: View {
11 var body: some View { 68 var body: some View {
12 - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) 69 + GeometryReader { geometry in
70 + ScrollView(showsIndicators: false) {
71 + VStack(alignment: .leading) {
72 +
73 + ImageView(withURL: coupon["img_preview"] as? String ?? "")
74 +
75 + Text(coupon["name"] as? String ?? "")
76 + .fontWeight(.bold)
77 + .font(.system(size: 16))
78 + .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
79 + .multilineTextAlignment(.leading)
80 + .padding(.horizontal)
81 + .padding(.top, self.uiscreen.height * 0.04)
82 +
83 + Text(coupon["short_description"] as? String ?? "")
84 + .fontWeight(.regular)
85 + .font(.system(size: 14))
86 + .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
87 + .multilineTextAlignment(.leading)
88 + .padding(.horizontal)
89 + .padding(.top, self.uiscreen.height * 0.02)
90 +
91 + VStack(alignment: .center) {
92 + VStack {}
93 + .frame(height: 1)
94 + .frame(width: self.uiscreen.width * 0.9)
95 + .background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255))
96 + }
97 + .frame(maxWidth: .infinity)
98 +
99 +
100 +
101 + VStack(alignment: .center) {
102 + VStack {}
103 + .frame(height: 1)
104 + .frame(width: self.uiscreen.width * 0.9)
105 + .background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255))
106 + }
107 + .frame(maxWidth: .infinity)
108 +
109 +
110 + Text("Το κουπόνι ισχύει έως " + CouponBarcodeView.couponContainer.convertDateFormat(inputDate: coupon["img_preview"] as? String ?? ""))
111 + .fontWeight(.medium)
112 + .font(.system(size: 14))
113 + .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
114 + .multilineTextAlignment(.center)
115 + .padding(.top, self.uiscreen.height * 0.03)
116 + .padding(.horizontal)
117 + .frame(maxWidth: .infinity)
118 +
119 + Spacer()
120 +
121 + VStack(alignment: .center) {
122 + Button {
123 + // Button Action
124 + print("Send Gift Button tapped!")
125 + } label: {
126 + HStack {
127 + Text("Κάντο δώρο!")
128 + .fontWeight(.medium)
129 + .font(.system(size: 16))
130 + .foregroundColor(Color(red: 0.3137254901960784, green: 0.6196078431372549, blue: 0.1843137254901961))
131 + .multilineTextAlignment(.center)
132 + .padding(.all)
133 + }
134 + }
135 + .frame(width: self.uiscreen.width * 0.8)
136 + .background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255))
137 + .cornerRadius(7)
138 + }
139 + .frame(maxWidth: .infinity)
140 + .padding(.top, self.uiscreen.height * 0.1)
141 +
142 + VStack(alignment: .center) {
143 + Button {
144 + // Button Action
145 + print("Shops Map Button tapped!")
146 + } label: {
147 + HStack {
148 + Text("Χάρτης Καταστημάτων")
149 + .fontWeight(.medium)
150 + .font(.system(size: 16))
151 + .foregroundColor(Color.white)
152 + .multilineTextAlignment(.center)
153 + .padding(.all)
13 } 154 }
155 + }
156 + .frame(width: self.uiscreen.width * 0.8)
157 + .background(Color(red: 0.4745098039215686, green: 0.7490196078431373, blue: 0.0784313725490196))
158 + .cornerRadius(7)
159 + }
160 + .frame(maxWidth: .infinity)
161 + .padding(.top, self.uiscreen.height * 0.02)
162 +
163 + Button {
164 + // Button Action
165 + print("Terms Button tapped!")
166 + } label: {
167 + Text("Όροι χρήσης")
168 + .fontWeight(.medium)
169 + .font(.system(size: 14))
170 + .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
171 + .underline()
172 + .multilineTextAlignment(.center)
173 + .padding(.vertical, self.uiscreen.height * 0.03)
174 + .padding(.horizontal)
175 + .frame(maxWidth: .infinity)
176 + }
177 + .frame(maxWidth: .infinity)
178 +
179 +
180 + }
181 + .frame(width:self.uiscreen.width)
182 + .frame(minHeight: geometry.size.height)
183 + .padding(.bottom, self.uiscreen.height * 0.03)
184 + }
185 + .frame(width:self.uiscreen.width)
186 + .frame(maxHeight: .infinity)
187 + }
188 + .frame(width:self.uiscreen.width)
189 + .frame(maxHeight: .infinity)
190 + }
191 + }
192 +
193 + struct ImageView: View {
194 + @ObservedObject var imageLoader:UrlImageModel
195 +
196 + var uiscreen = UIScreen.main.bounds
197 +
198 + init(withURL url:String) {
199 + imageLoader = UrlImageModel(urlString:url)
200 + }
201 +
202 + var body: some View {
203 +
204 + Image(uiImage: imageLoader.image ?? UIImage())
205 + .resizable()
206 + .aspectRatio(contentMode: .fill)
207 + .frame(width: self.uiscreen.width, height: self.uiscreen.height * 0.25)
208 + }
209 + }
210 +
14 } 211 }
15 212
16 -struct CouponBarcodeView_Previews: PreviewProvider { 213 +@available(iOS 13.0.0, *)
17 - static var previews: some View { 214 +struct CouponBarcodeView: View {
18 - CouponBarcodeView() 215 + var parentView: UIView
216 + var coupon: Dictionary<String, Any>
217 + @State var couponset: CouponSetItemModel?
218 +
219 + var uiscreen = UIScreen.main.bounds
220 +
221 + func goBack() {
222 + for subview in parentView.subviews {
223 + if(subview.tag == 7) {
224 + subview.removeFromSuperview()
225 + }
226 + }
227 + }
228 +
229 +
230 + var body: some View {
231 + VStack {
232 + headerView(goBack: goBack)
233 +
234 + VStack {
235 + couponContainer(coupon: coupon)
236 + }
237 + .background(Color.white)
238 + .cornerRadius(30, corners: [.topLeft])
239 + .frame(width:self.uiscreen.width)
240 + .frame(maxHeight: .infinity)
241 + }
242 + .edgesIgnoringSafeArea([.bottom])
243 + .frame(width:self.uiscreen.width)
244 + .frame(maxHeight: .infinity)
245 +// .onAppear {
246 +// // If you want to setup data with model
247 +// couponset = CouponSetItemModel(dictionary: coupon)
248 +//
249 +// }
19 } 250 }
20 } 251 }
252 +#endif
253 +
254 +//struct CouponBarcodeView_Previews: PreviewProvider {
255 +// static var previews: some View {
256 +// CouponBarcodeView()
257 +// }
258 +//}
......
...@@ -6,3 +6,14 @@ ...@@ -6,3 +6,14 @@
6 // 6 //
7 7
8 import Foundation 8 import Foundation
9 +import SwiftUI
10 +
11 +@available(iOS 13.0.0, *)
12 +@objc public class CouponBarcodeViewInterface : NSObject {
13 +
14 + @objc(couponBarcodeViewController::) static public func couponBarcodeViewController(parentView: UIView?, coupon: Dictionary<String, Any>) -> UIViewController {
15 + return UIHostingController(rootView: CouponBarcodeView(parentView: parentView!, coupon: coupon))
16 + }
17 +
18 +}
19 +
......