Vasilis

mfy added

{
"images" : [
{
"filename" : "MFY_container.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "MFY_container-1.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "MFY_container-2.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
......@@ -48,7 +48,7 @@ class DataModel {
var getData: Array<NSDictionary> {
get { // getter
return data
return data.filter({ $0["status"] as! String == "1" })
}
}
}
......@@ -219,7 +219,7 @@ struct CouponsView: View {
var body: some View {
VStack {
headerView(goBack: goBack)
ScrollView {
ScrollView(showsIndicators: false) {
VStack {
if (data.count) > 0 {
ForEach(Array(zip(data.indices, data)), id: \.0) { index, result in
......
......@@ -4,10 +4,30 @@
//
// 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
......@@ -19,7 +39,7 @@ extension MoreForYouView {
HStack {
Image("ic_back", bundle: Bundle(for: MyEmptyClass.self))
.resizable()
.frame(width: self.uiscreen.height * 0.022, height: self.uiscreen.height * 0.02)
.frame(width: self.uiscreen.height * 0.022, height: self.uiscreen.height * 0.04)
.offset(y: self.uiscreen.height * 0.015)
}
}
......@@ -31,25 +51,124 @@ extension MoreForYouView {
.frame(width: self.uiscreen.width, height: self.uiscreen.height * 0.1)
}
}
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 ?? ""))
.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 ?? ""))
.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 == 1) {
if(subview.tag == 4) {
subview.removeFromSuperview()
}
}
}
var body: some View {
headerView(goBack: goBack)
Text("More For you")
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(width:self.uiscreen.width, height:self.uiscreen.height * 0.9 )
.background(
LinearGradient(gradient: Gradient(colors: [Color(hex: 0x1AADCC), Color(hex: 0x83C062)]), startPoint: .top, endPoint: .bottom)
)
}
.frame(width:self.uiscreen.width, height:self.uiscreen.height )
}
}
......