Showing
7 changed files
with
148 additions
and
6 deletions
1 | +{ | ||
2 | + "images" : [ | ||
3 | + { | ||
4 | + "filename" : "MFY_container.png", | ||
5 | + "idiom" : "universal", | ||
6 | + "scale" : "1x" | ||
7 | + }, | ||
8 | + { | ||
9 | + "filename" : "MFY_container-1.png", | ||
10 | + "idiom" : "universal", | ||
11 | + "scale" : "2x" | ||
12 | + }, | ||
13 | + { | ||
14 | + "filename" : "MFY_container-2.png", | ||
15 | + "idiom" : "universal", | ||
16 | + "scale" : "3x" | ||
17 | + } | ||
18 | + ], | ||
19 | + "info" : { | ||
20 | + "author" : "xcode", | ||
21 | + "version" : 1 | ||
22 | + } | ||
23 | +} |
No preview for this file type
... | @@ -48,7 +48,7 @@ class DataModel { | ... | @@ -48,7 +48,7 @@ class DataModel { |
48 | 48 | ||
49 | var getData: Array<NSDictionary> { | 49 | var getData: Array<NSDictionary> { |
50 | get { // getter | 50 | get { // getter |
51 | - return data | 51 | + return data.filter({ $0["status"] as! String == "1" }) |
52 | } | 52 | } |
53 | } | 53 | } |
54 | } | 54 | } |
... | @@ -219,7 +219,7 @@ struct CouponsView: View { | ... | @@ -219,7 +219,7 @@ struct CouponsView: View { |
219 | var body: some View { | 219 | var body: some View { |
220 | VStack { | 220 | VStack { |
221 | headerView(goBack: goBack) | 221 | headerView(goBack: goBack) |
222 | - ScrollView { | 222 | + ScrollView(showsIndicators: false) { |
223 | VStack { | 223 | VStack { |
224 | if (data.count) > 0 { | 224 | if (data.count) > 0 { |
225 | ForEach(Array(zip(data.indices, data)), id: \.0) { index, result in | 225 | ForEach(Array(zip(data.indices, data)), id: \.0) { index, result in | ... | ... |
... | @@ -4,10 +4,30 @@ | ... | @@ -4,10 +4,30 @@ |
4 | // | 4 | // |
5 | // Created by Βασιλης Σκουρας on 20/4/22. | 5 | // Created by Βασιλης Σκουρας on 20/4/22. |
6 | // | 6 | // |
7 | - | ||
8 | import SwiftUI | 7 | import SwiftUI |
8 | +import Combine | ||
9 | +import Foundation | ||
10 | +import UIKit | ||
11 | + | ||
12 | +class DataMFYModel { | ||
13 | + var data: Array<NSDictionary> = [] | ||
14 | + | ||
15 | + init() { //initializer method | ||
16 | + let instanceOfMyApi = MyApi() | ||
17 | + let inbox = instanceOfMyApi.getInbox() as! Array<NSDictionary> | ||
18 | + data = inbox.filter({ $0["offer_category"] as! String == "more_for_you" }) | ||
19 | + } | ||
20 | + | ||
21 | + var getData: Array<NSDictionary> { | ||
22 | + get { // getter | ||
23 | + return data | ||
24 | + } | ||
25 | + } | ||
26 | +} | ||
9 | 27 | ||
10 | extension MoreForYouView { | 28 | extension MoreForYouView { |
29 | + | ||
30 | + | ||
11 | struct headerView: View { | 31 | struct headerView: View { |
12 | var goBack: () -> () | 32 | var goBack: () -> () |
13 | var uiscreen = UIScreen.main.bounds | 33 | var uiscreen = UIScreen.main.bounds |
... | @@ -19,7 +39,7 @@ extension MoreForYouView { | ... | @@ -19,7 +39,7 @@ extension MoreForYouView { |
19 | HStack { | 39 | HStack { |
20 | Image("ic_back", bundle: Bundle(for: MyEmptyClass.self)) | 40 | Image("ic_back", bundle: Bundle(for: MyEmptyClass.self)) |
21 | .resizable() | 41 | .resizable() |
22 | - .frame(width: self.uiscreen.height * 0.022, height: self.uiscreen.height * 0.02) | 42 | + .frame(width: self.uiscreen.height * 0.022, height: self.uiscreen.height * 0.04) |
23 | .offset(y: self.uiscreen.height * 0.015) | 43 | .offset(y: self.uiscreen.height * 0.015) |
24 | } | 44 | } |
25 | } | 45 | } |
... | @@ -31,25 +51,124 @@ extension MoreForYouView { | ... | @@ -31,25 +51,124 @@ extension MoreForYouView { |
31 | .frame(width: self.uiscreen.width, height: self.uiscreen.height * 0.1) | 51 | .frame(width: self.uiscreen.width, height: self.uiscreen.height * 0.1) |
32 | } | 52 | } |
33 | } | 53 | } |
54 | + | ||
55 | + struct ImageView: View { | ||
56 | + @ObservedObject var imageLoader:UrlImageModel | ||
57 | + @State var width:CGFloat | ||
58 | + @State var height:CGFloat | ||
59 | + @State var isFill:Bool | ||
60 | + | ||
61 | + var uiscreen = UIScreen.main.bounds | ||
62 | + | ||
63 | + init(withURL url:String , width:CGFloat, height: CGFloat, isFill:Bool) { | ||
64 | + imageLoader = UrlImageModel(urlString:url) | ||
65 | + self.width = width | ||
66 | + self.height = height | ||
67 | + self.isFill = isFill | ||
68 | + } | ||
69 | + | ||
70 | + var body: some View { | ||
71 | + | ||
72 | + Image(uiImage: imageLoader.image ?? UIImage()) | ||
73 | + .resizable() | ||
74 | + .frame(minWidth: self.uiscreen.width * 0.95, idealWidth: self.uiscreen.width * 0.95, maxWidth: self.uiscreen.width * 0.95, minHeight: self.uiscreen.height * 0.2, idealHeight: self.uiscreen.height * 0.2, maxHeight: self.uiscreen.height * 0.2, alignment: .leading) | ||
75 | + .scaledToFill() | ||
76 | + .aspectRatio(contentMode: isFill ? .fill : .fit) | ||
77 | + .cornerRadius(4) | ||
78 | + } | ||
79 | + } | ||
80 | + | ||
81 | + struct inboxView: View { | ||
82 | + var result: NSDictionary | ||
83 | + var index: Int | ||
84 | + | ||
85 | + var uiscreen = UIScreen.main.bounds | ||
86 | + | ||
87 | + static func localizedWithParameter(parameter: String) -> LocalizedStringKey { | ||
88 | + return "\(parameter)" | ||
89 | + } | ||
90 | + | ||
91 | + var body: some View { | ||
92 | + HStack { | ||
93 | + VStack(alignment: .leading) { | ||
94 | + Text(MoreForYouView.inboxView.localizedWithParameter(parameter: result["title"] as? String ?? "")) | ||
95 | + .frame(maxWidth: self.uiscreen.width * 0.65, alignment: .topLeading) | ||
96 | + .padding(.top, self.uiscreen.height * 0.01) | ||
97 | + .padding(.leading, self.uiscreen.width * 0.03) | ||
98 | + Spacer() | ||
99 | + Text(MoreForYouView.inboxView.localizedWithParameter(parameter: result["subtitle"] as? String ?? "")) | ||
100 | + .frame(maxWidth: self.uiscreen.width * 0.72, alignment: .topLeading) | ||
101 | + .padding(.leading, self.uiscreen.width * 0.03) | ||
102 | + .padding(.bottom, self.uiscreen.height * 0.01) | ||
103 | + } | ||
104 | + .frame(width: self.uiscreen.width * 0.85, height: self.uiscreen.height * 0.2, alignment: .leading) | ||
105 | + .background( | ||
106 | + Image("MFY_container", bundle: Bundle(for: MyEmptyClass.self)) | ||
107 | + .resizable() | ||
108 | + .frame(minWidth: self.uiscreen.width * 0.85, idealWidth: self.uiscreen.width * 0.85, maxWidth: self.uiscreen.width * 0.85, minHeight: self.uiscreen.height * 0.2, idealHeight: self.uiscreen.height * 0.2, maxHeight: self.uiscreen.height * 0.2, alignment: .leading) | ||
109 | + .scaledToFill() | ||
110 | + .aspectRatio(contentMode: .fill) | ||
111 | + ) | ||
112 | + .cornerRadius(4, corners: [.topLeft, .bottomLeft]) | ||
113 | + Spacer() | ||
114 | + } | ||
115 | + .frame(width: self.uiscreen.width * 0.95, height: self.uiscreen.height * 0.2) | ||
116 | + .background( | ||
117 | + ImageView(withURL: result["logo_url"] as! String, width: self.uiscreen.width * 0.95, height: self.uiscreen.height * 0.2, isFill: true) | ||
118 | + ) | ||
119 | + .padding(.bottom, self.uiscreen.height * 0.01) | ||
120 | + | ||
121 | + } | ||
122 | + } | ||
123 | +} | ||
124 | + | ||
125 | +extension Color { | ||
126 | + init(hex: Int, opacity: Double = 1.0) { | ||
127 | + let red = Double((hex & 0xff0000) >> 16) / 255.0 | ||
128 | + let green = Double((hex & 0xff00) >> 8) / 255.0 | ||
129 | + let blue = Double((hex & 0xff) >> 0) / 255.0 | ||
130 | + self.init(.sRGB, red: red, green: green, blue: blue, opacity: opacity) | ||
131 | + } | ||
34 | } | 132 | } |
35 | 133 | ||
36 | struct MoreForYouView: View { | 134 | struct MoreForYouView: View { |
37 | 135 | ||
136 | + var data:Array<NSDictionary> = DataMFYModel().getData | ||
137 | + | ||
38 | var parentView: UIView | 138 | var parentView: UIView |
39 | 139 | ||
40 | var uiscreen = UIScreen.main.bounds | 140 | var uiscreen = UIScreen.main.bounds |
41 | 141 | ||
42 | func goBack(){ | 142 | func goBack(){ |
43 | for subview in parentView.subviews { | 143 | for subview in parentView.subviews { |
44 | - if(subview.tag == 1) { | 144 | + if(subview.tag == 4) { |
45 | subview.removeFromSuperview() | 145 | subview.removeFromSuperview() |
46 | } | 146 | } |
47 | } | 147 | } |
48 | } | 148 | } |
49 | 149 | ||
50 | var body: some View { | 150 | var body: some View { |
151 | + VStack { | ||
51 | headerView(goBack: goBack) | 152 | headerView(goBack: goBack) |
52 | - Text("More For you") | 153 | + ScrollView(showsIndicators: false) { |
154 | + VStack { | ||
155 | + if (data.count) > 0 { | ||
156 | + ForEach(Array(zip(data.indices, data)), id: \.0) { index, result in | ||
157 | + inboxView(result: result, index: index) | ||
158 | + | ||
159 | + } | ||
160 | + } | ||
161 | + } | ||
162 | + .padding(.top, self.uiscreen.height * 0.04) | ||
163 | + .padding(.bottom, self.uiscreen.height * 0.05) | ||
164 | + } | ||
165 | + .frame(width:self.uiscreen.width, height:self.uiscreen.height * 0.9 ) | ||
166 | + .background( | ||
167 | + LinearGradient(gradient: Gradient(colors: [Color(hex: 0x1AADCC), Color(hex: 0x83C062)]), startPoint: .top, endPoint: .bottom) | ||
168 | + ) | ||
169 | + | ||
170 | + } | ||
171 | + .frame(width:self.uiscreen.width, height:self.uiscreen.height ) | ||
53 | } | 172 | } |
54 | } | 173 | } |
55 | 174 | ... | ... |
-
Please register or login to post a comment