From ccd1672e7252de9e0e88279a91044d82d46e49f7 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 21 Jan 2023 13:14:16 -0500 Subject: [PATCH] Show highlight on expand thread cell selection --- .../ExpandThreadCollectionViewCell.swift | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Tusker/Screens/Conversation/ExpandThreadCollectionViewCell.swift b/Tusker/Screens/Conversation/ExpandThreadCollectionViewCell.swift index 5a40676b..e7e1400d 100644 --- a/Tusker/Screens/Conversation/ExpandThreadCollectionViewCell.swift +++ b/Tusker/Screens/Conversation/ExpandThreadCollectionViewCell.swift @@ -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) + } + }