// // UpdateCollectionViewCell.swift // AltStore // // Created by Riley Testut on 7/16/19. // Copyright © 2019 Riley Testut. All rights reserved. // import UIKit extension UpdateCollectionViewCell { enum Mode { case collapsed case expanded } } @objc class UpdateCollectionViewCell: UICollectionViewCell { var mode: Mode = .expanded { didSet { self.update() } } @IBOutlet var appIconImageView: UIImageView! @IBOutlet var nameLabel: UILabel! @IBOutlet var dateLabel: UILabel! @IBOutlet var updateButton: PillButton! @IBOutlet var versionDescriptionTitleLabel: UILabel! @IBOutlet var versionDescriptionTextView: CollapsingTextView! @IBOutlet var betaBadgeView: UIImageView! override func awakeFromNib() { super.awakeFromNib() self.contentView.layer.cornerRadius = 20 self.contentView.layer.masksToBounds = true self.update() } override func tintColorDidChange() { super.tintColorDidChange() self.update() } override func apply(_ layoutAttributes: UICollectionViewLayoutAttributes) { // Animates transition to new attributes. let animator = UIViewPropertyAnimator(springTimingParameters: UISpringTimingParameters()) { self.layoutIfNeeded() } animator.startAnimation() } override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { let view = super.hitTest(point, with: event) if view == self.versionDescriptionTextView { // Forward touches on the text view (but not on the nested "more" button) // so cell selection works as expected. return self } else { return view } } } private extension UpdateCollectionViewCell { func update() { switch self.mode { case .collapsed: self.versionDescriptionTextView.isCollapsed = true case .expanded: self.versionDescriptionTextView.isCollapsed = false } self.versionDescriptionTitleLabel.textColor = self.tintColor self.contentView.backgroundColor = self.tintColor.withAlphaComponent(0.1) self.updateButton.setTitleColor(self.tintColor, for: .normal) self.updateButton.backgroundColor = self.tintColor.withAlphaComponent(0.15) self.updateButton.progressTintColor = self.tintColor self.setNeedsLayout() self.layoutIfNeeded() } }