Manos Chorianopoulos

CouponViewController fixes

...@@ -26,7 +26,6 @@ import UIKit ...@@ -26,7 +26,6 @@ import UIKit
26 @IBOutlet weak var couponCodeContainerView: UIView! 26 @IBOutlet weak var couponCodeContainerView: UIView!
27 @IBOutlet weak var couponCodeHeaderView: UIView! 27 @IBOutlet weak var couponCodeHeaderView: UIView!
28 @IBOutlet weak var couponCodeContentView: UIView! 28 @IBOutlet weak var couponCodeContentView: UIView!
29 - @IBOutlet weak var couponCodeContainerViewHeight: NSLayoutConstraint!
30 29
31 // Header elements 30 // Header elements
32 @IBOutlet weak var couponCodeTitleLabel: UILabel! 31 @IBOutlet weak var couponCodeTitleLabel: UILabel!
...@@ -45,7 +44,6 @@ import UIKit ...@@ -45,7 +44,6 @@ import UIKit
45 @IBOutlet weak var couponQRContainerView: UIView! 44 @IBOutlet weak var couponQRContainerView: UIView!
46 @IBOutlet weak var couponQRHeaderView: UIView! 45 @IBOutlet weak var couponQRHeaderView: UIView!
47 @IBOutlet weak var couponQRContentView: UIView! 46 @IBOutlet weak var couponQRContentView: UIView!
48 - @IBOutlet weak var couponQRContainerViewHeight: NSLayoutConstraint!
49 47
50 // Header elements 48 // Header elements
51 @IBOutlet weak var couponQRTitleLabel: UILabel! 49 @IBOutlet weak var couponQRTitleLabel: UILabel!
...@@ -108,7 +106,6 @@ import UIKit ...@@ -108,7 +106,6 @@ import UIKit
108 couponCodeButton.addTarget(self, action: #selector(toggleCouponCode), for: .touchUpInside) 106 couponCodeButton.addTarget(self, action: #selector(toggleCouponCode), for: .touchUpInside)
109 couponCodeContentHeightConstraint.constant = 0 107 couponCodeContentHeightConstraint.constant = 0
110 couponCodeContentView.isHidden = true 108 couponCodeContentView.isHidden = true
111 - couponCodeContainerViewHeight.constant = couponCodeContainerView.intrinsicContentSize.height
112 109
113 couponQRContainerView.backgroundColor = UIColor(rgb: 0xFFFFFF) 110 couponQRContainerView.backgroundColor = UIColor(rgb: 0xFFFFFF)
114 couponQRContainerView.layer.cornerRadius = 8.0 111 couponQRContainerView.layer.cornerRadius = 8.0
...@@ -116,7 +113,6 @@ import UIKit ...@@ -116,7 +113,6 @@ import UIKit
116 couponQRButton.addTarget(self, action: #selector(toggleCouponQR), for: .touchUpInside) 113 couponQRButton.addTarget(self, action: #selector(toggleCouponQR), for: .touchUpInside)
117 couponQRContentHeightConstraint.constant = 0 114 couponQRContentHeightConstraint.constant = 0
118 couponQRContentView.isHidden = true 115 couponQRContentView.isHidden = true
119 - couponQRContainerViewHeight.constant = couponQRContainerView.intrinsicContentSize.height
120 116
121 termsButtonTitleLabel.font = UIFont(name: "PingLCG-Bold", size: 16) 117 termsButtonTitleLabel.font = UIFont(name: "PingLCG-Bold", size: 16)
122 termsButtonTitleLabel.textColor = UIColor(rgb: 0x020E1C) 118 termsButtonTitleLabel.textColor = UIColor(rgb: 0x020E1C)
...@@ -204,24 +200,74 @@ import UIKit ...@@ -204,24 +200,74 @@ import UIKit
204 @objc private func toggleCouponCode() { 200 @objc private func toggleCouponCode() {
205 isCouponCodeExpanded.toggle() 201 isCouponCodeExpanded.toggle()
206 202
207 - UIView.animate(withDuration: 0.3) { 203 + // Calculate the target height before animation
208 - self.couponCodeArrowImage.image = UIImage(named: self.isCouponCodeExpanded ? "arrow_up" : "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) 204 + let targetHeight: CGFloat = isCouponCodeExpanded ? 80.67 : 0 // Set a fixed height instead of intrinsicContentSize
209 - self.couponCodeContentHeightConstraint.constant = self.isCouponCodeExpanded ? self.couponCodeContentView.intrinsicContentSize.height : 0 205 +
210 - self.couponCodeContentView.isHidden = !self.isCouponCodeExpanded 206 + // Show content immediately if expanding
211 - self.couponCodeContainerViewHeight.constant = self.couponCodeContainerView.intrinsicContentSize.height 207 + if isCouponCodeExpanded {
208 + couponCodeContentView.isHidden = false
209 + couponCodeContentView.alpha = 0
210 + }
211 +
212 + UIView.animate(withDuration: 0.3, animations: {
213 + // // Update arrow image
214 + // self.couponCodeArrowImage.image = UIImage(named: self.isCouponCodeExpanded ? "arrow_up" : "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
215 +
216 + // Update arrow with rotation
217 + let rotation = self.isCouponCodeExpanded ? CGAffineTransform(rotationAngle: .pi) : .identity
218 + self.couponCodeArrowImage.transform = rotation
219 +
220 + // Update height constraint
221 + self.couponCodeContentHeightConstraint.constant = targetHeight
222 +
223 + // Update alpha for smooth fade
224 + self.couponCodeContentView.alpha = self.isCouponCodeExpanded ? 1.0 : 0.0
225 +
226 + // Force layout update
212 self.view.layoutIfNeeded() 227 self.view.layoutIfNeeded()
228 +
229 + }) { _ in
230 + // Hide content after animation completes if collapsing
231 + if !self.isCouponCodeExpanded {
232 + self.couponCodeContentView.isHidden = true
233 + }
213 } 234 }
214 } 235 }
215 236
216 @objc private func toggleCouponQR() { 237 @objc private func toggleCouponQR() {
217 isCouponQRExpanded.toggle() 238 isCouponQRExpanded.toggle()
218 239
219 - UIView.animate(withDuration: 0.3) { 240 + // Calculate the target height before animation
220 - self.couponQRArrowImage.image = UIImage(named: self.isCouponQRExpanded ? "arrow_up" : "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) 241 + let targetHeight: CGFloat = isCouponQRExpanded ? 250 : 0 // Set a fixed height for QR code
221 - self.couponQRContentHeightConstraint.constant = self.isCouponQRExpanded ? self.couponQRContentView.intrinsicContentSize.height : 0 242 +
222 - self.couponQRContentView.isHidden = !self.isCouponQRExpanded 243 + // Show content immediately if expanding
223 - self.couponQRContainerViewHeight.constant = self.couponQRContainerView.intrinsicContentSize.height 244 + if isCouponQRExpanded {
245 + couponQRContentView.isHidden = false
246 + couponQRContentView.alpha = 0
247 + }
248 +
249 + UIView.animate(withDuration: 0.3, animations: {
250 + // Update arrow image
251 + // self.couponQRArrowImage.image = UIImage(named: self.isCouponQRExpanded ? "arrow_up" : "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
252 +
253 + // Update arrow with rotation
254 + let rotation = self.isCouponQRExpanded ? CGAffineTransform(rotationAngle: .pi) : .identity
255 + self.couponQRArrowImage.transform = rotation
256 +
257 + // Update height constraint
258 + self.couponQRContentHeightConstraint.constant = targetHeight
259 +
260 + // Update alpha for smooth fade
261 + self.couponQRContentView.alpha = self.isCouponQRExpanded ? 1.0 : 0.0
262 +
263 + // Force layout update
224 self.view.layoutIfNeeded() 264 self.view.layoutIfNeeded()
265 +
266 + }) { _ in
267 + // Hide content after animation completes if collapsing
268 + if !self.isCouponQRExpanded {
269 + self.couponQRContentView.isHidden = true
270 + }
225 } 271 }
226 } 272 }
227 273
...@@ -229,7 +275,12 @@ import UIKit ...@@ -229,7 +275,12 @@ import UIKit
229 isTermsExpanded.toggle() 275 isTermsExpanded.toggle()
230 276
231 UIView.animate(withDuration: 0.3) { 277 UIView.animate(withDuration: 0.3) {
232 - self.termsButtonArrowImage.image = UIImage(named: self.isTermsExpanded ? "arrow_up" : "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) 278 + // self.termsButtonArrowImage.image = UIImage(named: self.isTermsExpanded ? "arrow_up" : "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
279 +
280 + // Update arrow with rotation
281 + let rotation = self.isTermsExpanded ? CGAffineTransform(rotationAngle: .pi) : .identity
282 + self.termsButtonArrowImage.transform = rotation
283 +
233 self.termsLabelHeight.constant = self.isTermsExpanded ? self.termsLabel.intrinsicContentSize.height : 0 284 self.termsLabelHeight.constant = self.isTermsExpanded ? self.termsLabel.intrinsicContentSize.height : 0
234 self.view.layoutIfNeeded() 285 self.view.layoutIfNeeded()
235 } 286 }
......