Show background color before image loads (when the view is a placeholder). Give a corner radius to large thumbnails.

This commit is contained in:
Brent Simmons committed 2026-11-05 20:34:32 -08:00
1 parent eac971b275
commit cd6dd9ab29
5 files changed
+37 -20

No files matched your search

+16 -7
View File
@@ -38,7 +38,7 @@ final class MainTimelineCell: UICollectionViewCell {
thumbnailView.image
}
set {
thumbnailView.image = newValue
setThumbnailImage(newValue)
}
}
@@ -55,7 +55,7 @@ final class MainTimelineCell: UICollectionViewCell {
override func prepareForReuse() {
super.prepareForReuse()
indicatorView.isHidden = true
thumbnailView.image = nil
setThumbnailImage(nil)
}
override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
@@ -77,7 +77,8 @@ final class MainTimelineCell: UICollectionViewCell {
feedNameView.setFrameIfNotEqual(layout.feedNameRect)
dateView.setFrameIfNotEqual(layout.dateRect)
iconView.setFrameIfNotEqual(layout.iconImageRect)
thumbnailView.setFrameIfNotEqual(layout.thumbnailRect)
// Sized to the image, so the corner radius rounds the image itself. All of the rect until the image arrives.
thumbnailView.setFrameIfNotEqual(layout.thumbnailRect.aspectFitRect(for: thumbnailView.image?.size ?? .zero))
indicatorView.setFrameIfNotEqual(cellData.starred ? layout.starRect : layout.unreadIndicatorRect)
topSeparator.frame = CGRect(x: layout.separatorRect.minX, y: 0, width: layout.separatorRect.width, height: 1.0 / traitCollection.displayScale)
}
@@ -165,6 +166,7 @@ private extension MainTimelineCell {
thumbnailView.contentMode = .scaleAspectFit
thumbnailView.clipsToBounds = true
thumbnailView.layer.cornerRadius = MainTimelineDefaultCellLayout.thumbnailCornerRadius
thumbnailView.backgroundColor = Assets.Colors.thumbnailPlaceholder
for view in [titleView, summaryView, dateView, feedNameView, iconView, indicatorView, thumbnailView, topSeparator] {
contentView.addSubview(view)
view.isAccessibilityElement = false
@@ -183,6 +185,15 @@ private extension MainTimelineCell {
return MainTimelineDefaultCellLayout(width: width, insets: .zero, cellData: cellData)
}
/// Lays out again, since the thumbnail view is sized to the image. The placeholder color shows until there’s an image.
func setThumbnailImage(_ image: UIImage?) {
if thumbnailView.image !== image {
thumbnailView.image = image
thumbnailView.backgroundColor = image == nil ? Assets.Colors.thumbnailPlaceholder : nil
setNeedsLayout()
}
}
func setFrame(for label: UILabel, rect: CGRect) {
if Int(floor(rect.height)) == 0 || Int(floor(rect.width)) == 0 {
label.isHidden = true
@@ -224,12 +235,10 @@ private extension MainTimelineCell {
}
if cellData.showThumbnail {
thumbnailView.image = cellData.thumbnail
// Matches the Mac. The fill shows around the image, and in place of it until it arrives.
thumbnailView.backgroundColor = cellData.thumbnailsDisplay == .large ? .tertiarySystemFill : .systemFill
setThumbnailImage(cellData.thumbnail)
thumbnailView.isHidden = false
} else {
thumbnailView.image = nil
setThumbnailImage(nil)
thumbnailView.isHidden = true
}