Showing
6 changed files
with
72 additions
and
72 deletions
This diff could not be displayed because it is too large.
No preview for this file type
... | @@ -7,6 +7,9 @@ | ... | @@ -7,6 +7,9 @@ |
7 | 7 | ||
8 | #if canImport(SwiftUI) | 8 | #if canImport(SwiftUI) |
9 | import SwiftUI | 9 | import SwiftUI |
10 | +import Combine | ||
11 | +import Foundation | ||
12 | + | ||
10 | 13 | ||
11 | class DataModel { | 14 | class DataModel { |
12 | var data: Array<NSDictionary> = [] | 15 | var data: Array<NSDictionary> = [] |
... | @@ -50,63 +53,42 @@ class DataModel { | ... | @@ -50,63 +53,42 @@ class DataModel { |
50 | } | 53 | } |
51 | } | 54 | } |
52 | 55 | ||
53 | -struct UrlImageView: View { | 56 | +class ImageLoader: ObservableObject { |
54 | - @ObservedObject var urlImageModel: UrlImageModel | 57 | + var didChange = PassthroughSubject<Data, Never>() |
55 | - | 58 | + var data = Data() { |
56 | - init(urlString: String?) { | 59 | + didSet { |
57 | - urlImageModel = UrlImageModel(urlString: urlString) | 60 | + didChange.send(data) |
58 | } | 61 | } |
59 | - | ||
60 | - var body: some View { | ||
61 | - Image(uiImage: urlImageModel.image ?? UrlImageView.defaultImage!) | ||
62 | - .resizable() | ||
63 | - .scaledToFill() | ||
64 | } | 62 | } |
65 | 63 | ||
66 | - static var defaultImage = UIImage(systemName: "photo") | 64 | + init(urlString:String) { |
67 | -} | 65 | + guard let url = URL(string: urlString) else { return } |
68 | - | 66 | + let task = URLSession.shared.dataTask(with: url) { data, response, error in |
69 | -class UrlImageModel: ObservableObject { | 67 | + guard let data = data else { return } |
70 | - @Published var image: UIImage? | 68 | + DispatchQueue.main.async { |
71 | - var urlString: String? | 69 | + self.data = data |
72 | - | ||
73 | - init(urlString: String?) { | ||
74 | - self.urlString = urlString | ||
75 | - loadImage() | ||
76 | } | 70 | } |
77 | - | ||
78 | - func loadImage() { | ||
79 | - loadImageFromUrl() | ||
80 | } | 71 | } |
81 | - | ||
82 | - func loadImageFromUrl() { | ||
83 | - guard let urlString = urlString else { | ||
84 | - return | ||
85 | - } | ||
86 | - | ||
87 | - let url = URL(string: urlString)! | ||
88 | - let task = URLSession.shared.dataTask(with: url, completionHandler: | ||
89 | - getImageFromResponse(data:response:error:)) | ||
90 | task.resume() | 72 | task.resume() |
91 | } | 73 | } |
74 | +} | ||
92 | 75 | ||
76 | +struct ImageView: View { | ||
77 | + @ObservedObject var imageLoader:ImageLoader | ||
78 | + @State var image:UIImage = UIImage() | ||
93 | 79 | ||
94 | - func getImageFromResponse(data: Data?, response: URLResponse?, error: Error?) | 80 | + init(withURL url:String) { |
95 | - { | 81 | + imageLoader = ImageLoader(urlString:url) |
96 | - guard error == nil else { | ||
97 | - print("Error: \(error!)") | ||
98 | - return | ||
99 | - } | ||
100 | - guard let data = data else { | ||
101 | - print("No data found") | ||
102 | - return | ||
103 | } | 82 | } |
104 | 83 | ||
105 | - DispatchQueue.main.async { | 84 | + var body: some View { |
106 | - guard let loadedImage = UIImage(data: data) else { | 85 | + |
107 | - return | 86 | + Image(uiImage: image) |
108 | - } | 87 | + .resizable() |
109 | - self.image = loadedImage | 88 | + .aspectRatio(contentMode: .fit) |
89 | +// .frame(width:100, height:100) | ||
90 | + .onReceive(imageLoader.didChange) { data in | ||
91 | + self.image = UIImage(data: data) ?? UIImage() | ||
110 | } | 92 | } |
111 | } | 93 | } |
112 | } | 94 | } |
... | @@ -117,41 +99,61 @@ extension CouponsView { | ... | @@ -117,41 +99,61 @@ extension CouponsView { |
117 | var uiscreen = UIScreen.main.bounds | 99 | var uiscreen = UIScreen.main.bounds |
118 | 100 | ||
119 | var body: some View { | 101 | var body: some View { |
120 | - ZStack { | 102 | + HStack { |
121 | Image("ic_back", bundle: Bundle(for: MyEmptyClass.self)) | 103 | Image("ic_back", bundle: Bundle(for: MyEmptyClass.self)) |
122 | .resizable() | 104 | .resizable() |
123 | - .frame(width: self.uiscreen.height * 0.025, height: self.uiscreen.height * 0.02) | 105 | + .frame(width: self.uiscreen.width * 0.025, height: self.uiscreen.height * 0.02) |
124 | - .offset(x: -self.uiscreen.width / 2 + self.uiscreen.width * 0.05, y: self.uiscreen.height * 0.07) | 106 | + .offset(x: -self.uiscreen.width / 2 + self.uiscreen.width * 0.05, y: self.uiscreen.height * 0.04) |
125 | Text("Όλα τα κουπόνια μου") | 107 | Text("Όλα τα κουπόνια μου") |
126 | .frame(width: self.uiscreen.width * 0.8, height: self.uiscreen.height * 0.025, alignment: .center) | 108 | .frame(width: self.uiscreen.width * 0.8, height: self.uiscreen.height * 0.025, alignment: .center) |
127 | - .offset( y: self.uiscreen.height * 0.07) | 109 | + .offset( y: self.uiscreen.height * 0.04) |
128 | - .frame(width: self.uiscreen.width) | ||
129 | } | 110 | } |
111 | + .frame(width: self.uiscreen.width, height: self.uiscreen.height * 0.12) | ||
130 | } | 112 | } |
131 | } | 113 | } |
132 | 114 | ||
133 | - | ||
134 | - | ||
135 | struct couponView: View { | 115 | struct couponView: View { |
136 | var result: NSDictionary | 116 | var result: NSDictionary |
137 | var index: Int | 117 | var index: Int |
138 | 118 | ||
139 | var uiscreen = UIScreen.main.bounds | 119 | var uiscreen = UIScreen.main.bounds |
140 | 120 | ||
121 | + static func localizedWithParameter(parameter: String) -> LocalizedStringKey { | ||
122 | + return "\(parameter)" | ||
123 | + } | ||
124 | + | ||
141 | var body: some View { | 125 | var body: some View { |
142 | - ZStack { | 126 | + |
143 | - UrlImageView(urlString: result["img_preview"] as? String) | 127 | + HStack(alignment: .center) { |
144 | - .frame(width: self.uiscreen.height * 0.25, height: self.uiscreen.height * 0.05, alignment: .leading) | 128 | + HStack(alignment: .center) { |
145 | - .offset(x: self.uiscreen.width * 0.05, y: self.uiscreen.height * 0.06) | 129 | + ImageView(withURL: result["img_preview"] as! String) |
130 | + .frame(width: self.uiscreen.width * 0.2, height: self.uiscreen.height * 0.05) | ||
131 | +// .offset(x: -self.uiscreen.width / 2 + self.uiscreen.width * 0.2, y: -self.uiscreen.height * 0.05 * 0.96) | ||
132 | +// .padding(.leading, self.uiscreen.width * 0.05) | ||
133 | + Rectangle() | ||
134 | + .frame(width: 1, height: self.uiscreen.height * 0.1 * 0.93) | ||
135 | +// .offset(x: -self.uiscreen.width / 2 + self.uiscreen.width * 0.205, y: -self.uiscreen.height * 0.05 * 0.93) | ||
136 | + VStack { | ||
137 | + Text(CouponsView.couponView.localizedWithParameter(parameter: result["admin_name"] as! String)) | ||
138 | + Text(CouponsView.couponView.localizedWithParameter(parameter: result["discount"] as! String)) | ||
139 | + Text(CouponsView.couponView.localizedWithParameter(parameter: "Ισχύει εώς " + (result["expiration"] as! String).components(separatedBy: [" "]).filter({!$0.isEmpty})[0])) | ||
140 | + } | ||
141 | + .frame(maxHeight: .infinity) | ||
142 | + VStack { | ||
143 | + Text(CouponsView.couponView.localizedWithParameter(parameter: result["short_description"] as! String)) | ||
144 | + } | ||
145 | + .frame(maxWidth: self.uiscreen.width * 0.15, maxHeight: .infinity) | ||
146 | + | ||
147 | + } | ||
148 | + .frame(maxWidth: .infinity, maxHeight: .infinity) | ||
146 | 149 | ||
147 | } | 150 | } |
148 | .background( | 151 | .background( |
149 | Image("coupons_container", bundle: Bundle(for: MyEmptyClass.self)) | 152 | Image("coupons_container", bundle: Bundle(for: MyEmptyClass.self)) |
150 | - .resizable() | ||
151 | - .offset(x: self.uiscreen.width * 0.05, y: (CGFloat(index + 1) * self.uiscreen.height * 0.06) + CGFloat(index) * self.uiscreen.height * 0.17) | ||
152 | - .padding() | ||
153 | - .frame(width: UIScreen.main.bounds.width * 0.9, height: UIScreen.main.bounds.height * 0.17, alignment: .topLeading) | ||
154 | ) | 153 | ) |
154 | +// .padding(.top, self.uiscreen.height * 0.05) | ||
155 | + .frame(width: self.uiscreen.width * 0.9, height: self.uiscreen.height * 0.1) | ||
156 | + .background(Color.purple) | ||
155 | } | 157 | } |
156 | } | 158 | } |
157 | 159 | ||
... | @@ -175,9 +177,11 @@ struct CouponsView: View { | ... | @@ -175,9 +177,11 @@ struct CouponsView: View { |
175 | } | 177 | } |
176 | } | 178 | } |
177 | } | 179 | } |
178 | - .frame(width:self.uiscreen.width, height:self.uiscreen.height ) | 180 | + |
179 | - } | 181 | + }.frame(width:self.uiscreen.width, height:self.uiscreen.height * 0.88 ) |
180 | } | 182 | } |
183 | + .frame(width:self.uiscreen.width, height:self.uiscreen.height ) | ||
184 | + .background(Color.red) | ||
181 | } | 185 | } |
182 | } | 186 | } |
183 | #endif | 187 | #endif | ... | ... |
... | @@ -11,8 +11,8 @@ import SwiftUI | ... | @@ -11,8 +11,8 @@ import SwiftUI |
11 | @available(iOS 13.0.0, *) | 11 | @available(iOS 13.0.0, *) |
12 | @objc public class CouponsViewInterface : NSObject { | 12 | @objc public class CouponsViewInterface : NSObject { |
13 | 13 | ||
14 | - @objc static public func couponsViewController() -> UIViewController { | 14 | + @objc(couponsViewController:) static public func couponsViewController(parentView: UIView?) -> UIViewController { |
15 | - return UIHostingController(rootView: CouponsView()) | 15 | + return UIHostingController(rootView: CouponsView(parentView: parentView!)) |
16 | } | 16 | } |
17 | 17 | ||
18 | } | 18 | } | ... | ... |
... | @@ -15,7 +15,7 @@ | ... | @@ -15,7 +15,7 @@ |
15 | + (void)init:(NSDictionary *)launchOptions uuid:(NSString*)uuid merchantId:(NSString*)merchantId lang:(NSString*)lang; | 15 | + (void)init:(NSDictionary *)launchOptions uuid:(NSString*)uuid merchantId:(NSString*)merchantId lang:(NSString*)lang; |
16 | - (void) setToStage; | 16 | - (void) setToStage; |
17 | - (void) setLang:(NSString*) lang; | 17 | - (void) setLang:(NSString*) lang; |
18 | -- (UIViewController *) openCoupons; | 18 | +- (UIViewController *) openCoupons:(UIView*) parentView; |
19 | - (void) applicationDidEnterBackground:(UIApplication *)application; | 19 | - (void) applicationDidEnterBackground:(UIApplication *)application; |
20 | - (void) applicationWillEnterForeground:(UIApplication *)application; | 20 | - (void) applicationWillEnterForeground:(UIApplication *)application; |
21 | - (void) applicationDidBecomeActive:(UIApplication *)application; | 21 | - (void) applicationDidBecomeActive:(UIApplication *)application; | ... | ... |
... | @@ -46,12 +46,8 @@ NSString *LANG; | ... | @@ -46,12 +46,8 @@ NSString *LANG; |
46 | LANG = lang; | 46 | LANG = lang; |
47 | } | 47 | } |
48 | 48 | ||
49 | -- (UIViewController *) openCoupons{ | 49 | +- (UIViewController *) openCoupons:(UIView*) parentView{ |
50 | - | 50 | + UIViewController *couponsViewController = [CouponsViewInterface couponsViewController:parentView]; |
51 | - UIViewController *couponsViewController = [CouponsViewInterface couponsViewController]; | ||
52 | -// controller = [[UINavigationController alloc]initWithRootViewController:profileViewController]; | ||
53 | - | ||
54 | -// [window makeKeyAndVisible]; | ||
55 | return couponsViewController; | 51 | return couponsViewController; |
56 | } | 52 | } |
57 | 53 | ... | ... |
-
Please register or login to post a comment