Manos Chorianopoulos

CouponViewController fixes

......@@ -26,7 +26,6 @@ import UIKit
@IBOutlet weak var couponCodeContainerView: UIView!
@IBOutlet weak var couponCodeHeaderView: UIView!
@IBOutlet weak var couponCodeContentView: UIView!
@IBOutlet weak var couponCodeContainerViewHeight: NSLayoutConstraint!
// Header elements
@IBOutlet weak var couponCodeTitleLabel: UILabel!
......@@ -45,7 +44,6 @@ import UIKit
@IBOutlet weak var couponQRContainerView: UIView!
@IBOutlet weak var couponQRHeaderView: UIView!
@IBOutlet weak var couponQRContentView: UIView!
@IBOutlet weak var couponQRContainerViewHeight: NSLayoutConstraint!
// Header elements
@IBOutlet weak var couponQRTitleLabel: UILabel!
......@@ -108,7 +106,6 @@ import UIKit
couponCodeButton.addTarget(self, action: #selector(toggleCouponCode), for: .touchUpInside)
couponCodeContentHeightConstraint.constant = 0
couponCodeContentView.isHidden = true
couponCodeContainerViewHeight.constant = couponCodeContainerView.intrinsicContentSize.height
couponQRContainerView.backgroundColor = UIColor(rgb: 0xFFFFFF)
couponQRContainerView.layer.cornerRadius = 8.0
......@@ -116,7 +113,6 @@ import UIKit
couponQRButton.addTarget(self, action: #selector(toggleCouponQR), for: .touchUpInside)
couponQRContentHeightConstraint.constant = 0
couponQRContentView.isHidden = true
couponQRContainerViewHeight.constant = couponQRContainerView.intrinsicContentSize.height
termsButtonTitleLabel.font = UIFont(name: "PingLCG-Bold", size: 16)
termsButtonTitleLabel.textColor = UIColor(rgb: 0x020E1C)
......@@ -204,32 +200,87 @@ import UIKit
@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.couponCodeContentView.isHidden = !self.isCouponCodeExpanded
self.couponCodeContainerViewHeight.constant = self.couponCodeContainerView.intrinsicContentSize.height
// Calculate the target height before animation
let targetHeight: CGFloat = isCouponCodeExpanded ? 80.67 : 0 // Set a fixed height instead of intrinsicContentSize
// Show content immediately if expanding
if isCouponCodeExpanded {
couponCodeContentView.isHidden = false
couponCodeContentView.alpha = 0
}
UIView.animate(withDuration: 0.3, animations: {
// // Update arrow image
// self.couponCodeArrowImage.image = UIImage(named: self.isCouponCodeExpanded ? "arrow_up" : "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
// Update arrow with rotation
let rotation = self.isCouponCodeExpanded ? CGAffineTransform(rotationAngle: .pi) : .identity
self.couponCodeArrowImage.transform = rotation
// Update height constraint
self.couponCodeContentHeightConstraint.constant = targetHeight
// Update alpha for smooth fade
self.couponCodeContentView.alpha = self.isCouponCodeExpanded ? 1.0 : 0.0
// Force layout update
self.view.layoutIfNeeded()
}) { _ in
// Hide content after animation completes if collapsing
if !self.isCouponCodeExpanded {
self.couponCodeContentView.isHidden = true
}
}
}
@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.couponQRContentView.isHidden = !self.isCouponQRExpanded
self.couponQRContainerViewHeight.constant = self.couponQRContainerView.intrinsicContentSize.height
// Calculate the target height before animation
let targetHeight: CGFloat = isCouponQRExpanded ? 250 : 0 // Set a fixed height for QR code
// Show content immediately if expanding
if isCouponQRExpanded {
couponQRContentView.isHidden = false
couponQRContentView.alpha = 0
}
UIView.animate(withDuration: 0.3, animations: {
// Update arrow image
// self.couponQRArrowImage.image = UIImage(named: self.isCouponQRExpanded ? "arrow_up" : "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
// Update arrow with rotation
let rotation = self.isCouponQRExpanded ? CGAffineTransform(rotationAngle: .pi) : .identity
self.couponQRArrowImage.transform = rotation
// Update height constraint
self.couponQRContentHeightConstraint.constant = targetHeight
// Update alpha for smooth fade
self.couponQRContentView.alpha = self.isCouponQRExpanded ? 1.0 : 0.0
// Force layout update
self.view.layoutIfNeeded()
}) { _ in
// Hide content after animation completes if collapsing
if !self.isCouponQRExpanded {
self.couponQRContentView.isHidden = true
}
}
}
@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.termsButtonArrowImage.image = UIImage(named: self.isTermsExpanded ? "arrow_up" : "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
// Update arrow with rotation
let rotation = self.isTermsExpanded ? CGAffineTransform(rotationAngle: .pi) : .identity
self.termsButtonArrowImage.transform = rotation
self.termsLabelHeight.constant = self.isTermsExpanded ? self.termsLabel.intrinsicContentSize.height : 0
self.view.layoutIfNeeded()
}
......