Manos Chorianopoulos

CouponVC expandables functionality

......@@ -56,6 +56,9 @@ import UIKit
// Constraints for animation
@IBOutlet weak var couponQRContentHeightConstraint: NSLayoutConstraint!
@IBOutlet weak var termsButtonView: UIView!
@IBOutlet weak var termsButtonTitleLabel: UILabel!
@IBOutlet weak var termsButtonArrowImage: UIImageView!
@IBOutlet weak var termsButton: UIButton!
@IBOutlet weak var termsLabel: UILabel!
@IBOutlet weak var termsLabelHeight: NSLayoutConstraint!
......@@ -67,7 +70,7 @@ import UIKit
var coupon: OfferModel?
private var isDetailsExpanded = false
private var isCouponCodeExpanded = false
private var isCouponBarcodeExpanded = false
private var isCouponQRExpanded = false
private var isTermsExpanded = false
public override func viewDidLoad() {
......@@ -89,6 +92,7 @@ import UIKit
copyButtonImage.image = UIImage(named: "copy", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
couponQRArrowImage.image = UIImage(named: "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
couponQRImage.image = UIImage(named: "barcode", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
termsButtonArrowImage.image = UIImage(named: "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
infoLabel.font = UIFont(name: "PingLCG-Regular", size: 13)
infoLabel.textColor = UIColor(rgb: 0x020E1C)
......@@ -99,22 +103,19 @@ import UIKit
couponCodeContainerView.backgroundColor = UIColor(rgb: 0xFFFFFF)
couponCodeContainerView.layer.cornerRadius = 8.0
couponCodeContainerView.clipsToBounds = true
couponCodeButton.addTarget(self, action: #selector(toggleCouponCode), for: .touchUpInside)
couponCodeContentHeightConstraint.constant = 0
couponQRContainerView.backgroundColor = UIColor(rgb: 0xFFFFFF)
couponQRContainerView.layer.cornerRadius = 8.0
couponQRContainerView.clipsToBounds = true
couponQRButton.addTarget(self, action: #selector(toggleCouponQR), for: .touchUpInside)
couponQRContentHeightConstraint.constant = 0
termsButton.titleLabel?.font = UIFont(name: "PingLCG-Bold", size: 16)
// termsButton.imageView?.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1.5)
termsButton.setTitle("Όροι Χρήσης", for: .normal)
termsButton.setTitleColor(UIColor(rgb: 0x020E1C), for: .normal)
termsButton.setImage(UIImage(named: "arrow_down.png", in: MyEmptyClass.resourceBundle(), compatibleWith: nil), for: .normal)
termsButton.semanticContentAttribute = .forceRightToLeft
termsButton.tintColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 1.00)
termsButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 0);
termsButton.titleEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 5);
termsButton.imageView?.layer.transform = CATransform3DMakeScale(0.8, 0.8, 0.8)
termsButtonTitleLabel.font = UIFont(name: "PingLCG-Bold", size: 16)
termsButtonTitleLabel.textColor = UIColor(rgb: 0x020E1C)
termsButtonTitleLabel.text = "Όροι Χρήσης"
termsButton.addTarget(self, action: #selector(toggleTerms), for: .touchUpInside)
termsLabelHeight.constant = 0
mapButton.titleLabel?.font = UIFont(name: "PingLCG-Bold", size: 16)
......@@ -180,12 +181,12 @@ import UIKit
detailsLabel.textColor = UIColor(rgb: 0x020E1C)
// Add tap gesture
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(toggleDetailsExpansion))
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(toggleDetails))
detailsLabel.isUserInteractionEnabled = true
detailsLabel.addGestureRecognizer(tapGesture)
}
@objc private func toggleDetailsExpansion() {
@objc private func toggleDetails() {
isDetailsExpanded.toggle()
UIView.animate(withDuration: 0.3) {
......@@ -193,4 +194,34 @@ import UIKit
self.view.layoutIfNeeded()
}
}
@objc private func toggleCouponCode() {
isCouponCodeExpanded.toggle()
UIView.animate(withDuration: 0.3) {
self.couponCodeArrowImage.image = UIImage(named: self.isCouponCodeExpanded ? "arrow_up" : "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
self.couponCodeContentHeightConstraint.constant = self.isCouponCodeExpanded ? self.couponCodeContentView.intrinsicContentSize.height : 0
self.view.layoutIfNeeded()
}
}
@objc private func toggleCouponQR() {
isCouponQRExpanded.toggle()
UIView.animate(withDuration: 0.3) {
self.couponQRArrowImage.image = UIImage(named: self.isCouponQRExpanded ? "arrow_up" : "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
self.couponQRContentHeightConstraint.constant = self.isCouponQRExpanded ? self.couponQRContentView.intrinsicContentSize.height : 0
self.view.layoutIfNeeded()
}
}
@objc private func toggleTerms() {
isTermsExpanded.toggle()
UIView.animate(withDuration: 0.3) {
self.termsButtonArrowImage.image = UIImage(named: self.isTermsExpanded ? "arrow_up" : "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
self.termsLabelHeight.constant = self.isTermsExpanded ? self.termsLabel.intrinsicContentSize.height : 0
self.view.layoutIfNeeded()
}
}
}
......