MoreForYouView.swift
7.1 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
//
// MoreForYouView.swift
// WarplySDKFrameworkIOS
//
// Created by Βασιλης Σκουρας on 20/4/22.
//
import SwiftUI
import Combine
import Foundation
import UIKit
class DataMFYModel {
var data: Array<NSDictionary> = []
init() { //initializer method
let instanceOfMyApi = MyApi()
let inbox = instanceOfMyApi.getInbox() as! Array<NSDictionary>
data = inbox.filter({ $0["offer_category"] as! String == "more_for_you" })
}
var getData: Array<NSDictionary> {
get { // getter
return data
}
}
}
extension MoreForYouView {
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("More for you")
.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 ImageView: View {
@ObservedObject var imageLoader:UrlImageModel
@State var width:CGFloat
@State var height:CGFloat
@State var isFill:Bool
var uiscreen = UIScreen.main.bounds
init(withURL url:String , width:CGFloat, height: CGFloat, isFill:Bool) {
imageLoader = UrlImageModel(urlString:url)
self.width = width
self.height = height
self.isFill = isFill
}
var body: some View {
Image(uiImage: imageLoader.image ?? UIImage())
.resizable()
.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)
.scaledToFill()
.aspectRatio(contentMode: isFill ? .fill : .fit)
.cornerRadius(4)
}
}
struct inboxView: View {
var result: NSDictionary
var index: Int
var uiscreen = UIScreen.main.bounds
static func localizedWithParameter(parameter: String) -> LocalizedStringKey {
return "\(parameter)"
}
var body: some View {
HStack {
VStack(alignment: .leading) {
Text(MoreForYouView.inboxView.localizedWithParameter(parameter: result["title"] as? String ?? ""))
.font(.system(size: 17).italic())
.fontWeight(.bold)
.foregroundColor(Color(hex: 0x3A5266))
.frame(maxWidth: self.uiscreen.width * 0.65, alignment: .topLeading)
.padding(.top, self.uiscreen.height * 0.01)
.padding(.leading, self.uiscreen.width * 0.03)
Spacer()
Text(MoreForYouView.inboxView.localizedWithParameter(parameter: result["subtitle"] as? String ?? ""))
.font(.system(size: 16))
.fontWeight(.medium)
.foregroundColor(Color(hex: 0x415564))
.frame(maxWidth: self.uiscreen.width * 0.72, alignment: .topLeading)
.padding(.leading, self.uiscreen.width * 0.03)
.padding(.bottom, self.uiscreen.height * 0.01)
}
.frame(width: self.uiscreen.width * 0.85, height: self.uiscreen.height * 0.2, alignment: .leading)
.background(
Image("MFY_container", bundle: Bundle(for: MyEmptyClass.self))
.resizable()
.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)
.scaledToFill()
.aspectRatio(contentMode: .fill)
)
.cornerRadius(4, corners: [.topLeft, .bottomLeft])
Spacer()
}
.frame(width: self.uiscreen.width * 0.95, height: self.uiscreen.height * 0.2)
.background(
ImageView(withURL: result["logo_url"] as! String, width: self.uiscreen.width * 0.95, height: self.uiscreen.height * 0.2, isFill: true)
)
.padding(.bottom, self.uiscreen.height * 0.01)
}
}
}
extension Color {
init(hex: Int, opacity: Double = 1.0) {
let red = Double((hex & 0xff0000) >> 16) / 255.0
let green = Double((hex & 0xff00) >> 8) / 255.0
let blue = Double((hex & 0xff) >> 0) / 255.0
self.init(.sRGB, red: red, green: green, blue: blue, opacity: opacity)
}
}
struct MoreForYouView: View {
var data:Array<NSDictionary> = DataMFYModel().getData
var parentView: UIView
var uiscreen = UIScreen.main.bounds
func goBack(){
for subview in parentView.subviews {
if(subview.tag == 4) {
subview.removeFromSuperview()
}
}
}
var body: some View {
VStack {
headerView(goBack: goBack)
ScrollView(showsIndicators: false) {
VStack {
if (data.count) > 0 {
ForEach(Array(zip(data.indices, data)), id: \.0) { index, result in
inboxView(result: result, index: index)
}
}
}
.padding(.top, self.uiscreen.height * 0.04)
.padding(.bottom, self.uiscreen.height * 0.05)
}
.frame(maxWidth: .infinity, maxHeight: .infinity )
.background(
LinearGradient(gradient: Gradient(colors: [Color(hex: 0x1AADCC), Color(hex: 0x83C062)]), startPoint: .top, endPoint: .bottom)
)
.cornerRadius(20, corners: [.topLeft])
}
.frame(maxWidth: .infinity, maxHeight: .infinity )
// .frame(width:self.uiscreen.width, height:self.uiscreen.height )
}
}
//struct MoreForYouView_Previews: PreviewProvider {
// static var previews: some View {
// MoreForYouView()
// }
//}