2019-07-19 16:42:40 -07:00
|
|
|
//
|
|
|
|
|
// 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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-04 09:52:12 -05:00
|
|
|
@objc final class UpdateCollectionViewCell: UICollectionViewCell
|
2019-07-19 16:42:40 -07:00
|
|
|
{
|
|
|
|
|
var mode: Mode = .expanded {
|
|
|
|
|
didSet {
|
2025-02-27 23:39:03 +05:30
|
|
|
switch self.mode {
|
|
|
|
|
case .collapsed:
|
|
|
|
|
self.versionDescriptionTextView.isCollapsed = true
|
|
|
|
|
case .expanded:
|
|
|
|
|
self.versionDescriptionTextView.isCollapsed = false
|
|
|
|
|
}
|
|
|
|
|
self.setNeedsLayout()
|
2019-07-19 16:42:40 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-23 13:32:17 -07:00
|
|
|
@IBOutlet var bannerView: AppBannerView!
|
2025-02-27 23:39:03 +05:30
|
|
|
// @IBOutlet var versionDescriptionTextView: CollapsingTextView!
|
|
|
|
|
@IBOutlet var versionDescriptionTextView: CollapsingMarkdownView!
|
2019-10-23 13:32:17 -07:00
|
|
|
|
|
|
|
|
@IBOutlet private var blurView: UIVisualEffectView!
|
2019-11-05 18:08:58 -08:00
|
|
|
|
|
|
|
|
private var originalTintColor: UIColor?
|
2019-07-24 12:23:54 -07:00
|
|
|
|
2019-07-19 16:42:40 -07:00
|
|
|
override func awakeFromNib()
|
|
|
|
|
{
|
|
|
|
|
super.awakeFromNib()
|
|
|
|
|
|
2019-10-23 13:32:17 -07:00
|
|
|
// Prevent temporary unsatisfiable constraint errors due to UIView-Encapsulated-Layout constraints.
|
|
|
|
|
self.contentView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
|
|
|
self.contentView.preservesSuperviewLayoutMargins = true
|
|
|
|
|
|
|
|
|
|
self.bannerView.backgroundEffectView.isHidden = true
|
2023-11-30 18:50:54 -06:00
|
|
|
|
2019-10-23 13:32:17 -07:00
|
|
|
self.blurView.layer.cornerRadius = 20
|
|
|
|
|
self.blurView.layer.masksToBounds = true
|
2019-07-19 16:42:40 -07:00
|
|
|
|
|
|
|
|
self.update()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func tintColorDidChange()
|
|
|
|
|
{
|
|
|
|
|
super.tintColorDidChange()
|
|
|
|
|
|
2019-11-05 18:08:58 -08:00
|
|
|
if self.tintAdjustmentMode != .dimmed
|
|
|
|
|
{
|
|
|
|
|
self.originalTintColor = self.tintColor
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-19 16:42:40 -07:00
|
|
|
self.update()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func apply(_ layoutAttributes: UICollectionViewLayoutAttributes)
|
|
|
|
|
{
|
|
|
|
|
// Animates transition to new attributes.
|
|
|
|
|
let animator = UIViewPropertyAnimator(springTimingParameters: UISpringTimingParameters()) {
|
|
|
|
|
self.layoutIfNeeded()
|
|
|
|
|
}
|
|
|
|
|
animator.startAnimation()
|
|
|
|
|
}
|
2019-09-12 13:51:03 -07:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-14 17:16:44 -06:00
|
|
|
|
|
|
|
|
override func systemLayoutSizeFitting(_ targetSize: CGSize, withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, verticalFittingPriority: UILayoutPriority) -> CGSize
|
|
|
|
|
{
|
|
|
|
|
// Ensure cell is laid out so it will report correct size.
|
|
|
|
|
self.versionDescriptionTextView.setNeedsLayout()
|
|
|
|
|
self.versionDescriptionTextView.layoutIfNeeded()
|
|
|
|
|
|
|
|
|
|
let size = super.systemLayoutSizeFitting(targetSize, withHorizontalFittingPriority: horizontalFittingPriority, verticalFittingPriority: verticalFittingPriority)
|
|
|
|
|
|
|
|
|
|
return size
|
|
|
|
|
}
|
2019-07-19 16:42:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private extension UpdateCollectionViewCell
|
|
|
|
|
{
|
|
|
|
|
func update()
|
|
|
|
|
{
|
2019-07-24 12:23:54 -07:00
|
|
|
switch self.mode
|
|
|
|
|
{
|
|
|
|
|
case .collapsed: self.versionDescriptionTextView.isCollapsed = true
|
|
|
|
|
case .expanded: self.versionDescriptionTextView.isCollapsed = false
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-05 18:08:58 -08:00
|
|
|
self.blurView.backgroundColor = self.originalTintColor ?? self.tintColor
|
|
|
|
|
self.bannerView.button.progressTintColor = self.originalTintColor ?? self.tintColor
|
2019-07-19 16:42:40 -07:00
|
|
|
|
|
|
|
|
self.setNeedsLayout()
|
|
|
|
|
self.layoutIfNeeded()
|
|
|
|
|
}
|
|
|
|
|
}
|