Show highlight on expand thread cell selection

This commit is contained in:
Shadowfacts 2023-01-21 13:14:16 -05:00
parent addcc2dacc
commit ccd1672e72
1 changed files with 16 additions and 3 deletions

View File

@ -8,7 +8,7 @@
import UIKit
class ExpandThreadCollectionViewCell: UICollectionViewCell {
class ExpandThreadCollectionViewCell: UICollectionViewListCell {
private var avatarContainerView: UIView!
private var avatarContainerWidthConstraint: NSLayoutConstraint!
@ -46,8 +46,6 @@ class ExpandThreadCollectionViewCell: UICollectionViewCell {
contentView.addSubview(hStack)
stackViewLeadingConstraint = hStack.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 16)
// TODO: separator
threadLinkView = UIView()
threadLinkView.backgroundColor = .tintColor.withAlphaComponent(0.5)
threadLinkView.layer.cornerRadius = 2.5
@ -142,4 +140,19 @@ class ExpandThreadCollectionViewCell: UICollectionViewCell {
}
}
override func updateConfiguration(using state: UICellConfigurationState) {
var config = UIBackgroundConfiguration.listPlainCell()
if state.isSelected || state.isHighlighted {
var hue: CGFloat = 0
var saturation: CGFloat = 0
var brightness: CGFloat = 0
UIColor.secondarySystemBackground.getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: nil)
let sign: CGFloat = traitCollection.userInterfaceStyle == .dark ? 1 : -1
config.backgroundColor = UIColor(hue: hue, saturation: saturation, brightness: max(0, brightness + sign * 0.1), alpha: 1)
} else {
config.backgroundColor = .secondarySystemBackground
}
backgroundConfiguration = config.updated(for: state)
}
}