From cd6dd9ab29ec27ec99dc23ec48e6ceea54f266e7 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 5 Nov 2026 20:34:32 -0800 Subject: [PATCH] Show background color before image loads (when the view is a placeholder). Give a corner radius to large thumbnails. --- Mac/MainWindow/IconView.swift | 9 +++----- .../Timeline/Cell/ThumbnailView.swift | 5 +++- .../Timeline/Cell/TimelineTableCellView.swift | 17 ++++++++++---- Shared/Extensions/IconImageView.swift | 3 +-- iOS/MainTimeline/Cell/MainTimelineCell.swift | 23 +++++++++++++------ 5 files changed, 37 insertions(+), 20 deletions(-) diff --git a/Mac/MainWindow/IconView.swift b/Mac/MainWindow/IconView.swift index f2c1e4785..c40e87faa 100644 --- a/Mac/MainWindow/IconView.swift +++ b/Mac/MainWindow/IconView.swift @@ -59,9 +59,6 @@ final class IconView: NSView { return imageView.frame.size.height < bounds.size.height } - private static var lightBackgroundColor = Assets.Colors.iconLightBackground - private static var darkBackgroundColor = Assets.Colors.iconDarkBackground - override init(frame frameRect: NSRect) { super.init(frame: frameRect) commonInit() @@ -93,9 +90,9 @@ final class IconView: NSView { guard !(iconImage?.isBackgroundSuppressed ?? false) else { return } guard hasExposedVerticalBackground || !isDiscernable else { return } - let color = NSApplication.shared.effectiveAppearance.isDarkMode ? IconView.darkBackgroundColor : IconView.lightBackgroundColor - color.set() - dirtyRect.fill() + // The fill is translucent, so it’s blended, not copied. + Assets.Colors.iconBackground.set() + dirtyRect.fill(using: .sourceOver) } } diff --git a/Mac/MainWindow/Timeline/Cell/ThumbnailView.swift b/Mac/MainWindow/Timeline/Cell/ThumbnailView.swift index 15ba8f48e..2ec7698be 100644 --- a/Mac/MainWindow/Timeline/Cell/ThumbnailView.swift +++ b/Mac/MainWindow/Timeline/Cell/ThumbnailView.swift @@ -9,7 +9,8 @@ import AppKit /// An article’s thumbnail in a timeline cell. /// -/// The whole image shows, scaled to fit, on a fill that is also the placeholder until the image arrives. +/// The whole image shows, scaled to fit. The cell sizes the view to the image, so the corner radius rounds the image itself. +/// A placeholder color shows until the image arrives. final class ThumbnailView: NSView { var image: NSImage? { @@ -50,6 +51,8 @@ final class ThumbnailView: NSView { override func updateLayer() { layer?.contents = image?.cgImage(forProposedRect: nil, context: nil, hints: nil) + // Resolved here so the placeholder follows light and dark mode. + layer?.backgroundColor = image == nil ? Assets.Colors.thumbnailPlaceholder.cgColor : nil } } diff --git a/Mac/MainWindow/Timeline/Cell/TimelineTableCellView.swift b/Mac/MainWindow/Timeline/Cell/TimelineTableCellView.swift index ae497f8dc..1788444a6 100644 --- a/Mac/MainWindow/Timeline/Cell/TimelineTableCellView.swift +++ b/Mac/MainWindow/Timeline/Cell/TimelineTableCellView.swift @@ -50,7 +50,7 @@ final class TimelineTableCellView: NSTableCellView { thumbnailView.image } set { - thumbnailView.image = newValue + setThumbnailImage(newValue) } } @@ -118,7 +118,8 @@ final class TimelineTableCellView: NSTableCellView { unreadIndicatorView.setFrameIfNotEqual(layoutRects.unreadIndicatorRect) feedNameView.setFrameIfNotEqual(layoutRects.feedNameRect) iconView.setFrameIfNotEqual(layoutRects.iconImageRect) - thumbnailView.setFrameIfNotEqual(layoutRects.thumbnailRect) + // Sized to the image, so the corner radius rounds the image itself. All of the rect until the image arrives. + thumbnailView.setFrameIfNotEqual(layoutRects.thumbnailRect.aspectFitRect(for: thumbnailView.image?.size ?? .zero)) starView.setFrameIfNotEqual(layoutRects.starRect) } } @@ -306,7 +307,7 @@ private extension TimelineTableCellView { showView(thumbnailView) needsLayout = true } - thumbnailView.image = cellData.thumbnail + setThumbnailImage(cellData.thumbnail) } func makeThumbnailEmpty() { @@ -314,7 +315,15 @@ private extension TimelineTableCellView { hideView(thumbnailView) needsLayout = true } - thumbnailView.image = nil + setThumbnailImage(nil) + } + + /// Lays out again, since the thumbnail view is sized to the image. + func setThumbnailImage(_ image: NSImage?) { + if thumbnailView.image !== image { + thumbnailView.image = image + needsLayout = true + } } func hideView(_ view: NSView) { diff --git a/Shared/Extensions/IconImageView.swift b/Shared/Extensions/IconImageView.swift index 59c7f3d3b..bb513ffc1 100644 --- a/Shared/Extensions/IconImageView.swift +++ b/Shared/Extensions/IconImageView.swift @@ -65,8 +65,7 @@ struct IconImageView: View { private var backgroundColor: Color { #if os(macOS) - let nsColor = isDarkMode ? Assets.Colors.iconDarkBackground : Assets.Colors.iconLightBackground - return Color(nsColor: nsColor) + return Color(nsColor: Assets.Colors.iconBackground) #else return Color(Assets.Colors.iconBackground) #endif diff --git a/iOS/MainTimeline/Cell/MainTimelineCell.swift b/iOS/MainTimeline/Cell/MainTimelineCell.swift index 0348f7213..1256e138a 100644 --- a/iOS/MainTimeline/Cell/MainTimelineCell.swift +++ b/iOS/MainTimeline/Cell/MainTimelineCell.swift @@ -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 }