Skip to content

Commit 74f2539

Browse files
authored
Adds a capsule background for the unread page count on ThreadListCell (#1217)
1 parent 38f6fb1 commit 74f2539

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

App/View Controllers/Threads/ThreadListCell.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ private let Log = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "Th
99

1010
final class ThreadListCell: UITableViewCell {
1111

12+
private let pageCountBackgroundView = UIView()
1213
private let pageCountLabel = UILabel()
1314
private let pageIconView = UIImageView()
1415
private let postInfoLabel = UILabel()
@@ -30,6 +31,13 @@ final class ThreadListCell: UITableViewCell {
3031
backgroundColor = viewModel.backgroundColor
3132

3233
pageCountLabel.attributedText = viewModel.pageCount
34+
35+
if let color = viewModel.unreadCount.attribute(.foregroundColor, at: 0, effectiveRange: nil) as? UIColor {
36+
pageCountBackgroundView.backgroundColor = color.withAlphaComponent(0.2)
37+
} else {
38+
pageCountBackgroundView.backgroundColor = .clear
39+
}
40+
pageCountBackgroundView.isHidden = viewModel.unreadCount.length == 0
3341

3442
pageIconView.image = UIImage(named: "page")?.withTintColor(viewModel.pageIconColor)
3543

@@ -83,6 +91,7 @@ final class ThreadListCell: UITableViewCell {
8391
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
8492
super.init(style: style, reuseIdentifier: reuseIdentifier)
8593

94+
contentView.addSubview(pageCountBackgroundView)
8695
contentView.addSubview(pageCountLabel)
8796
contentView.addSubview(pageIconView)
8897
contentView.addSubview(postInfoLabel)
@@ -92,6 +101,8 @@ final class ThreadListCell: UITableViewCell {
92101
contentView.addSubview(unreadCountLabel)
93102
contentView.addSubview(secondaryTagImageView)
94103
contentView.addSubview(stickyImageView)
104+
105+
pageCountBackgroundView.clipsToBounds = true
95106
}
96107

97108
required init?(coder: NSCoder) {
@@ -102,6 +113,16 @@ final class ThreadListCell: UITableViewCell {
102113
super.layoutSubviews()
103114

104115
let layout = Layout(width: contentView.bounds.width, viewModel: viewModel)
116+
// Background behind the page count label, with padding and pill shape
117+
if viewModel.unreadCount.length > 0 {
118+
let backgroundPadding = UIEdgeInsets(top: -2, left: -6, bottom: -2, right: -6)
119+
let bgFrame = layout.unreadCountFrame.inset(by: backgroundPadding)
120+
pageCountBackgroundView.frame = bgFrame
121+
pageCountBackgroundView.layer.cornerRadius = bgFrame.height / 2
122+
} else {
123+
pageCountBackgroundView.frame = .zero
124+
}
125+
105126
pageCountLabel.frame = layout.pageCountFrame
106127
pageIconView.frame = layout.pageIconFrame
107128
postInfoLabel.frame = layout.postInfoFrame

0 commit comments

Comments
 (0)