Vasilis
......@@ -7,7 +7,7 @@
<key>Pods-WarplySDKFrameworkIOS.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>0</integer>
</dict>
</dict>
</dict>
......
......@@ -7,7 +7,7 @@
<key>WarplySDKFrameworkIOS.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>1</integer>
</dict>
</dict>
</dict>
......
......@@ -57,7 +57,8 @@ extension CampaignWebview {
}
func updateUIView(_ webView: WKWebView, context: Context) {
let request = URLRequest(url: URL(string: url)!)
var request = URLRequest(url: URL(string: url)!)
request.cachePolicy = .reloadRevalidatingCacheData
webView.load(request)
}
}
......
......@@ -5,18 +5,194 @@
// Created by Βασιλης Σκουρας on 21/4/22.
//
#if canImport(SwiftUI)
import SwiftUI
import Combine
import Foundation
import UIKit
struct CouponView: View {
extension CouponView {
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("Εκπτωτικό κουπόνι")
.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 couponContainer: View {
@State var coupon: Dictionary<String, Any>
// @State var couponset:CouponSetItemModel
var uiscreen = UIScreen.main.bounds
var body: some View {
GeometryReader { geometry in
ScrollView(showsIndicators: false) {
VStack(alignment: .leading) {
ImageView(withURL: coupon["img_preview"] as? String ?? "")
Text(coupon["name"] as? String ?? "")
.fontWeight(.bold)
.font(.system(size: 16))
.foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
.multilineTextAlignment(.leading)
.padding(.horizontal)
.padding(.top, self.uiscreen.height * 0.04)
Text(coupon["short_description"] as? String ?? "")
.fontWeight(.regular)
.font(.system(size: 14))
.foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
.multilineTextAlignment(.leading)
.padding(.horizontal)
.padding(.top, self.uiscreen.height * 0.02)
Spacer()
VStack(alignment: .center) {
Button {
// Button Action
print("Back Button tapped!")
} label: {
HStack {
Text("Απόκτησέ το")
.fontWeight(.medium)
.font(.system(size: 16))
.foregroundColor(Color.white)
.multilineTextAlignment(.center)
.padding(.all)
}
}
.frame(width: self.uiscreen.width * 0.8)
.background(Color(red: 0.4745098039215686, green: 0.7490196078431373, blue: 0.0784313725490196))
.cornerRadius(7)
}
.frame(maxWidth: .infinity)
.padding(.top, self.uiscreen.height * 0.06)
Button {
// Button Action
print("Terms Button tapped!")
} label: {
Text("Όροι χρήσης")
.fontWeight(.medium)
.font(.system(size: 14))
.foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
.underline()
.multilineTextAlignment(.center)
.padding(.vertical, self.uiscreen.height * 0.03)
.padding(.horizontal)
.frame(maxWidth: .infinity)
}
.frame(maxWidth: .infinity)
}
.frame(width:self.uiscreen.width)
.frame(minHeight: geometry.size.height)
.padding(.bottom, self.uiscreen.height * 0.03)
}
.frame(width:self.uiscreen.width)
.frame(maxHeight: .infinity)
}
.frame(width:self.uiscreen.width)
.frame(maxHeight: .infinity)
}
}
struct ImageView: View {
@ObservedObject var imageLoader:ImageLoaderGifts
@State var image:UIImage = UIImage()
var uiscreen = UIScreen.main.bounds
init(withURL url:String) {
imageLoader = ImageLoaderGifts(urlString:url)
}
var body: some View {
Image(uiImage: image)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: self.uiscreen.width, height: self.uiscreen.height * 0.25)
.onReceive(imageLoader.didChange) { data in
self.image = UIImage(data: data) ?? UIImage()
}
}
}
}
@available(iOS 13.0.0, *)
struct CouponView: View {
var parentView: UIView
var coupon: Dictionary<String, Any>
@State var couponset: CouponSetItemModel?
var uiscreen = UIScreen.main.bounds
func goBack() {
for subview in parentView.subviews {
if(subview.tag == 2) {
subview.removeFromSuperview()
}
}
}
var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
VStack {
headerView(goBack: goBack)
VStack {
couponContainer(coupon: coupon)
}
.background(Color.white)
.cornerRadius(30, corners: [.topLeft])
.frame(width:self.uiscreen.width)
.frame(maxHeight: .infinity)
}
.edgesIgnoringSafeArea([.bottom])
.frame(width:self.uiscreen.width)
.frame(maxHeight: .infinity)
// .onAppear {
// // If you want to setup data with model
// couponset = CouponSetItemModel(dictionary: coupon)
//
// }
}
}
#endif
//struct CouponView_Previews: PreviewProvider {
// static var previews: some View {
......
......@@ -11,8 +11,8 @@ import SwiftUI
@available(iOS 13.0.0, *)
@objc public class CouponViewInterface : NSObject {
@objc(couponViewController:) static public func couponViewController(parentView: UIView?) -> UIViewController {
return UIHostingController(rootView: CouponView(parentView: parentView!))
@objc(couponViewController::) static public func couponViewController(parentView: UIView?, coupon: Dictionary<String, Any>) -> UIViewController {
return UIHostingController(rootView: CouponView(parentView: parentView!, coupon: coupon))
}
}
......
......@@ -11,7 +11,6 @@ import SwiftUI
import Combine
import Foundation
import UIKit
import WarplySDKFrameworkIOS
class CouponSetItemModel {
......@@ -40,12 +39,25 @@ class CouponSetItemModel {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd hh:mm"
let date = dateFormatter.date(from: expirationString ?? "")
dateFormatter.dateFormat = "dd/MM/yyyy"
let resultString = dateFormatter.string(from: date!)
self.expiration = resultString
if let date = dateFormatter.date(from: expirationString ?? "") {
dateFormatter.dateFormat = "dd/MM/yyyy"
let resultString = dateFormatter.string(from: date)
self.expiration = resultString
} else {
self.expiration = ""
}
}
var asDictionary : [String:Any] {
let mirror = Mirror(reflecting: self)
let dict = Dictionary(uniqueKeysWithValues: mirror.children.lazy.map({ (label:String?, value:Any) -> (String, Any)? in
guard let label = label else { return nil }
return (label, value)
}).compactMap { $0 })
return dict
}
}
class CouponDataModel {
......@@ -382,6 +394,7 @@ extension GiftsView {
struct couponsContainer: View {
@State var coupons:Array<CouponSetItemModel> = []
@State var title:String = ""
@State var parentView:UIView
var uiscreen = UIScreen.main.bounds
......@@ -401,7 +414,7 @@ extension GiftsView {
HStack(alignment: .center) {
ForEach(Array(coupons.enumerated()), id: \.offset) { index, item in
couponItemView(item: item, isFirst: index == 0, isLast: index == (coupons.count-1))
couponItemView(item: item, isFirst: index == 0, isLast: index == (coupons.count-1), parentView: parentView)
}
}
......@@ -419,13 +432,21 @@ extension GiftsView {
var item: CouponSetItemModel
var isFirst: Bool
var isLast: Bool
var parentView: UIView
var uiscreen = UIScreen.main.bounds
var body: some View {
Button {
// GiftItem Action
print("GiftItem tapped!")
let tempItem = item.asDictionary
let instanceOfMyApi = MyApi()
let couponViewController = instanceOfMyApi.openCoupon(parentView, coupon: tempItem)!
couponViewController.view.tag = 2
// addChild(couponsViewController)
couponViewController.view.frame = parentView.frame
parentView.addSubview(couponViewController.view)
couponViewController.didMove(toParent: UIHostingController(rootView: self))
} label: {
HStack(alignment: .center) {
......@@ -547,7 +568,7 @@ struct GiftsView: View {
}
if (coupons.count) > 0 {
couponsContainer(coupons: coupons, title: "ΚΟΥΠΟΝΙΑ" )
couponsContainer(coupons: coupons, title: "ΚΟΥΠΟΝΙΑ", parentView: parentView )
}
}
......
......@@ -18,7 +18,7 @@
- (void) setToStage;
- (void) setLang:(NSString*) lang;
- (UIViewController *) openCoupons:(UIView*) parentView;
- (UIViewController *) openCoupon:(UIView*) parentView;
- (UIViewController *) openCoupon:(UIView*) parentView coupon:(NSDictionary*) coupon;
- (UIViewController *) openGifts:(UIView*) parentView;
- (UIViewController *) openWallet:(UIView*) parentView;
- (UIViewController *) openMoreForYou:(UIView*) parentView;
......
......@@ -53,9 +53,9 @@ NSString *LANG;
return couponsViewController;
}
- (UIViewController *) openCoupon:(UIView*) parentView{
- (UIViewController *) openCoupon:(UIView*) parentView coupon:(NSDictionary*) coupon {
UIViewController *couponViewController = [CouponViewInterface couponViewController:parentView];
UIViewController *couponViewController = [CouponViewInterface couponViewController:parentView :coupon];
return couponViewController;
}
......