Manos Chorianopoulos

CouponVC expandables functionality

...@@ -56,6 +56,9 @@ import UIKit ...@@ -56,6 +56,9 @@ import UIKit
56 // Constraints for animation 56 // Constraints for animation
57 @IBOutlet weak var couponQRContentHeightConstraint: NSLayoutConstraint! 57 @IBOutlet weak var couponQRContentHeightConstraint: NSLayoutConstraint!
58 58
59 + @IBOutlet weak var termsButtonView: UIView!
60 + @IBOutlet weak var termsButtonTitleLabel: UILabel!
61 + @IBOutlet weak var termsButtonArrowImage: UIImageView!
59 @IBOutlet weak var termsButton: UIButton! 62 @IBOutlet weak var termsButton: UIButton!
60 @IBOutlet weak var termsLabel: UILabel! 63 @IBOutlet weak var termsLabel: UILabel!
61 @IBOutlet weak var termsLabelHeight: NSLayoutConstraint! 64 @IBOutlet weak var termsLabelHeight: NSLayoutConstraint!
...@@ -67,7 +70,7 @@ import UIKit ...@@ -67,7 +70,7 @@ import UIKit
67 var coupon: OfferModel? 70 var coupon: OfferModel?
68 private var isDetailsExpanded = false 71 private var isDetailsExpanded = false
69 private var isCouponCodeExpanded = false 72 private var isCouponCodeExpanded = false
70 - private var isCouponBarcodeExpanded = false 73 + private var isCouponQRExpanded = false
71 private var isTermsExpanded = false 74 private var isTermsExpanded = false
72 75
73 public override func viewDidLoad() { 76 public override func viewDidLoad() {
...@@ -89,6 +92,7 @@ import UIKit ...@@ -89,6 +92,7 @@ import UIKit
89 copyButtonImage.image = UIImage(named: "copy", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) 92 copyButtonImage.image = UIImage(named: "copy", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
90 couponQRArrowImage.image = UIImage(named: "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) 93 couponQRArrowImage.image = UIImage(named: "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
91 couponQRImage.image = UIImage(named: "barcode", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) 94 couponQRImage.image = UIImage(named: "barcode", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
95 + termsButtonArrowImage.image = UIImage(named: "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
92 96
93 infoLabel.font = UIFont(name: "PingLCG-Regular", size: 13) 97 infoLabel.font = UIFont(name: "PingLCG-Regular", size: 13)
94 infoLabel.textColor = UIColor(rgb: 0x020E1C) 98 infoLabel.textColor = UIColor(rgb: 0x020E1C)
...@@ -99,22 +103,19 @@ import UIKit ...@@ -99,22 +103,19 @@ import UIKit
99 couponCodeContainerView.backgroundColor = UIColor(rgb: 0xFFFFFF) 103 couponCodeContainerView.backgroundColor = UIColor(rgb: 0xFFFFFF)
100 couponCodeContainerView.layer.cornerRadius = 8.0 104 couponCodeContainerView.layer.cornerRadius = 8.0
101 couponCodeContainerView.clipsToBounds = true 105 couponCodeContainerView.clipsToBounds = true
106 + couponCodeButton.addTarget(self, action: #selector(toggleCouponCode), for: .touchUpInside)
107 + couponCodeContentHeightConstraint.constant = 0
102 108
103 couponQRContainerView.backgroundColor = UIColor(rgb: 0xFFFFFF) 109 couponQRContainerView.backgroundColor = UIColor(rgb: 0xFFFFFF)
104 couponQRContainerView.layer.cornerRadius = 8.0 110 couponQRContainerView.layer.cornerRadius = 8.0
105 couponQRContainerView.clipsToBounds = true 111 couponQRContainerView.clipsToBounds = true
112 + couponQRButton.addTarget(self, action: #selector(toggleCouponQR), for: .touchUpInside)
113 + couponQRContentHeightConstraint.constant = 0
106 114
107 - termsButton.titleLabel?.font = UIFont(name: "PingLCG-Bold", size: 16) 115 + termsButtonTitleLabel.font = UIFont(name: "PingLCG-Bold", size: 16)
108 -// termsButton.imageView?.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1.5) 116 + termsButtonTitleLabel.textColor = UIColor(rgb: 0x020E1C)
109 - termsButton.setTitle("Όροι Χρήσης", for: .normal) 117 + termsButtonTitleLabel.text = "Όροι Χρήσης"
110 - termsButton.setTitleColor(UIColor(rgb: 0x020E1C), for: .normal) 118 + termsButton.addTarget(self, action: #selector(toggleTerms), for: .touchUpInside)
111 - termsButton.setImage(UIImage(named: "arrow_down.png", in: MyEmptyClass.resourceBundle(), compatibleWith: nil), for: .normal)
112 - termsButton.semanticContentAttribute = .forceRightToLeft
113 - termsButton.tintColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 1.00)
114 - termsButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 0);
115 - termsButton.titleEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 5);
116 - termsButton.imageView?.layer.transform = CATransform3DMakeScale(0.8, 0.8, 0.8)
117 -
118 termsLabelHeight.constant = 0 119 termsLabelHeight.constant = 0
119 120
120 mapButton.titleLabel?.font = UIFont(name: "PingLCG-Bold", size: 16) 121 mapButton.titleLabel?.font = UIFont(name: "PingLCG-Bold", size: 16)
...@@ -180,12 +181,12 @@ import UIKit ...@@ -180,12 +181,12 @@ import UIKit
180 detailsLabel.textColor = UIColor(rgb: 0x020E1C) 181 detailsLabel.textColor = UIColor(rgb: 0x020E1C)
181 182
182 // Add tap gesture 183 // Add tap gesture
183 - let tapGesture = UITapGestureRecognizer(target: self, action: #selector(toggleDetailsExpansion)) 184 + let tapGesture = UITapGestureRecognizer(target: self, action: #selector(toggleDetails))
184 detailsLabel.isUserInteractionEnabled = true 185 detailsLabel.isUserInteractionEnabled = true
185 detailsLabel.addGestureRecognizer(tapGesture) 186 detailsLabel.addGestureRecognizer(tapGesture)
186 } 187 }
187 188
188 - @objc private func toggleDetailsExpansion() { 189 + @objc private func toggleDetails() {
189 isDetailsExpanded.toggle() 190 isDetailsExpanded.toggle()
190 191
191 UIView.animate(withDuration: 0.3) { 192 UIView.animate(withDuration: 0.3) {
...@@ -193,4 +194,34 @@ import UIKit ...@@ -193,4 +194,34 @@ import UIKit
193 self.view.layoutIfNeeded() 194 self.view.layoutIfNeeded()
194 } 195 }
195 } 196 }
197 +
198 + @objc private func toggleCouponCode() {
199 + isCouponCodeExpanded.toggle()
200 +
201 + UIView.animate(withDuration: 0.3) {
202 + self.couponCodeArrowImage.image = UIImage(named: self.isCouponCodeExpanded ? "arrow_up" : "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
203 + self.couponCodeContentHeightConstraint.constant = self.isCouponCodeExpanded ? self.couponCodeContentView.intrinsicContentSize.height : 0
204 + self.view.layoutIfNeeded()
205 + }
206 + }
207 +
208 + @objc private func toggleCouponQR() {
209 + isCouponQRExpanded.toggle()
210 +
211 + UIView.animate(withDuration: 0.3) {
212 + self.couponQRArrowImage.image = UIImage(named: self.isCouponQRExpanded ? "arrow_up" : "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
213 + self.couponQRContentHeightConstraint.constant = self.isCouponQRExpanded ? self.couponQRContentView.intrinsicContentSize.height : 0
214 + self.view.layoutIfNeeded()
215 + }
216 + }
217 +
218 + @objc private func toggleTerms() {
219 + isTermsExpanded.toggle()
220 +
221 + UIView.animate(withDuration: 0.3) {
222 + self.termsButtonArrowImage.image = UIImage(named: self.isTermsExpanded ? "arrow_up" : "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
223 + self.termsLabelHeight.constant = self.isTermsExpanded ? self.termsLabel.intrinsicContentSize.height : 0
224 + self.view.layoutIfNeeded()
225 + }
226 + }
196 } 227 }
......